|
| 1 | +class InputPipelineFile { |
| 2 | + constructor(file) { |
| 3 | + this.original = file; |
| 4 | + _.extend(this, _.omit(file, 'getContentsAsString')); |
| 5 | + } |
| 6 | + getContentsAsString() { |
| 7 | + if (!this._content) { |
| 8 | + this._content = this.original.getContentsAsString(arguments); |
| 9 | + } |
| 10 | + return this._content; |
| 11 | + } |
| 12 | + setContentAsString(content) { |
| 13 | + this._content = content; |
| 14 | + } |
| 15 | +}; |
| 16 | + |
| 17 | +Pipeline = class PipelineClass { |
| 18 | + constructor() { |
| 19 | + this.pipeline = []; |
| 20 | + } |
| 21 | + compileOneFile(_inputFiles) { |
| 22 | + inputFiles = []; |
| 23 | + for(let file of _inputFiles) { |
| 24 | + inputFiles.push(new InputPipelineFile(file)); |
| 25 | + } |
| 26 | + for(let step of this.pipeline) { |
| 27 | + if (step.compileOneFile) { |
| 28 | + step.compileOneFile(inputFiles); |
| 29 | + } |
| 30 | + } |
| 31 | + } |
| 32 | + processFilesForTarget(_inputFiles) { |
| 33 | + inputFiles = []; |
| 34 | + for(let file of _inputFiles) { |
| 35 | + inputFiles.push(new InputPipelineFile(file)); |
| 36 | + } |
| 37 | + for(let step of this.pipeline) { |
| 38 | + if (step.processFilesForTarget) { |
| 39 | + step.processFilesForTarget(inputFiles); |
| 40 | + } |
| 41 | + } |
| 42 | + } |
| 43 | + setDiskCacheDirectory(diskCache) { |
| 44 | + let step = this.pipeline[this.pipeline.length - 1]; |
| 45 | + if (step && step.setDiskCacheDirectory) { |
| 46 | + return step.setDiskCacheDirectory(diskCache); |
| 47 | + } |
| 48 | + } |
| 49 | + sourceMapSize(sm) { |
| 50 | + let step = this.pipeline[this.pipeline.length - 1]; |
| 51 | + if (step && step.sourceMapSize) { |
| 52 | + return step.sourceMapSize(sm); |
| 53 | + } |
| 54 | + } |
| 55 | + parseCompileResult(stringifiedCompileResult) { |
| 56 | + let step = this.pipeline[this.pipeline.length - 1]; |
| 57 | + if (step && step.parseCompileResult) { |
| 58 | + return step.parseCompileResult(stringifiedCompileResult); |
| 59 | + } |
| 60 | + } |
| 61 | + stringifyCompileResult(compileResult) { |
| 62 | + let step = this.pipeline[this.pipeline.length - 1]; |
| 63 | + if (step && step.stringifyCompileResult) { |
| 64 | + return step.stringifyCompileResult(compileResult); |
| 65 | + } |
| 66 | + } |
| 67 | + compileResultSize(compileResult) { |
| 68 | + let step = this.pipeline[this.pipeline.length - 1]; |
| 69 | + if (step && step.compileResultSize) { |
| 70 | + return step.compileResultSize(compileResult); |
| 71 | + } |
| 72 | + } |
| 73 | + addCompileResult(inputFile, compileResult) { |
| 74 | + for(let step of this.pipeline) { |
| 75 | + if (step.addCompileResult) { |
| 76 | + step.addCompileResult(compileResult); |
| 77 | + } |
| 78 | + } |
| 79 | + } |
| 80 | + getCacheKey(inputFile) { |
| 81 | + let step = this.pipeline[this.pipeline.length - 1]; |
| 82 | + if (step && step.getCacheKey) { |
| 83 | + return step.getCacheKey(inputFile); |
| 84 | + } |
| 85 | + } |
| 86 | + getAbsoluteImportPath(inputFile) { |
| 87 | + let step = this.pipeline[this.pipeline.length - 1]; |
| 88 | + if (step && step.getAbsoluteImportPath) { |
| 89 | + return step.getAbsoluteImportPath(inputFile); |
| 90 | + } |
| 91 | + } |
| 92 | + push(Compiler) { |
| 93 | + this.pipeline.push(new Compiler()); |
| 94 | + } |
| 95 | +}; |
0 commit comments