Skip to content

Instantly share code, notes, and snippets.

@ahmednuaman
Created July 9, 2014 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmednuaman/8f11f288dfbf6684e94d to your computer and use it in GitHub Desktop.
Save ahmednuaman/8f11f288dfbf6684e94d to your computer and use it in GitHub Desktop.
GULP Y U NO RUN IN SERIES
var compass = require('gulp-compass'),
concat = require('gulp-concat'),
cssmin = require('gulp-cssmin'),
gulp = require('gulp'),
imagemin = require('gulp-imagemin'),
jscs = require('gulp-jscs'),
jshint = require('gulp-jshint'),
livereload = require('gulp-livereload'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
rimraf = require('rimraf'),
sha1 = require('sha1'),
uglify = require('gulp-uglify'),
distFolder,
jsFiles,
hash,
htmlFiles,
sassFiles;
hash = sha1((new Date()).getTime());
distFolder = './dist/';
jsFiles = [
'./*.js',
'./assets/js/*.js'
];
htmlFiles = [
'./*.html'
];
sassFiles = [
'./assets/sass/styles.sass'
];
gulp.task('clean', function (done) {
rimraf(distFolder, done);
});
gulp.task('compass', function () {
gulp.src(sassFiles)
.pipe(compass({
css: 'assets/css',
sass: 'assets/sass',
image: 'assets/images'
}))
.pipe(gulp.dest('assets/css'));
});
gulp.task('lint', function () {
gulp.src(jsFiles)
.pipe(jshint())
.pipe(jscs());
});
gulp.task('move', function () {
gulp.src('api/**/*')
.pipe(gulp.dest(distFolder + 'api'));
gulp.src('index.html')
.pipe(replace('app.js', hash + '.js'))
.pipe(replace('styles.css', hash + '.css'))
.pipe(
replace(
'assets/vendor/bootstrap/dist/css/bootstrap.css',
'//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'
)
)
.pipe(
replace(
'assets/vendor/bootstrap/dist/js/bootstrap.min.js',
'//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js'
)
)
.pipe(
replace(
'assets/vendor/jquery/dist/jquery.min.js',
'//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'
)
)
.pipe(gulp.dest(distFolder));
});
gulp.task('minify', function () {
gulp.src('assets/css/*.css')
.pipe(concat('styles.css'))
.pipe(cssmin())
.pipe(rename(hash + '.css'))
.pipe(gulp.dest(distFolder + 'assets/css'));
gulp.src('assets/img/*.{png,gif,jpg}')
.pipe(imagemin())
.pipe(gulp.dest(distFolder + 'assets/img'));
gulp.src('assets/js/*.js')
.pipe(concat('app.js'))
.pipe(uglify())
.pipe(rename(hash + '.js'))
.pipe(gulp.dest(distFolder + 'assets/js'));
});
gulp.task('watch', function () {
livereload.listen();
gulp.watch([
htmlFiles,
jsFiles,
'assets/css/*.css'
])
.on('change', livereload.changed);
gulp.watch(jsFiles, [
'lint'
]);
gulp.watch(sassFiles, [
'compass'
]);
});
gulp.task('default', [
'watch'
]);
gulp.task('build', [
'clean',
'compass',
'lint',
'minify',
'move'
]);
@ahmednuaman
Copy link
Author

sigh

[19:29:43] Using gulpfile ~/Sites/xxx/gulpfile.js
[19:29:43] Starting 'clean'...
[19:29:43] Starting 'compass'...
[19:29:43] Finished 'compass' after 11 ms
[19:29:43] Starting 'lint'...
[19:29:44] Finished 'lint' after 114 ms
[19:29:44] Starting 'minify'...
[19:29:44] Finished 'minify' after 14 ms
[19:29:44] Starting 'move'...
[19:29:44] Finished 'move' after 5.08 ms
[19:29:44] Finished 'clean' after 155 ms
[19:29:44] Starting 'build'...
[19:29:44] Finished 'build' after 12 μs
[19:29:44] gulp-imagemin: Minified 0 images (saved 0 B - 0%)
unchanged assets/sass/styles.sass

@davej
Copy link

davej commented Jul 9, 2014

Probably best not to use gulp.start but here's a quick fix:

gulp.task('build', ['clean'], function() {
    return gulp.start('compass', 'lint', 'minify', 'move');
});

@ahmednuaman
Copy link
Author

Hmmm, gulpjs/gulp#426 (comment)

I was looking for something like gulp.start, but in the end I just use run-sequence instead. It does what I want, just slightly annoyed that there's no way to specify directly in gulp whether tasks should be concurrent or series, whereas you can in Grunt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment