Coder Social home page Coder Social 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

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cha's Issues

Future design

Hi there, just want to know what are the use cases for this library?

  • If you want to have a task runner, there is grunt
  • If you want to have a fast build tool with nested dependencies using streams, there is gulp
  • If you like virtual build paths you could try fez
  • Something more tree-based (seems to be a mix between grunt and fez) would be broccoli
  • Mimosa is fast, very flexible and very solid, but has a bigger overhead if only being used as build tool

So now I'm trying to understand, what are the use cases for this library?

For my opinion, these are the problems with the current libraries:

  • Grunt is very widely spread, but slow because of high IO.
  • Gulp is very fast, but lacks in a lot of plugins that are missing.
  • Fez seems to be even more dynamic, but it's very young and not widely known.
  • Broccoli seems to be good for using Trees, which means you don't treat one single input stream but rather a bundle of them
  • Mimosa handles RequireJS, linting, testing and all that stuff in the correct order without you needing to step in in most cases, but still provides a config to setup some special rules for your app.

Would love to get some clarifications, thanks!

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.