-
Notifications
You must be signed in to change notification settings - Fork 1
/
cli.js
73 lines (58 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
#! /usr/bin/env node
// Modules
const commander = require('commander');
const updateNotifier = require('update-notifier');
const pkg = require('./package.json');
// Classes
const pkgJson = require('./package.json');
const Starter = require('./lib/starter');
const Generator = require('./lib/generator');
const Verification = require('./lib/verification');
const logger = require('./lib/logger');
const config = {
gitDomain: 'github',
boilerplateRepo: 'Ceicom/html_boilerplate',
jsInitFolder: './dev/js',
avaibleTypes: ['page', 'template', 'less', 'webform', 'combo']
};
updateNotifier({ pkg, isGlobal: true }).notify();
function newProject(projectName) {
if (!projectName) {
logger.warn('you need to pass a project name!');
return;
}
const starter = new Starter(config);
starter.newProject(projectName);
}
function generateFiles(type, name, options) {
const verification = new Verification();
if (!verification.isProjectValid()) return;
if (!config.avaibleTypes.includes(type)) {
logger.warn('you need to pass a valid type!');
logger.info(`avaible types: ${config.avaibleTypes.join(', ')}`);
return;
}
name = name.replace(/\.\w*/g, '');
const generator = new Generator(config, {
type, options
});
generator[type](name);
}
// Version
commander.version(pkgJson.version, '-v, --version');
// Start a new project
commander.command('new <projectName>')
.alias('n')
.description('start a new project')
.action(newProject);
// Generate Things
commander.command('generate <type> <value>')
.alias('g')
.option('--filename [filename]', 'custom webform filename')
.option('--template', 'do template aside page')
.description(`generate new files, avaible types: ${config.avaibleTypes.join(', ')}`)
.action(generateFiles);
// Commands that not exist
commander.command('*')
.action(env => logger.warn(`command "${env}" not exist, use --help for avaible commands`));
commander.parse(process.argv);