Skip to content

Commit e5224d2

Browse files
committed
chore(build): make watch faster / only build what is needed
1 parent 88aac42 commit e5224d2

2 files changed

Lines changed: 32 additions & 31 deletions

File tree

gulpfile.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ var ejs = require('gulp-ejs');
1111
var path = require('path');
1212

1313
// import js2dart and traceur build tasks
14-
require('./tools/js2dart/gulpfile').install(gulp);
14+
var js2dartTasks = require('./tools/js2dart/gulp-tasks');
15+
js2dartTasks.install(gulp);
1516

1617
var traceurJsOptions = {
1718
annotations: true, // parse annotations
@@ -20,8 +21,7 @@ var traceurJsOptions = {
2021
modules: 'register',
2122
typeAssertionModule: 'assert',
2223
typeAssertions: true,
23-
moduleName: true,
24-
reload: true
24+
moduleName: true
2525
};
2626

2727
var traceur = require('./tools/js2dart/gulp-traceur');
@@ -58,24 +58,18 @@ gulp.task('modules/clean', function() {
5858
.pipe(clean());
5959
});
6060

61-
function removeSrc(path) {
62-
//path.dirname = path.dirname.replace('/src', '');
63-
}
64-
6561
function createModuleTask(sourceTypeConfig, isWatch) {
6662
var start = isWatch ? watch : gulp.src.bind(gulp);
6763
return function(done) {
6864
var transpile = start(sourceTypeConfig.transpileSrc)
6965
.pipe(rename({extname: '.'+sourceTypeConfig.outputExt}))
70-
.pipe(rename(removeSrc))
7166
.pipe(sourceTypeConfig.compiler())
7267
.pipe(gulp.dest(sourceTypeConfig.outputDir));
7368
var copy = start(sourceTypeConfig.copySrc)
74-
.pipe(rename(removeSrc))
7569
.pipe(gulp.dest(sourceTypeConfig.outputDir));
7670
// TODO: provide the list of files to the template
71+
// automatically!
7772
var html = start(sourceTypeConfig.htmlSrc)
78-
.pipe(rename(removeSrc))
7973
.pipe(ejs({
8074
type: sourceTypeConfig.outputExt
8175
}))
@@ -86,9 +80,7 @@ function createModuleTask(sourceTypeConfig, isWatch) {
8680
}
8781

8882
gulp.task('modules/build.dart', createModuleTask(sourceTypeConfigs.dart, false));
89-
gulp.task('modules/watch.dart', createModuleTask(sourceTypeConfigs.dart, true));
9083
gulp.task('modules/build.js', createModuleTask(sourceTypeConfigs.js, false));
91-
gulp.task('modules/watch.js', createModuleTask(sourceTypeConfigs.js, true));
9284

9385
// ------------------
9486
// WEB SERVER
@@ -111,27 +103,36 @@ gulp.task('serve', connect.server({
111103
// general targets
112104

113105
gulp.task('clean', function(done) {
114-
return runSequence(['traceur/clean', 'modules/clean'], done);
106+
return runSequence(['traceur/clean', 'js2dart/clean', 'modules/clean'], done);
115107
});
116108

117-
gulp.task('build', function(done) {
118-
// By using runSequence here we are decoupling the cleaning from the rest of the build tasks
119-
// Otherwise, we have to add clean as a dependency on every task to ensure that it completes
120-
// before they begin.
121-
runSequence(
122-
'js2dart/build',
123-
['modules/build.dart', 'modules/build.js'],
124-
done
109+
gulp.task('build', function() {
110+
return runSequence(
111+
// sequential
112+
'traceur/build', 'js2dart/build',
113+
// parallel
114+
['modules/build.dart', 'modules/build.js']
125115
);
126116
});
127117

128-
gulp.task('watch', function(done) {
129-
// By using runSequence here we are decoupling the cleaning from the rest of the build tasks
130-
// Otherwise, we have to add clean as a dependency on every task to ensure that it completes
131-
// before they begin.
132-
runSequence(
133-
'build',
134-
['js2dart/watch', 'modules/watch.dart', 'modules/watch.js'],
135-
done
136-
);
118+
gulp.task('watch', function() {
119+
var traceurWatch = watch(js2dartTasks.paths.traceurSrc, function(_, done) {
120+
runSequence(
121+
// sequential
122+
'traceur/build', 'js2dart/build', 'js2dart/test',
123+
// parallel
124+
['modules/build.dart', 'modules/build.js'],
125+
done);
126+
});
127+
var js2dartWatch = watch(js2dartTasks.paths.js2dartSrc, function(_, done) {
128+
runSequence(
129+
// sequential
130+
'js2dart/build', 'js2dart/test',
131+
// parallel
132+
['modules/build.dart', 'modules/build.js'],
133+
done);
134+
});
135+
var dartModuleWatch = createModuleTask(sourceTypeConfigs.dart, true)();
136+
var jsModuleWatch = createModuleTask(sourceTypeConfigs.js, true)();
137+
return mergeStreams(traceurWatch, js2dartWatch, dartModuleWatch, jsModuleWatch);
137138
});

tools/js2dart

0 commit comments

Comments
 (0)