-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·74 lines (63 loc) · 2.21 KB
/
index.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
#!/usr/bin/env node
const pkg = require('./package.json');
const { program } = require('commander');
const chalk = require('chalk');
const inquirer = require('inquirer');
const { templates } = require('./templates');
const { spawn } = require('child_process');
const challengeNames = templates
.filter((template) => template.type === 'challenge')
.map((template) => `${template.emoji} ${template.name}`);
const projectNames = templates
.filter((template) => template.type === 'project')
.map((template) => `${template.emoji} ${template.name}`)
async function main() {
console.log(`
${chalk.bold.magenta('Welcome to 🏗 create-scaffold-eth!')}
`);
program
.version(pkg.version)
.option('--https', 'use https instead of ssh')
.action((options) => {
const { https } = options;
inquirer.prompt([
{
type: 'list',
name: 'template',
message: 'Pick your template',
loop: false,
choices: [
new inquirer.Separator('---- Projects ----'),
...projectNames,
new inquirer.Separator('---- Challenges ----'),
...challengeNames,
new inquirer.Separator('---- End ----'),
]
},
{
type: 'input',
name: 'directory',
message: 'Directory name',
default: (answers) => answers.template
},
])
.then((answers) => {
const { template, directory } = answers;
console.log(chalk.greenBright(`${pkg.name}: building '${template}' into '${directory}'...`));
const { httpUrl, sshUrl, branch } = templates.find((t) => `${t.emoji} ${t.name}` === template);
const args = [];
args.push(https ? httpUrl : sshUrl);
if (branch) {
args.push(branch);
};
args.push(directory);
spawn('git', ['clone', ...args], { stdio: 'inherit' });
})
.catch((e) => {
console.error(e);
process.exit(1);
});
})
program.parse(process.argv);
}
main();