-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·107 lines (99 loc) · 2.56 KB
/
cli.js
File metadata and controls
executable file
·107 lines (99 loc) · 2.56 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env node
/**
* The main command line interface for running Angularity
* from the npm global install.
*/
'use strict';
var path = require('path'),
gulp = require('gulp'),
gutil = require('gulp-util'),
chalk = require('chalk'),
prettyTime = require('pretty-hrtime'),
yargs = require('yargs');
var taskYargsRun = require('../lib/util/task-yargs-run');
// we need to duplicate some event handlers from the gulp cli since we have bypassed it
gulp.on('task_start', function (e) {
gutil.log('Starting', '\'' + chalk.cyan(e.task) + '\'...');
});
gulp.on('task_stop', function (e) {
var time = prettyTime(e.hrDuration);
gutil.log(
'Finished', '\'' + chalk.cyan(e.task) + '\'',
'after', chalk.magenta(time)
);
});
var packageJson = require(path.join(__dirname, '..', 'package.json'));
var helpOption = {
key: 'help',
value: {
describe: 'This help message, or help on a specific task',
alias: ['h'],
boolean: true
}
};
var defaultYargsInstance = yargs
.usage([
packageJson.description,
'',
'Tasks include:',
'',
'init, webstorm, build, watch, test, release, css, javascript, html',
'',
'Examples:',
'',
'angularity -v Display the version of angularity',
'angularity <task name> -h Get help on a particular task',
'angularity <task name> Run the given task'
].join('\n'))
.option('version', {
describe: 'Display the curent version',
alias: ['v'],
boolean: true
})
.option(helpOption.key, helpOption.value);
taskYargsRun.taskYargs.register('help', {
description: 'Displays context-specific help messages',
prerequisiteTasks: [],
options: [
{
key: 'help',
value: {
describe: 'This help message, or help on a specific task',
alias: ['h'],
boolean: true
}
}
],
checks: [],
onInit: function onInitHelpTask() {
// Do nothing
},
onRun: function onRunHelpTask() {
defaultYargsInstance.showHelp();
}
});
var cliArgs;
cliArgs = defaultYargsInstance.argv;
var hasCommands = (cliArgs._.length > 0);
if (hasCommands) {
require('../index');
var taskName = taskYargsRun.taskYargs.getCurrentName();
if (taskName) {
taskYargsRun.current();
}
else {
console.log('Task specified is not recognised');
defaultYargsInstance.showHelp();
}
}
else {
if (cliArgs.version) {
console.log('angularity:', packageJson.version);
}
else {
if (!cliArgs.help) {
console.log('No task specified');
}
defaultYargsInstance.showHelp();
}
}