-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
executable file
·48 lines (36 loc) · 1000 Bytes
/
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
#!/usr/bin/env node
const cac = require("cac")
const cli = cac()
const fs = require('fs');
const replace = require('replace-in-file');
const { execSync } = require('child_process');
cli.command("<name>")
.option('-o, --open', 'Open with vscode')
.option('-i, --install', 'Install dependencies')
.action((name, options) => {
fs.mkdirSync(name)
const files = fs.readdirSync(`${__dirname}/template/`)
for(file of files) fs.copyFileSync(`${__dirname}/template/${file}`, `${name}/${file}`)
const replaceOptions = {
files: [
`${name}/index.html`,
`${name}/package.json`
],
from: /{{name}}/g,
to: name
};
try {
replace.sync(replaceOptions);
}
catch (error) {
console.error('Error occurred:', error);
}
if(options.install) {
execSync('npm i --prefix ' + name)
}
if(options.open) {
execSync('code ' + name)
}
console.log('Project successfully created!')
})
cli.parse()