-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
executable file
·86 lines (73 loc) · 2 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env node
const inquirer = require('inquirer');
const path = require('path');
const clear = require('clear');
const figlet = require('figlet');
const chalk = require('chalk');
const memFs = require('mem-fs');
const memFsEditor = require('mem-fs-editor');
const npm = require('npm');
const argv = require('minimist')(process.argv.slice(2));
const questions = require('./questions');
const mfsEditor = memFsEditor.create(memFs.create());
class WebComponentsCLI {
constructor() {
this.root = path.resolve(__dirname, './');
this.src = path.resolve(__dirname, './cva-boilerplate');
this.dest = ''
this.log = console.log;
}
showLogo() {
clear();
this.log(
chalk.yellow(
figlet.textSync('Create Vanilla App', {
horizontalLayout: 'default',
verticalLayout: 'default'
})
)
);
}
showInfo(message) {
this.log(chalk.blue(`[CVA CLI] Info: ${message}`));
}
showSuccess(message) {
this.log(chalk.green(`[CVA CLI] Success: ${message}`));
}
showError(message) {
this.log(chalk.red(`[CVA CLI] Error: ${message}`));
}
copyBoilerplate(projectData) {
mfsEditor.copy(
`${this.root}/gitignore`,
`${this.dest}/.gitignore`
);
mfsEditor.copyTpl(
`${this.src}`,
`${this.dest}`,
projectData
);
}
async createProject() {
const name = argv['_'][0];
this.dest = path.resolve(name);
await this.showLogo();
const anwsers = await inquirer.prompt(questions);
this.copyBoilerplate({name, ...anwsers});
mfsEditor.commit(() => {
process.chdir(this.dest);
npm.load(() => npm.commands.install([], () => {
this.showSuccess(`${name} project has been successfully created!`);
this.showInfo('To launch the application just type npm start');
}));
});
}
load() {
if (argv['_'].length > 0) {
this.createProject();
} else {
this.showError('Type the name of your application!');
}
}
}
new WebComponentsCLI().load();