-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·62 lines (53 loc) · 1.1 KB
/
cli.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
#!/usr/bin/env node
const fs = require('fs');
const meow = require('meow');
const chalk = require('chalk');
const initit = require('./uninitit');
const logo = chalk.hex('#d07922')('[vue-parcel]');
const log = (...args) => {
console.log(logo, ...args);
};
log.error = (...args) => {
console.log(chalk.red('[ERROR]'), ...args);
};
const template = 'edm00se/vue-parcel-starter';
const cli = meow(
`
Usage
$ npm init vue-parcel my-app-name
$ npx create-vue-parcel my-app-name
`,
{
booleanDefault: undefined,
flags: {
help: {
type: 'boolean',
alias: 'h'
},
version: {
type: 'boolean',
alias: 'v'
}
}
}
);
const [name] = cli.input;
if (!name) {
cli.showHelp(0);
}
if (!fs.existsSync(name)) {
initit({ name, template })
.then(res => {
log('created vue-parcel app');
process.exit(0);
})
.catch(err => {
log.error('failed to create vue-parcel app');
log.error(err);
process.exit(1);
});
} else {
log.error(`'${name}' already exists!`);
log.error('exiting...');
process.exit(1);
}