How to make gulp-git pause until the git command finishes? -
i've been tearing hair out on 2 hours.
here simplified gulpfile:
var gulp = require('gulp'); var concat = require("gulp-concat"); var rename = require("gulp-rename"); var run_sequence = require("run-sequence"); var del = require("del"); var git = require("gulp-git"); var wait = require("gulp-wait"); var dest = 'build/'; var vendor_javascript_files = [ 'node_modules/jquery/dist/jquery.js', ]; var app_javascript_files = [ 'app.js', ]; // remove existing build directory gulp.task("prepare",function() { return del([dest, "branding_assets/"]); }); gulp.task("get-branding", function() { return git.clone('http://gitserver.local/prod-branding.git', {args: './branding_assets'}, function (err) { if (err) { throw err; } }); }); gulp.task("get-dev-branding", function() { return git.clone('http://gitserver.local/dev-branding.git', {args: './branding_assets'}, function (err) { if (err) { throw err; } }); }); gulp.task('vendor-js', function() { return gulp.src(vendor_javascript_files) .pipe(concat("vendor.js")) .pipe(gulp.dest(dest+"app")); }); gulp.task('app-files', function() { return gulp.src(['app.js']) .pipe(gulp.dest(dest+"app")); }); gulp.task('branding', function() { return gulp.src('branding_assets/*') .pipe(wait(2000)) .pipe(gulp.dest(dest+"assets")) }); gulp.task('app-js', function() { return gulp.src("index.html.dist") .pipe(rename("index.html")) .pipe(gulp.dest(dest)); }); gulp.task('build', function() { run_sequence( "prepare", "get-branding", [ "app-files", "app-js", "vendor-js", // imagine there many more tasks here - "app-css", "vendor-css", "app-sass", etc. upwards of 10 tasks. "branding", ], ); }); gulp.task('build-dev', function() { run_sequence( "prepare", "get-dev-branding", [ "app-files", "app-js", "vendor-js", // imagine there many more tasks here - "app-css", "vendor-css", "app-sass", etc. upwards of 10 tasks. "branding", ], ); }); gulp.task('default', ['build']);
what trying is, during gulp task, pull in assets respective project version , use them in build process.
the problem gulp.clone
task returns immediately, before clone has completed. thus, branding
task nothing since files don't yet exist when starts.
i tried using .wait(2000)
pause branding task, 1) doesn't work (it still finishes branding task in tens of ms) , 2) wouldn't work if pause did occur because source files selected @ time src
function runs, right?
maybe gulp
isn't appropriate task runner task, have no choice - production environment uses gulp.
using get-branding
task dependency on each of individual build tasks (e.g. "app-files") won't work since want run get-dev-branding
instead. tried doing "nesting" strategy of moving individual app build tasks separate tasks get-branding
dependency , still did not work - since git.clone
task returns before clone has finished, doesn't work.
i can't find would, say, "wait until file exists". can't find reliably pause gulp task before starts enumerating source files. i'm going in circles on google hitting same pages on , on no solution.
you should add callback function, can pass callback status of command gulp.
gulp.task("get-branding", function(done) { git.clone('http://gitserver.local/prod-branding.git', {args: './branding_assets'}, function (err) { if (err) { done(err); } done(); }); });
for more information how done callback function works internally, can see: gulp: gulp task callback function defined?
the callback function comes orchestrator (or new 1 -- undertaker -- in gulp 4) , nothing more call tell task system task "done". that's why changed to
gulp.task('something', function(done) { ... });
in upcoming docs make point clearer.
Comments
Post a Comment