feat(broccoli): add incremental dartfmt plugin

Closes #2211
This commit is contained in:
Caitlin Potter 2015-05-28 18:54:54 -04:00
parent d523613329
commit e5d06e479a
5 changed files with 71 additions and 17 deletions

View File

@ -210,12 +210,6 @@ gulp.task('build/pubbuild.dart', pubbuild(gulp, gulpPlugins, {
// ------------
// formatting
gulp.task('build/format.dart', function() {
return util.processToPromise(spawn(DART_SDK.DARTFMT, ['-w', CONFIG.dest.dart], {
stdio: logs.dartfmt ? 'inherit' : ['ignore', 'ignore', 'inherit']
}));
});
function doCheckFormat() {
return gulp.src(['Brocfile*.js', 'modules/**/*.ts', 'tools/**/*.ts', '!**/typings/**/*.d.ts',
// skipped due to https://github.com/angular/clang-format/issues/4
@ -433,7 +427,6 @@ gulp.task('!test.unit.js/karma-run', function(done) {
gulp.task('test.unit.dart', function (done) {
runSequence(
'build/tree.dart',
'build/format.dart',
'!test.unit.dart/karma-server',
'!test.unit.dart/karma-run',
function(error) {
@ -446,7 +439,6 @@ gulp.task('test.unit.dart', function (done) {
watch('modules/angular2/**', { ignoreInitial: true, log: watchLog }, [
'!build/tree.dart',
'build/format.dart',
'!test.unit.dart/karma-run'
]);
}
@ -597,7 +589,6 @@ gulp.task('build/packages.dart', function(done) {
'!build/pubget.angular2.dart',
'!build/change_detect.dart',
'build/pure-packages.dart',
'build/format.dart',
done);
});
@ -640,7 +631,11 @@ gulp.task('!build.tools', function() {
tsResult.js.pipe(destDir)
]).on('end', function() {
var AngularBuilder = require('./dist/tools/broccoli/angular_builder').AngularBuilder;
angularBuilder = new AngularBuilder('dist');
angularBuilder = new AngularBuilder({
outputPath: 'dist',
dartSDK: DART_SDK,
logs: logs
});
});
return mergedStream;

5
tools/broccoli/angular_builder.d.ts vendored Normal file
View File

@ -0,0 +1,5 @@
interface AngularBuilderOptions {
outputPath: string;
dartSDK?: any;
logs?: any;
}

View File

@ -7,7 +7,6 @@ var path = require('path');
var printSlowTrees = require('broccoli-slow-trees');
var Q = require('q');
/**
* BroccoliBuilder facade for all of our build pipelines.
*/
@ -16,9 +15,9 @@ export class AngularBuilder {
private browserDevBuilder: BroccoliBuilder;
private browserProdBuilder: BroccoliBuilder;
private dartBuilder: BroccoliBuilder;
private outputPath: string;
constructor(private outputPath: string) {}
constructor(public options: AngularBuilderOptions) { this.outputPath = options.outputPath; }
public rebuildBrowserDevTree(): Promise<BuildResult> {
@ -75,7 +74,12 @@ export class AngularBuilder {
private makeDartBuilder(): BroccoliBuilder {
let tree = makeDartTree(path.join(this.outputPath, 'dart'));
let options = {
outputPath: path.join(this.outputPath, 'dart'),
dartSDK: this.options.dartSDK,
logs: this.options.logs
};
let tree = makeDartTree(options);
return new broccoli.Builder(tree);
}

View File

@ -0,0 +1,47 @@
/// <reference path="../typings/node/node.d.ts" />
/// <reference path="../typings/fs-extra/fs-extra.d.ts" />
import fse = require('fs-extra');
import path = require('path');
import {wrapDiffingPlugin, DiffingBroccoliPlugin, DiffResult} from './diffing-broccoli-plugin';
var spawn = require('child_process').spawn;
function processToPromise(process) {
return new Promise(function(resolve, reject) {
process.on('close', function(code) {
if (code) {
reject(code);
} else {
resolve();
}
});
});
}
class DartFormatter implements DiffingBroccoliPlugin {
private DARTFMT: string;
private verbose: boolean;
constructor(public inputPath: string, public cachePath: string, options) {
if (!options.dartSDK) throw new Error("Missing Dart SDK");
this.DARTFMT = options.dartSDK.DARTFMT;
this.verbose = options.logs.dartfmt;
}
rebuild(treeDiff: DiffResult): Promise<any> {
let args = ['-w'];
treeDiff.changedPaths.forEach((changedFile) => {
let sourcePath = path.join(this.inputPath, changedFile);
let destPath = path.join(this.cachePath, changedFile);
if (/\.dart$/.test(changedFile)) args.push(destPath);
fse.copySync(sourcePath, destPath);
});
treeDiff.removedPaths.forEach((removedFile) => {
let destPath = path.join(this.cachePath, removedFile);
fse.removeSync(destPath);
});
return processToPromise(spawn(
this.DARTFMT, args, {stdio: this.verbose ? 'inherit' : ['ignore', 'ignore', 'inherit']}));
}
}
export default wrapDiffingPlugin(DartFormatter);

View File

@ -1,4 +1,5 @@
/// <reference path="../../typings/node/node.d.ts" />
/// <reference path="../angular_builder.d.ts" />
'use strict';
import {MultiCopy} from './../multi_copy';
@ -11,6 +12,7 @@ var renderLodashTemplate = require('broccoli-lodash');
var replace = require('broccoli-replace');
var stew = require('broccoli-stew');
import ts2dart from '../broccoli-ts2dart';
import dartfmt from '../broccoli-dartfmt';
/**
* A funnel starting at modules, including the given filters, and moving into the root.
@ -138,11 +140,12 @@ function getDocsTree() {
return mergeTrees([licenses, mdTree, docs]);
}
module.exports = function makeDartTree(destinationPath) {
var sourceTree = mergeTrees([getSourceTree(), getHtmlSourcesTree()]);
module.exports = function makeDartTree(options: AngularBuilderOptions) {
var dartSources = dartfmt(getSourceTree(), {dartSDK: options.dartSDK, logs: options.logs});
var sourceTree = mergeTrees([dartSources, getHtmlSourcesTree()]);
sourceTree = fixDartFolderLayout(sourceTree);
var dartTree = mergeTrees([sourceTree, getTemplatedPubspecsTree(), getDocsTree()]);
return destCopy(dartTree, destinationPath);
return destCopy(dartTree, options.outputPath);
};