-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.js
68 lines (59 loc) · 1.53 KB
/
main.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
const shell = require("shelljs");
const colors = require("colors");
const store = require("data-store")("guc");
const { getAppname, check, install_npm_packages } = require("./utils/utils");
const run = async (url, options) => {
check();
const appname = getAppname(url);
if (appname === null) {
shell.echo("Please enter a valid url".red);
shell.exit(1);
}
let folder = options.folder;
if (folder !== undefined) {
if (folder === "current") {
folder = shell.pwd();
} else if (store.has(folder)) {
folder = store.get(folder);
}
}
if (folder === undefined) {
if (store.has("default")) {
folder = store.get("default");
}
}
if (folder === undefined) {
folder = shell.pwd();
}
shell.cd(folder);
shell.exec(`git clone ${url}`);
await install_npm_packages(appname);
shell.cd(appname);
const folders = shell.ls("-d", "*");
for (let i = 0; i < folders.length; i++) {
await install_npm_packages(folders[i]);
}
let ide = options.ide || store.get("ide");
if (ide) {
console.log("Opening in", ide);
if (ide === "vscode") {
shell.exec(`code .`);
} else if (ide === "atom") {
shell.exec(`atom .`);
} else if (ide === "sublime") {
shell.exec(`subl .`);
} else {
shell.echo(
"Please enter a valid editor.\n Right now we support only [vscode,atom,sublime]"
.red
);
shell.exit(1);
}
} else {
if (shell.which("code")) {
shell.exec(`code .`);
}
}
shell.exit(200);
};
module.exports = run;