james

James is a composable build tool which prefers code over configuration.

Synopsis

James.js is a composable build tool which prefers code over configuration.

// Jamesfile.js
var james  = require('james'),
    coffee = require('james-coffee'),
    uglify = require('james-uglify');

james.task('build', function() {

  james.list('src/**/*.coffee').forEach(function(file) {

    james.read(file)
      .transform(coffee({bare: true}))
      .transform(uglify)
      .write(file.replace('src', 'dist').replace('.coffee', '.min.js'));
  });
});

james.task('watch', function() {
  james.watch('test/**/*.coffee', function(event, file) {
    james.read(file)
      .transform(coffee({bare: true}))
      .write(file.replace('.coffee', '.js')));
  });
});

james.task('default', ['build', 'watch']);

API

james.task(name, task)Define a new task with given name. taskcan be either a callback or a list of existing task names.

james.list(glob1, glob2, ...)List files matching to a given globs.

james.watch(glob, callback)Watch files matching the glob.

james.dest(filename)Returns a Writable stream. Handy if you want to concatenate files to a single destination.

james.read(filename)Read a file. Returns a Pipelineobject. Use Pipeline.stream, if you need an access to the underlying ReadableStream.

james.wait(writes)Waits for Pipeline.writeoperation to finish. writescan be a single write operation or a list of write operations, e.g.,

js = james.list('src/**/*.coffee').map(function(file) {
  james.read(file).transform(coffee).write(file.replace(/\.coffee/, '.js'));
});

// After james.wait, it's safe to read files, e.g., with browserify or r.js
james.wait(js, function(js) { js.forEach(function(filename){ james.read(filename).write(process.stdout) }) });

Pipeline.transform(transformation)Transform the underlying stream with a given transformation. transformationcan be either a Transform streamor a Transform stream constructor.

Pipeline.write(dest)Write the underlying stream to a dest. destcan be either a Writable streamor a filename. Returns the Writable stream with stream.promiseproperty. Promise is resolved when the file has been written. Promise is used by james.wait.

Command-line

By default, james runs defaulttask. Specific tasks can be run by listing them on the command-line.

> npm install -g james
> james
> james build watch

Transformations

Existing transformations are listed in the wiki. Please add your transformations, too!

Creating new transformations

James uses node.js streams for transformations. Create a Transform stream, or use james.createTransformationhelper.

// james-coffee/index.js
var james  = require('james'),
    coffee = require('coffee-script');

coffee.createStream = function() {
  return james.createTransformation(function(content, callback) {

    // Process the file content and call the callback with the result.
    callback(coffee.compile(content));
  });
};

james.read('./hello.coffee')
  .transform(coffee.createStream)
  .write(process.stdout);

Repository

http://github.com/leonidas/james.js.git


上一篇:iso-countries
下一篇:james-uglify

相关推荐

  • james-uglify

    James transformer for Uglify2.js Synopsis UglifyJS 2 transformer for James.js(https://github.com/...

    10 个月前
  • james-bond

    Hire James Bond to deeply observe your (object) targets. James Bond Hire James Bond to deeply obs...

    1 个月前
  • @jameslnewell/typescript-config

    undefined @jameslnewell/typescriptconfig Typescript configuration. Installation Usage ...

    3 个月前
  • @jameslnewell/prettier-config

    undefined @jameslnewell/prettierconfig Prettier configuration. Installation Usage Rep...

    3 个月前
  • @jameslnewell/jest-preset-test

    undefined @jameslnewell/jestpresettest A test preset for my personal projects that use . Instal...

    3 个月前
  • @jameslnewell/eslint-config

    undefined @jameslnewell/eslintconfig ESLint configuration. Installation Usage Create a ESL...

    3 个月前
  • @jameslnewell/editor-config

    undefined @jameslnewell/editorconfig Editorconfig. Installation When installation is comple...

    3 个月前
  • @jameslnewell/cancelable-promise

    undefined @jameslnewell/cancelablepromise A cancelable promise implementation. Why? Unlike ot...

    5 个月前
  • @james-proxy/james-browser-launcher

    Detect, launch and stop browser versions jamesbrowserlauncher Build Status(https://travisci.org/ja...

    17 天前

官方社区

扫码加入 JavaScript 社区