Comparing version 0.6.0 to 0.6.1
@@ -13,2 +13,6 @@ /* | ||
var namespace = 'var gear = gear || {};' + | ||
'gear.tasks = gear.tasks || {};' + | ||
'gear.vendor = gear.vendor || {};'; | ||
var files = [ | ||
@@ -27,2 +31,3 @@ 'vendor/async.js', | ||
new gear.Queue({registry: new gear.Registry({module: 'gear-lib'})}) | ||
.load(namespace) | ||
.read(files) | ||
@@ -29,0 +34,0 @@ .concat() |
@@ -58,2 +58,69 @@ /* | ||
}; | ||
})(typeof exports === 'undefined' ? this.gear || (this.gear = {}) : exports); | ||
var readFile = { | ||
server: function(name, encoding, callback) { | ||
var fs = require('fs'); | ||
fs.readFile(name, encoding, function(err, data) { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
callback(null, new Blob(data, {name: name})); | ||
} | ||
}); | ||
}, | ||
client: function(name, encoding, callback) { | ||
if (name in localStorage) { | ||
callback(null, new Blob(localStorage[name], {name: name})); | ||
} else { | ||
callback('localStorage has no item ' + name); | ||
} | ||
} | ||
}; | ||
Blob.readFile = Blob.prototype.readFile = (typeof require === 'undefined') ? readFile.client : readFile.server; | ||
var writeFile = { | ||
server: function(name, blob, encoding, callback) { | ||
var fs = require('fs'), | ||
path = require('path'), | ||
mkdirp = require('mkdirp').mkdirp, | ||
Crypto = require('crypto'); | ||
function writeFile(filename, b) { | ||
fs.writeFile(filename, b.toString(), function(err) { | ||
callback(err, new Blob(b, {name: filename})); | ||
}); | ||
} | ||
var dirname = path.resolve(path.dirname(name)), | ||
checksum; | ||
if (name.indexOf('{checksum}') > -1) { // Replace {checksum} with md5 string | ||
checksum = Crypto.createHash('md5'); | ||
checksum.update(blob.toString()); | ||
name = name.replace('{checksum}', checksum.digest('hex')); | ||
} | ||
path.exists(dirname, function(exists) { | ||
if (!exists) { | ||
mkdirp(dirname, '0755', function(err) { | ||
if (err) { | ||
callback(err); | ||
} else { | ||
writeFile(name, blob); | ||
} | ||
}); | ||
} | ||
else { | ||
writeFile(name, blob); | ||
} | ||
}); | ||
}, | ||
client: function(name, blob, encoding, callback) { | ||
localStorage[name] = blob.toString(); | ||
callback(null, new blob.constructor(blob, {name: name})); | ||
} | ||
}; | ||
Blob.writeFile = Blob.prototype.writeFile = (typeof require === 'undefined') ? writeFile.client : writeFile.server; | ||
})(typeof exports === 'undefined' ? this.gear : exports); |
@@ -7,14 +7,6 @@ /* | ||
(function(exports) { | ||
var async, Registry, Blob; | ||
if (typeof require !== 'undefined') { | ||
async = require('async'); | ||
Registry = require('./registry').Registry; | ||
Blob = require('./blob').Blob; | ||
} | ||
else { | ||
async = this.async; | ||
Registry = this.gear.Registry; | ||
Blob = this.gear.Blob; | ||
} | ||
var async = typeof require !== 'undefined' ? require('async') : this.gear.vendor.async, | ||
Registry = typeof require !== 'undefined' ? require('./registry').Registry : this.gear.Registry, | ||
Blob = typeof require !== 'undefined' ? require('./blob').Blob : this.gear.Blob; | ||
/* | ||
@@ -26,2 +18,3 @@ * Queue | ||
options = options || {}; | ||
this._logger = options.logger || console; | ||
this._registry = options.registry || new Registry(); | ||
@@ -41,3 +34,3 @@ this._queue = [ | ||
Queue.prototype._log = function(message) { | ||
console.log(message); | ||
this._logger.log(message); | ||
}; | ||
@@ -92,2 +85,2 @@ | ||
}; | ||
})(typeof exports === 'undefined' ? this.gear || (this.gear = {}) : exports); | ||
})(typeof exports === 'undefined' ? this.gear : exports); |
@@ -8,7 +8,6 @@ /* | ||
if (typeof require !== 'undefined') { | ||
var path = require('path'), | ||
fs = require('fs'); | ||
var path = require('path'); | ||
} | ||
else { | ||
var default_tasks = this.tasks; | ||
var default_tasks = this.gear.tasks; | ||
} | ||
@@ -69,3 +68,4 @@ | ||
_loadDir: function(dirname) { | ||
var files = fs.readdirSync(dirname), | ||
var fs = require('fs'), | ||
files = fs.readdirSync(dirname), | ||
self = this; | ||
@@ -103,5 +103,8 @@ | ||
task: function(name) { | ||
if (!(name in this._tasks)) { | ||
throw new Error('Task ' + name + ' doesn\'t exist'); | ||
} | ||
return this._tasks[name]; | ||
} | ||
}; | ||
})(typeof exports === 'undefined' ? this.gear || (this.gear = {}) : exports); | ||
})(typeof exports === 'undefined' ? this.gear : exports); |
@@ -20,3 +20,2 @@ /* | ||
concat.type = 'reduce'; | ||
concat.browser = true; | ||
})(typeof exports === 'undefined' ? this.tasks || (this.tasks = {}) : exports); | ||
})(typeof exports === 'undefined' ? gear.tasks : exports); |
@@ -7,4 +7,17 @@ /* | ||
(function(exports) { | ||
var Blob = typeof require !== 'undefined' ? require('../blob').Blob : gear.Blob; | ||
/** | ||
* Add a blob string. | ||
* | ||
* @param index {Integer} Index of blobs. | ||
* @param blobs {Array} Incoming blobs. | ||
* @param done {Function} Callback on task completion. | ||
*/ | ||
var load = exports.load = function load(string, done) { | ||
done(null, new Blob(string)); | ||
}; | ||
load.type = 'append'; | ||
/** | ||
* Gets a blob. | ||
@@ -20,3 +33,2 @@ * | ||
get.type = 'iterate'; | ||
get.browser = true; | ||
@@ -35,3 +47,2 @@ /** | ||
log.type = 'iterate'; | ||
log.browser = true; | ||
@@ -56,3 +67,2 @@ /** | ||
inspect.type = 'iterate'; | ||
inspect.browser = true; | ||
@@ -69,3 +79,2 @@ /** | ||
}; | ||
noop.browser = true; | ||
})(typeof exports === 'undefined' ? this.tasks || (this.tasks = {}) : exports); | ||
})(typeof exports === 'undefined' ? gear.tasks : exports); |
@@ -7,10 +7,3 @@ /* | ||
(function(exports) { | ||
var Blob; | ||
if (typeof require !== 'undefined') { | ||
var fs = require('fs'); | ||
Blob = require('../blob').Blob; | ||
} | ||
else { | ||
Blob = gear.Blob; | ||
} | ||
var Blob = typeof require !== 'undefined' ? require('../blob').Blob : gear.Blob; | ||
@@ -21,3 +14,4 @@ /** | ||
* @param options {Object} File options or filename. | ||
* @param options.name {Object} Filename to read. | ||
* @param options.name {String} Filename to read. | ||
* @param options.encoding {String} File encoding. | ||
* @param done {Function} Callback on task completion. | ||
@@ -27,19 +21,6 @@ */ | ||
options = (typeof options === 'string') ? {name: options} : options; | ||
if (typeof fs === 'undefined') { | ||
if (options.name in localStorage) { | ||
done(null, new Blob(localStorage[options.name], {name: options.name})); | ||
} | ||
else { | ||
done('localStorage has no item ' + options.name); | ||
} | ||
} | ||
else { | ||
fs.readFile(options.name, function(err, data) { | ||
done(err, new Blob(data, {name: options.name})); | ||
}); | ||
} | ||
var encoding = options.encoding || 'utf8'; | ||
Blob.readFile(options.name, encoding, done); | ||
}; | ||
read.type = 'append'; | ||
read.browser = true; | ||
})(typeof exports === 'undefined' ? this.tasks || (this.tasks = {}) : exports); | ||
})(typeof exports === 'undefined' ? gear.tasks : exports); |
@@ -7,9 +7,3 @@ /* | ||
(function(exports) { | ||
var async; | ||
if (typeof require !== 'undefined') { | ||
async = require('async'); | ||
} | ||
else { | ||
async = this.async; | ||
} | ||
var async = typeof require !== 'undefined' ? require('async') : gear.vendor.async; | ||
@@ -81,3 +75,2 @@ /** | ||
tasks.type = 'iterate'; | ||
tasks.browser = true; | ||
})(typeof exports === 'undefined' ? this.tasks || (this.tasks = {}) : exports); | ||
})(typeof exports === 'undefined' ? gear.tasks : exports); |
@@ -7,9 +7,2 @@ /* | ||
(function(exports) { | ||
if (typeof require !== 'undefined') { | ||
var fs = require('fs'), | ||
path = require('path'), | ||
mkdirp = require('mkdirp').mkdirp, | ||
Crypto = require('crypto'); | ||
} | ||
/** | ||
@@ -25,41 +18,6 @@ * Write the blob to disk with an optional checksum in the filename. | ||
options = (typeof options === 'string') ? {name: options} : options; | ||
function writeFile(name, b) { | ||
fs.writeFile(name, blob.toString(), function(err) { | ||
done(err, new blob.constructor(blob, {name: name})); | ||
}); | ||
} | ||
if (typeof fs !== 'undefined') { | ||
var dirname = path.resolve(path.dirname(options.name)), | ||
checksum; | ||
if (options.name.indexOf('{checksum}') > -1) { // Replace {checksum} with md5 string | ||
checksum = Crypto.createHash('md5'); | ||
checksum.update(blob.toString()); | ||
options.name = options.name.replace('{checksum}', checksum.digest('hex')); | ||
} | ||
path.exists(dirname, function(exists) { | ||
if (!exists) { | ||
mkdirp(dirname, '0755', function(err) { | ||
if (err) { | ||
done(err); | ||
} else { | ||
writeFile(options.name, blob); | ||
} | ||
}); | ||
} | ||
else { | ||
writeFile(options.name, blob); | ||
} | ||
}); | ||
} | ||
else { | ||
localStorage[options.name] = blob.toString(); | ||
done(null, new blob.constructor(blob, {name: name})); | ||
} | ||
var encoding = options.encoding || 'utf8'; | ||
blob.writeFile(options.name, blob, encoding, done); | ||
}; | ||
write.type = 'slice'; | ||
write.browser = true; | ||
})(typeof exports === 'undefined' ? this.tasks || (this.tasks = {}) : exports); | ||
})(typeof exports === 'undefined' ? gear.tasks : exports); |
{ | ||
"name": "gear", | ||
"version": "0.6.0", | ||
"version": "0.6.1", | ||
"description": "Gear.js - Task-based build system.", | ||
@@ -5,0 +5,0 @@ "author": "Stephen Murphy <stephen@hypernaut.com>", |
293
README.md
@@ -17,3 +17,3 @@ # Gear.js | ||
To get the most out of Gear.js, you will want to install [gear-lib](/twobit/gear-lib) which contains tasks for linting, minifying, and deploying JS/CSS assets. | ||
To get the most out of Gear.js, you will want to install [gear-lib](/yahoo/gear-lib) which contains tasks for linting, minifying, and deploying JS/CSS assets. | ||
@@ -56,6 +56,6 @@ ```bash | ||
.tasks({ | ||
read: {task: ['read', ['foo.js', 'bar.js', 'baz.js']]} | ||
combine: {requires: 'read', task: 'concat'} | ||
minify: {requires: 'combine', task: 'jsminify'} | ||
print: {requires: ['read', 'combine', 'minify'], task: 'inspect'} // Runs when read, combine, and minify complete | ||
read: {task: ['read', ['foo.js', 'bar.js', 'baz.js']]}, | ||
combine: {requires: 'read', task: 'concat'}, | ||
minify: {requires: 'combine', task: 'jsminify'}, | ||
print: {requires: ['read', 'combine', 'minify'], task: 'inspect'}, // Runs when read, combine, and minify complete | ||
parallel: {task: ['log', "Hello Gear.js world!"]} // Run parallel to read | ||
@@ -65,282 +65,3 @@ }).run(); | ||
## Documentation | ||
### [Core](#Core) | ||
* [Queue](#Core.Queue) | ||
* [Queue.task](#Core.Queue.task) | ||
* [Queue.run](#Core.Queue.run) | ||
* [Registry](#Core.Registry) | ||
* [Registry.load](#Core.Registry.load) | ||
### [Core Tasks](#Tasks) | ||
* [read](#Tasks.read) | ||
* [write](#Tasks.write) | ||
* [concat](#Tasks.concat) | ||
* [inspect](#Tasks.inspect) | ||
* [log](#Tasks.log) | ||
* [tasks](#Tasks.tasks) | ||
### [Library Tasks](#Library) | ||
### [Custom Tasks](#Custom) | ||
<a name="Core" /> | ||
## Core | ||
<a name="Core.Queue" /> | ||
### Queue(options) | ||
Queue constructor. | ||
__Arguments__ | ||
* options.registry - Registry loaded with available tasks. | ||
__Example__ | ||
```javascript | ||
new Queue() | ||
.log('test') | ||
.run(); | ||
``` | ||
--------------------------------------- | ||
<a name="Core.Queue.task" /> | ||
### Queue.task(name, options) | ||
Helper method to run the specified task. Preferred task execution style is to call the task directly i.e. `inspect()` instead of `task('inspect')`. | ||
__Arguments__ | ||
* name - Name of task in registry. | ||
__Example__ | ||
```javascript | ||
new Queue() | ||
.task('log', 'Hello, world!') | ||
.run(); | ||
``` | ||
--------------------------------------- | ||
<a name="Core.Queue.run" /> | ||
### Queue.run(callback) | ||
Runs the queue. | ||
__Arguments__ | ||
* callback - (optional) Callback accepting (err, results) | ||
__Example__ | ||
```javascript | ||
new Queue() | ||
.log('test') | ||
.run(); | ||
``` | ||
--------------------------------------- | ||
<a name="Core.Registry" /> | ||
### Registry() | ||
Creates a new Registry instance. Registries contain available tasks. | ||
__Arguments__ | ||
* options - (optional) Same as .load | ||
__Example__ | ||
```javascript | ||
new Registry(); | ||
``` | ||
--------------------------------------- | ||
<a name="Core.Registry.load" /> | ||
### Registry.load(options) | ||
Load tasks from NPM, directory, or file. | ||
__Arguments__ | ||
* options.module - Module to load tasks from. | ||
* options.dirname - Directory to load tasks from. | ||
* options.filename - File to load tasks from. | ||
* options.tasks - Object to load tasks from. | ||
__Example__ | ||
```javascript | ||
new Registry().load({dirname: 'foo'}); | ||
``` | ||
--------------------------------------- | ||
<a name="Tasks" /> | ||
## Tasks | ||
<a name="Tasks.read" /> | ||
### read(name) | ||
### read([{name: name}]) | ||
Appends file contents onto queue. | ||
__Arguments__ | ||
* name - (string) Filename to read. | ||
__Example__ | ||
```javascript | ||
// file - Filename to read. | ||
// file.name - Filename of resource. | ||
.read('foo') | ||
.read(['foo', 'baz']) | ||
.read([{name: 'foo'}, {name: 'bar'}, {name: 'baz'}]) | ||
``` | ||
--------------------------------------- | ||
<a name="Tasks.write" /> | ||
### write(options) | ||
__Arguments__ | ||
* options.name - File to write, will replace {checksum} with hash of blob content. | ||
Write the blob to disk. | ||
__Example__ | ||
```javascript | ||
.write('foo') | ||
.write({name: 'foo'}) | ||
``` | ||
--------------------------------------- | ||
<a name="Tasks.concat" /> | ||
### concat() | ||
Concatenates blobs. | ||
__Example__ | ||
```javascript | ||
.concat() | ||
``` | ||
--------------------------------------- | ||
<a name="Tasks.inspect" /> | ||
### inspect() | ||
Inspects blobs. | ||
__Example__ | ||
```javascript | ||
.inspect() | ||
``` | ||
--------------------------------------- | ||
<a name="Tasks.log" /> | ||
### log(string) | ||
__Arguments__ | ||
* string - String to log. | ||
Log a message. | ||
__Example__ | ||
```javascript | ||
.log('Finished') | ||
``` | ||
--------------------------------------- | ||
<a name="Tasks.tasks" /> | ||
### tasks(workflow) | ||
__Arguments__ | ||
* workflow - Task workflow. | ||
Execute tasks in parallel with optional dependencies. Data is joined on completion. | ||
__Example__ | ||
```javascript | ||
// label - Task instance name. | ||
// label.task - Task name and optionally options. | ||
// label.requires - List of labels that must be executed before this task runs. | ||
.tasks({ | ||
label_1: {task: 'log'} | ||
label_2: {task: ['log', 'Hello, world!']} | ||
label_3: {requires: 'label_2', task: ['log', 'Hello, world 2!']} | ||
}) | ||
``` | ||
<a name="Library" /> | ||
## Library Tasks | ||
Install [gear-lib](/twobit/gear-lib) which contains tasks such as: | ||
* jslint | ||
* jsminify | ||
* csslint | ||
* cssminify | ||
* s3 | ||
```bash | ||
$ npm install gear-lib | ||
``` | ||
<a name="Custom" /> | ||
## Custom Tasks | ||
Writing a task is especially easy compared to other Node build systems. There is no need to use Gear.js internals within a task. Tasks operate on immutable blobs. Blobs have a body property. The task returns transformed data via its callback. | ||
__Arguments__ | ||
* options - Options for the task. | ||
* blob - Immutable blob. | ||
* done(err, result) - Callback executed when task is complete. | ||
__Example__ | ||
```javascript | ||
// example.js | ||
// Example task creates new blob containing `string` | ||
exports.example = function(string, blob, done) { | ||
done(null, new blob.constructor(string)); // blob.constructor() is equivalent to Blob() | ||
}; | ||
``` | ||
__Running Example Task__ | ||
```javascript | ||
new Queue({registry: new Registry({filename: 'example.js'})}) | ||
.example('EXAMPLE') | ||
.run(); | ||
``` | ||
## Who's Using Gear.js | ||
* [Mojito Shaker](/yahoo/mojito-shaker) by [Yahoo](/yahoo). | ||
## Special Thanks | ||
Gear.js takes inspiration from a few sources: | ||
* [buildy](/mosen/buildy) created by [mosen](/mosen). | ||
* [grunt](/cowboy/grunt) created by [cowboy](/cowboy). | ||
* [Documentation](http://yahoo.github.com/gear) | ||
* [Issues](http://github.com/yahoo/gear/issues) |
@@ -692,2 +692,2 @@ /*global setTimeout: false, console: false */ | ||
}()); | ||
}).call(gear.vendor); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
102215
36
1465
64