forked from googlearchive/erlnmyr
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgulpfile.js
143 lines (124 loc) · 5.11 KB
/
gulpfile.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
var gulp = require('gulp');
var parseArgs = require('minimist');
var fs = require('fs');
var mocha = require('gulp-mocha');
// TODO: device and experiment are only loaded so that they can be initialized with options.
// There must be a nicer way to set options across a project.
var device = require('./core/device');
var experiment = require('./core/experiment');
var stageLoader = require('./core/stage-loader');
var fancyStages = require('./core/fancy-stages');
var stream = require('./core/stream');
var options = parseArgs(process.argv.slice(2));
device.init(options);
var tasks = {};
gulp.task('test', function() {
return gulp.src(['tests/*.js', 'tests/pipeline/*.js'], {read: false})
.pipe(mocha({
ui: 'bdd',
ignoreLeaks: true,
reporter: 'nyan'
}));
});
function buildTask(name, stageList) {
tasks[name] = stageList;
gulp.task(name, function(incb) {
var cb = function(data) { incb(); };
stageList = stageList.map(stageLoader.stageSpecificationToStage);
stageLoader.processStages(stageList, cb, function(e) { throw e; });
});
};
/*
* Some example pipelines.
*/
buildTask('html', ['JSON:' + options.file, 'HTMLWriter', 'output:result.html.html']);
buildTask('js', ['JSON:' + options.file, 'JSWriter', 'output:result.js.html']);
buildTask('stats', ['JSON:' + options.file, 'StatsWriter', 'consoleOutput']);
/*
* examples using filters
*/
buildTask('compactComputedStyle', ['JSON:' + options.file, 'StyleFilter', 'output:' + options.file + '.filter']);
buildTask('extractStyle', ['JSON:' + options.file, 'StyleMinimizationFilter', 'output:' + options.file + '.filter']);
buildTask('tokenStyles', ['JSON:' + options.file, 'StyleTokenizerFilter', 'output:' + options.file + '.filter']);
buildTask('nukeIFrame', ['JSON:' + options.file, 'NukeIFrameFilter', 'output:' + options.file + '.filter']);
/*
* example of fabrication
*/
buildTask('generate', ['JSON:' + options.file, 'SchemaBasedFabricator', 'output:' + options.file + '.gen']);
/*
* examples using device telemetry
*/
buildTask('get', ['immediate:' + options.url, 'telemetrySave', 'output:result.json']);
buildTask('perf', ['immediate:' + options.url, 'telemetryPerf', 'output:trace.json']);
buildTask('endToEnd', ['immediate:' + options.url, 'telemetrySave', 'HTMLWriter', 'simplePerfer', 'output:trace.json']);
/*
* running an experiment
*/
buildTask('runExperiment', ['file:' + options.file, 'doExperiment']);
/*
* ejs fabrication
*/
gulp.task('ejs', function(incb) {
var cb = function(data) { incb(); };
stageLoader.processStages(
[
stageLoader.stageSpecificationToStage('file:' + options.file),
stageLoader.stageSpecificationToStage('ejs:' + options.outputPrefix),
fancyStages.mapToTuples(),
fancyStages.map(stageLoader.stageSpecificationToStage('toFile'))
], cb, function(e) { throw e; });
});
/*
* TODO: Refactor stage-loader so it can load fancy stages too.
*
* example of using stages directly
*/
gulp.task('mhtml', function(incb) {
var cb = function(data) { incb(); };
stageLoader.processStages(
[
fancyStages.fileInputs(options.inputSpec),
fancyStages.map(fancyStages.tee()),
fancyStages.map(fancyStages.right(stageLoader.stageSpecificationToStage('fileToJSON'))),
fancyStages.map(fancyStages.right(stageLoader.stageSpecificationToStage('HTMLWriter'))),
fancyStages.map(fancyStages.left(fancyStages.outputName(options.inputSpec, options.outputSpec))),
fancyStages.map(stageLoader.stageSpecificationToStage('toFile'))
], cb, function(e) { throw e; });
});
function tagFilename() {
return stream.tag(function(data, tags) { return {key: 'filename', value: data} });
}
function genFilename() {
return stream.tag(function(data, tags) {
var filename = tags['filename'].replace(new RegExp(options.inputSpec), options.outputSpec);
return {key: 'filename', value: filename} });
}
gulp.task('mhtml2', function(incb) {
var cb = function(data) { incb(); };
stageLoader.processStages(
[
stream.streamedStage(fancyStages.fileInputs(options.inputSpec)),
tagFilename(),
stream.streamedStage(stageLoader.stageSpecificationToStage('fileToJSON')),
stream.streamedStage(stageLoader.stageSpecificationToStage('HTMLWriter')),
genFilename(),
stream.write()
], cb, function(e) { throw e; });
});
gulp.task('processLogs', function(incb) {
var cb = function(data) { incb(); };
stageLoader.processStages(
[
stream.streamedStage(fancyStages.fileInputs(options.inputSpec)),
stream.streamedStage(stageLoader.stage(
[
stageLoader.stageSpecificationToStage('fileToJSON'),
stageLoader.stageSpecificationToStage('traceFilter'),
stageLoader.stageSpecificationToStage('tracePIDSplitter'),
fancyStages.valueMap(stageLoader.stageSpecificationToStage('traceTree')),
fancyStages.valueMap(stageLoader.stageSpecificationToStage('tracePrettyPrint')),
])),
stream.streamedStage(fancyStages.valueMap(stageLoader.stageSpecificationToStage('consoleOutput')))
], cb, function(e) { throw e; });
});
module.exports.tasks = tasks;