-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
96 lines (83 loc) · 2.45 KB
/
Copy pathindex.js
File metadata and controls
96 lines (83 loc) · 2.45 KB
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
#! /usr/bin/env node
const { spawn } = require("child_process");
const inquirer = require("inquirer");
const path = require("path");
const configFiles = ["nodejs", "nodejs-babel", "nodejs-typescript"];
const packageManager = ["npm", "yarn"];
const nodeExpressRepoURL =
"https://github.com/Jayvirrathi/node-express-api-starter.git";
const nodeExpressBabelRepoURL =
"https://github.com/Jayvirrathi/node-express-es6-api-starter.git";
const nodeExpressTypeScriptRepoURL =
"https://github.com/Jayvirrathi/node-express-typescript-api-starter.git";
let repoURL;
(async () => {
const { framework } = await inquirer.prompt([
{
type: "list",
message: "Pick the framework you're using:",
name: "framework",
choices: configFiles,
},
]);
console.log(framework);
if (framework === "nodejs") {
repoURL = nodeExpressRepoURL;
} else if (framework === "nodejs-babel") {
repoURL = nodeExpressBabelRepoURL;
} else if (framework === "nodejs-typescript") {
repoURL = nodeExpressTypeScriptRepoURL;
} else {
repoURL = nodeExpressRepoURL;
}
const { name } = await inquirer.prompt([
{
type: "input",
message: "Pick the name:",
name: "name",
validate: function (name) {
let valid = !(name == "");
return valid || `Please enter a valid name`;
},
},
]);
const { tool } = await inquirer.prompt([
{
type: "list",
choices: packageManager,
message: "Pick the package manager:",
name: "tool",
},
]);
runCommand("git", ["clone", repoURL, name])
.then(() => {
return runCommand("rm", ["-rf", `${name}/.git`]);
})
.then(() => {
console.log("Installing dependencies...");
return runCommand(tool == "yarn" ? "yarn.cmd" : "npm.cmd", ["install"], {
cwd: process.cwd() + "/" + name,
});
})
.then(() => {
console.log("Done! 🏁");
console.log("");
console.log("To get started:");
console.log("cd", name);
console.log(tool == "yarn" ? "yarn dev" : "npm run dev");
});
function runCommand(command, args, options = undefined) {
const spawned = spawn(command, args, options);
return new Promise((resolve) => {
spawned.stdout.on("data", (data) => {
console.log(data.toString());
});
spawned.stderr.on("data", (data) => {
console.error(data.toString());
});
spawned.on("close", () => {
resolve();
});
});
}
})();