feat(diffing-broccoli-plugin): support multiple inputTrees

Closes #1815
Closes #2064
This commit is contained in:
Caitlin Potter 2015-05-21 12:07:23 -04:00
parent 8a52375fb8
commit 41ae8e76f0
1 changed files with 33 additions and 8 deletions

View File

@ -28,7 +28,7 @@ export function wrapDiffingPlugin(pluginClass): DiffingPluginWrapperFactory {
export interface DiffingBroccoliPlugin { export interface DiffingBroccoliPlugin {
rebuild(diff: DiffResult): (Promise<any>| void); rebuild(diff: (DiffResult | DiffResult[])): (Promise<any>| void);
cleanup ? () : void; cleanup ? () : void;
} }
@ -38,7 +38,8 @@ type DiffingPluginWrapperFactory = (inputTrees: (BroccoliTree | BroccoliTree[]),
class DiffingPluginWrapper implements BroccoliTree { class DiffingPluginWrapper implements BroccoliTree {
treeDiffer: TreeDiffer; treeDiffer: TreeDiffer = null;
treeDiffers: TreeDiffer[] = null;
initialized = false; initialized = false;
wrappedPlugin: DiffingBroccoliPlugin = null; wrappedPlugin: DiffingBroccoliPlugin = null;
inputTree = null; inputTree = null;
@ -47,6 +48,7 @@ class DiffingPluginWrapper implements BroccoliTree {
// props monkey-patched by broccoli builder: // props monkey-patched by broccoli builder:
inputPath = null; inputPath = null;
inputPaths = null;
cachePath = null; cachePath = null;
outputPath = null; outputPath = null;
@ -61,13 +63,29 @@ class DiffingPluginWrapper implements BroccoliTree {
} }
private calculateDiff(firstRun: boolean): (DiffResult | DiffResult[]) {
if (this.treeDiffer) {
let diffResult = this.treeDiffer.diffTree();
diffResult.log(!firstRun);
return diffResult;
} else if (this.treeDiffers) {
return this.treeDiffers.map((treeDiffer) => treeDiffer.diffTree())
.map((diffResult) => {
diffResult.log(!firstRun);
return diffResult;
});
} else {
throw new Error("Missing TreeDiffer");
}
}
rebuild() { rebuild() {
try { try {
let firstRun = !this.initialized; let firstRun = !this.initialized;
this.init(); this.init();
let diffResult = this.treeDiffer.diffTree(); let diffResult = this.calculateDiff(firstRun);
diffResult.log(!firstRun);
var rebuildPromise = this.wrappedPlugin.rebuild(diffResult); var rebuildPromise = this.wrappedPlugin.rebuild(diffResult);
@ -101,11 +119,18 @@ class DiffingPluginWrapper implements BroccoliTree {
if (!this.initialized) { if (!this.initialized) {
let includeExtensions = this.pluginClass.includeExtensions || []; let includeExtensions = this.pluginClass.includeExtensions || [];
let excludeExtensions = this.pluginClass.excludeExtensions || []; let excludeExtensions = this.pluginClass.excludeExtensions || [];
let description = this.description;
this.initialized = true; this.initialized = true;
this.treeDiffer = if (this.inputPaths) {
new TreeDiffer(this.description, this.inputPath, includeExtensions, excludeExtensions); this.treeDiffers =
this.wrappedPlugin = this.inputPaths.map((inputPath) => new TreeDiffer(
new this.pluginClass(this.inputPath, this.cachePath, this.wrappedPluginArguments[1]); description, inputPath, includeExtensions, excludeExtensions));
} else if (this.inputPath) {
this.treeDiffer =
new TreeDiffer(description, this.inputPath, includeExtensions, excludeExtensions);
}
this.wrappedPlugin = new this.pluginClass(this.inputPaths || this.inputPath, this.cachePath,
this.wrappedPluginArguments[1]);
} }
} }