gulp-tasks-manager
v1.0.2
Published
Gulp tasks manager
Maintainers
Readme
gulp-tasks-manager
Gulp tasks manager. If you have too many tasks, you can split tasks into multiple pieces with this tool.
Install
npm install gulp-tasks-manager --save-devDemo
For example, here is the file structure of an app:
/--app
|--build
|--tasks
|--script.js
|--style.js
|--gulpfile.js
|--js
|--css
|--node_modules
|--package.jsonin gulpfile.js:
var gulp = require('gulp'),
plugins = require('gulp-load-plugins')(),
tasks = require('gulp-tasks-manager'),
task = tasks(gulp, plugins, {
rootDir: '../',
taskDir: './tasks'
});
task('script');
task('style');
gulp.task('default', tasks.list());in tasks/script.js:
module.exports = function(gulp, plugins, ns) {
var cxt = ns.context('./js'),
path = {
src: cxt('./**/*.js'),
dst: cxt('./build')
};
gulp.task(ns('build'), function() {
gulp.src(path.src)
.pipe(plugins.uglify())
.pipe(gulp.dest(path.dst));
});
gulp.task(ns('watch'), function() {
gulp.watch(path.js, ns(['build']));
});
};in tasks/style.js:
module.exports = function(gulp, plugins, ns) {
var cxt = ns.context('./css'),
path = {
src: cxt('./**/*.less'),
dst: cxt('./build')
};
gulp.task(ns('build'), function() {
gulp.src(path.src)
.pipe(plugins.less())
.pipe(gulp.dest(path.dst));
});
gulp.task(ns('watch'), function() {
gulp.watch(path.less, ns(['build']));
});
};then just run gulp.
If you want:
- just build and watch script, run
gulp script - just build but not watch style, run
gulp style:build
when executing task(script), it is just:
gulp.task('script:build', function(){})gulp.task('script:watch', function(){})gulp.task('script', ['script:build', 'script:watch'])
API
- tasks(gulp, plugins [, opts])
gulp: the gulp as we all knowplugins:gulp-load-plugins(preferred) or a self-defined objectopts: optionsrootDir: default to./taskDir: default to./
- tasks.list()
- list main tasks
- return value is the format of
[namespace1, namespace2, ...]
- tasks.listAll()
- list all tasks(main tasks and subtasks)
- return value is the format of
{namespace1: [subtask1, subtask2], namespace2: [...], ...}
- task(name [, filename])
name: namespacefilename: if missed, default toname
- ns
ns.name: the namespacens.context(dir): locate the context dir of a namespace, return a function which is used to locate resources in the module represented by this namespacens(taskName): return string ofnamespace:taskNameand add it to the task listns([taskName1, taskName2, ...]): return an array of string with each item is the format ofnamespace:taskNamex
License
MIT
