Make task chaining.
Cha allows tasks to be connected together into a chain that makes better readability and easier to maintain.
Installing cha via NPM, this will install the latest version of cha in your project folder
and adding it to your devDependencies
in package.json
:
npm install cha --save-dev
Touch a tasks file and naming whatever you love like build.js
:
// Load cha library.
var cha = require('cha')
// Register tasks that should chaining.
cha.in('glob', require('task-glob'))
.in('combine', require('task-combine'))
.in('replace', require('task-replace'))
.in('writer', require('task-writer'))
.in('uglifyjs',require('task-uglifyjs'))
.in('copy', require('task-copy'))
.in('request', require('task-request'))
// Define task via chaining calls.
cha()
.glob({
patterns: './fixtures/js/*.js',
cwd: __dirname
})
.replace({
search: 'TIMESTAMP',
replace: +new Date
})
.replace({
search: /DEBUG/g,
replace: true
})
.request('http://underscorejs.org/underscore-min.js')
.combine()
.uglifyjs()
.writer('./out/foobar.js')
.copy('./out/foobar2.js')
Add a arbitrary command to the scripts
object:
{
"name": "cha-example",
"scripts": {
"build": "node ./build.js"
},
"devDependencies": {
"cha": "~0.1.0"
}
}
To run the command we prepend our script name with run:
$ npm run build
> cha@0.0.1 build
> node ./test/build
request http://underscorejs.org/underscore-min.js
concat ./test/fixtures/bar.js,./test/fixtures/foo.js,http://underscorejs.org/underscore-min.js
write ./out/foobar.js
copy out/foobar.js > ./out/foobar2.js
- cha-load - Automatically load cha and register tasks.
- cha-watch - File watcher.
- cha-target - Target runner.
// Load cha library.
var cha = require('cha')
// Register tasks that should chaining.
cha.in('glob', require('task-glob'))
.in('combine', require('task-combine'))
.in('replace', require('task-replace'))
.in('writer', require('task-writer'))
.in('uglifyjs',require('task-uglifyjs'))
.in('request', require('task-request'))
// Start with cha expressions.
cha(['glob:./fixtures/js/*.js', 'request:http://underscorejs.org/underscore-min.js'])
.replace({
search: 'TIMESTAMP',
replace: +new Date
})
.replace({
search: /DEBUG/g,
replace: true
})
.combine()
.uglifyjs()
.writer('./test/out/foobar.js')
To run the command we prepend our script name with run:
$ npm run expr
> cha@0.0.1 expr
> node ./test/expr
request http://underscorejs.org/underscore-min.js
concat http://underscorejs.org/underscore-min.js
write ./out/foobar.js
// Load cha library.
var cha = require('cha')
// Register tasks that should chaining.
cha.in('glob', require('task-glob'))
.in('writer', require('task-writer'))
.in('uglifyjs',require('task-uglifyjs'))
.in('request', require('task-request'))
// Start with cha expressions.
cha()
.glob({
patterns: './fixtures/js/*.js'
})
.request({
url: 'http://underscorejs.org/underscore.js'
}, {
ignore: true, // Ignore task inputs.
timeout: 2000 // 2000ms timeout.
})
.uglifyjs()
.writer('./underscore-min.js')
All register task should based on the JavaScript Task specification. You could get available tasks from [JavaScript Task Packages] (http://taskjs.github.io/packages/) website.
- 2014-05-19 0.2.1 Task accept
settings
param with general options. - 2014-05-18 0.2.0 Remove Internal methods.
- 2014-03-17 0.1.2 Extensions for cha.
- 2014-03-10 0.1.1 Custom tasks could override internal methods.
- 2014-03-05 0.1.0 Initial release.