Giter Club home page Giter Club logo

cha's Introduction

cha NPM version Build Status

Make task chaining.

Cha allows tasks to be connected together into a chain that makes better readability and easier to maintain.

Getting Started

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

> [email protected] 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 Extensions

Cha Expressions

// 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

> [email protected] expr
> node ./test/expr

request http://underscorejs.org/underscore-min.js
concat http://underscorejs.org/underscore-min.js
write ./out/foobar.js

Task Settings

// 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')

JavaScript Tasks

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.

Release History

  • 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.

cha's People

Contributors

yuanyan avatar

Watchers

 avatar  avatar

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.