Skip to content

Instantly share code, notes, and snippets.

@ryankinal
Created July 5, 2016 19:37
Show Gist options
  • Save ryankinal/154d8fb3f3d511d562c5bbaf51ca7ce2 to your computer and use it in GitHub Desktop.
Save ryankinal/154d8fb3f3d511d562c5bbaf51ca7ce2 to your computer and use it in GitHub Desktop.
Synchronous vs. Asynchronous tasks
/*
There are three main tasks I want to run one after the other (synchronously).
Some of these tasks are divided into smaller tasks which can be run concurrently.
Based on the output of gulp, it seems that this isn't quite happening,
though I may be misreading it.
Output:
[15:14:07] Using gulpfile ~\projects\colibri\common-client\gulpfile.js
[15:14:07] Starting 'lint'...
[15:14:07] Finished 'lint' after 18 ms
[15:14:07] Starting 'clean-dist'...
[15:14:07] Starting 'clean-demo'...
[15:14:07] Starting 'build-bower'...
[15:14:07] Starting 'build-common-js'...
[15:14:07] Starting 'build-common-tpl'...
[15:14:07] Finished 'clean-demo' after 82 ms
[15:14:07] Finished 'clean-dist' after 88 ms
[15:14:07] Starting 'clean'...
[15:14:07] Finished 'clean' after 5.38 μs
[15:14:08] Finished 'build-common-tpl' after 438 ms
[15:14:14] Finished 'build-common-js' after 6.41 s
[15:14:14] Finished 'build-bower' after 6.42 s
[15:14:14] Starting 'build'...
[15:14:14] Finished 'build' after 6.35 μs
[15:14:14] Starting 'default'...
[15:14:14] Finished 'default' after 9.78 μs
It looks to me like the "build" subtasks are starting before "clean" is finished. How can I prevent this?
Is my desired result even possible?
*/
var gulp = require('gulp'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
clean = require('gulp-clean'),
html2js = require('gulp-html2js'),
lint = require('gulp-jshint'),
lintConfig = require('./jshint');
gulp.task('lint', function(cb) {
gulp.src([
'base/**/*.js',
'services/**/*.js',
'widgets/**/*.js'
])
.pipe(lint(lintConfig))
.pipe(lint.reporter('default'));
cb();
});
gulp.task('clean-dist', function() {
return gulp.src('dist', {read: false, force: true})
.pipe(clean());
});
gulp.task('clean-demo', function() {
return gulp.src('demo/scripts', { read: false, force: true})
.pipe(clean());
});
gulp.task('clean', ['clean-dist', 'clean-demo'], function(cb) {
cb();
});
gulp.task('build-bower', function() {
return gulp.src([
'bower_components/angular/angular.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/angular-ui-router/release/angular-ui-router.js',
'bower_components/angular-bootstrap/ui-bootstrap.js',
'bower_components/angular-bootstrap/ui-bootstrap-tpls.js',
'bower_components/angular-local-storage/dist/angular-local-storage.js',
'bower_components/angular-sanitize/angular-sanitize.js',
'bower_components/lodash/lodash.js'
])
.pipe(concat('bower.js'))
.pipe(rename('bower.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'))
.pipe(gulp.dest('demo/scripts'));
});
gulp.task('build-common-js', function() {
return gulp.src([
'base/**/*.js',
'services/**/*.js',
'widgets/**/*.js',
'!**/*.spec.js'
])
.pipe(concat('common-client.js'))
.pipe(gulp.dest('demo/scripts'))
.pipe(rename('common-client.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
gulp.task('build-common-tpl', function() {
return gulp.src('widgets/**/*.html')
.pipe(html2js('angular.js', {
adapter: 'angular',
base: 'templates',
name: 'ColibriCommonClient'
}))
.pipe(rename('common-client-tpl.js'))
.pipe(gulp.dest('demo/scripts'))
.pipe(uglify())
.pipe(rename('common-client-tpl.min.js'))
.pipe(gulp.dest('dist'));
})
gulp.task('build', ['build-bower', 'build-common-js', 'build-common-tpl'], function(cb) {
cb();
});
gulp.task('default', ['lint', 'clean', 'build']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment