-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
55 lines (46 loc) · 1.59 KB
/
setup.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
const fs = require("fs");
const path = require("path");
const childProcess = require("child_process");
const readline = require("readline");
const os = require("os");
const pkg = require("./package.json");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
const answers = {};
const ask = (question, key, defaultAnswer) =>
new Promise(resolve => {
const defaults = defaultAnswer || pkg[key];
rl.question(`${question} (default: ${defaults})\n`, answer => {
answers[key] = answer || defaults;
resolve();
});
});
const defaultName = path.basename(__dirname);
ask("What is your project name?", "name", path.basename(__dirname))
.then(() => ask("What is description?", "description", answers.name))
.then(() =>
ask("What is repository?", "repository", `cantonjs/${answers.name}`)
)
.then(() => ask("Who is the author?", "author"))
.then(() => {
rl.close();
console.log(JSON.stringify(answers, null, 2));
Object.assign(pkg, answers);
const pkgFile = path.resolve(__dirname, "package.json");
const newPkg = JSON.stringify(pkg, null, 2);
// console.log('\npackage.json:\n', newPkg);
fs.writeFileSync(pkgFile, newPkg, "utf8");
const isWindows = /^win32/.test(os.platform());
const rimrafCommand = isWindows ? "rd /s /q" : "rm -rf";
const gitDir = path.resolve(__dirname, ".git");
// console.log(`${rimrafCommand} ${gitDir}`);
childProcess.exec(`${rimrafCommand} ${gitDir}`);
console.log("Success.\n");
console.log("To install dependencies, please run `yarn` manually.\n");
fs.unlinkSync(__filename);
})
.catch(err => {
throw err;
});