-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·57 lines (51 loc) · 1.75 KB
/
cli.js
File metadata and controls
executable file
·57 lines (51 loc) · 1.75 KB
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
#!/usr/bin/env node
/**
* @file
* The definition of the CLI for the application
*
*/
'use strict';
var program = require('commander');
var chalk = require('chalk');
var rqt = require('./rqt');
var batchInsert = require('./batch-insert');
program
.version('1.0.1')
.arguments('<file> [otherFiles...]')
.action(function (file, otherFiles) {
if (program.batch) {
batchInsert(program.esversion, program.type, file, _logResults);
if (otherFiles) {
otherFiles.forEach(function (path) {
batchInsert(program.esversion, program.type, path, _logResults);
});
}
}
else {
rqt.createComponent(program.esversion, program.type, file, _logResults);
if (otherFiles) {
otherFiles.forEach(function (path) {
rqt.createComponent(program.esversion, program.type, path, _logResults);
});
}
}
})
.option('-t --type <type>',
'Container (c) or presentation (p) components', /^(c|p)$/i, 'c')
.option('-e --esversion <esversion>', 'ES5 (es5) or ES6 (es6) style components', /^(es5|es6)$/i, 'es6')
.option('-b --batch', 'Create components from a text file with a list of components', false);
program.parse(process.argv);
/**
* The callback function used to tell the user the results after writing the file
* @param {String} error - Error message if there is an error
* @param {String} filePath - Path to the file which should have been written
* @param {String} componentName - Name of the component which should have been created
*/
function _logResults(error, filePath, componentName) {
if (error === null) {
console.log(chalk.green('Successfully created component ' + componentName + ' at ' + filePath + '!'));
}
else {
console.log(chalk.red('Error creating the component ' + componentName + ' at ' + filePath + '. ' + error));
}
}