1.0.2 • Published 9 years ago
gulp-tasks-manager v1.0.2
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-dev
Demo
For example, here is the file structure of an app:
/--app
|--build
|--tasks
|--script.js
|--style.js
|--gulpfile.js
|--js
|--css
|--node_modules
|--package.json
in 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 know -plugins
:gulp-load-plugins
(preferred) or a self-defined object -opts
: options -rootDir
: 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
: namespace -filename
: if missed, default toname
- ns
-
ns.name
: the namespace -ns.context(dir)
: locate the context dir of a namespace, return a function which is used to locate resources in the module represented by this namespace -ns(taskName)
: return string ofnamespace:taskName
and add it to the task list -ns([taskName1, taskName2, ...])
: return an array of string with each item is the format ofnamespace:taskNamex
License
MIT