Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document gulp.start() #505

Closed
binarykitchen opened this issue Jun 6, 2014 · 16 comments
Closed

Document gulp.start() #505

binarykitchen opened this issue Jun 6, 2014 · 16 comments

Comments

@binarykitchen
Copy link

I've been searching for docu on how gulp.start() works.

I wonder if I can pass on parameters to a new gulp task through that start function?

Also, how can I start another gulp task inside a running gulp task? I mean, can I pipe gulp.start to somewhere else in the middle?

@binarykitchen
Copy link
Author

Also I wonder if I can pass on a callback to start()?

@yocontra
Copy link
Member

yocontra commented Jun 6, 2014

No you can't. I won't document gulp.start because we're removing it in the next version, see #355

@yocontra yocontra closed this as completed Jun 6, 2014
@binarykitchen
Copy link
Author

Okay, will wait for the next version. Thx.

But for now, is there a trick how I can call a gulp task inside a another running gulp task? Or pipe to there?

@yocontra
Copy link
Member

yocontra commented Jun 7, 2014

Break tasks out into functions, then reuse them in other tasks if you need to

@binarykitchen
Copy link
Author

@contra Yeah I had that in mind too but do not how to call a reusable function when I am already piping something. Can you show an example?

@yocontra
Copy link
Member

yocontra commented Jun 7, 2014

@binarykitchen Have you looked at the lazypipe module? It lets you break out operations you do in multiple tasks into a function. For example, lets say you .pipe(size()).pipe(gulp.dest('dist')).pipe(lr()) in every single task. You can change this:

gulp.task('js', function() {
  return gulp.src('js/**/*.js')
    .pipe(uglify())
    .pipe(size())
    .pipe(gulp.dest('dist'))
    .pipe(lr());
});

gulp.task('css', function() {
  return gulp.src('css/**/*.css')
    .pipe(csso())
    .pipe(size())
    .pipe(gulp.dest('dist'))
    .pipe(lr());
});

Into this:

var end = lazypipe()
  .pipe(size)
  .pipe(gulp.dest, 'dist')
  .pipe(lr);

gulp.task('js', function() {
  return gulp.src('js/**/*.js')
    .pipe(uglify())
    .pipe(end());
});

gulp.task('css', function() {
  return gulp.src('css/**/*.css')
    .pipe(csso())
    .pipe(end());
});

Does that solve the problem?

@binarykitchen
Copy link
Author

Hmmm, that's almost what I want but few things are missing. Let me explain what I need here with a real example:

function bundle(watch, cb) {
    var bundler;

    if (watch) {
        bundler = watchify(paths.browserEntry);
    } else {
        bundler = watchify.browserify(paths.browserEntry);
    }

    var rebundle = function(cb) {
        bundler
            .bundle({
                insertGlobals:  false,
                debug:          !settings.PRODUCTION // for source maps
            })

            .on('error', util.log)
            .on('log',   util.log)
            .on('end',   cb)

            // how can I call clean:js here???
            // this is the point where I want to clean 
            // the javascript directory before
            // browserify is going to write the new file

            .pipe(source(paths.browserEntry))
            .pipe(buffer()) // because the next steps do not support streams
            .pipe(uglify())
            .pipe(concat('bundle.min.js'))
            .pipe(rev())
            .pipe(gulp.dest(paths.compressedBrowser))
            .pipe(rev.manifest())
            .pipe(gulp.dest(path.join(paths.rev, 'js')));
    };

    // when not watching, just bundle once
    if (!watch) {
        rebundle(cb);
    } else {
        bundler.on('update', rebundle);
        cb();
    }
}

gulp.task('clean:js', function() {
    return gulp.src(paths.compressedBrowser, {read: false}).pipe(clean());
});

gulp.task('browserify', ['clean:js'], function(cb) {
    bundle(false, cb);
});

gulp.task('watchify', ['clean:js'], function(cb) {
    bundle(true, cb);
});

See my comment inbetween. How can I move clean:js between these lines. Lazypipe won't help here because you cannot have two different sources within lazypipes.

@yocontra
Copy link
Member

yocontra commented Jun 8, 2014

Okay so you're making a task that never ends in some cases - use the rimraf module to delete folders

@binarykitchen
Copy link
Author

@contra Yeah, it never ends due to the update event. I could use rimraf but I wonder if this can be done the "gulp" way with pipes + gulp-clean instead??

@yocontra
Copy link
Member

yocontra commented Jun 8, 2014

@binarykitchen That's not the gulp way. I highly recommend against using gulp-clean/gulp-rimraf unless you are deleting files that match a specific glob. If you need to just wipe a folder using rimraf is much cleaner and faster

@binarykitchen
Copy link
Author

Okay, I get it now. Thanks for your advice!

@moander
Copy link

moander commented Jul 14, 2015

gulp.task('build', ['clean', 'task1']);

dont work because of parallelism.. Dirty solution:

gulp.task('build', ['clean'], function() {
    gulp.start('task1');
});

What is the best practice to solve this without having task1 to depend on the clean task?

@wfayeBerman
Copy link

gulp.start() still works, is it deprecated? is there a better way to do the following if one is not using gulpfile.js?

var gulp = require('gulp');

gulp.task('testing', function() {
    console.log('test started')
});

gulp.task('default', ['testing'])

gulp.start();

@Prinzhorn
Copy link

I have the same question as @wfayeBerman . I'll explain my use case because it's an edge case (I'm good at those I guess...).

I want to use gulp from within another node process. The other node process is an express app. An example use case is when someone in the UI hits the "publish" button a POST request to the server is made. Within the request handler I want to run the gulp "publish" task which takes some data from the disk and a database and uploads it to S3. Since gulp does a great job with this task, I don't see a reason not to use gulp or to reinvent the wheel. But I understand that using gulp on something else than a development machine is not the intended use-case, but a viable one.

@basvandenheuvel
Copy link

No documentation because it's being removed from the code? Looks like it's stil there after 2 years?

@phated
Copy link
Member

phated commented Apr 22, 2016

@basvandenheuvel all work is being done in the 4.0 branch. This is not a supported API and will not be documented. Locking.

@gulpjs gulpjs locked and limited conversation to collaborators Apr 22, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants