-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.js
96 lines (95 loc) · 2.66 KB
/
pipeline.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
class InputPipelineFile {
constructor(file) {
this.original = file;
_.extend(this, _.omit(file, 'getContentsAsString'));
}
getContentsAsString() {
if (!this._content) {
this._content = this.original.getContentsAsString(arguments);
}
return this._content;
}
setContentAsString(content) {
this._content = content;
}
};
Pipeline = class PipelineClass {
constructor() {
this.pipeline = [];
}
compileOneFile(_inputFiles) {
inputFiles = [];
for(let file of _inputFiles) {
inputFiles.push(new InputPipelineFile(file));
}
for(let step of this.pipeline) {
if (step.compileOneFile) {
step.compileOneFile(inputFiles);
}
}
}
processFilesForTarget(_inputFiles) {
inputFiles = [];
for(let file of _inputFiles) {
inputFiles.push(new InputPipelineFile(file));
}
for(let step of this.pipeline) {
if (step.compiler.processFilesForTarget) {
step.compiler.processFilesForTarget(inputFiles);
}
}
}
setDiskCacheDirectory(diskCache) {
let step = this.pipeline[this.pipeline.length - 1];
if (step && step.setDiskCacheDirectory) {
return step.setDiskCacheDirectory(diskCache);
}
}
sourceMapSize(sm) {
let step = this.pipeline[this.pipeline.length - 1];
if (step && step.sourceMapSize) {
return step.sourceMapSize(sm);
}
}
parseCompileResult(stringifiedCompileResult) {
let step = this.pipeline[this.pipeline.length - 1];
if (step && step.parseCompileResult) {
return step.parseCompileResult(stringifiedCompileResult);
}
}
stringifyCompileResult(compileResult) {
let step = this.pipeline[this.pipeline.length - 1];
if (step && step.stringifyCompileResult) {
return step.stringifyCompileResult(compileResult);
}
}
compileResultSize(compileResult) {
let step = this.pipeline[this.pipeline.length - 1];
if (step && step.compileResultSize) {
return step.compileResultSize(compileResult);
}
}
addCompileResult(inputFile, compileResult) {
for(let step of this.pipeline) {
if (step.addCompileResult) {
step.addCompileResult(compileResult);
}
}
}
getCacheKey(inputFile) {
let step = this.pipeline[this.pipeline.length - 1];
if (step && step.getCacheKey) {
return step.getCacheKey(inputFile);
}
}
getAbsoluteImportPath(inputFile) {
let step = this.pipeline[this.pipeline.length - 1];
if (step && step.getAbsoluteImportPath) {
return step.getAbsoluteImportPath(inputFile);
}
}
add(weight, compiler) {
this.pipeline.push({weight: weight, compiler: compiler});
this.pipeline = _.sortBy(this.pipeline, 'weight');
}
};