-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsphinx.js
106 lines (93 loc) · 2.83 KB
/
sphinx.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
'use strict';
var argv = require('./src/cli.js');
var pkg = require('./package.json');
var Liftoff = require('liftoff');
var gutil = require('gulp-util');
var gulp = require('gulp');
var chalk = gutil.colors;
var prettyTime = require('pretty-hrtime');
var tasks = argv._;
var cli = new Liftoff({
name: 'sphinx',
configName: 'sphinx-conf',
extensions: {
'.js': null,
'.json': null
}
});
cli.launch({
cwd: argv.cwd || process.cwd(),
configPath: argv.sphinxconf
}, invoke);
function invoke(env) {
var version = [];
if (argv.version && tasks.length === 0) {
console.log('\n\r v' + pkg.version + '\n');
version.push('\t┏┛ ┻━━━━━┛ ┻┓');
version.push('\t┃ ┃');
version.push('\t┃ ━ ┃');
version.push('\t┃ ┳┛ ┗┳ ┃');
version.push('\t┃ ┃');
version.push('\t┃ ┻ ┃');
version.push('\t┗━┓ ┏━━━━┛');
version.push('\t ┃ ┃');
version.push('\t ┃ ┗━━━━━━━━┓');
version.push('\t ┃ ┣┓');
version.push('\t ┃ ┏┛');
version.push('\t ┗━┓ ┓ ┏━┳ ┓ ┏━┛');
version.push('\t ┃ ┫ ┫ ┃ ┫ ┫');
version.push('\t ┗━┻━┛ ┗━┻━┛\n\r');
console.log(chalk.yellow(version.join('\n')));
process.exit(0);
}
if (tasks.length === 0) {
tasks = ['release'];
}
// 加载配置文件
require('./index')(argv, env);
gulp.on('start', function (e) {
gutil.log('Starting', '\'' + chalk.cyan(e.name) + '\'...');
});
gulp.on('stop', function (e) {
var time = prettyTime(e.duration);
gutil.log(
'Finished', '\'' + chalk.cyan(e.name) + '\'',
'after', chalk.magenta(time)
);
});
gulp.on('error', function (e) {
var msg = formatError(e);
var time = prettyTime(e.duration);
gutil.log(
'\'' + chalk.cyan(e.name) + '\'',
chalk.red('errored after'),
chalk.magenta(time)
);
gutil.log(msg || e.error.stack);
});
process.nextTick(function () {
try {
gulp.parallel(tasks)(function (err) {
if (err) {
process.exit(1);
}
});
} catch (e) {
};
});
}
function formatError(e) {
if (!e.error) {
return e.message;
}
// PluginError
if (typeof e.error.showStack === 'boolean') {
return e.error.toString();
}
// Normal error
if (e.error.stack) {
return e.error.stack;
}
// Unknown (string, number, etc.)
return new Error(String(e.error)).stack;
}