chore(build): use a Filter plugin to write the dest folder.

This lets broccoli keep the dest folder up-to-date in 'watch' mode,
so we should be able to use that for Karma.
This commit is contained in:
Alex Eagle 2015-04-13 09:52:02 -07:00
parent 3667854a8f
commit 70433e6b73
5 changed files with 62 additions and 26 deletions

View File

@ -43,6 +43,7 @@
"angular": "1.3.5",
"bower": "^1.3.12",
"broccoli": "^0.15.3",
"broccoli-filter": "^0.1.12",
"broccoli-flatten": "^0.1.1",
"broccoli-funnel": "igorminar/broccoli-funnel#perf-files",
"broccoli-lodash": "^0.1.1",
@ -52,7 +53,6 @@
"broccoli-stew": "^0.2.1",
"broccoli-writer": "^0.1.1",
"canonical-path": "0.0.2",
"copy-dereference": "^1.0.0",
"css": "mlaval/css#issue65",
"del": "~1",
"dgeni": "^0.4.1",
@ -95,8 +95,8 @@
"temp": "^0.8.1",
"ternary-stream": "^1.2.3",
"through2": "^0.6.1",
"typescript": "alexeagle/TypeScript#93dbbe2a2d0b42cefd02ac949e4bc8ab6b5b5823",
"ts2dart": "^0.3.0",
"typescript": "alexeagle/TypeScript#93dbbe2a2d0b42cefd02ac949e4bc8ab6b5b5823",
"vinyl": "^0.4.6",
"walk-sync": "^0.1.3",
"xtend": "^4.0.0",

View File

@ -0,0 +1,33 @@
/// <reference path="./broccoli-filter.d.ts" />
/// <reference path="../typings/node/node.d.ts" />
/// <reference path="../typings/fs-extra/fs-extra.d.ts" />
import Filter = require('broccoli-filter');
import fse = require('fs-extra');
import path = require('path');
/**
* Intercepts each file as it is copied to the destination tempdir,
* and tees a copy to the given path outside the tmp dir.
*/
class DestCopy extends Filter {
constructor(private inputTree, private outputRoot: string) { super(inputTree); }
getDestFilePath(relativePath: string): string { return relativePath; }
processString(content: string, relativePath: string): string { return content; }
processFile(srcDir, destDir, relativePath): Promise<any> {
return super.processFile(srcDir, destDir, relativePath)
.then(x => {
var destFile = path.join(this.outputRoot, this.getDestFilePath(relativePath));
var dir = path.dirname(destFile);
fse.mkdirsSync(dir);
fse.copySync(path.join(srcDir, relativePath), destFile);
});
}
}
export = function destCopy(inputTree, outputRoot) {
return new DestCopy(inputTree, outputRoot);
}

11
tools/broccoli/broccoli-filter.d.ts vendored Normal file
View File

@ -0,0 +1,11 @@
/// <reference path="../typings/es6-promise/es6-promise.d.ts" />
declare class Filter {
constructor(inputTree: any);
processString(contents: string, relativePath: string): string;
// NB: This function is probably not intended as part of the public API
processFile(srcDir: string, destDir: string, relativePath: string): Promise<any>;
}
export = Filter;

View File

@ -1,5 +1,5 @@
var broccoli = require('broccoli');
var copyDereferenceSync = require('copy-dereference').sync;
var destCopy = require('../broccoli-dest-copy');
var fse = require('fs-extra');
var path = require('path');
var printSlowTrees = require('broccoli-slow-trees');
@ -26,31 +26,23 @@ function broccoliBuild(tree, outputRoot) {
// We do a clean build every time to avoid stale outputs.
// Broccoli's cache folders allow it to remain incremental without reading this dir.
fse.removeSync(distPath);
fse.mkdirsSync(path.join(distPath, '..'));
tree = destCopy(tree, 'dist');
var builder = new broccoli.Builder(tree);
return builder.build()
.then(function(hash) {
console.log('=== Stats for %s (total: %ds) ===', outputRoot,
Math.round(hash.totalTime / 1000000) / 1000);
printSlowTrees(hash.graph);
var dir = hash.directory;
try {
time('Write build output', function() {
copyDereferenceSync(path.join(dir, outputRoot), distPath);
});
} catch (err) {
if (err.code === 'EEXIST') err.message += ' (we cannot build into an existing directory)';
throw err;
}
})
.finally(function() {
time('Build cleanup', function() { builder.cleanup(); });
console.log('=== Done building %s ===', outputRoot);
})
.catch(function(err) {
.then(hash =>
{
console.log('=== Stats for %s (total: %ds) ===', outputRoot,
Math.round(hash.totalTime / 1000000) / 1000);
printSlowTrees(hash.graph);
})
.finally(() =>
{
time('Build cleanup', () => builder.cleanup());
console.log('=== Done building %s ===', outputRoot);
})
.catch(err => {
// Should show file and line/col if present
if (err.file) {
console.error('File: ' + err.file);

View File

@ -37,7 +37,7 @@ class TraceurFilter extends Writer {
// TODO: we should fix the sourceMappingURL written by Traceur instead of overriding
// (but we might switch to typescript first)
var mapFilepath = filepath.replace(/\.\w+$/, '') + this.destSourceMapExtension;
result.js = result.js + '\n //# sourceMappingURL=./' + path.basename(mapFilepath);
result.js = result.js + '\n//# sourceMappingURL=./' + path.basename(mapFilepath);
var destFilepath = filepath.replace(/\.\w+$/, this.destExtension);
var destFile = path.join(destDir, destFilepath);