-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
101 lines (68 loc) · 2.35 KB
/
index.js
File metadata and controls
101 lines (68 loc) · 2.35 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
const NO_STEP_NAME_ERROR_MSG = 'No step name was specified in a gulp.step call! A step name is required.';
const NOT_FOUND_INDEX = -1;
const GulpStepPlugin = {
gulp: null,
gulpFunctions: {},
steps: {},
stepsAsTasks: false,
_addStepsToArgs (args) {
return args.map(arg => {
if (typeof arg !== 'string')
return arg;
const isGulpTask = !!GulpStepPlugin.gulp.registry().get(arg);
if (isGulpTask || !GulpStepPlugin.steps[arg])
return arg;
return GulpStepPlugin.steps[arg];
});
},
install (gulp, opts) {
if (!gulp)
gulp = require('gulp');
if (!opts)
opts = {};
GulpStepPlugin.gulp = gulp;
GulpStepPlugin.gulpFunctions = {
series: gulp.series,
parallel: gulp.parallel
};
GulpStepPlugin.stepsAsTasks = 'stepsAsTasks' in opts
? opts.stepsAsTasks
: process.argv.indexOf('--steps-as-tasks') > NOT_FOUND_INDEX;
gulp.step = GulpStepPlugin.step;
if (!GulpStepPlugin.stepsAsTasks) {
gulp.series = GulpStepPlugin.series;
gulp.parallel = GulpStepPlugin.parallel;
}
},
uninstall () {
const { gulp } = GulpStepPlugin;
if (!gulp)
return;
delete gulp.step;
gulp.series = GulpStepPlugin.gulpFunctions.series;
gulp.parallel = GulpStepPlugin.gulpFunctions.parallel;
this.gulp = null;
this.gulpFunctions = {};
GulpStepPlugin.stepsAsTasks = false;
},
step (...args) {
if (GulpStepPlugin.stepsAsTasks)
return GulpStepPlugin.gulp.task(...args);
const [name, fn] = args;
if (!name)
throw new Error(NO_STEP_NAME_ERROR_MSG);
if (!fn)
return GulpStepPlugin.steps[name];
GulpStepPlugin.steps[name] = fn;
fn.displayName = name;
},
series (...args) {
args = GulpStepPlugin._addStepsToArgs(args);
return GulpStepPlugin.gulpFunctions.series.apply(GulpStepPlugin.gulp, args);
},
parallel (...args) {
args = GulpStepPlugin._addStepsToArgs(args);
return GulpStepPlugin.gulpFunctions.parallel.apply(GulpStepPlugin.gulp, args);
}
};
module.exports = GulpStepPlugin;