Code Monkey home page Code Monkey logo

Comments (11)

greypants avatar greypants commented on July 19, 2024

This makes a lot of sense. And thanks for var tasks = fs.readdirSync('./gulp/tasks/');! I knew there was a way to do that, but I'm new to Node, and hadn't taken the time to figure that out. I'll play with this over the weekend.

from blendid.

greypants avatar greypants commented on July 19, 2024

Actually... I think I've been down this road already. I think that in order to add dependencies to a task, those tasks have to already exist. I'll double check, but I think this is true. If we're just looping through a bunch of files, there's no way to ensure that the tasks that open.js depend on have already been created by the loop.

That's why in gulpfile.js I'm creating my batch tasks (build and default) separately, once all the tasks they depend on have been created.

So the solution would be to change the task callback above into it's own dependency3 task, and move the 'open' task creation to gulpfile.js

// tasks/dependency3.js
var gulp = require('gulp');
var open = require("gulp-open");

gulp.task('dependency3', function() {

    var options = {
        url: "http://localhost:8080",
        app: "google chrome"
    };

    return gulp.src("./index.html").pipe(open("", options));
};
// gulpfile.js
...
gulp.task('open', ['dependency1', 'dependency2', 'dependency3']);

Definitely adding fs.readdirSync though!

from blendid.

elcontraption avatar elcontraption commented on July 19, 2024

Cool. I'm not sure if task definition order matters–definitely worth looking up. I'll post here if I figure anything out. Thanks for a great resource!

from blendid.

p3drosola avatar p3drosola commented on July 19, 2024

I'm just running dependencies using run-sequence. It has the benefit of being able to run some tasks in series and others in parallel to find the fastest path.

module.exports = function (callback) {
  runSequence('clean', 'static', 'html', ['javascripts', 'sass', 'templates', 'translations'], ['uglify', 'minify-css'], 'cachebust', 'manifest', function () {
    gulp.src('src/foo/*.bar')
      .pipe(whatever())
      .on('end', callback);
  });
};

from blendid.

greypants avatar greypants commented on July 19, 2024

@elcontraption - looks like you were totally right! Definition order doesn't seem to matter, so your proposed solution is pretty perfect. Gonna run it through the wringer, and if all goes well, I'll push these updates. Thanks for the insight.

from blendid.

lyzadanger avatar lyzadanger commented on July 19, 2024

I took a slightly different approach by modifying gulp/index.js. Right now my quick-and-dirty variant looks like:

var gulp = require('gulp');

module.exports = function(tasks) {
  tasks.forEach(function(task) {
    task = (typeof task === 'string') ? { name: task } : task;
    task.deps = task.deps || [];
    gulp.task(task.name, task.deps, require('./tasks/' + task.name));

  });

  return gulp;
};

From gulpfile.js, I can then:

var gulp = require('./gulp')([
  'browserify',
  'css',
  'files',
  'indexer',
  'javascript',
  { name: 'screens', deps: ['build']},
  'serve',
  'templates',
  'vendor',
  'watch'
]);

Just another way to skin the cat. Seems to work in my case! The nice thing about this way is that I don't have to touch my existing task modules. But there may well be shortcomings I'm not thinking of.

from blendid.

elcontraption avatar elcontraption commented on July 19, 2024

@lyzadanger's method allows the task modules to be unaware of each other–which seems more modular–and all dependency configuration happens in one place. It's just a matter of where you prefer your dependencies to be declared.

from blendid.

greypants avatar greypants commented on July 19, 2024

@lyzadanger - that's a great solution too. I'm leaning towards @elcontraption's version only because I like the idea of automatically including tasks from ./gulp/tasks. Saves from having to mange the task list manually, and reduces the gulpfile.js to just one line :neckbeard:. Take a look at #5 and let me know if you see any downsides. Once I get some input, I'll merge it and add a note to the blog post.

from blendid.

lyzadanger avatar lyzadanger commented on July 19, 2024

Ooh, I do like the fs-based auto-inclusion of tasks. Neato!

On Apr 15, 2014, at 4:57 PM, Dan Tello [email protected] wrote:

@lyzadanger - that's a great solution too. I'm leaning towards @elcontraption's version only because I like the idea of automatically including tasks from ./gulp/tasks. Saves from having to mange the task list manually, and reduces the gulpfile.js to just one line . Take a look at #5 and let me know if you see any downsides. Once I get some input, I'll merge it and add a note to the blog post.


Reply to this email directly or view it on GitHub.

from blendid.

elcontraption avatar elcontraption commented on July 19, 2024

#5 is looking good to me, and solves this issue. You might want to bounce it off someone more node and gulp savvy to be sure.

from blendid.

greypants avatar greypants commented on July 19, 2024

Updated and merged. Thanks for the input!

from blendid.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.