diff --git a/gulpfile.js b/gulpfile.js index b47602204e..a02a1ddb40 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -13,6 +13,7 @@ var pubbuild = require('./tools/build/pubbuild'); var dartanalyzer = require('./tools/build/dartanalyzer'); var jsserve = require('./tools/build/jsserve'); var pubserve = require('./tools/build/pubserve'); +var rundartpackage = require('./tools/build/rundartpackage'); var karma = require('karma').server; var minimist = require('minimist'); @@ -166,6 +167,10 @@ var CONFIG = { }, pubspec: { src: 'modules/*/pubspec.yaml' + }, + formatDart: { + packageName: 'dart_style', + args: ['dart_style:format', '-w', 'dist/dart'] } }; @@ -310,6 +315,15 @@ gulp.task('build/pubbuild.dart', pubbuild(gulp, gulpPlugins, { command: DART_SDK.PUB })); +// ------------ +// format dart + +gulp.task('build/format.dart', rundartpackage(gulp, gulpPlugins, { + pub: DART_SDK.PUB, + packageName: CONFIG.formatDart.packageName, + args: CONFIG.formatDart.args +})); + // ------------------ // web servers gulp.task('serve.js.dev', jsserve(gulp, gulpPlugins, { @@ -430,7 +444,8 @@ gulp.task('build.dart', function() { ['build/deps.js.dart2js', 'build/transpile.dart', 'build/html.dart'], 'build/pubspec.dart', 'build/pubbuild.dart', - 'build/analyze.dart' + 'build/analyze.dart', + 'build/format.dart' ); }); diff --git a/tools/build/rundartpackage.js b/tools/build/rundartpackage.js new file mode 100644 index 0000000000..3d4b98537a --- /dev/null +++ b/tools/build/rundartpackage.js @@ -0,0 +1,44 @@ +var util = require('./util'); +var Q = require('q'); +var spawn = require('child_process').spawn; +var readline = require('readline'); + +module.exports = function(gulp, plugins, config) { + return function() { + return isInstalled().then(function(installed) { + if (!installed) { + return util.processToPromise(spawn(config.pub, + ['global', 'activate', config.packageName, '--no-executables'], { + stdio: 'inherit' + })); + } + }).then(function() { + return util.processToPromise(spawn(config.pub, ['global', 'run'].concat(config.args), { + stdio: 'inherit' + })); + }); + }; + + function isInstalled() { + var subProcess = spawn(config.pub, ['global', 'list'], { + // inherit stdin and stderr, but filter stdout + stdio: [process.stdin, 'pipe', process.stderr] + }); + var rl = readline.createInterface({ + input: subProcess.stdout, + output: process.stdout, + terminal: false + }); + var found = false; + rl.on('line', function(line) { + if (line.indexOf(config.packageName) !== -1) { + found = true; + } + console.log(line); + }); + return util.processToPromise(subProcess).then( function() { + return found; + }); + } + +};