This repository has been archived by the owner on Aug 7, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
109 lines (95 loc) · 3.33 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env node
const program = require('commander');
const colors = require('colors');
const cmd = require('node-cmd');
const sudo = require('sudo-prompt');
let make_gray = (txt) => {
return colors.gray(txt); //display the help text in red on the console
}
let runner = (dir, c) => {
if (!dir._args) {
reactAppCreator(dir, c);
}
}
let reactAppCreator = (dir, c) => {
console.log("path of rp-app:", c.parent.rawArgs[1]);
let superx = "";
if(process.platform.toLowerCase() !== "win32"){
superx = "sudo ";
const options = {
name: 'RP APP CLI',
};
sudo.exec('pwd', options,
(error, stdout, stderr) => {
if (error) throw error;
core(superx, dir);
}
);
}
else{
core(superx, dir);
}
}
let core = (superx, dir) => {
console.log(colors.green("\n[rp-app-cli] is running..."));
console.log(colors.gray("Creating directory \`" + dir + "\` And Initializing"));
console.log(colors.gray("Please wait\nIt might take several minutes!"));
const printer = setInterval(() => {
process.stdout.write(colors.grey("-"));
}, 150);
const cmnd1 = `mkdir ${dir} && cd ./${dir} && ${superx}npm install rp-app-core --no-save --prefix ./ && cp -rf ./node_modules/rp-app-core/. ./ && ${superx} rm -rf ./node_modules/rp-app-core`;
cmd.get(
cmnd1, (err, data, stderr) => {
clearInterval(printer);
console.log("");
if (err) {
console.log(colors.red(err));
return;
} else if (stderr) {
// console.log(colors.yellow(stderr));
}
let odd = true;
const printer2 = setInterval(() => {
process.stdout.write(colors.bold.gray(odd?"<":">"));
odd = !odd;
}, 700);
cmd.get(`cd ${dir} && ${superx}npm install`, (err, data, stderr) => {
clearInterval(printer2);
if (err) {
console.log(colors.red(err));
return;
} else if (stderr) {
// console.log(colors.yellow(stderr));
}
const _done =
`
-------------------------------------
- ___ ___ _ _ ____ __ -
- | \\ | | | \\ | | | | -
- | | | | | \\ | |___ | | -
- | | | | | \\ | | \\ / -
- |___/ |___| |_ \\| |____ \\/ -
- () -
-------------------------------------
`
console.log("");
console.log(data);
console.log(colors.grey(_done));
console.log(colors.cyan("\n|Successfully created|\n\n")+"To run, type the commands below:\n");
console.log(colors.magenta("cd " + dir));
console.log("");
console.log(colors.magenta(superx+"npm start") + " or " + colors.magenta(superx+"yarn start"));
console.log("");
})
}
);
}
program
.version('0.0.1')
.command('create <dir_name>')
.description('creates a directory with the given name and initializes the react-php app')
.action(runner);
if (!process.argv.slice(2).length) {
program.outputHelp(make_gray);
}
program.parse(process.argv); // end with parse to parse through the input