diff --git a/gen-tests.js b/gen-tests.js index c7b5517d..51d28b2e 100644 --- a/gen-tests.js +++ b/gen-tests.js @@ -1,12 +1,12 @@ /** - * Generate asteroid unit tests from documentation... + * Generate asteroid unit tests from README... */ fs = require('fs') -readme = fs.readFileSync('./README.md').toString(); +readme = fs.readFileSync('../README.md').toString(); -var alias = { +alias = { myModel: 'Model', model: 'Model', ctx: 'Model', @@ -24,6 +24,9 @@ function getName(line) { function Doc(line, lineNum, docIndex) { this.name = getName(line); + + line = line.replace(/#+\s/, ''); + this.line = line; this.lineNum = lineNum; this.docIndex = docIndex; @@ -59,7 +62,30 @@ Doc.prototype.example = function () { } }); - return result.join('\n'); + return result; +} + +Doc.prototype.desc = function () { + var content = this.contents(); + var result = []; + var first; + + content.forEach(function (line) { + if(first) { + // ignore + } else if(line[0] === '#' || line[0] === ' ') { + // ignore + } else { + first = line; + } + }); + + // only want the first sentence (to keep it brief) + if(first) { + first = first.split(/\.\s|\n/)[0] + } + + return first; } lines = readme.split('\n') @@ -84,27 +110,35 @@ sh.rm('-rf', 'g-tests'); sh.mkdir('g-tests'); Object.keys(byName).forEach(function (group) { - var testFile = - "var asteroid = require('../');" + - "\n" + - "describe('app', function(){" - testFile - - describe('app', function(){ - var app; - - beforeEach(function () { - app = asteroid(); - }); - - describe('asteroid.createModel(name, properties, settings)', function(){ - var User = asteroid.createModel('user', { - first: String, - last: String, - age: Number - }); - }); + var testFile = [ + "describe('" + group + "', function() {", + ""]; + + byName[group].forEach(function (doc) { + var example = doc.example(); + var exampleLines = example && example.length && example; + + testFile = testFile.concat([ + " describe('" + doc.line + "', function() {", + " it(\"" + doc.desc() + "\", function(done) {"]); + + if(exampleLines) { + exampleLines.unshift("/* example - "); + exampleLines.push("*/") + testFile = testFile.concat( + exampleLines.map(function (l) { + return ' ' + l; + }) + ) + } + + testFile.push( + " done(new Error('test not implemented'));", + " });", + " });", + "});" + ); }); - -}) \ No newline at end of file + testFile.join('\n').to('g-tests/' + group + '.test.js'); +}); \ No newline at end of file diff --git a/node_modules/.bin/_mocha b/node_modules/.bin/_mocha deleted file mode 120000 index f2a54ffd..00000000 --- a/node_modules/.bin/_mocha +++ /dev/null @@ -1 +0,0 @@ -../mocha/bin/_mocha \ No newline at end of file diff --git a/node_modules/.bin/express b/node_modules/.bin/express deleted file mode 120000 index b741d99c..00000000 --- a/node_modules/.bin/express +++ /dev/null @@ -1 +0,0 @@ -../express/bin/express \ No newline at end of file diff --git a/node_modules/.bin/mocha b/node_modules/.bin/mocha deleted file mode 120000 index 43c668d9..00000000 --- a/node_modules/.bin/mocha +++ /dev/null @@ -1 +0,0 @@ -../mocha/bin/mocha \ No newline at end of file diff --git a/node_modules/.bin/shjs b/node_modules/.bin/shjs deleted file mode 120000 index a0449975..00000000 --- a/node_modules/.bin/shjs +++ /dev/null @@ -1 +0,0 @@ -../shelljs/bin/shjs \ No newline at end of file diff --git a/node_modules/asteroid-module/.gitignore b/node_modules/asteroid-module/.gitignore deleted file mode 100644 index 6af74074..00000000 --- a/node_modules/asteroid-module/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.DS_Store -*.seed -*.log -*.csv -*.dat -*.out -*.pid -*.swp -*.swo -node_modules/ diff --git a/node_modules/asteroid-module/README.md b/node_modules/asteroid-module/README.md deleted file mode 100644 index b71768ce..00000000 --- a/node_modules/asteroid-module/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# asteroid-module -v0.0.1 - -## About - -Asteroid applications are a combination of regular Node.js modules and Asteroid modules. Asteroid modules may be initialized using JavaScript or by writing config files. - -## Using Asteroid Modules - -There are two distinct ways to use an Asteroid Module in your application. - -### App API - -The `app` API allows you to define [data sources](../data-source) and [models](../model) in regular Node JavaScript. [See the docs for more info](../../readme.md#API). - -### Config Files - -You may also define [data sources](../data-source), [models](../model) and other asteroid modules by writing `config.json` files. See the documentation for a given module to see what config data it requires. - -## Extending Asteroid - -The core of asteroid is very lightweight and unopionated. All features are added on as `AsteroidModule`s. This means you can add your own functionality, modify existing functionality, or extend existing functionality by creating your own `AsteroidModule` class. - -An `AsteroidModule` is an abstract class that provides a base for all asteroid modules. Its constructor takes an `options` argument provided by a `config.json`. It is also supplied with dependencies it lists on its constructor based on information in the `config.json` file. - -See [model](../model) for an example. - -### AsteroidModule.dependencies - -An asteroid module may define dependencies on other modules that can be configured in `config.json`. Eg. the [collection](../collection/lib/collection.js) module defines a [model](../model) dependency. - - Collection.dependencies = { - model: 'model' - } - -A configuration then must define: - - { - "dependencies": { - "model": "some-model-module" - } - } - -Where `some-model-module` is an existing `model` instance. - -### AsteroidModule.options - -Asteroid Modules may also describe the options they accept. This will validate the configuration and make sure users have supplied required information and in a way that the module can use to construct a working instance. - -Here is an example options description for the [oracle database connection module](../connections/oracle-connection). - - OracleConnection.options = { - 'hostname': {type: 'string', required: true}, - 'port': {type: 'number', min: 10, max: 99999}, - 'username': {type: 'string'}, - 'password': {type: 'string'} - }; - -**key** the option name given in `config.json`. - -**type** must be one of: - - - string - - boolean - - number - - array - -**min/max** depend on the type - - { - min: 10, // minimum length or value - max: 100, // max length or value - } \ No newline at end of file diff --git a/node_modules/asteroid-module/index.js b/node_modules/asteroid-module/index.js deleted file mode 100644 index abb2ce9d..00000000 --- a/node_modules/asteroid-module/index.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * asteroid-module ~ public api - */ - -module.exports = require('./lib/asteroid-module'); \ No newline at end of file diff --git a/node_modules/asteroid-module/lib/asteroid-module.js b/node_modules/asteroid-module/lib/asteroid-module.js deleted file mode 100644 index ab06d017..00000000 --- a/node_modules/asteroid-module/lib/asteroid-module.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Expose `AsteroidModule`. - */ - -module.exports = AsteroidModule; - -/** - * Module dependencies. - */ - -var Module = require('sl-module-loader').Module - , debug = require('debug')('asteroid-module') - , util = require('util') - , inherits = util.inherits - , assert = require('assert'); - -/** - * Create a new `AsteroidModule` with the given `options`. - * - * @param {Object} options - * @return {AsteroidModule} - */ - -function AsteroidModule(options) { - Module.apply(this, arguments); - - // throw an error if args are not supplied - assert(typeof options === 'object', 'AsteroidModule requires an options object'); - - debug('created with options', options); -} - -/** - * Inherit from `Module`. - */ - -inherits(AsteroidModule, Module); diff --git a/node_modules/asteroid-module/package.json b/node_modules/asteroid-module/package.json deleted file mode 100644 index 7a779309..00000000 --- a/node_modules/asteroid-module/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "asteroid-module", - "description": "asteroid-module", - "version": "0.0.1", - "scripts": { - "test": "mocha" - }, - "dependencies": { - "debug": "latest" - }, - "devDependencies": { - "mocha": "latest" - } -} \ No newline at end of file diff --git a/node_modules/asteroid-module/test/asteroid-module.test.js b/node_modules/asteroid-module/test/asteroid-module.test.js deleted file mode 100644 index 9e9973a3..00000000 --- a/node_modules/asteroid-module/test/asteroid-module.test.js +++ /dev/null @@ -1,24 +0,0 @@ -var AsteroidModule = require('../'); - -describe('AsteroidModule', function(){ - var asteroidModule; - - beforeEach(function(){ - asteroidModule = new AsteroidModule; - }); - - describe('.myMethod', function(){ - // example sync test - it('should ', function() { - asteroidModule.myMethod(); - }); - - // example async test - it('should ', function(done) { - setTimeout(function () { - asteroidModule.myMethod(); - done(); - }, 0); - }); - }); -}); \ No newline at end of file diff --git a/node_modules/asteroid-module/test/support.js b/node_modules/asteroid-module/test/support.js deleted file mode 100644 index a9572cf5..00000000 --- a/node_modules/asteroid-module/test/support.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * asteroid-module test setup and support. - */ - -assert = require('assert'); \ No newline at end of file diff --git a/node_modules/data-source/.gitignore b/node_modules/data-source/.gitignore deleted file mode 100644 index 6af74074..00000000 --- a/node_modules/data-source/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.DS_Store -*.seed -*.log -*.csv -*.dat -*.out -*.pid -*.swp -*.swo -node_modules/ diff --git a/node_modules/data-source/README.md b/node_modules/data-source/README.md deleted file mode 100644 index e0f7301e..00000000 --- a/node_modules/data-source/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# data-source - -## About - -A `DataSource` is the base `AsteroidModule` class for all data sources. Data sources provide APIs for reading and writing remote data from databases and various http apis. - -### Creating a custom Data Source - -To create a custom data source you must define a class that inherits from `DataSource`. This class should define all the required options using the [asteroid module option api](../asteroid-module) (eg. host, port, username, etc). - -The inherited class must provide a property `adapter` that points to a [jugglingdb adapter](https://github.com/1602/jugglingdb#jugglingdb-adapters). \ No newline at end of file diff --git a/node_modules/data-source/index.js b/node_modules/data-source/index.js deleted file mode 100644 index 3b2c35c6..00000000 --- a/node_modules/data-source/index.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * connection ~ public api - */ - -module.exports = require('./lib/data-source'); \ No newline at end of file diff --git a/node_modules/data-source/lib/data-source.js b/node_modules/data-source/lib/data-source.js deleted file mode 100644 index 59047f4a..00000000 --- a/node_modules/data-source/lib/data-source.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Expose `DataSource`. - */ - -module.exports = DataSource; - -/** - * Module dependencies. - */ - -var AsteroidModule = require('asteroid-module') - , Schema = require('jugglingdb').Schema - , debug = require('debug')('connection') - , util = require('util') - , inherits = util.inherits - , assert = require('assert'); - -/** - * Create a new `DataSource` with the given `options`. - * - * @param {Object} options - * @return {DataSource} - */ - -function DataSource(options) { - AsteroidModule.apply(this, arguments); - this.options = options; - - // construct a schema with the available adapter - // or use the default in memory adapter - this.schema = new Schema(this.adapter || require('./memory'), options); - - debug('created with options', options); -} - -/** - * Inherit from `AsteroidModule`. - */ - -inherits(DataSource, AsteroidModule); \ No newline at end of file diff --git a/node_modules/data-source/lib/memory.js b/node_modules/data-source/lib/memory.js deleted file mode 100644 index 1061d932..00000000 --- a/node_modules/data-source/lib/memory.js +++ /dev/null @@ -1,260 +0,0 @@ -exports.initialize = function initializeSchema(schema, callback) { - schema.adapter = new Memory(); - schema.adapter.connect(callback); -}; - -function Memory(m) { - if (m) { - this.isTransaction = true; - this.cache = m.cache; - this.ids = m.ids; - this._models = m._models; - } else { - this.isTransaction = false; - // use asteroid cache, otherwise state will be reset during configuration - this.cache = process.__asteroidCache.memoryStore || (process.__asteroidCache.memoryStore = {}); - this.ids = {}; - this._models = {}; - } -} - -Memory.prototype.connect = function(callback) { - if (this.isTransaction) { - this.onTransactionExec = callback; - } else { - process.nextTick(callback); - } -}; - -Memory.prototype.define = function defineModel(descr) { - var m = descr.model.modelName; - this._models[m] = descr; - // allow reuse of data - this.cache[m] = this.cache[m] || {}; - this.ids[m] = 1; -}; - -Memory.prototype.create = function create(model, data, callback) { - var id = data.id || this.ids[model]++; - data.id = id; - this.cache[model][id] = JSON.stringify(data); - process.nextTick(function() { - callback(null, id); - }); -}; - -Memory.prototype.updateOrCreate = function (model, data, callback) { - var mem = this; - this.exists(model, data.id, function (err, exists) { - if (exists) { - mem.save(model, data, callback); - } else { - mem.create(model, data, function (err, id) { - data.id = id; - callback(err, data); - }); - } - }); -}; - -Memory.prototype.save = function save(model, data, callback) { - this.cache[model][data.id] = JSON.stringify(data); - process.nextTick(function () { - callback(null, data); - }); -}; - -Memory.prototype.exists = function exists(model, id, callback) { - process.nextTick(function () { - callback(null, this.cache[model].hasOwnProperty(id)); - }.bind(this)); -}; - -Memory.prototype.find = function find(model, id, callback) { - process.nextTick(function () { - callback(null, id in this.cache[model] && this.fromDb(model, this.cache[model][id])); - }.bind(this)); -}; - -Memory.prototype.destroy = function destroy(model, id, callback) { - delete this.cache[model][id]; - process.nextTick(callback); -}; - -Memory.prototype.fromDb = function(model, data) { - if (!data) return null; - data = JSON.parse(data); - var props = this._models[model].properties; - Object.keys(data).forEach(function (key) { - var val = data[key]; - if (typeof val === 'undefined' || val === null) { - return; - } - if (props[key]) { - switch(props[key].type.name) { - case 'Date': - val = new Date(val.toString().replace(/GMT.*$/, 'GMT')); - break; - case 'Boolean': - val = new Boolean(val); - break; - } - } - data[key] = val; - }); - return data; -}; - -Memory.prototype.all = function all(model, filter, callback) { - var self = this; - var nodes = []; - var data = this.cache[model]; - var keys = Object.keys(data); - var scanned = 0; - - while(scanned < keys.length) { - nodes.push(this.fromDb(model, data[keys[scanned]])); - scanned++; - } - - if (filter) { - - // do we need some sorting? - if (filter.order) { - var props = this._models[model].properties; - var orders = filter.order; - if (typeof filter.order === "string") { - orders = [filter.order]; - } - orders.forEach(function (key, i) { - var reverse = 1; - var m = key.match(/\s+(A|DE)SC$/i); - if (m) { - key = key.replace(/\s+(A|DE)SC/i, ''); - if (m[1].toLowerCase() === 'de') reverse = -1; - } - orders[i] = {"key": key, "reverse": reverse}; - }); - nodes = nodes.sort(sorting.bind(orders)); - } - - // do we need some filtration? - if (filter.where) { - nodes = nodes ? nodes.filter(applyFilter(filter)) : nodes; - } - - // skip - if(filter.skip) { - nodes = nodes.slice(filter.skip, nodes.length); - } - - if(filter.limit) { - nodes = nodes.slice(0, filter.limit); - } - } - - process.nextTick(function () { - if (filter && filter.include) { - self._models[model].model.include(nodes, filter.include, callback); - } else { - callback(null, nodes); - } - }); - - function sorting(a, b) { - for (var i=0, l=this.length; i b[this[i].key]) { - return 1*this[i].reverse; - } else if (a[this[i].key] < b[this[i].key]) { - return -1*this[i].reverse; - } - } - return 0; - } -}; - -function applyFilter(filter) { - if (typeof filter.where === 'function') { - return filter.where; - } - var keys = Object.keys(filter.where); - return function (obj) { - var pass = true; - keys.forEach(function (key) { - if (!test(filter.where[key], obj[key])) { - pass = false; - } - }); - return pass; - } - - function test(example, value) { - if (typeof value === 'string' && example && example.constructor.name === 'RegExp') { - return value.match(example); - } - if (typeof example === 'undefined') return undefined; - if (typeof value === 'undefined') return undefined; - if (typeof example === 'object') { - if (example.inq) { - if (!value) return false; - for (var i = 0; i < example.inq.length; i += 1) { - if (example.inq[i] == value) return true; - } - return false; - } - } - // not strict equality - return (example !== null ? example.toString() : example) == (value !== null ? value.toString() : value); - } -} - -Memory.prototype.destroyAll = function destroyAll(model, callback) { - Object.keys(this.cache[model]).forEach(function (id) { - delete this.cache[model][id]; - }.bind(this)); - this.cache[model] = {}; - process.nextTick(callback); -}; - -Memory.prototype.count = function count(model, callback, where) { - var cache = this.cache[model]; - var data = Object.keys(cache) - if (where) { - data = data.filter(function (id) { - var ok = true; - Object.keys(where).forEach(function (key) { - if (JSON.parse(cache[id])[key] != where[key]) { - ok = false; - } - }); - return ok; - }); - } - process.nextTick(function () { - callback(null, data.length); - }); -}; - -Memory.prototype.updateAttributes = function updateAttributes(model, id, data, cb) { - data.id = id; - - var base = JSON.parse(this.cache[model][id]); - this.save(model, merge(base, data), cb); -}; - -Memory.prototype.transaction = function () { - return new Memory(this); -}; - -Memory.prototype.exec = function(callback) { - this.onTransactionExec(); - setTimeout(callback, 50); -}; - -function merge(base, update) { - if (!base) return update; - Object.keys(update).forEach(function (key) { - base[key] = update[key]; - }); - return base; -} diff --git a/node_modules/data-source/package.json b/node_modules/data-source/package.json deleted file mode 100644 index c329007b..00000000 --- a/node_modules/data-source/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "data-source", - "description": "data-source", - "version": "0.0.1", - "scripts": { - "test": "mocha" - }, - "dependencies": { - "debug": "latest", - "jugglingdb": "~0.2.0-30" - }, - "devDependencies": { - "mocha": "latest" - } -} diff --git a/node_modules/data-source/test/data-source.test.js b/node_modules/data-source/test/data-source.test.js deleted file mode 100644 index 681c974b..00000000 --- a/node_modules/data-source/test/data-source.test.js +++ /dev/null @@ -1,24 +0,0 @@ -var DataSource = require('../'); - -describe('DataSource', function(){ - var connection; - - beforeEach(function(){ - dataSource = new DataSource; - }); - - describe('.myMethod', function(){ - // example sync test - it('should ', function() { - dataSource.myMethod(); - }); - - // example async test - it('should ', function(done) { - setTimeout(function () { - dataSource.myMethod(); - done(); - }, 0); - }); - }); -}); \ No newline at end of file diff --git a/node_modules/data-source/test/support.js b/node_modules/data-source/test/support.js deleted file mode 100644 index 4d8c7d8c..00000000 --- a/node_modules/data-source/test/support.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * connection test setup and support. - */ - -assert = require('assert'); \ No newline at end of file diff --git a/node_modules/model/.gitignore b/node_modules/model/.gitignore deleted file mode 100644 index 6af74074..00000000 --- a/node_modules/model/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.DS_Store -*.seed -*.log -*.csv -*.dat -*.out -*.pid -*.swp -*.swo -node_modules/ diff --git a/node_modules/model/README.md b/node_modules/model/README.md deleted file mode 100644 index cd312953..00000000 --- a/node_modules/model/README.md +++ /dev/null @@ -1,255 +0,0 @@ -# model - -## About - -A `Model` represents the data of your application. Asteroid `Model`s are mostly used for validating interactions with a [DataSource](../data-source). Usually your models will correspond to a namespace in your data source (database table, http url, etc). The bulk of your application's business logic will be in your `Model` or Node.js scripts that require your model. - -## Data Definition Language - -TODO ~ document - -## API - -### Defining Models - -The following assumes your have reference to a class that inherits from `Model`. The simplest way to get this is by using the [app API](../../readme.md#API). - - // define a model class using the app api - var Color = app.define('color'); - - // provide an exact plural name - var Color = app.define('color', {plural: 'colors'}); - -**Note:** If a plural name is not defined, the model will try to pluralize the singular form. - -#### MyModel.defineSchema(schema) - -Define the data the model represents using the data definition language. - - // define the color model - var Color = app.define('color'); - - // define the schema for the Color model - Color.defineSchema({ - name: 'string', - id: 'uid', - tweets: 'array' - }); - -##### MyModel.dataSource(name, namespace) - -Set the data source for the model. Must provide a name of an existing data source. If the `namespace` is not provided the plural model name (eg. `colors`) will be used. - - // set the data source - Color.dataSource('color-db', 'COLOR_NAMES'); - -**Note:** If you do not set a data source or a map (or both) the default data source will be used (an in memory database). - -#### MyModel.defineMap(map) - -Define a mapping between the data source representation of your data and your app's representation. - - // manually map Color to existing table columns - Color.defineMap({ - dataSource: 'color-db', // optional, will use model's data source - table: 'COLOR_NAMES', // required - map: { // optional if schema defined - id: 'COLOR_ID', - name: 'COLOR_NAME' - } - }); - - // mix in a mapping from another data source - Color.defineMap({ - dataSource: 'twitter', - url: function(color) { - return '/search?limit=5&q=' + color.name; - }, - map: { - // provides the color.tweets property - tweets: function(tweets) { - return tweets; - } - } - }); - -**Note:** You may define multiple maps for a single model. The model will combine the data for you. - -#### MyModel.discoverSchema(fn) - -Using the mapped data source, try to discover the schema of a table or other namespace (url, collection, etc). - - // use existing schema to map to desired properties - Color.dataSource('color-db', 'COLOR_NAMES'); - Color.discoverSchema(function (err, oracleSchema) { - var schema = {tweets: 'array'}; - var map = {dataSource: 'color-db', table: 'COLOR_NAMES'}; - - // inspect the existing table schema to create a mapping - Object - .keys(oracleSchema) - .forEach(function (oracleProperty) { - // remove prefix - var property = oracleProperty.toLowerCase().split('_')[0]; - - // build new schema - schema[property] = oracleProperty[oracleProperty]; - // create mapping to existing schema - map[property] = oracleProperty; - }); - - Color.defineSchema(schema); - Color.defineMap(map); - }); - -### Custom Methods - -There are two types of custom methods. Static and instance. - -**Static** - -Static methods are available on the Model class itself and are used to operate on many models at the same time. - -**Instance** - -Instance methods are available on an instance of a Model and usually act on a single model at a time. - -#### Defining a Static Method - -The following example shows how to define a simple static method. - - Color.myStaticMethod = function() { - // only has access to other static methods - this.find(function(err, colors) { - console.log(colors); // [...] - }); - } - -#### Defining an Instance Method - -The following is an example of a simple instance method. - - Color.prototype.myInstanceMethod = function() { - console.log(this.name); // red - } - -#### Remotable Methods - -Both types of methods may be set as `remotable` as long as they conform to the remotable requirements. Asteroid will expose these methods over the network for you. - -##### Remotable Requirements - -Static and instance methods must accept a callback as the last argument. This callback must be called with an error as the first argument and the results as arguments afterward. - -You must also define the input and output of your remoteable method. Describe the input or arguments of the function by providing an `accepts` array and describe the output by defining a `returns` array. - - // this method meets the remotable requirements - Color.getByName = function (name, callback) { - Color.find({where: {name: name}}, function (err, colors) { - // if an error occurs callback with the error - if(err) { - callback(err); - } else { - callback(null, colors); - } - }); - } - - // accepts a name of type string - Color.getByName.accepts = [ - {arg: 'name', type: 'String'} // data definition language - ]; - - // returns an array of type Color - Color.getByName.returns = [ - {arg: 'colors', type: ['Color']} // data definition language - ]; - -**Note:** any types included in `accepts`/`returns` must be native JavaScript types or Model classes. - -### Working with Models - -The following assumes you have access to an instance of a `Model` class. - - // define a model - var Color = app.define('color'); - - // create an instance - var color = new Color({name: red}); - -#### myModel.save([options], [callback]) - -**Remoteable** - -Save the model using its configured data source. - - var color = new Color(); - color.name = 'green'; - - // fire and forget - color.save(); - - // callback - color.save(function(err, color) { - if(err) { - console.log(err); // validation or other error - } else { - console.log(color); // updated with id - } - }); - -#### myModel.destroy([callback]) - -**Remoteable** - -Delete the instance using attached data source. Invoke callback when ready. - - var color = Color.create({id: 10}); - - color.destroy(function(err) { - if(err) { - console.log(err); // could not destroy - } else { - console.log('model has been destroyed!'); - } - }); - -#### MyModel.all() -#### MyModel.find() -#### MyModel.count() - -### Model Relationships - -## Config - -### Options - -#### namespace - -A table, collection, url, or other namespace. - -#### properties - -An array of properties describing the model's schema. - - "properties": [ - { - "name": "title", - "type": "string" - }, - { - "name": "done", - "type": "boolean" - }, - { - "name": "order", - "type": "number" - } - ] - } - -### Dependencies - -#### data source - -The name of a data source [data-source](../data-source) for persisting data. \ No newline at end of file diff --git a/node_modules/model/example/example.js b/node_modules/model/example/example.js deleted file mode 100644 index a3fbffea..00000000 --- a/node_modules/model/example/example.js +++ /dev/null @@ -1,12 +0,0 @@ -/** - * A generated `Model` example... - * - * Examples should show a working module api - * and be used in tests to continously check - * they function as expected. - */ - -var Model = require('../'); -var model = Model.create(); - -model.myMethod(); \ No newline at end of file diff --git a/node_modules/model/index.js b/node_modules/model/index.js deleted file mode 100644 index 9d72d647..00000000 --- a/node_modules/model/index.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * model ~ public api - */ - -module.exports = require('./lib/model-configuration'); \ No newline at end of file diff --git a/node_modules/model/lib/model-configuration.js b/node_modules/model/lib/model-configuration.js deleted file mode 100644 index cb536472..00000000 --- a/node_modules/model/lib/model-configuration.js +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Expose `ModelConfiguration`. - */ - -module.exports = ModelConfiguration; - -/** - * Module dependencies. - */ - -var AsteroidModule = require('asteroid-module') - , Model = require('./model') - , debug = require('debug')('model-configuration') - , util = require('util') - , inherits = util.inherits - , assert = require('assert'); - -/** - * Create a new `ModelConfiguration` with the given `options`. - * - * @param {Object} options - * @return {Model} - */ - -function ModelConfiguration(options) { - AsteroidModule.apply(this, arguments); - this.options = options; - - var dependencies = this.dependencies; - var dataSource = dependencies['data-source']; - var schema = this.schema = dataSource.schema; - - assert(Array.isArray(options.properties), 'the ' + options._name + ' model requires an options.properties array'); - - // define model - var ModelCtor = this.ModelCtor = this.BaseModel.extend(options); - - assert(dataSource.name, 'cannot map a model to a datasource without a name'); - - // define provided mappings - if(options.maps) { - options.maps.forEach(function (config) { - assert(config.dataSource, 'Model config.options.maps requires a `dataSource` when defining maps'); - assert(config.map, 'Model config.options.maps requires a `map` when defining maps'); - - ModelCtor.defineMap(dataSource.name, config); - }); - } -} - -/** - * Inherit from `AsteroidModule`. - */ - -inherits(ModelConfiguration, AsteroidModule); - -/** - * The model to extend (should be overridden in sub classes). - */ - -ModelConfiguration.prototype.BaseModel = Model; - -/** - * Dependencies. - */ - -ModelConfiguration.dependencies = { - 'data-source': 'data-source' -}; - -/** - * Options. - */ - -ModelConfiguration.options = { - 'name': {type: 'string'}, - 'properties': {type: 'array'}, - 'maps': {type: 'array'} -}; diff --git a/node_modules/model/lib/model.js b/node_modules/model/lib/model.js deleted file mode 100644 index cf687a96..00000000 --- a/node_modules/model/lib/model.js +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Expose `Model`. - */ - -module.exports = Model; - -/** - * Module dependencies. - */ - -var EventEmitter = require('events').EventEmitter - , debug = require('debug')('model') - , util = require('util') - , inherits = util.inherits - , assert = require('assert'); - -/** - * Create a new `Model` with the given `options`. - * - * @param {Object} options - * @return {Model} - */ - -function Model(data) { - EventEmitter.call(this); - - var ModelCtor = this.constructor; - var schema = ModelCtor.schema; - - // get properties that match the schema - var matchedProperties = schema.getMatchedProperties(data); - - // set properties that match the schema - Object.keys(matchedProperties).forEach(function (property) { - this[property] = matchedProperties[property]; - }.bind(this)); -} - -/** - * Inherit from `EventEmitter`. - */ - -inherits(Model, EventEmitter); - -/** - * Create a new Model class from the given options. - * - * @param options {Object} - * @return {Model} - */ - -Model.extend = function (options) { - var Super = this; - - // the new constructor - function Model() { - Super.apply(this, arguments); - } - - Model.options = options; - - assert(options.name, 'must provide a name when extending from model'); - - // model namespace - Model.namespace = options.name; - - // define the remote namespace - Model.remoteNamespace = options.plural || pluralize(Model.namespace); - - // inherit all static methods - Object.keys(Super).forEach(function (key) { - if(typeof Super[key] === 'function') { - MyModel[key] = Super[key]; - } - }); - - // inherit all other things - inherits(MyModel, Super); - - return Model; -} - -/** - * Construct a model instance for remote use. - */ - -Model.sharedCtor = function (data, fn) { - var ModelCtor = this; - - fn(null, new ModelCtor(data)); -} - -/** - * Define the data the model represents using the data definition language. - */ - -Model.defineSchema = function (schema) { - throw new Error('not implemented'); -} - -/** - * Set the data source for the model. Must provide a name of an existing data source. - * If the namespace is not provided the plural model name (eg. colors) will be used. - * - * **Note:** If you do not set a data source or a map (or both) the default data source - * will be used (an in memory database). - */ - -Model.dataSource = function (dataSourceName, namespace) { - namespace = namespace || this.namespace; - throw new Error('not implemented'); -} - -/** - * Define a mapping between the data source representation of your data and your app's representation. - */ - -Model.defineMap = function (mapping) { - // see: https://github.com/strongloop/asteroid/tree/master/node_modules/model#mymodeldefinemapmap - throw new Error('not implemented'); -} \ No newline at end of file diff --git a/node_modules/model/package.json b/node_modules/model/package.json deleted file mode 100644 index d21c693a..00000000 --- a/node_modules/model/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "model", - "description": "model", - "version": "0.0.1", - "scripts": { - "test": "mocha" - }, - "dependencies": { - "debug": "latest" - }, - "devDependencies": { - "mocha": "latest" - } -} \ No newline at end of file diff --git a/node_modules/model/test/model.test.js b/node_modules/model/test/model.test.js deleted file mode 100644 index 928953e2..00000000 --- a/node_modules/model/test/model.test.js +++ /dev/null @@ -1,24 +0,0 @@ -var Model = require('../'); - -describe('Model', function(){ - var model; - - beforeEach(function(){ - model = new Model; - }); - - describe('.myMethod', function(){ - // example sync test - it('should ', function() { - model.myMethod(); - }); - - // example async test - it('should ', function(done) { - setTimeout(function () { - model.myMethod(); - done(); - }, 0); - }); - }); -}); \ No newline at end of file diff --git a/node_modules/model/test/support.js b/node_modules/model/test/support.js deleted file mode 100644 index e8db5346..00000000 --- a/node_modules/model/test/support.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * model test setup and support. - */ - -assert = require('assert'); \ No newline at end of file diff --git a/node_modules/oracle-data-source/.gitignore b/node_modules/oracle-data-source/.gitignore deleted file mode 100644 index 6af74074..00000000 --- a/node_modules/oracle-data-source/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.DS_Store -*.seed -*.log -*.csv -*.dat -*.out -*.pid -*.swp -*.swo -node_modules/ diff --git a/node_modules/oracle-data-source/README.md b/node_modules/oracle-data-source/README.md deleted file mode 100644 index 43ae30de..00000000 --- a/node_modules/oracle-data-source/README.md +++ /dev/null @@ -1,12 +0,0 @@ -# oracle-data-source - -## About - -Configures the oracle adapter for use in a [data store](../../store). - -### Options - -#### hostname -#### port -#### username -#### password \ No newline at end of file diff --git a/node_modules/oracle-data-source/index.js b/node_modules/oracle-data-source/index.js deleted file mode 100644 index 3312ce08..00000000 --- a/node_modules/oracle-data-source/index.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * connection ~ public api - */ - -module.exports = require('./lib/oracle-data-source'); \ No newline at end of file diff --git a/node_modules/oracle-data-source/lib/oracle-data-source.js b/node_modules/oracle-data-source/lib/oracle-data-source.js deleted file mode 100644 index 7fa13b79..00000000 --- a/node_modules/oracle-data-source/lib/oracle-data-source.js +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Expose `OracleDataSource`. - */ - -module.exports = OracleDataSource; - -/** - * Module dependencies. - */ - -var DataSource = require('data-source') - , debug = require('debug')('oracle-data-source') - , util = require('util') - , inherits = util.inherits - , assert = require('assert'); - -/** - * Create a new `OracleDataSource` with the given `options`. - * - * @param {Object} options - * @return {DataSource} - */ - -function OracleDataSource(options) { - DataSource.apply(this, arguments); - debug('created with options', options); -} - -/** - * Inherit from `AsteroidModule`. - */ - -inherits(OracleDataSource, DataSource); - -/** - * Define options. - */ - -OracleDataSource.options = { - 'database': {type: 'string', required: true}, - 'host': {type: 'string', required: true}, - 'port': {type: 'number', min: 10, max: 99999}, - 'username': {type: 'string'}, - 'password': {type: 'string'} -}; - -/** - * Provide the oracle jugglingdb adapter - */ - -OracleDataSource.prototype.adapter = require('jugglingdb-oracle'); \ No newline at end of file diff --git a/node_modules/oracle-data-source/package.json b/node_modules/oracle-data-source/package.json deleted file mode 100644 index ce0e8550..00000000 --- a/node_modules/oracle-data-source/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "oracle-data-source", - "description": "oracle-data-source", - "version": "0.0.1", - "scripts": { - "test": "mocha" - }, - "dependencies": { - "jugglingdb-oracle": "latest", - "debug": "latest" - }, - "devDependencies": { - "mocha": "latest" - } -} \ No newline at end of file diff --git a/node_modules/route/.gitignore b/node_modules/route/.gitignore deleted file mode 100644 index 6af74074..00000000 --- a/node_modules/route/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -.DS_Store -*.seed -*.log -*.csv -*.dat -*.out -*.pid -*.swp -*.swo -node_modules/ diff --git a/node_modules/route/README.md b/node_modules/route/README.md deleted file mode 100644 index 7fcb89a2..00000000 --- a/node_modules/route/README.md +++ /dev/null @@ -1,73 +0,0 @@ -# asteroid.Route - -## About - -A `Route` inherits from the [asteroid module](../asteroid-module) class. It wraps an asteroid application so that it can be used as a sub application initialized by a configuration file. - -This example shows the basic usage of a `Route` as a sub application. You should never have to write this code since the route will be created and mounted for you by asteroid. - - var asteroid = require('asteroid'); - var Route = require('route'); - - var app = asteroid(); - var subApp = new Route({root: '/my-sub-app'}); - subApp.mount(app); - - subApp.get('/', function (req, res) { - res.send(req.url); // /my-sub-app - }); - - app.listen(3000); - -## route.app - -Each route is constructed with a asteroid/express sub app at the path provided in the route's `config.json` options. - -### myRoute.app.VERB(path, [callback...], callback) - -The `myRoute.VERB()` methods provide routing functionality inherited from [Express](http://expressjs.com/api.html#app.get), where **VERB** is one of the HTTP verbs, such as `myRoute.post()`. See the [Express docs](http://expressjs.com/api.html#app.get) for more info. - - -**Examples** - - myRoute.get('/hello-world', function(req, res) { - res.send('hello world'); - }); - - -### myRoute.app.use([path], middleware) - -Use the given middleware function. - -**Examples** - - // a logger middleware - myRoute.use(function(req, res, next){ - console.log(req.method, req.url); // GET /my-route - next(); - }); - -## Config - -### Options - -#### path - -The `asteroid.Route` path where the route will be mounted. - -**Examples** - - { - "options": { - "path": "/foo" // responds at /foo - } - } - - - - { - "options": { - "path": "/foo/:bar" // provides :bar param at `req.param('bar')`. - } - } - diff --git a/node_modules/route/index.js b/node_modules/route/index.js deleted file mode 100644 index 3b31f452..00000000 --- a/node_modules/route/index.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * resource ~ public api - */ - -module.exports = require('./lib/route'); \ No newline at end of file diff --git a/node_modules/route/lib/http-context.js b/node_modules/route/lib/http-context.js deleted file mode 100644 index b1c72c7f..00000000 --- a/node_modules/route/lib/http-context.js +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Expose `HttpContext`. - */ - -module.exports = HttpContext; - -/** - * Module dependencies. - */ - -var EventEmitter = require('events').EventEmitter - , debug = require('debug')('http-context') - , util = require('util') - , inherits = util.inherits - , assert = require('assert'); - -/** - * Create a new `HttpContext` with the given `options`. - * - * @param {Object} options - * @return {HttpContext} - */ - -function HttpContext(resource, req, res, next) { - EventEmitter.apply(this, arguments); - - this.resource = resource; - this.req = req; - this.res = res; - this.next = next; -} - -/** - * Inherit from `EventEmitter`. - */ - -inherits(HttpContext, EventEmitter); - -/** - * Override the default emitter behavior to support async or sync hooks before and after an event. - */ - -HttpContext.prototype.emit = function (ev) { - var ctx = this; - var resource = this.resource; - var origArgs = arguments; - var args = Array.prototype.slice.call(arguments, 0) - var success = arguments[arguments.length - 1]; - - assert(typeof success === 'function', 'ctx.emit requires a callback'); - args.pop(); - - var evName = ev; - assert(typeof evName === 'string'); - args.shift(); - - var listeners = resource.listeners(evName); - var listener; - - // start - next(); - - function next(err) { - if(err) return fail(err); - - try { - if(listener = listeners.shift()) { - var expectsCallback = listener._expects === args.length + 2; - - // if a listener expects all the `args` - // plus ctx, and a callback - if(expectsCallback) { - // include ctx (this) and pass next to continue - listener.apply(resource, args.concat([this, next])); - } else { - // dont include the callback - listener.apply(resource, args.concat([this])); - // call next directly - next(); - } - } else { - success(done); - } - } catch(e) { - fail(e); - } - } - - function fail(err) { - ctx.done(err); - } - - function done(err, result) { - if(err) { - return fail(err); - } - - ctx.emit.apply(ctx, - ['after:' + evName] // after event - .concat(args) // include original arguments/data - .concat([function () { // success callback - ctx.done.call(ctx, err, result); - }]) - ); - }; -} - -HttpContext.prototype.done = function (err, result) { - if(err) { - this.next(err); - } else { - this.res.send(result); - } -} \ No newline at end of file diff --git a/node_modules/route/lib/route.js b/node_modules/route/lib/route.js deleted file mode 100644 index b445b619..00000000 --- a/node_modules/route/lib/route.js +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Expose `Route`. - */ - -module.exports = Route; - -/** - * Module dependencies. - */ - -var asteroid = require('asteroid') - , AsteroidModule = require('asteroid-module') - , HttpContext = require('./http-context') - , debug = require('debug')('asteroid:resource') - , util = require('util') - , inherits = util.inherits - , assert = require('assert'); - -/** - * Create a new `Route` with the given `options`. - * - * @param {Object} options - * @return {Route} - */ - -function Route(options) { - AsteroidModule.apply(this, arguments); - - // throw an error if args are not supplied - assert(typeof options === 'object', 'Route requires an options object'); - assert(options.path, 'Route requires a path'); - - // create the sub app - var app = this.app = asteroid(); - - this.options = options; - - debug('created with options', options); - - this.on('destroyed', function () { - app.disuse(this.options.path); - }); -} - -/** - * Inherit from `AsteroidModule`. - */ - -inherits(Route, AsteroidModule); - -/** - * Mount the sub app on the given parent app at the configured path. - */ - -Route.prototype.mount = function (parent) { - this.parent = parent; - parent.use(this.options.path, this.app); -} - -/** - * Create an http context bound to the current resource. - */ - -Route.prototype.createContext = function (req, res, next) { - return new HttpContext(this, req, res, next); -} - -/** - * Override `on` to determine how many arguments an event handler expects. - */ - -Route.prototype.on = function () { - var fn = arguments[arguments.length - 1]; - - if(typeof fn === 'function') { - // parse expected arguments from function src - // fn.listener handles the wrapped function during `.once()` - var src = (fn.listener || fn).toString(); - fn._expects = src.split('{')[0].split(',').length; - } - - AsteroidModule.prototype.on.apply(this, arguments); -} \ No newline at end of file diff --git a/node_modules/route/package.json b/node_modules/route/package.json deleted file mode 100644 index db5da708..00000000 --- a/node_modules/route/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "resource", - "description": "resource", - "version": "0.0.1", - "scripts": { - "test": "mocha" - }, - "dependencies": { - "debug": "latest" - }, - "devDependencies": { - "mocha": "latest" - } -} \ No newline at end of file diff --git a/node_modules/route/test/http-context.test.js b/node_modules/route/test/http-context.test.js deleted file mode 100644 index 6cadac3e..00000000 --- a/node_modules/route/test/http-context.test.js +++ /dev/null @@ -1,95 +0,0 @@ -var HttpContext = require('../lib/http-context.js'); -var Resource = require('../lib/resource.js'); - -describe('HttpContext', function(){ - var ctx; - var resource; - - function createRequest() { - return {}; - } - - function createResponse() { - return {}; - } - - beforeEach(function(){ - resource = new Resource({path: '/foo'}); - ctx = new HttpContext(resource, createRequest(), createResponse()); - }); - - describe('.emit(ev, arg, done)', function(){ - it('should emit events on a resource', function(done) { - var emitted, data; - - resource.once('foo', function (arg, ctx, fn) { - emitted = true; - data = arg; - fn(); - }); - - ctx.emit('foo', {bar: true}, function () { - assert(emitted, 'event should be emitted'); - assert(data, 'arg should be supplied'); - assert(data.bar, 'arg should be the correct object'); - done(); - }); - }); - - it('should handle multiple args', function(done) { - var emitted, data; - - resource.once('foo', function (arg1, arg2, arg3, arg4, ctx, fn) { - emitted = true; - assert(arg1 === 1, 'arg1 should equal 1'); - assert(arg2 === 2, 'arg2 should equal 2'); - assert(arg3 === 3, 'arg3 should equal 3'); - assert(arg4 === 4, 'arg4 should equal 4'); - fn(); - }); - - ctx.emit('foo', 1, 2, 3, 4, function (fn) { - assert(emitted, 'event should be emitted'); - done(); - }); - }); - - it('should have an after event', function(done) { - var emitted, emittedAfter; - - ctx.done = done; - - resource.once('foo', function (arg1, arg2, arg3, arg4, ctx, fn) { - emitted = true; - fn(); - }); - - resource.once('after:foo', function (arg1, arg2, arg3, arg4, ctx, fn) { - emittedAfter = true; - fn(); - }); - - ctx.emit('foo', 1, 2, 3, 4, function (fn) { - assert(emitted, 'event should be emitted'); - fn(); - }); - }); - - it('should be able to emit synchronously', function(done) { - var emitted, data; - - resource.once('foo', function (arg1, arg2, arg3, arg4, ctx) { - emitted = true; - assert(arg1 === 1, 'arg1 should equal 1'); - assert(arg2 === 2, 'arg2 should equal 2'); - assert(arg3 === 3, 'arg3 should equal 3'); - assert(arg4 === 4, 'arg4 should equal 4'); - }); - - ctx.emit('foo', 1, 2, 3, 4, function () { - assert(emitted); - done(); - }); - }); - }); -}); \ No newline at end of file diff --git a/node_modules/route/test/support.js b/node_modules/route/test/support.js deleted file mode 100644 index 94e12000..00000000 --- a/node_modules/route/test/support.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * resource test setup and support. - */ - -assert = require('assert'); \ No newline at end of file diff --git a/node_modules/shelljs/.documentup.json b/node_modules/shelljs/.documentup.json deleted file mode 100644 index 57fe3011..00000000 --- a/node_modules/shelljs/.documentup.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "ShellJS", - "twitter": [ - "r2r" - ] -} diff --git a/node_modules/shelljs/.npmignore b/node_modules/shelljs/.npmignore deleted file mode 100644 index c2658d7d..00000000 --- a/node_modules/shelljs/.npmignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ diff --git a/node_modules/shelljs/.travis.yml b/node_modules/shelljs/.travis.yml deleted file mode 100644 index 5caf5998..00000000 --- a/node_modules/shelljs/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: node_js -node_js: - - 0.6 - - 0.8 - diff --git a/node_modules/shelljs/LICENSE b/node_modules/shelljs/LICENSE deleted file mode 100644 index 1b35ee9f..00000000 --- a/node_modules/shelljs/LICENSE +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 2012, Artur Adib -All rights reserved. - -You may use this project under the terms of the New BSD license as follows: - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - * Neither the name of Artur Adib nor the - names of the contributors may be used to endorse or promote products - derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL ARTUR ADIB BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND -ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/node_modules/shelljs/README.md b/node_modules/shelljs/README.md deleted file mode 100644 index 8b455929..00000000 --- a/node_modules/shelljs/README.md +++ /dev/null @@ -1,513 +0,0 @@ -# ShellJS - Unix shell commands for Node.js [![Build Status](https://secure.travis-ci.org/arturadib/shelljs.png)](http://travis-ci.org/arturadib/shelljs) - -ShellJS is a portable **(Windows/Linux/OS X)** implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping its familiar and powerful commands. You can also install it globally so you can run it from outside Node projects - say goodbye to those gnarly Bash scripts! - -The project is [unit-tested](http://travis-ci.org/arturadib/shelljs) and battled-tested in projects like: - -+ [PDF.js](http://github.com/mozilla/pdf.js) - Firefox's next-gen PDF reader -+ [Firebug](http://getfirebug.com/) - Firefox's infamous debugger -+ [JSHint](http://jshint.com) - Most popular JavaScript linter -+ [Zepto](http://zeptojs.com) - jQuery-compatible JavaScript library for modern browsers -+ [Yeoman](http://yeoman.io/) - Web application stack and development tool -+ [Deployd.com](http://deployd.com) - Open source PaaS for quick API backend generation - -and [many more](https://npmjs.org/browse/depended/shelljs). - -## Installing - -Via npm: - -```bash -$ npm install [-g] shelljs -``` - -If the global option `-g` is specified, the binary `shjs` will be installed. This makes it possible to -run ShellJS scripts much like any shell script from the command line, i.e. without requiring a `node_modules` folder: - -```bash -$ shjs my_script -``` - -You can also just copy `shell.js` into your project's directory, and `require()` accordingly. - - -## Examples - -### JavaScript - -```javascript -require('shelljs/global'); - -if (!which('git')) { - echo('Sorry, this script requires git'); - exit(1); -} - -// Copy files to release dir -mkdir('-p', 'out/Release'); -cp('-R', 'stuff/*', 'out/Release'); - -// Replace macros in each .js file -cd('lib'); -ls('*.js').forEach(function(file) { - sed('-i', 'BUILD_VERSION', 'v0.1.2', file); - sed('-i', /.*REMOVE_THIS_LINE.*\n/, '', file); - sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat('macro.js'), file); -}); -cd('..'); - -// Run external tool synchronously -if (exec('git commit -am "Auto-commit"').code !== 0) { - echo('Error: Git commit failed'); - exit(1); -} -``` - -### CoffeeScript - -```coffeescript -require 'shelljs/global' - -if not which 'git' - echo 'Sorry, this script requires git' - exit 1 - -# Copy files to release dir -mkdir '-p', 'out/Release' -cp '-R', 'stuff/*', 'out/Release' - -# Replace macros in each .js file -cd 'lib' -for file in ls '*.js' - sed '-i', 'BUILD_VERSION', 'v0.1.2', file - sed '-i', /.*REMOVE_THIS_LINE.*\n/, '', file - sed '-i', /.*REPLACE_LINE_WITH_MACRO.*\n/, cat 'macro.js', file -cd '..' - -# Run external tool synchronously -if (exec 'git commit -am "Auto-commit"').code != 0 - echo 'Error: Git commit failed' - exit 1 -``` - -## Global vs. Local - -The example above uses the convenience script `shelljs/global` to reduce verbosity. If polluting your global namespace is not desirable, simply require `shelljs`. - -Example: - -```javascript -var shell = require('shelljs'); -shell.echo('hello world'); -``` - -## Make tool - -A convenience script `shelljs/make` is also provided to mimic the behavior of a Unix Makefile. In this case all shell objects are global, and command line arguments will cause the script to execute only the corresponding function in the global `target` object. To avoid redundant calls, target functions are executed only once per script. - -Example (CoffeeScript): - -```coffeescript -require 'shelljs/make' - -target.all = -> - target.bundle() - target.docs() - -target.bundle = -> - cd __dirname - mkdir 'build' - cd 'lib' - (cat '*.js').to '../build/output.js' - -target.docs = -> - cd __dirname - mkdir 'docs' - cd 'lib' - for file in ls '*.js' - text = grep '//@', file # extract special comments - text.replace '//@', '' # remove comment tags - text.to 'docs/my_docs.md' -``` - -To run the target `all`, call the above script without arguments: `$ node make`. To run the target `docs`: `$ node make docs`, and so on. - - - - - - -## Command reference - - -All commands run synchronously, unless otherwise stated. - - -### cd('dir') -Changes to directory `dir` for the duration of the script - -### pwd() -Returns the current directory. - -### ls([options ,] path [,path ...]) -### ls([options ,] path_array) -Available options: - -+ `-R`: recursive -+ `-A`: all files (include files beginning with `.`, except for `.` and `..`) - -Examples: - -```javascript -ls('projs/*.js'); -ls('-R', '/users/me', '/tmp'); -ls('-R', ['/users/me', '/tmp']); // same as above -``` - -Returns array of files in the given path, or in current directory if no path provided. - -### find(path [,path ...]) -### find(path_array) -Examples: - -```javascript -find('src', 'lib'); -find(['src', 'lib']); // same as above -find('.').filter(function(file) { return file.match(/\.js$/); }); -``` - -Returns array of all files (however deep) in the given paths. - -The main difference from `ls('-R', path)` is that the resulting file names -include the base directories, e.g. `lib/resources/file1` instead of just `file1`. - -### cp([options ,] source [,source ...], dest) -### cp([options ,] source_array, dest) -Available options: - -+ `-f`: force -+ `-r, -R`: recursive - -Examples: - -```javascript -cp('file1', 'dir1'); -cp('-Rf', '/tmp/*', '/usr/local/*', '/home/tmp'); -cp('-Rf', ['/tmp/*', '/usr/local/*'], '/home/tmp'); // same as above -``` - -Copies files. The wildcard `*` is accepted. - -### rm([options ,] file [, file ...]) -### rm([options ,] file_array) -Available options: - -+ `-f`: force -+ `-r, -R`: recursive - -Examples: - -```javascript -rm('-rf', '/tmp/*'); -rm('some_file.txt', 'another_file.txt'); -rm(['some_file.txt', 'another_file.txt']); // same as above -``` - -Removes files. The wildcard `*` is accepted. - -### mv(source [, source ...], dest') -### mv(source_array, dest') -Available options: - -+ `f`: force - -Examples: - -```javascript -mv('-f', 'file', 'dir/'); -mv('file1', 'file2', 'dir/'); -mv(['file1', 'file2'], 'dir/'); // same as above -``` - -Moves files. The wildcard `*` is accepted. - -### mkdir([options ,] dir [, dir ...]) -### mkdir([options ,] dir_array) -Available options: - -+ `p`: full path (will create intermediate dirs if necessary) - -Examples: - -```javascript -mkdir('-p', '/tmp/a/b/c/d', '/tmp/e/f/g'); -mkdir('-p', ['/tmp/a/b/c/d', '/tmp/e/f/g']); // same as above -``` - -Creates directories. - -### test(expression) -Available expression primaries: - -+ `'-b', 'path'`: true if path is a block device -+ `'-c', 'path'`: true if path is a character device -+ `'-d', 'path'`: true if path is a directory -+ `'-e', 'path'`: true if path exists -+ `'-f', 'path'`: true if path is a regular file -+ `'-L', 'path'`: true if path is a symboilc link -+ `'-p', 'path'`: true if path is a pipe (FIFO) -+ `'-S', 'path'`: true if path is a socket - -Examples: - -```javascript -if (test('-d', path)) { /* do something with dir */ }; -if (!test('-f', path)) continue; // skip if it's a regular file -``` - -Evaluates expression using the available primaries and returns corresponding value. - -### cat(file [, file ...]) -### cat(file_array) - -Examples: - -```javascript -var str = cat('file*.txt'); -var str = cat('file1', 'file2'); -var str = cat(['file1', 'file2']); // same as above -``` - -Returns a string containing the given file, or a concatenated string -containing the files if more than one file is given (a new line character is -introduced between each file). Wildcard `*` accepted. - -### 'string'.to(file) - -Examples: - -```javascript -cat('input.txt').to('output.txt'); -``` - -Analogous to the redirection operator `>` in Unix, but works with JavaScript strings (such as -those returned by `cat`, `grep`, etc). _Like Unix redirections, `to()` will overwrite any existing file!_ - -### sed([options ,] search_regex, replace_str, file) -Available options: - -+ `-i`: Replace contents of 'file' in-place. _Note that no backups will be created!_ - -Examples: - -```javascript -sed('-i', 'PROGRAM_VERSION', 'v0.1.3', 'source.js'); -sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js'); -``` - -Reads an input string from `file` and performs a JavaScript `replace()` on the input -using the given search regex and replacement string. Returns the new string after replacement. - -### grep([options ,] regex_filter, file [, file ...]) -### grep([options ,] regex_filter, file_array) -Available options: - -+ `-v`: Inverse the sense of the regex and print the lines not matching the criteria. - -Examples: - -```javascript -grep('-v', 'GLOBAL_VARIABLE', '*.js'); -grep('GLOBAL_VARIABLE', '*.js'); -``` - -Reads input string from given files and returns a string containing all lines of the -file that match the given `regex_filter`. Wildcard `*` accepted. - -### which(command) - -Examples: - -```javascript -var nodeExec = which('node'); -``` - -Searches for `command` in the system's PATH. On Windows looks for `.exe`, `.cmd`, and `.bat` extensions. -Returns string containing the absolute path to the command. - -### echo(string [,string ...]) - -Examples: - -```javascript -echo('hello world'); -var str = echo('hello world'); -``` - -Prints string to stdout, and returns string with additional utility methods -like `.to()`. - -### dirs([options | '+N' | '-N']) - -Available options: - -+ `-c`: Clears the directory stack by deleting all of the elements. - -Arguments: - -+ `+N`: Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero. -+ `-N`: Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero. - -Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified. - -See also: pushd, popd - -### pushd([options,] [dir | '-N' | '+N']) - -Available options: - -+ `-n`: Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated. - -Arguments: - -+ `dir`: Makes the current working directory be the top of the stack, and then executes the equivalent of `cd dir`. -+ `+N`: Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. -+ `-N`: Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. - -Examples: - -```javascript -// process.cwd() === '/usr' -pushd('/etc'); // Returns /etc /usr -pushd('+1'); // Returns /usr /etc -``` - -Save the current directory on the top of the directory stack and then cd to `dir`. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack. - -### popd([options,] ['-N' | '+N']) - -Available options: - -+ `-n`: Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated. - -Arguments: - -+ `+N`: Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero. -+ `-N`: Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero. - -Examples: - -```javascript -echo(process.cwd()); // '/usr' -pushd('/etc'); // '/etc /usr' -echo(process.cwd()); // '/etc' -popd(); // '/usr' -echo(process.cwd()); // '/usr' -``` - -When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. - -### exit(code) -Exits the current process with the given exit code. - -### env['VAR_NAME'] -Object containing environment variables (both getter and setter). Shortcut to process.env. - -### exec(command [, options] [, callback]) -Available options (all `false` by default): - -+ `async`: Asynchronous execution. Defaults to true if a callback is provided. -+ `silent`: Do not echo program output to console. - -Examples: - -```javascript -var version = exec('node --version', {silent:true}).output; - -var child = exec('some_long_running_process', {async:true}); -child.stdout.on('data', function(data) { - /* ... do something with data ... */ -}); - -exec('some_long_running_process', function(code, output) { - console.log('Exit code:', code); - console.log('Program output:', output); -}); -``` - -Executes the given `command` _synchronously_, unless otherwise specified. -When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's -`output` (stdout + stderr) and its exit `code`. Otherwise returns the child process object, and -the `callback` gets the arguments `(code, output)`. - -**Note:** For long-lived processes, it's best to run `exec()` asynchronously as -the current synchronous implementation uses a lot of CPU. This should be getting -fixed soon. - -### chmod(octal_mode || octal_string, file) -### chmod(symbolic_mode, file) - -Available options: - -+ `-v`: output a diagnostic for every file processed -+ `-c`: like verbose but report only when a change is made -+ `-R`: change files and directories recursively - -Examples: - -```javascript -chmod(755, '/Users/brandon'); -chmod('755', '/Users/brandon'); // same as above -chmod('u+x', '/Users/brandon'); -``` - -Alters the permissions of a file or directory by either specifying the -absolute permissions in octal form or expressing the changes in symbols. -This command tries to mimic the POSIX behavior as much as possible. -Notable exceptions: - -+ In symbolic modes, 'a-r' and '-r' are identical. No consideration is - given to the umask. -+ There is no "quiet" option since default behavior is to run silent. - -## Configuration - - -### config.silent -Example: - -```javascript -var silentState = config.silent; // save old silent state -config.silent = true; -/* ... */ -config.silent = silentState; // restore old silent state -``` - -Suppresses all command output if `true`, except for `echo()` calls. -Default is `false`. - -### config.fatal -Example: - -```javascript -config.fatal = true; -cp('this_file_does_not_exist', '/dev/null'); // dies here -/* more commands... */ -``` - -If `true` the script will die on errors. Default is `false`. - -## Non-Unix commands - - -### tempdir() -Searches and returns string containing a writeable, platform-dependent temporary directory. -Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir). - -### error() -Tests if error occurred in the last command. Returns `null` if no error occurred, -otherwise returns string explaining the error diff --git a/node_modules/shelljs/bin/shjs b/node_modules/shelljs/bin/shjs deleted file mode 100755 index d239a7ad..00000000 --- a/node_modules/shelljs/bin/shjs +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env node -require('../global'); - -if (process.argv.length < 3) { - console.log('ShellJS: missing argument (script name)'); - console.log(); - process.exit(1); -} - -var args, - scriptName = process.argv[2]; -env['NODE_PATH'] = __dirname + '/../..'; - -if (!scriptName.match(/\.js/) && !scriptName.match(/\.coffee/)) { - if (test('-f', scriptName + '.js')) - scriptName += '.js'; - if (test('-f', scriptName + '.coffee')) - scriptName += '.coffee'; -} - -if (!test('-f', scriptName)) { - console.log('ShellJS: script not found ('+scriptName+')'); - console.log(); - process.exit(1); -} - -args = process.argv.slice(3); - -for (var i = 0, l = args.length; i < l; i++) { - if (args[i][0] !== "-"){ - args[i] = '"' + args[i] + '"'; // fixes arguments with multiple words - } -} - -if (scriptName.match(/\.coffee$/)) { - // - // CoffeeScript - // - if (which('coffee')) { - exec('coffee ' + scriptName + ' ' + args.join(' '), { async: true }); - } else { - console.log('ShellJS: CoffeeScript interpreter not found'); - console.log(); - process.exit(1); - } -} else { - // - // JavaScript - // - exec('node ' + scriptName + ' ' + args.join(' '), { async: true }); -} diff --git a/node_modules/shelljs/global.js b/node_modules/shelljs/global.js deleted file mode 100644 index 97f0033c..00000000 --- a/node_modules/shelljs/global.js +++ /dev/null @@ -1,3 +0,0 @@ -var shell = require('./shell.js'); -for (var cmd in shell) - global[cmd] = shell[cmd]; diff --git a/node_modules/shelljs/jshint.json b/node_modules/shelljs/jshint.json deleted file mode 100644 index 205ed9c2..00000000 --- a/node_modules/shelljs/jshint.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "loopfunc": true, - "sub": true -} \ No newline at end of file diff --git a/node_modules/shelljs/make.js b/node_modules/shelljs/make.js deleted file mode 100644 index b636447e..00000000 --- a/node_modules/shelljs/make.js +++ /dev/null @@ -1,48 +0,0 @@ -require('./global'); -config.fatal = true; - -global.target = {}; - -// This ensures we only execute the script targets after the entire script has -// been evaluated -var args = process.argv.slice(2); -setTimeout(function() { - var t; - - if (args.length === 1 && args[0] === '--help') { - console.log('Available targets:'); - for (t in target) - console.log(' ' + t); - return; - } - - // Wrap targets to prevent duplicate execution - for (t in target) { - (function(t, oldTarget){ - - // Wrap it - target[t] = function(force) { - if (oldTarget.done && !force) - return; - oldTarget.done = true; - return oldTarget.apply(oldTarget, arguments); - }; - - })(t, target[t]); - } - - // Execute desired targets - if (args.length > 0) { - args.forEach(function(arg) { - if (arg in target) - target[arg](); - else { - console.log('no such target: ' + arg); - exit(1); - } - }); - } else if ('all' in target) { - target.all(); - } - -}, 0); diff --git a/node_modules/shelljs/package.json b/node_modules/shelljs/package.json deleted file mode 100644 index d5b0597a..00000000 --- a/node_modules/shelljs/package.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "name": "shelljs", - "version": "0.1.4", - "author": { - "name": "Artur Adib", - "email": "aadib@mozilla.com" - }, - "description": "Portable Unix shell commands for Node.js", - "keywords": [ - "unix", - "shell", - "makefile", - "make", - "jake", - "synchronous" - ], - "repository": { - "type": "git", - "url": "git://github.com/arturadib/shelljs.git" - }, - "homepage": "http://github.com/arturadib/shelljs", - "main": "./shell.js", - "scripts": { - "test": "node scripts/run-tests" - }, - "bin": { - "shjs": "./bin/shjs" - }, - "dependencies": {}, - "devDependencies": { - "jshint": "~1.1.0" - }, - "optionalDependencies": {}, - "engines": { - "node": "*" - }, - "readme": "# ShellJS - Unix shell commands for Node.js [![Build Status](https://secure.travis-ci.org/arturadib/shelljs.png)](http://travis-ci.org/arturadib/shelljs)\n\nShellJS is a portable **(Windows/Linux/OS X)** implementation of Unix shell commands on top of the Node.js API. You can use it to eliminate your shell script's dependency on Unix while still keeping its familiar and powerful commands. You can also install it globally so you can run it from outside Node projects - say goodbye to those gnarly Bash scripts!\n\nThe project is [unit-tested](http://travis-ci.org/arturadib/shelljs) and battled-tested in projects like:\n\n+ [PDF.js](http://github.com/mozilla/pdf.js) - Firefox's next-gen PDF reader\n+ [Firebug](http://getfirebug.com/) - Firefox's infamous debugger\n+ [JSHint](http://jshint.com) - Most popular JavaScript linter\n+ [Zepto](http://zeptojs.com) - jQuery-compatible JavaScript library for modern browsers\n+ [Yeoman](http://yeoman.io/) - Web application stack and development tool\n+ [Deployd.com](http://deployd.com) - Open source PaaS for quick API backend generation\n\nand [many more](https://npmjs.org/browse/depended/shelljs).\n\n## Installing\n\nVia npm:\n\n```bash\n$ npm install [-g] shelljs\n```\n\nIf the global option `-g` is specified, the binary `shjs` will be installed. This makes it possible to\nrun ShellJS scripts much like any shell script from the command line, i.e. without requiring a `node_modules` folder:\n\n```bash\n$ shjs my_script\n```\n\nYou can also just copy `shell.js` into your project's directory, and `require()` accordingly.\n\n\n## Examples\n\n### JavaScript\n\n```javascript\nrequire('shelljs/global');\n\nif (!which('git')) {\n echo('Sorry, this script requires git');\n exit(1);\n}\n\n// Copy files to release dir\nmkdir('-p', 'out/Release');\ncp('-R', 'stuff/*', 'out/Release');\n\n// Replace macros in each .js file\ncd('lib');\nls('*.js').forEach(function(file) {\n sed('-i', 'BUILD_VERSION', 'v0.1.2', file);\n sed('-i', /.*REMOVE_THIS_LINE.*\\n/, '', file);\n sed('-i', /.*REPLACE_LINE_WITH_MACRO.*\\n/, cat('macro.js'), file);\n});\ncd('..');\n\n// Run external tool synchronously\nif (exec('git commit -am \"Auto-commit\"').code !== 0) {\n echo('Error: Git commit failed');\n exit(1);\n}\n```\n\n### CoffeeScript\n\n```coffeescript\nrequire 'shelljs/global'\n\nif not which 'git'\n echo 'Sorry, this script requires git'\n exit 1\n\n# Copy files to release dir\nmkdir '-p', 'out/Release'\ncp '-R', 'stuff/*', 'out/Release'\n\n# Replace macros in each .js file\ncd 'lib'\nfor file in ls '*.js'\n sed '-i', 'BUILD_VERSION', 'v0.1.2', file\n sed '-i', /.*REMOVE_THIS_LINE.*\\n/, '', file\n sed '-i', /.*REPLACE_LINE_WITH_MACRO.*\\n/, cat 'macro.js', file\ncd '..'\n\n# Run external tool synchronously\nif (exec 'git commit -am \"Auto-commit\"').code != 0\n echo 'Error: Git commit failed'\n exit 1\n```\n\n## Global vs. Local\n\nThe example above uses the convenience script `shelljs/global` to reduce verbosity. If polluting your global namespace is not desirable, simply require `shelljs`.\n\nExample:\n\n```javascript\nvar shell = require('shelljs');\nshell.echo('hello world');\n```\n\n## Make tool\n\nA convenience script `shelljs/make` is also provided to mimic the behavior of a Unix Makefile. In this case all shell objects are global, and command line arguments will cause the script to execute only the corresponding function in the global `target` object. To avoid redundant calls, target functions are executed only once per script.\n\nExample (CoffeeScript):\n\n```coffeescript\nrequire 'shelljs/make'\n\ntarget.all = ->\n target.bundle()\n target.docs()\n\ntarget.bundle = ->\n cd __dirname\n mkdir 'build'\n cd 'lib'\n (cat '*.js').to '../build/output.js'\n\ntarget.docs = ->\n cd __dirname\n mkdir 'docs'\n cd 'lib'\n for file in ls '*.js'\n text = grep '//@', file # extract special comments\n text.replace '//@', '' # remove comment tags\n text.to 'docs/my_docs.md'\n```\n\nTo run the target `all`, call the above script without arguments: `$ node make`. To run the target `docs`: `$ node make docs`, and so on.\n\n\n\n\n\n\n## Command reference\n\n\nAll commands run synchronously, unless otherwise stated.\n\n\n### cd('dir')\nChanges to directory `dir` for the duration of the script\n\n### pwd()\nReturns the current directory.\n\n### ls([options ,] path [,path ...])\n### ls([options ,] path_array)\nAvailable options:\n\n+ `-R`: recursive\n+ `-A`: all files (include files beginning with `.`, except for `.` and `..`)\n\nExamples:\n\n```javascript\nls('projs/*.js');\nls('-R', '/users/me', '/tmp');\nls('-R', ['/users/me', '/tmp']); // same as above\n```\n\nReturns array of files in the given path, or in current directory if no path provided.\n\n### find(path [,path ...])\n### find(path_array)\nExamples:\n\n```javascript\nfind('src', 'lib');\nfind(['src', 'lib']); // same as above\nfind('.').filter(function(file) { return file.match(/\\.js$/); });\n```\n\nReturns array of all files (however deep) in the given paths.\n\nThe main difference from `ls('-R', path)` is that the resulting file names\ninclude the base directories, e.g. `lib/resources/file1` instead of just `file1`.\n\n### cp([options ,] source [,source ...], dest)\n### cp([options ,] source_array, dest)\nAvailable options:\n\n+ `-f`: force\n+ `-r, -R`: recursive\n\nExamples:\n\n```javascript\ncp('file1', 'dir1');\ncp('-Rf', '/tmp/*', '/usr/local/*', '/home/tmp');\ncp('-Rf', ['/tmp/*', '/usr/local/*'], '/home/tmp'); // same as above\n```\n\nCopies files. The wildcard `*` is accepted.\n\n### rm([options ,] file [, file ...])\n### rm([options ,] file_array)\nAvailable options:\n\n+ `-f`: force\n+ `-r, -R`: recursive\n\nExamples:\n\n```javascript\nrm('-rf', '/tmp/*');\nrm('some_file.txt', 'another_file.txt');\nrm(['some_file.txt', 'another_file.txt']); // same as above\n```\n\nRemoves files. The wildcard `*` is accepted.\n\n### mv(source [, source ...], dest')\n### mv(source_array, dest')\nAvailable options:\n\n+ `f`: force\n\nExamples:\n\n```javascript\nmv('-f', 'file', 'dir/');\nmv('file1', 'file2', 'dir/');\nmv(['file1', 'file2'], 'dir/'); // same as above\n```\n\nMoves files. The wildcard `*` is accepted.\n\n### mkdir([options ,] dir [, dir ...])\n### mkdir([options ,] dir_array)\nAvailable options:\n\n+ `p`: full path (will create intermediate dirs if necessary)\n\nExamples:\n\n```javascript\nmkdir('-p', '/tmp/a/b/c/d', '/tmp/e/f/g');\nmkdir('-p', ['/tmp/a/b/c/d', '/tmp/e/f/g']); // same as above\n```\n\nCreates directories.\n\n### test(expression)\nAvailable expression primaries:\n\n+ `'-b', 'path'`: true if path is a block device\n+ `'-c', 'path'`: true if path is a character device\n+ `'-d', 'path'`: true if path is a directory\n+ `'-e', 'path'`: true if path exists\n+ `'-f', 'path'`: true if path is a regular file\n+ `'-L', 'path'`: true if path is a symboilc link\n+ `'-p', 'path'`: true if path is a pipe (FIFO)\n+ `'-S', 'path'`: true if path is a socket\n\nExamples:\n\n```javascript\nif (test('-d', path)) { /* do something with dir */ };\nif (!test('-f', path)) continue; // skip if it's a regular file\n```\n\nEvaluates expression using the available primaries and returns corresponding value.\n\n### cat(file [, file ...])\n### cat(file_array)\n\nExamples:\n\n```javascript\nvar str = cat('file*.txt');\nvar str = cat('file1', 'file2');\nvar str = cat(['file1', 'file2']); // same as above\n```\n\nReturns a string containing the given file, or a concatenated string\ncontaining the files if more than one file is given (a new line character is\nintroduced between each file). Wildcard `*` accepted.\n\n### 'string'.to(file)\n\nExamples:\n\n```javascript\ncat('input.txt').to('output.txt');\n```\n\nAnalogous to the redirection operator `>` in Unix, but works with JavaScript strings (such as\nthose returned by `cat`, `grep`, etc). _Like Unix redirections, `to()` will overwrite any existing file!_\n\n### sed([options ,] search_regex, replace_str, file)\nAvailable options:\n\n+ `-i`: Replace contents of 'file' in-place. _Note that no backups will be created!_\n\nExamples:\n\n```javascript\nsed('-i', 'PROGRAM_VERSION', 'v0.1.3', 'source.js');\nsed(/.*DELETE_THIS_LINE.*\\n/, '', 'source.js');\n```\n\nReads an input string from `file` and performs a JavaScript `replace()` on the input\nusing the given search regex and replacement string. Returns the new string after replacement.\n\n### grep([options ,] regex_filter, file [, file ...])\n### grep([options ,] regex_filter, file_array)\nAvailable options:\n\n+ `-v`: Inverse the sense of the regex and print the lines not matching the criteria.\n\nExamples:\n\n```javascript\ngrep('-v', 'GLOBAL_VARIABLE', '*.js');\ngrep('GLOBAL_VARIABLE', '*.js');\n```\n\nReads input string from given files and returns a string containing all lines of the\nfile that match the given `regex_filter`. Wildcard `*` accepted.\n\n### which(command)\n\nExamples:\n\n```javascript\nvar nodeExec = which('node');\n```\n\nSearches for `command` in the system's PATH. On Windows looks for `.exe`, `.cmd`, and `.bat` extensions.\nReturns string containing the absolute path to the command.\n\n### echo(string [,string ...])\n\nExamples:\n\n```javascript\necho('hello world');\nvar str = echo('hello world');\n```\n\nPrints string to stdout, and returns string with additional utility methods\nlike `.to()`.\n\n### dirs([options | '+N' | '-N'])\n\nAvailable options:\n\n+ `-c`: Clears the directory stack by deleting all of the elements.\n\nArguments:\n\n+ `+N`: Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero.\n+ `-N`: Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero.\n\nDisplay the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified.\n\nSee also: pushd, popd\n\n### pushd([options,] [dir | '-N' | '+N'])\n\nAvailable options:\n\n+ `-n`: Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated.\n\nArguments:\n\n+ `dir`: Makes the current working directory be the top of the stack, and then executes the equivalent of `cd dir`.\n+ `+N`: Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.\n+ `-N`: Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack.\n\nExamples:\n\n```javascript\n// process.cwd() === '/usr'\npushd('/etc'); // Returns /etc /usr\npushd('+1'); // Returns /usr /etc\n```\n\nSave the current directory on the top of the directory stack and then cd to `dir`. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack.\n\n### popd([options,] ['-N' | '+N'])\n\nAvailable options:\n\n+ `-n`: Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated.\n\nArguments:\n\n+ `+N`: Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero.\n+ `-N`: Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero.\n\nExamples:\n\n```javascript\necho(process.cwd()); // '/usr'\npushd('/etc'); // '/etc /usr'\necho(process.cwd()); // '/etc'\npopd(); // '/usr'\necho(process.cwd()); // '/usr'\n```\n\nWhen no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack.\n\n### exit(code)\nExits the current process with the given exit code.\n\n### env['VAR_NAME']\nObject containing environment variables (both getter and setter). Shortcut to process.env.\n\n### exec(command [, options] [, callback])\nAvailable options (all `false` by default):\n\n+ `async`: Asynchronous execution. Defaults to true if a callback is provided.\n+ `silent`: Do not echo program output to console.\n\nExamples:\n\n```javascript\nvar version = exec('node --version', {silent:true}).output;\n\nvar child = exec('some_long_running_process', {async:true});\nchild.stdout.on('data', function(data) {\n /* ... do something with data ... */\n});\n\nexec('some_long_running_process', function(code, output) {\n console.log('Exit code:', code);\n console.log('Program output:', output);\n});\n```\n\nExecutes the given `command` _synchronously_, unless otherwise specified.\nWhen in synchronous mode returns the object `{ code:..., output:... }`, containing the program's\n`output` (stdout + stderr) and its exit `code`. Otherwise returns the child process object, and\nthe `callback` gets the arguments `(code, output)`.\n\n**Note:** For long-lived processes, it's best to run `exec()` asynchronously as\nthe current synchronous implementation uses a lot of CPU. This should be getting\nfixed soon.\n\n### chmod(octal_mode || octal_string, file)\n### chmod(symbolic_mode, file)\n\nAvailable options:\n\n+ `-v`: output a diagnostic for every file processed\n+ `-c`: like verbose but report only when a change is made\n+ `-R`: change files and directories recursively\n\nExamples:\n\n```javascript\nchmod(755, '/Users/brandon');\nchmod('755', '/Users/brandon'); // same as above \nchmod('u+x', '/Users/brandon');\n```\n\nAlters the permissions of a file or directory by either specifying the\nabsolute permissions in octal form or expressing the changes in symbols.\nThis command tries to mimic the POSIX behavior as much as possible.\nNotable exceptions:\n\n+ In symbolic modes, 'a-r' and '-r' are identical. No consideration is\n given to the umask.\n+ There is no \"quiet\" option since default behavior is to run silent.\n\n## Configuration\n\n\n### config.silent\nExample:\n\n```javascript\nvar silentState = config.silent; // save old silent state\nconfig.silent = true;\n/* ... */\nconfig.silent = silentState; // restore old silent state\n```\n\nSuppresses all command output if `true`, except for `echo()` calls.\nDefault is `false`.\n\n### config.fatal\nExample:\n\n```javascript\nconfig.fatal = true;\ncp('this_file_does_not_exist', '/dev/null'); // dies here\n/* more commands... */\n```\n\nIf `true` the script will die on errors. Default is `false`.\n\n## Non-Unix commands\n\n\n### tempdir()\nSearches and returns string containing a writeable, platform-dependent temporary directory.\nFollows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir).\n\n### error()\nTests if error occurred in the last command. Returns `null` if no error occurred,\notherwise returns string explaining the error\n", - "readmeFilename": "README.md", - "_id": "shelljs@0.1.4", - "dist": { - "shasum": "a399e144823d69e91f5dc48c52a58a2fe5ea45d4" - }, - "_from": "shelljs@", - "_resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.1.4.tgz" -} diff --git a/node_modules/shelljs/scripts/docs.js b/node_modules/shelljs/scripts/docs.js deleted file mode 100755 index 68a2138e..00000000 --- a/node_modules/shelljs/scripts/docs.js +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env node -require('../global'); - -echo('Appending docs to README.md'); - -cd(__dirname + '/..'); - -// Extract docs from shell.js -var docs = grep('//@', 'shell.js'); -// Remove '//@' -docs = docs.replace(/\/\/\@ ?/g, ''); -// Append docs to README -sed('-i', /## Command reference(.|\n)*/, '## Command reference\n\n' + docs, 'README.md'); - -echo('All done.'); diff --git a/node_modules/shelljs/scripts/run-tests.js b/node_modules/shelljs/scripts/run-tests.js deleted file mode 100755 index a9d32fca..00000000 --- a/node_modules/shelljs/scripts/run-tests.js +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env node -require('../global'); - -var path = require('path'); - -var failed = false; - -// -// Lint -// -JSHINT_BIN = './node_modules/jshint/bin/jshint'; -cd(__dirname + '/..'); - -if (!test('-f', JSHINT_BIN)) { - echo('JSHint not found. Run `npm install` in the root dir first.'); - exit(1); -} - -if (exec(JSHINT_BIN + ' --config jshint.json *.js test/*.js').code !== 0) { - failed = true; - echo('*** JSHINT FAILED! (return code != 0)'); - echo(); -} else { - echo('All JSHint tests passed'); - echo(); -} - -// -// Unit tests -// -cd(__dirname + '/../test'); -ls('*.js').forEach(function(file) { - echo('Running test:', file); - if (exec('node ' + file).code !== 123) { // 123 avoids false positives (e.g. premature exit) - failed = true; - echo('*** TEST FAILED! (missing exit code "123")'); - echo(); - } -}); - -if (failed) { - echo(); - echo('*******************************************************'); - echo('WARNING: Some tests did not pass!'); - echo('*******************************************************'); - exit(1); -} else { - echo(); - echo('All tests passed.'); -} diff --git a/node_modules/shelljs/shell.js b/node_modules/shelljs/shell.js deleted file mode 100644 index 7a4f4c8a..00000000 --- a/node_modules/shelljs/shell.js +++ /dev/null @@ -1,1901 +0,0 @@ -// -// ShellJS -// Unix shell commands on top of Node's API -// -// Copyright (c) 2012 Artur Adib -// http://github.com/arturadib/shelljs -// - -var fs = require('fs'), - path = require('path'), - util = require('util'), - vm = require('vm'), - child = require('child_process'), - os = require('os'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -var config = { - silent: false, - fatal: false -}; - -var state = { - error: null, - currentCmd: 'shell.js', - tempDir: null - }, - platform = os.type().match(/^Win/) ? 'win' : 'unix'; - - -//@ -//@ All commands run synchronously, unless otherwise stated. -//@ - - -//@ -//@ ### cd('dir') -//@ Changes to directory `dir` for the duration of the script -function _cd(options, dir) { - if (!dir) - error('directory not specified'); - - if (!fs.existsSync(dir)) - error('no such file or directory: ' + dir); - - if (!fs.statSync(dir).isDirectory()) - error('not a directory: ' + dir); - - process.chdir(dir); -} -exports.cd = wrap('cd', _cd); - -//@ -//@ ### pwd() -//@ Returns the current directory. -function _pwd(options) { - var pwd = path.resolve(process.cwd()); - return ShellString(pwd); -} -exports.pwd = wrap('pwd', _pwd); - - -//@ -//@ ### ls([options ,] path [,path ...]) -//@ ### ls([options ,] path_array) -//@ Available options: -//@ -//@ + `-R`: recursive -//@ + `-A`: all files (include files beginning with `.`, except for `.` and `..`) -//@ -//@ Examples: -//@ -//@ ```javascript -//@ ls('projs/*.js'); -//@ ls('-R', '/users/me', '/tmp'); -//@ ls('-R', ['/users/me', '/tmp']); // same as above -//@ ``` -//@ -//@ Returns array of files in the given path, or in current directory if no path provided. -function _ls(options, paths) { - options = parseOptions(options, { - 'R': 'recursive', - 'A': 'all', - 'a': 'all_deprecated' - }); - - if (options.all_deprecated) { - // We won't support the -a option as it's hard to image why it's useful - // (it includes '.' and '..' in addition to '.*' files) - // For backwards compatibility we'll dump a deprecated message and proceed as before - log('ls: Option -a is deprecated. Use -A instead'); - options.all = true; - } - - if (!paths) - paths = ['.']; - else if (typeof paths === 'object') - paths = paths; // assume array - else if (typeof paths === 'string') - paths = [].slice.call(arguments, 1); - - var list = []; - - // Conditionally pushes file to list - returns true if pushed, false otherwise - // (e.g. prevents hidden files to be included unless explicitly told so) - function pushFile(file, query) { - // hidden file? - if (path.basename(file)[0] === '.') { - // not explicitly asking for hidden files? - if (!options.all && !(path.basename(query)[0] === '.' && path.basename(query).length > 1)) - return false; - } - - if (platform === 'win') - file = file.replace(/\\/g, '/'); - - list.push(file); - return true; - } - - paths.forEach(function(p) { - if (fs.existsSync(p)) { - var stats = fs.statSync(p); - // Simple file? - if (stats.isFile()) { - pushFile(p, p); - return; // continue - } - - // Simple dir? - if (stats.isDirectory()) { - // Iterate over p contents - fs.readdirSync(p).forEach(function(file) { - if (!pushFile(file, p)) - return; - - // Recursive? - if (options.recursive) { - var oldDir = _pwd(); - _cd('', p); - if (fs.statSync(file).isDirectory()) - list = list.concat(_ls('-R'+(options.all?'A':''), file+'/*')); - _cd('', oldDir); - } - }); - return; // continue - } - } - - // p does not exist - possible wildcard present - - var basename = path.basename(p); - var dirname = path.dirname(p); - // Wildcard present on an existing dir? (e.g. '/tmp/*.js') - if (basename.search(/\*/) > -1 && fs.existsSync(dirname) && fs.statSync(dirname).isDirectory) { - // Escape special regular expression chars - var regexp = basename.replace(/(\^|\$|\(|\)|<|>|\[|\]|\{|\}|\.|\+|\?)/g, '\\$1'); - // Translates wildcard into regex - regexp = '^' + regexp.replace(/\*/g, '.*') + '$'; - // Iterate over directory contents - fs.readdirSync(dirname).forEach(function(file) { - if (file.match(new RegExp(regexp))) { - if (!pushFile(path.normalize(dirname+'/'+file), basename)) - return; - - // Recursive? - if (options.recursive) { - var pp = dirname + '/' + file; - if (fs.lstatSync(pp).isDirectory()) - list = list.concat(_ls('-R'+(options.all?'A':''), pp+'/*')); - } // recursive - } // if file matches - }); // forEach - return; - } - - error('no such file or directory: ' + p, true); - }); - - return list; -} -exports.ls = wrap('ls', _ls); - - -//@ -//@ ### find(path [,path ...]) -//@ ### find(path_array) -//@ Examples: -//@ -//@ ```javascript -//@ find('src', 'lib'); -//@ find(['src', 'lib']); // same as above -//@ find('.').filter(function(file) { return file.match(/\.js$/); }); -//@ ``` -//@ -//@ Returns array of all files (however deep) in the given paths. -//@ -//@ The main difference from `ls('-R', path)` is that the resulting file names -//@ include the base directories, e.g. `lib/resources/file1` instead of just `file1`. -function _find(options, paths) { - if (!paths) - error('no path specified'); - else if (typeof paths === 'object') - paths = paths; // assume array - else if (typeof paths === 'string') - paths = [].slice.call(arguments, 1); - - var list = []; - - function pushFile(file) { - if (platform === 'win') - file = file.replace(/\\/g, '/'); - list.push(file); - } - - // why not simply do ls('-R', paths)? because the output wouldn't give the base dirs - // to get the base dir in the output, we need instead ls('-R', 'dir/*') for every directory - - paths.forEach(function(file) { - pushFile(file); - - if (fs.statSync(file).isDirectory()) { - _ls('-RA', file+'/*').forEach(function(subfile) { - pushFile(subfile); - }); - } - }); - - return list; -} -exports.find = wrap('find', _find); - - -//@ -//@ ### cp([options ,] source [,source ...], dest) -//@ ### cp([options ,] source_array, dest) -//@ Available options: -//@ -//@ + `-f`: force -//@ + `-r, -R`: recursive -//@ -//@ Examples: -//@ -//@ ```javascript -//@ cp('file1', 'dir1'); -//@ cp('-Rf', '/tmp/*', '/usr/local/*', '/home/tmp'); -//@ cp('-Rf', ['/tmp/*', '/usr/local/*'], '/home/tmp'); // same as above -//@ ``` -//@ -//@ Copies files. The wildcard `*` is accepted. -function _cp(options, sources, dest) { - options = parseOptions(options, { - 'f': 'force', - 'R': 'recursive', - 'r': 'recursive' - }); - - // Get sources, dest - if (arguments.length < 3) { - error('missing and/or '); - } else if (arguments.length > 3) { - sources = [].slice.call(arguments, 1, arguments.length - 1); - dest = arguments[arguments.length - 1]; - } else if (typeof sources === 'string') { - sources = [sources]; - } else if ('length' in sources) { - sources = sources; // no-op for array - } else { - error('invalid arguments'); - } - - var exists = fs.existsSync(dest), - stats = exists && fs.statSync(dest); - - // Dest is not existing dir, but multiple sources given - if ((!exists || !stats.isDirectory()) && sources.length > 1) - error('dest is not a directory (too many sources)'); - - // Dest is an existing file, but no -f given - if (exists && stats.isFile() && !options.force) - error('dest file already exists: ' + dest); - - if (options.recursive) { - // Recursive allows the shortcut syntax "sourcedir/" for "sourcedir/*" - // (see Github issue #15) - sources.forEach(function(src, i) { - if (src[src.length - 1] === '/') - sources[i] += '*'; - }); - - // Create dest - try { - fs.mkdirSync(dest, parseInt('0777', 8)); - } catch (e) { - // like Unix's cp, keep going even if we can't create dest dir - } - } - - sources = expand(sources); - - sources.forEach(function(src) { - if (!fs.existsSync(src)) { - error('no such file or directory: '+src, true); - return; // skip file - } - - // If here, src exists - if (fs.statSync(src).isDirectory()) { - if (!options.recursive) { - // Non-Recursive - log(src + ' is a directory (not copied)'); - } else { - // Recursive - // 'cp /a/source dest' should create 'source' in 'dest' - var newDest = path.join(dest, path.basename(src)), - checkDir = fs.statSync(src); - try { - fs.mkdirSync(newDest, checkDir.mode); - } catch (e) { - //if the directory already exists, that's okay - if (e.code !== 'EEXIST') throw e; - } - - cpdirSyncRecursive(src, newDest, {force: options.force}); - } - return; // done with dir - } - - // If here, src is a file - - // When copying to '/path/dir': - // thisDest = '/path/dir/file1' - var thisDest = dest; - if (fs.existsSync(dest) && fs.statSync(dest).isDirectory()) - thisDest = path.normalize(dest + '/' + path.basename(src)); - - if (fs.existsSync(thisDest) && !options.force) { - error('dest file already exists: ' + thisDest, true); - return; // skip file - } - - copyFileSync(src, thisDest); - }); // forEach(src) -} -exports.cp = wrap('cp', _cp); - -//@ -//@ ### rm([options ,] file [, file ...]) -//@ ### rm([options ,] file_array) -//@ Available options: -//@ -//@ + `-f`: force -//@ + `-r, -R`: recursive -//@ -//@ Examples: -//@ -//@ ```javascript -//@ rm('-rf', '/tmp/*'); -//@ rm('some_file.txt', 'another_file.txt'); -//@ rm(['some_file.txt', 'another_file.txt']); // same as above -//@ ``` -//@ -//@ Removes files. The wildcard `*` is accepted. -function _rm(options, files) { - options = parseOptions(options, { - 'f': 'force', - 'r': 'recursive', - 'R': 'recursive' - }); - if (!files) - error('no paths given'); - - if (typeof files === 'string') - files = [].slice.call(arguments, 1); - // if it's array leave it as it is - - files = expand(files); - - files.forEach(function(file) { - if (!fs.existsSync(file)) { - // Path does not exist, no force flag given - if (!options.force) - error('no such file or directory: '+file, true); - - return; // skip file - } - - // If here, path exists - - var stats = fs.statSync(file); - // Remove simple file - if (stats.isFile()) { - - // Do not check for file writing permissions - if (options.force) { - _unlinkSync(file); - return; - } - - if (isWriteable(file)) - _unlinkSync(file); - else - error('permission denied: '+file, true); - - return; - } // simple file - - // Path is an existing directory, but no -r flag given - if (stats.isDirectory() && !options.recursive) { - error('path is a directory', true); - return; // skip path - } - - // Recursively remove existing directory - if (stats.isDirectory() && options.recursive) { - rmdirSyncRecursive(file, options.force); - } - }); // forEach(file) -} // rm -exports.rm = wrap('rm', _rm); - -//@ -//@ ### mv(source [, source ...], dest') -//@ ### mv(source_array, dest') -//@ Available options: -//@ -//@ + `f`: force -//@ -//@ Examples: -//@ -//@ ```javascript -//@ mv('-f', 'file', 'dir/'); -//@ mv('file1', 'file2', 'dir/'); -//@ mv(['file1', 'file2'], 'dir/'); // same as above -//@ ``` -//@ -//@ Moves files. The wildcard `*` is accepted. -function _mv(options, sources, dest) { - options = parseOptions(options, { - 'f': 'force' - }); - - // Get sources, dest - if (arguments.length < 3) { - error('missing and/or '); - } else if (arguments.length > 3) { - sources = [].slice.call(arguments, 1, arguments.length - 1); - dest = arguments[arguments.length - 1]; - } else if (typeof sources === 'string') { - sources = [sources]; - } else if ('length' in sources) { - sources = sources; // no-op for array - } else { - error('invalid arguments'); - } - - sources = expand(sources); - - var exists = fs.existsSync(dest), - stats = exists && fs.statSync(dest); - - // Dest is not existing dir, but multiple sources given - if ((!exists || !stats.isDirectory()) && sources.length > 1) - error('dest is not a directory (too many sources)'); - - // Dest is an existing file, but no -f given - if (exists && stats.isFile() && !options.force) - error('dest file already exists: ' + dest); - - sources.forEach(function(src) { - if (!fs.existsSync(src)) { - error('no such file or directory: '+src, true); - return; // skip file - } - - // If here, src exists - - // When copying to '/path/dir': - // thisDest = '/path/dir/file1' - var thisDest = dest; - if (fs.existsSync(dest) && fs.statSync(dest).isDirectory()) - thisDest = path.normalize(dest + '/' + path.basename(src)); - - if (fs.existsSync(thisDest) && !options.force) { - error('dest file already exists: ' + thisDest, true); - return; // skip file - } - - if (path.resolve(src) === path.dirname(path.resolve(thisDest))) { - error('cannot move to self: '+src, true); - return; // skip file - } - - fs.renameSync(src, thisDest); - }); // forEach(src) -} // mv -exports.mv = wrap('mv', _mv); - -//@ -//@ ### mkdir([options ,] dir [, dir ...]) -//@ ### mkdir([options ,] dir_array) -//@ Available options: -//@ -//@ + `p`: full path (will create intermediate dirs if necessary) -//@ -//@ Examples: -//@ -//@ ```javascript -//@ mkdir('-p', '/tmp/a/b/c/d', '/tmp/e/f/g'); -//@ mkdir('-p', ['/tmp/a/b/c/d', '/tmp/e/f/g']); // same as above -//@ ``` -//@ -//@ Creates directories. -function _mkdir(options, dirs) { - options = parseOptions(options, { - 'p': 'fullpath' - }); - if (!dirs) - error('no paths given'); - - if (typeof dirs === 'string') - dirs = [].slice.call(arguments, 1); - // if it's array leave it as it is - - dirs.forEach(function(dir) { - if (fs.existsSync(dir)) { - if (!options.fullpath) - error('path already exists: ' + dir, true); - return; // skip dir - } - - // Base dir does not exist, and no -p option given - var baseDir = path.dirname(dir); - if (!fs.existsSync(baseDir) && !options.fullpath) { - error('no such file or directory: ' + baseDir, true); - return; // skip dir - } - - if (options.fullpath) - mkdirSyncRecursive(dir); - else - fs.mkdirSync(dir, parseInt('0777', 8)); - }); -} // mkdir -exports.mkdir = wrap('mkdir', _mkdir); - -//@ -//@ ### test(expression) -//@ Available expression primaries: -//@ -//@ + `'-b', 'path'`: true if path is a block device -//@ + `'-c', 'path'`: true if path is a character device -//@ + `'-d', 'path'`: true if path is a directory -//@ + `'-e', 'path'`: true if path exists -//@ + `'-f', 'path'`: true if path is a regular file -//@ + `'-L', 'path'`: true if path is a symboilc link -//@ + `'-p', 'path'`: true if path is a pipe (FIFO) -//@ + `'-S', 'path'`: true if path is a socket -//@ -//@ Examples: -//@ -//@ ```javascript -//@ if (test('-d', path)) { /* do something with dir */ }; -//@ if (!test('-f', path)) continue; // skip if it's a regular file -//@ ``` -//@ -//@ Evaluates expression using the available primaries and returns corresponding value. -function _test(options, path) { - if (!path) - error('no path given'); - - // hack - only works with unary primaries - options = parseOptions(options, { - 'b': 'block', - 'c': 'character', - 'd': 'directory', - 'e': 'exists', - 'f': 'file', - 'L': 'link', - 'p': 'pipe', - 'S': 'socket' - }); - - var canInterpret = false; - for (var key in options) - if (options[key] === true) { - canInterpret = true; - break; - } - - if (!canInterpret) - error('could not interpret expression'); - - if (options.link) { - try { - return fs.lstatSync(path).isSymbolicLink(); - } catch(e) { - return false; - } - } - - if (!fs.existsSync(path)) - return false; - - if (options.exists) - return true; - - var stats = fs.statSync(path); - - if (options.block) - return stats.isBlockDevice(); - - if (options.character) - return stats.isCharacterDevice(); - - if (options.directory) - return stats.isDirectory(); - - if (options.file) - return stats.isFile(); - - if (options.pipe) - return stats.isFIFO(); - - if (options.socket) - return stats.isSocket(); -} // test -exports.test = wrap('test', _test); - - -//@ -//@ ### cat(file [, file ...]) -//@ ### cat(file_array) -//@ -//@ Examples: -//@ -//@ ```javascript -//@ var str = cat('file*.txt'); -//@ var str = cat('file1', 'file2'); -//@ var str = cat(['file1', 'file2']); // same as above -//@ ``` -//@ -//@ Returns a string containing the given file, or a concatenated string -//@ containing the files if more than one file is given (a new line character is -//@ introduced between each file). Wildcard `*` accepted. -function _cat(options, files) { - var cat = ''; - - if (!files) - error('no paths given'); - - if (typeof files === 'string') - files = [].slice.call(arguments, 1); - // if it's array leave it as it is - - files = expand(files); - - files.forEach(function(file) { - if (!fs.existsSync(file)) - error('no such file or directory: ' + file); - - cat += fs.readFileSync(file, 'utf8') + '\n'; - }); - - if (cat[cat.length-1] === '\n') - cat = cat.substring(0, cat.length-1); - - return ShellString(cat); -} -exports.cat = wrap('cat', _cat); - -//@ -//@ ### 'string'.to(file) -//@ -//@ Examples: -//@ -//@ ```javascript -//@ cat('input.txt').to('output.txt'); -//@ ``` -//@ -//@ Analogous to the redirection operator `>` in Unix, but works with JavaScript strings (such as -//@ those returned by `cat`, `grep`, etc). _Like Unix redirections, `to()` will overwrite any existing file!_ -function _to(options, file) { - if (!file) - error('wrong arguments'); - - if (!fs.existsSync( path.dirname(file) )) - error('no such file or directory: ' + path.dirname(file)); - - try { - fs.writeFileSync(file, this.toString(), 'utf8'); - } catch(e) { - error('could not write to file (code '+e.code+'): '+file, true); - } -} -// In the future, when Proxies are default, we can add methods like `.to()` to primitive strings. -// For now, this is a dummy function to bookmark places we need such strings -function ShellString(str) { - return str; -} -String.prototype.to = wrap('to', _to); - -//@ -//@ ### sed([options ,] search_regex, replace_str, file) -//@ Available options: -//@ -//@ + `-i`: Replace contents of 'file' in-place. _Note that no backups will be created!_ -//@ -//@ Examples: -//@ -//@ ```javascript -//@ sed('-i', 'PROGRAM_VERSION', 'v0.1.3', 'source.js'); -//@ sed(/.*DELETE_THIS_LINE.*\n/, '', 'source.js'); -//@ ``` -//@ -//@ Reads an input string from `file` and performs a JavaScript `replace()` on the input -//@ using the given search regex and replacement string. Returns the new string after replacement. -function _sed(options, regex, replacement, file) { - options = parseOptions(options, { - 'i': 'inplace' - }); - - if (typeof replacement === 'string') - replacement = replacement; // no-op - else if (typeof replacement === 'number') - replacement = replacement.toString(); // fallback - else - error('invalid replacement string'); - - if (!file) - error('no file given'); - - if (!fs.existsSync(file)) - error('no such file or directory: ' + file); - - var result = fs.readFileSync(file, 'utf8').replace(regex, replacement); - if (options.inplace) - fs.writeFileSync(file, result, 'utf8'); - - return ShellString(result); -} -exports.sed = wrap('sed', _sed); - -//@ -//@ ### grep([options ,] regex_filter, file [, file ...]) -//@ ### grep([options ,] regex_filter, file_array) -//@ Available options: -//@ -//@ + `-v`: Inverse the sense of the regex and print the lines not matching the criteria. -//@ -//@ Examples: -//@ -//@ ```javascript -//@ grep('-v', 'GLOBAL_VARIABLE', '*.js'); -//@ grep('GLOBAL_VARIABLE', '*.js'); -//@ ``` -//@ -//@ Reads input string from given files and returns a string containing all lines of the -//@ file that match the given `regex_filter`. Wildcard `*` accepted. -function _grep(options, regex, files) { - options = parseOptions(options, { - 'v': 'inverse' - }); - - if (!files) - error('no paths given'); - - if (typeof files === 'string') - files = [].slice.call(arguments, 2); - // if it's array leave it as it is - - files = expand(files); - - var grep = ''; - files.forEach(function(file) { - if (!fs.existsSync(file)) { - error('no such file or directory: ' + file, true); - return; - } - - var contents = fs.readFileSync(file, 'utf8'), - lines = contents.split(/\r*\n/); - lines.forEach(function(line) { - var matched = line.match(regex); - if ((options.inverse && !matched) || (!options.inverse && matched)) - grep += line + '\n'; - }); - }); - - return ShellString(grep); -} -exports.grep = wrap('grep', _grep); - - -//@ -//@ ### which(command) -//@ -//@ Examples: -//@ -//@ ```javascript -//@ var nodeExec = which('node'); -//@ ``` -//@ -//@ Searches for `command` in the system's PATH. On Windows looks for `.exe`, `.cmd`, and `.bat` extensions. -//@ Returns string containing the absolute path to the command. -function _which(options, cmd) { - if (!cmd) - error('must specify command'); - - var pathEnv = process.env.path || process.env.Path || process.env.PATH, - pathArray = splitPath(pathEnv), - where = null; - - // No relative/absolute paths provided? - if (cmd.search(/\//) === -1) { - // Search for command in PATH - pathArray.forEach(function(dir) { - if (where) - return; // already found it - - var attempt = path.resolve(dir + '/' + cmd); - if (fs.existsSync(attempt)) { - where = attempt; - return; - } - - if (platform === 'win') { - var baseAttempt = attempt; - attempt = baseAttempt + '.exe'; - if (fs.existsSync(attempt)) { - where = attempt; - return; - } - attempt = baseAttempt + '.cmd'; - if (fs.existsSync(attempt)) { - where = attempt; - return; - } - attempt = baseAttempt + '.bat'; - if (fs.existsSync(attempt)) { - where = attempt; - return; - } - } // if 'win' - }); - } - - // Command not found anywhere? - if (!fs.existsSync(cmd) && !where) - return null; - - where = where || path.resolve(cmd); - - return ShellString(where); -} -exports.which = wrap('which', _which); - -//@ -//@ ### echo(string [,string ...]) -//@ -//@ Examples: -//@ -//@ ```javascript -//@ echo('hello world'); -//@ var str = echo('hello world'); -//@ ``` -//@ -//@ Prints string to stdout, and returns string with additional utility methods -//@ like `.to()`. -function _echo() { - var messages = [].slice.call(arguments, 0); - console.log.apply(this, messages); - return ShellString(messages.join(' ')); -} -exports.echo = _echo; // don't wrap() as it could parse '-options' - -// Pushd/popd/dirs internals -var _dirStack = []; - -function _isStackIndex(index) { - return (/^[\-+]\d+$/).test(index); -} - -function _parseStackIndex(index) { - if (_isStackIndex(index)) { - if (Math.abs(index) < _dirStack.length + 1) { // +1 for pwd - return (/^-/).test(index) ? Number(index) - 1 : Number(index); - } else { - error(index + ': directory stack index out of range'); - } - } else { - error(index + ': invalid number'); - } -} - -function _actualDirStack() { - return [process.cwd()].concat(_dirStack); -} - -//@ -//@ ### dirs([options | '+N' | '-N']) -//@ -//@ Available options: -//@ -//@ + `-c`: Clears the directory stack by deleting all of the elements. -//@ -//@ Arguments: -//@ -//@ + `+N`: Displays the Nth directory (counting from the left of the list printed by dirs when invoked without options), starting with zero. -//@ + `-N`: Displays the Nth directory (counting from the right of the list printed by dirs when invoked without options), starting with zero. -//@ -//@ Display the list of currently remembered directories. Returns an array of paths in the stack, or a single path if +N or -N was specified. -//@ -//@ See also: pushd, popd -function _dirs(options, index) { - if (_isStackIndex(options)) { - index = options; - options = ''; - } - - options = parseOptions(options, { - 'c' : 'clear' - }); - - if (options['clear']) { - _dirStack = []; - return _dirStack; - } - - var stack = _actualDirStack(); - - if (index) { - index = _parseStackIndex(index); - - if (index < 0) { - index = stack.length + index; - } - - log(stack[index]); - return stack[index]; - } - - log(stack.join(' ')); - - return stack; -} -exports.dirs = wrap("dirs", _dirs); - -//@ -//@ ### pushd([options,] [dir | '-N' | '+N']) -//@ -//@ Available options: -//@ -//@ + `-n`: Suppresses the normal change of directory when adding directories to the stack, so that only the stack is manipulated. -//@ -//@ Arguments: -//@ -//@ + `dir`: Makes the current working directory be the top of the stack, and then executes the equivalent of `cd dir`. -//@ + `+N`: Brings the Nth directory (counting from the left of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. -//@ + `-N`: Brings the Nth directory (counting from the right of the list printed by dirs, starting with zero) to the top of the list by rotating the stack. -//@ -//@ Examples: -//@ -//@ ```javascript -//@ // process.cwd() === '/usr' -//@ pushd('/etc'); // Returns /etc /usr -//@ pushd('+1'); // Returns /usr /etc -//@ ``` -//@ -//@ Save the current directory on the top of the directory stack and then cd to `dir`. With no arguments, pushd exchanges the top two directories. Returns an array of paths in the stack. -function _pushd(options, dir) { - if (_isStackIndex(options)) { - dir = options; - options = ''; - } - - options = parseOptions(options, { - 'n' : 'no-cd' - }); - - var dirs = _actualDirStack(); - - if (dir === '+0') { - return dirs; // +0 is a noop - } else if (!dir) { - if (dirs.length > 1) { - dirs = dirs.splice(1, 1).concat(dirs); - } else { - return error('no other directory'); - } - } else if (_isStackIndex(dir)) { - var n = _parseStackIndex(dir); - dirs = dirs.slice(n).concat(dirs.slice(0, n)); - } else { - if (options['no-cd']) { - dirs.splice(1, 0, dir); - } else { - dirs.unshift(dir); - } - } - - if (options['no-cd']) { - dirs = dirs.slice(1); - } else { - dir = path.resolve(dirs.shift()); - _cd('', dir); - } - - _dirStack = dirs; - return _dirs(''); -} -exports.pushd = wrap('pushd', _pushd); - -//@ -//@ ### popd([options,] ['-N' | '+N']) -//@ -//@ Available options: -//@ -//@ + `-n`: Suppresses the normal change of directory when removing directories from the stack, so that only the stack is manipulated. -//@ -//@ Arguments: -//@ -//@ + `+N`: Removes the Nth directory (counting from the left of the list printed by dirs), starting with zero. -//@ + `-N`: Removes the Nth directory (counting from the right of the list printed by dirs), starting with zero. -//@ -//@ Examples: -//@ -//@ ```javascript -//@ echo(process.cwd()); // '/usr' -//@ pushd('/etc'); // '/etc /usr' -//@ echo(process.cwd()); // '/etc' -//@ popd(); // '/usr' -//@ echo(process.cwd()); // '/usr' -//@ ``` -//@ -//@ When no arguments are given, popd removes the top directory from the stack and performs a cd to the new top directory. The elements are numbered from 0 starting at the first directory listed with dirs; i.e., popd is equivalent to popd +0. Returns an array of paths in the stack. -function _popd(options, index) { - if (_isStackIndex(options)) { - index = options; - options = ''; - } - - options = parseOptions(options, { - 'n' : 'no-cd' - }); - - if (!_dirStack.length) { - return error('directory stack empty'); - } - - index = _parseStackIndex(index || '+0'); - - if (options['no-cd'] || index > 0 || _dirStack.length + index === 0) { - index = index > 0 ? index - 1 : index; - _dirStack.splice(index, 1); - } else { - var dir = path.resolve(_dirStack.shift()); - _cd('', dir); - } - - return _dirs(''); -} -exports.popd = wrap("popd", _popd); - -//@ -//@ ### exit(code) -//@ Exits the current process with the given exit code. -exports.exit = process.exit; - -//@ -//@ ### env['VAR_NAME'] -//@ Object containing environment variables (both getter and setter). Shortcut to process.env. -exports.env = process.env; - -//@ -//@ ### exec(command [, options] [, callback]) -//@ Available options (all `false` by default): -//@ -//@ + `async`: Asynchronous execution. Defaults to true if a callback is provided. -//@ + `silent`: Do not echo program output to console. -//@ -//@ Examples: -//@ -//@ ```javascript -//@ var version = exec('node --version', {silent:true}).output; -//@ -//@ var child = exec('some_long_running_process', {async:true}); -//@ child.stdout.on('data', function(data) { -//@ /* ... do something with data ... */ -//@ }); -//@ -//@ exec('some_long_running_process', function(code, output) { -//@ console.log('Exit code:', code); -//@ console.log('Program output:', output); -//@ }); -//@ ``` -//@ -//@ Executes the given `command` _synchronously_, unless otherwise specified. -//@ When in synchronous mode returns the object `{ code:..., output:... }`, containing the program's -//@ `output` (stdout + stderr) and its exit `code`. Otherwise returns the child process object, and -//@ the `callback` gets the arguments `(code, output)`. -//@ -//@ **Note:** For long-lived processes, it's best to run `exec()` asynchronously as -//@ the current synchronous implementation uses a lot of CPU. This should be getting -//@ fixed soon. -function _exec(command, options, callback) { - if (!command) - error('must specify command'); - - // Callback is defined instead of options. - if (typeof options === 'function') { - callback = options; - options = { async: true }; - } - - // Callback is defined with options. - if (typeof options === 'object' && typeof callback === 'function') { - options.async = true; - } - - options = extend({ - silent: config.silent, - async: false - }, options); - - if (options.async) - return execAsync(command, options, callback); - else - return execSync(command, options); -} -exports.exec = wrap('exec', _exec, {notUnix:true}); - -var PERMS = (function (base) { - return { - OTHER_EXEC : base.EXEC, - OTHER_WRITE : base.WRITE, - OTHER_READ : base.READ, - - GROUP_EXEC : base.EXEC << 3, - GROUP_WRITE : base.WRITE << 3, - GROUP_READ : base.READ << 3, - - OWNER_EXEC : base.EXEC << 6, - OWNER_WRITE : base.WRITE << 6, - OWNER_READ : base.READ << 6, - - // Literal octal numbers are apparently not allowed in "strict" javascript. Using parseInt is - // the preferred way, else a jshint warning is thrown. - STICKY : parseInt('01000', 8), - SETGID : parseInt('02000', 8), - SETUID : parseInt('04000', 8), - - TYPE_MASK : parseInt('0770000', 8) - }; -})({ - EXEC : 1, - WRITE : 2, - READ : 4 -}); - - -//@ -//@ ### chmod(octal_mode || octal_string, file) -//@ ### chmod(symbolic_mode, file) -//@ -//@ Available options: -//@ -//@ + `-v`: output a diagnostic for every file processed//@ -//@ + `-c`: like verbose but report only when a change is made//@ -//@ + `-R`: change files and directories recursively//@ -//@ -//@ Examples: -//@ -//@ ```javascript -//@ chmod(755, '/Users/brandon'); -//@ chmod('755', '/Users/brandon'); // same as above -//@ chmod('u+x', '/Users/brandon'); -//@ ``` -//@ -//@ Alters the permissions of a file or directory by either specifying the -//@ absolute permissions in octal form or expressing the changes in symbols. -//@ This command tries to mimic the POSIX behavior as much as possible. -//@ Notable exceptions: -//@ -//@ + In symbolic modes, 'a-r' and '-r' are identical. No consideration is -//@ given to the umask. -//@ + There is no "quiet" option since default behavior is to run silent. -function _chmod(options, mode, filePattern) { - if (!filePattern) { - if (options.length > 0 && options.charAt(0) === '-') { - // Special case where the specified file permissions started with - to subtract perms, which - // get picked up by the option parser as command flags. - // If we are down by one argument and options starts with -, shift everything over. - filePattern = mode; - mode = options; - options = ''; - } - else { - error('You must specify a file.'); - } - } - - options = parseOptions(options, { - 'R': 'recursive', - 'c': 'changes', - 'v': 'verbose' - }); - - if (typeof filePattern === 'string') { - filePattern = [ filePattern ]; - } - - var files; - - if (options.recursive) { - files = []; - expand(filePattern).forEach(function addFile(expandedFile) { - var stat = fs.lstatSync(expandedFile); - - if (!stat.isSymbolicLink()) { - files.push(expandedFile); - - if (stat.isDirectory()) { // intentionally does not follow symlinks. - fs.readdirSync(expandedFile).forEach(function (child) { - addFile(expandedFile + '/' + child); - }); - } - } - }); - } - else { - files = expand(filePattern); - } - - files.forEach(function innerChmod(file) { - file = path.resolve(file); - if (!fs.existsSync(file)) { - error('File not found: ' + file); - } - - // When recursing, don't follow symlinks. - if (options.recursive && fs.lstatSync(file).isSymbolicLink()) { - return; - } - - var perms = fs.statSync(file).mode; - var type = perms & PERMS.TYPE_MASK; - - var newPerms = perms; - - if (isNaN(parseInt(mode, 8))) { - // parse options - mode.split(',').forEach(function (symbolicMode) { - /*jshint regexdash:true */ - var pattern = /([ugoa]*)([=\+-])([rwxXst]*)/i; - var matches = pattern.exec(symbolicMode); - - if (matches) { - var applyTo = matches[1]; - var operator = matches[2]; - var change = matches[3]; - - var changeOwner = applyTo.indexOf('u') != -1 || applyTo === 'a' || applyTo === ''; - var changeGroup = applyTo.indexOf('g') != -1 || applyTo === 'a' || applyTo === ''; - var changeOther = applyTo.indexOf('o') != -1 || applyTo === 'a' || applyTo === ''; - - var changeRead = change.indexOf('r') != -1; - var changeWrite = change.indexOf('w') != -1; - var changeExec = change.indexOf('x') != -1; - var changeSticky = change.indexOf('t') != -1; - var changeSetuid = change.indexOf('s') != -1; - - var mask = 0; - if (changeOwner) { - mask |= (changeRead ? PERMS.OWNER_READ : 0) + (changeWrite ? PERMS.OWNER_WRITE : 0) + (changeExec ? PERMS.OWNER_EXEC : 0) + (changeSetuid ? PERMS.SETUID : 0); - } - if (changeGroup) { - mask |= (changeRead ? PERMS.GROUP_READ : 0) + (changeWrite ? PERMS.GROUP_WRITE : 0) + (changeExec ? PERMS.GROUP_EXEC : 0) + (changeSetuid ? PERMS.SETGID : 0); - } - if (changeOther) { - mask |= (changeRead ? PERMS.OTHER_READ : 0) + (changeWrite ? PERMS.OTHER_WRITE : 0) + (changeExec ? PERMS.OTHER_EXEC : 0); - } - - // Sticky bit is special - it's not tied to user, group or other. - if (changeSticky) { - mask |= PERMS.STICKY; - } - - switch (operator) { - case '+': - newPerms |= mask; - break; - - case '-': - newPerms &= ~mask; - break; - - case '=': - newPerms = type + mask; - - // According to POSIX, when using = to explicitly set the permissions, setuid and setgid can never be cleared. - if (fs.statSync(file).isDirectory()) { - newPerms |= (PERMS.SETUID + PERMS.SETGID) & perms; - } - break; - } - - if (options.verbose) { - log(file + ' -> ' + newPerms.toString(8)); - } - - if (perms != newPerms) { - if (!options.verbose && options.changes) { - log(file + ' -> ' + newPerms.toString(8)); - } - fs.chmodSync(file, newPerms); - } - } - else { - error('Invalid symbolic mode change: ' + symbolicMode); - } - }); - } - else { - // they gave us a full number - newPerms = type + parseInt(mode, 8); - - // POSIX rules are that setuid and setgid can only be added using numeric form, but not cleared. - if (fs.statSync(file).isDirectory()) { - newPerms |= (PERMS.SETUID + PERMS.SETGID) & perms; - } - - fs.chmodSync(file, newPerms); - } - }); -} -exports.chmod = wrap('chmod', _chmod); - - -//@ -//@ ## Configuration -//@ - - - -exports.config = config; - -//@ -//@ ### config.silent -//@ Example: -//@ -//@ ```javascript -//@ var silentState = config.silent; // save old silent state -//@ config.silent = true; -//@ /* ... */ -//@ config.silent = silentState; // restore old silent state -//@ ``` -//@ -//@ Suppresses all command output if `true`, except for `echo()` calls. -//@ Default is `false`. - -//@ -//@ ### config.fatal -//@ Example: -//@ -//@ ```javascript -//@ config.fatal = true; -//@ cp('this_file_does_not_exist', '/dev/null'); // dies here -//@ /* more commands... */ -//@ ``` -//@ -//@ If `true` the script will die on errors. Default is `false`. - - - - -//@ -//@ ## Non-Unix commands -//@ - - - - - - -//@ -//@ ### tempdir() -//@ Searches and returns string containing a writeable, platform-dependent temporary directory. -//@ Follows Python's [tempfile algorithm](http://docs.python.org/library/tempfile.html#tempfile.tempdir). -exports.tempdir = wrap('tempdir', tempDir); - - -//@ -//@ ### error() -//@ Tests if error occurred in the last command. Returns `null` if no error occurred, -//@ otherwise returns string explaining the error -exports.error = function() { - return state.error; -}; - - - - - -//////////////////////////////////////////////////////////////////////////////////////////////// -// -// Auxiliary functions (internal use only) -// - -function log() { - if (!config.silent) - console.log.apply(this, arguments); -} - -function deprecate(what, msg) { - console.log('*** ShellJS.'+what+': This function is deprecated.', msg); -} - -function write(msg) { - if (!config.silent) - process.stdout.write(msg); -} - -// Shows error message. Throws unless _continue or config.fatal are true -function error(msg, _continue) { - if (state.error === null) - state.error = ''; - state.error += state.currentCmd + ': ' + msg + '\n'; - - log(state.error); - - if (config.fatal) - process.exit(1); - - if (!_continue) - throw ''; -} - -// Returns {'alice': true, 'bob': false} when passed: -// parseOptions('-a', {'a':'alice', 'b':'bob'}); -function parseOptions(str, map) { - if (!map) - error('parseOptions() internal error: no map given'); - - // All options are false by default - var options = {}; - for (var letter in map) - options[map[letter]] = false; - - if (!str) - return options; // defaults - - if (typeof str !== 'string') - error('parseOptions() internal error: wrong str'); - - // e.g. match[1] = 'Rf' for str = '-Rf' - var match = str.match(/^\-(.+)/); - if (!match) - return options; - - // e.g. chars = ['R', 'f'] - var chars = match[1].split(''); - - chars.forEach(function(c) { - if (c in map) - options[map[c]] = true; - else - error('option not recognized: '+c); - }); - - return options; -} - -// Common wrapper for all Unix-like commands -function wrap(cmd, fn, options) { - return function() { - var retValue = null; - - state.currentCmd = cmd; - state.error = null; - - try { - var args = [].slice.call(arguments, 0); - - if (options && options.notUnix) { - retValue = fn.apply(this, args); - } else { - if (args.length === 0 || typeof args[0] !== 'string' || args[0][0] !== '-') - args.unshift(''); // only add dummy option if '-option' not already present - retValue = fn.apply(this, args); - } - } catch (e) { - if (!state.error) { - // If state.error hasn't been set it's an error thrown by Node, not us - probably a bug... - console.log('shell.js: internal error'); - console.log(e.stack || e); - process.exit(1); - } - if (config.fatal) - throw e; - } - - state.currentCmd = 'shell.js'; - return retValue; - }; -} // wrap - -// Buffered file copy, synchronous -// (Using readFileSync() + writeFileSync() could easily cause a memory overflow -// with large files) -function copyFileSync(srcFile, destFile) { - if (!fs.existsSync(srcFile)) - error('copyFileSync: no such file or directory: ' + srcFile); - - var BUF_LENGTH = 64*1024, - buf = new Buffer(BUF_LENGTH), - bytesRead = BUF_LENGTH, - pos = 0, - fdr = null, - fdw = null; - - try { - fdr = fs.openSync(srcFile, 'r'); - } catch(e) { - error('copyFileSync: could not read src file ('+srcFile+')'); - } - - try { - fdw = fs.openSync(destFile, 'w'); - } catch(e) { - error('copyFileSync: could not write to dest file (code='+e.code+'):'+destFile); - } - - while (bytesRead === BUF_LENGTH) { - bytesRead = fs.readSync(fdr, buf, 0, BUF_LENGTH, pos); - fs.writeSync(fdw, buf, 0, bytesRead); - pos += bytesRead; - } - - fs.closeSync(fdr); - fs.closeSync(fdw); -} - -// Recursively copies 'sourceDir' into 'destDir' -// Adapted from https://github.com/ryanmcgrath/wrench-js -// -// Copyright (c) 2010 Ryan McGrath -// Copyright (c) 2012 Artur Adib -// -// Licensed under the MIT License -// http://www.opensource.org/licenses/mit-license.php -function cpdirSyncRecursive(sourceDir, destDir, opts) { - if (!opts) opts = {}; - - /* Create the directory where all our junk is moving to; read the mode of the source directory and mirror it */ - var checkDir = fs.statSync(sourceDir); - try { - fs.mkdirSync(destDir, checkDir.mode); - } catch (e) { - //if the directory already exists, that's okay - if (e.code !== 'EEXIST') throw e; - } - - var files = fs.readdirSync(sourceDir); - - for(var i = 0; i < files.length; i++) { - var currFile = fs.lstatSync(sourceDir + "/" + files[i]); - - if (currFile.isDirectory()) { - /* recursion this thing right on back. */ - cpdirSyncRecursive(sourceDir + "/" + files[i], destDir + "/" + files[i], opts); - } else if (currFile.isSymbolicLink()) { - var symlinkFull = fs.readlinkSync(sourceDir + "/" + files[i]); - fs.symlinkSync(symlinkFull, destDir + "/" + files[i]); - } else { - /* At this point, we've hit a file actually worth copying... so copy it on over. */ - if (fs.existsSync(destDir + "/" + files[i]) && !opts.force) { - log('skipping existing file: ' + files[i]); - } else { - copyFileSync(sourceDir + "/" + files[i], destDir + "/" + files[i]); - } - } - - } // for files -} // cpdirSyncRecursive - -// Recursively removes 'dir' -// Adapted from https://github.com/ryanmcgrath/wrench-js -// -// Copyright (c) 2010 Ryan McGrath -// Copyright (c) 2012 Artur Adib -// -// Licensed under the MIT License -// http://www.opensource.org/licenses/mit-license.php -function rmdirSyncRecursive(dir, force) { - var files; - - files = fs.readdirSync(dir); - - // Loop through and delete everything in the sub-tree after checking it - for(var i = 0; i < files.length; i++) { - var file = dir + "/" + files[i], - currFile = fs.lstatSync(file); - - if(currFile.isDirectory()) { // Recursive function back to the beginning - rmdirSyncRecursive(file, force); - } - - else if(currFile.isSymbolicLink()) { // Unlink symlinks - if (force || isWriteable(file)) { - try { - _unlinkSync(file); - } catch (e) { - error('could not remove file (code '+e.code+'): ' + file, true); - } - } - } - - else // Assume it's a file - perhaps a try/catch belongs here? - if (force || isWriteable(file)) { - try { - _unlinkSync(file); - } catch (e) { - error('could not remove file (code '+e.code+'): ' + file, true); - } - } - } - - // Now that we know everything in the sub-tree has been deleted, we can delete the main directory. - // Huzzah for the shopkeep. - - var result; - try { - result = fs.rmdirSync(dir); - } catch(e) { - error('could not remove directory (code '+e.code+'): ' + dir, true); - } - - return result; -} // rmdirSyncRecursive - -// Recursively creates 'dir' -function mkdirSyncRecursive(dir) { - var baseDir = path.dirname(dir); - - // Base dir exists, no recursion necessary - if (fs.existsSync(baseDir)) { - fs.mkdirSync(dir, parseInt('0777', 8)); - return; - } - - // Base dir does not exist, go recursive - mkdirSyncRecursive(baseDir); - - // Base dir created, can create dir - fs.mkdirSync(dir, parseInt('0777', 8)); -} - -// e.g. 'shelljs_a5f185d0443ca...' -function randomFileName() { - function randomHash(count) { - if (count === 1) - return parseInt(16*Math.random(), 10).toString(16); - else { - var hash = ''; - for (var i=0; i&1'; // works on both win/unix - - var script = - "var child = require('child_process')," + - " fs = require('fs');" + - "child.exec('"+escape(cmd)+"', {env: process.env, maxBuffer: 20*1024*1024}, function(err) {" + - " fs.writeFileSync('"+escape(codeFile)+"', err ? err.code.toString() : '0');" + - "});"; - - if (fs.existsSync(scriptFile)) _unlinkSync(scriptFile); - if (fs.existsSync(stdoutFile)) _unlinkSync(stdoutFile); - if (fs.existsSync(codeFile)) _unlinkSync(codeFile); - - fs.writeFileSync(scriptFile, script); - child.exec('"'+process.execPath+'" '+scriptFile, { - env: process.env, - cwd: exports.pwd(), - maxBuffer: 20*1024*1024 - }); - - // The wait loop - // sleepFile is used as a dummy I/O op to mitigate unnecessary CPU usage - // (tried many I/O sync ops, writeFileSync() seems to be only one that is effective in reducing - // CPU usage, though apparently not so much on Windows) - while (!fs.existsSync(codeFile)) { updateStdout(); fs.writeFileSync(sleepFile, 'a'); } - while (!fs.existsSync(stdoutFile)) { updateStdout(); fs.writeFileSync(sleepFile, 'a'); } - - // At this point codeFile exists, but it's not necessarily flushed yet. - // Keep reading it until it is. - var code = parseInt('', 10); - while (isNaN(code)) { - code = parseInt(fs.readFileSync(codeFile, 'utf8'), 10); - } - - var stdout = fs.readFileSync(stdoutFile, 'utf8'); - - // No biggie if we can't erase the files now -- they're in a temp dir anyway - try { _unlinkSync(scriptFile); } catch(e) {} - try { _unlinkSync(stdoutFile); } catch(e) {} - try { _unlinkSync(codeFile); } catch(e) {} - try { _unlinkSync(sleepFile); } catch(e) {} - - // True if successful, false if not - var obj = { - code: code, - output: stdout - }; - return obj; -} // execSync() - -// Expands wildcards with matching file names. For a given array of file names 'list', returns -// another array containing all file names as per ls(list[i]). -// For example: -// expand(['file*.js']) = ['file1.js', 'file2.js', ...] -// (if the files 'file1.js', 'file2.js', etc, exist in the current dir) -function expand(list) { - var expanded = []; - list.forEach(function(listEl) { - // Wildcard present? - if (listEl.search(/\*/) > -1) { - _ls('', listEl).forEach(function(file) { - expanded.push(file); - }); - } else { - expanded.push(listEl); - } - }); - return expanded; -} - -// Cross-platform method for splitting environment PATH variables -function splitPath(p) { - if (!p) - return []; - - if (platform === 'win') - return p.split(';'); - else - return p.split(':'); -} - -// extend(target_obj, source_obj1 [, source_obj2 ...]) -// Shallow extend, e.g.: -// extend({A:1}, {b:2}, {c:3}) returns {A:1, b:2, c:3} -function extend(target) { - var sources = [].slice.call(arguments, 1); - sources.forEach(function(source) { - for (var key in source) - target[key] = source[key]; - }); - - return target; -} - -// Normalizes _unlinkSync() across platforms to match Unix behavior, i.e. -// file can be unlinked even if it's read-only, see joyent/node#3006 -function _unlinkSync(file) { - try { - fs.unlinkSync(file); - } catch(e) { - // Try to override file permission - if (e.code === 'EPERM') { - fs.chmodSync(file, '0666'); - fs.unlinkSync(file); - } else { - throw e; - } - } -} - -// Hack to determine if file has write permissions for current user -// Avoids having to check user, group, etc, but it's probably slow -function isWriteable(file) { - var writePermission = true; - try { - var __fd = fs.openSync(file, 'a'); - fs.closeSync(__fd); - } catch(e) { - writePermission = false; - } - - return writePermission; -} diff --git a/node_modules/shelljs/test/.npmignore b/node_modules/shelljs/test/.npmignore deleted file mode 100644 index a1632ab5..00000000 --- a/node_modules/shelljs/test/.npmignore +++ /dev/null @@ -1,2 +0,0 @@ -tmp/ - diff --git a/node_modules/shelljs/test/cat.js b/node_modules/shelljs/test/cat.js deleted file mode 100644 index d0d9ddb0..00000000 --- a/node_modules/shelljs/test/cat.js +++ /dev/null @@ -1,57 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -// save current dir -var cur = shell.pwd(); - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -shell.cat(); -assert.ok(shell.error()); - -assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check -shell.cat('/adsfasdf'); // file does not exist -assert.ok(shell.error()); - -// -// Valids -// - -// simple -var result = shell.cat('resources/file1'); -assert.equal(shell.error(), null); -assert.equal(result, 'test1'); - -// multiple files -var result = shell.cat('resources/file2', 'resources/file1'); -assert.equal(shell.error(), null); -assert.equal(result, 'test2\ntest1'); - -// multiple files, array syntax -var result = shell.cat(['resources/file2', 'resources/file1']); -assert.equal(shell.error(), null); -assert.equal(result, 'test2\ntest1'); - -var result = shell.cat('resources/file*.txt'); -assert.equal(shell.error(), null); -assert.ok(result.search('test1') > -1); // file order might be random -assert.ok(result.search('test2') > -1); - -shell.exit(123); diff --git a/node_modules/shelljs/test/cd.js b/node_modules/shelljs/test/cd.js deleted file mode 100644 index e6f6c387..00000000 --- a/node_modules/shelljs/test/cd.js +++ /dev/null @@ -1,64 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -// save current dir -var cur = shell.pwd(); - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -shell.cd(); -assert.ok(shell.error()); - -assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check -shell.cd('/adsfasdf'); // dir does not exist -assert.ok(shell.error()); - -assert.equal(fs.existsSync('resources/file1'), true); // sanity check -shell.cd('resources/file1'); // file, not dir -assert.ok(shell.error()); - -// -// Valids -// - -shell.cd(cur); -shell.cd('tmp'); -assert.equal(shell.error(), null); -assert.equal(path.basename(process.cwd()), 'tmp'); - -shell.cd(cur); -shell.cd('/'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), path.resolve('/')); - -// cd + other commands - -shell.cd(cur); -shell.rm('-f', 'tmp/*'); -assert.equal(fs.existsSync('tmp/file1'), false); -shell.cd('resources'); -assert.equal(shell.error(), null); -shell.cp('file1', '../tmp'); -assert.equal(shell.error(), null); -shell.cd('../tmp'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('file1'), true); - -shell.exit(123); diff --git a/node_modules/shelljs/test/chmod.js b/node_modules/shelljs/test/chmod.js deleted file mode 100644 index b31e25e0..00000000 --- a/node_modules/shelljs/test/chmod.js +++ /dev/null @@ -1,81 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -shell.config.silent = true; - -// -// Invalids -// - -shell.chmod('blah'); // missing args -assert.ok(shell.error()); -shell.chmod('893', 'resources/chmod'); // invalid permissions - mode must be in octal -assert.ok(shell.error()); - -// -// Valids -// - -// Test files - the bitmasking is to ignore the upper bits. -shell.chmod('755', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('755', 8)); -shell.chmod('644', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8)); - -shell.chmod('o+x', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('007', 8), parseInt('005', 8)); -shell.chmod('644', 'resources/chmod/file1'); - -shell.chmod('+x', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('755', 8)); -shell.chmod('644', 'resources/chmod/file1'); - -// Test setuid -shell.chmod('u+s', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('4000', 8), parseInt('4000', 8)); -shell.chmod('u-s', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8)); - -// according to POSIX standards at http://linux.die.net/man/1/chmod, -// setuid is never cleared from a directory unless explicitly asked for. -shell.chmod('u+s', 'resources/chmod/c'); -shell.chmod('755', 'resources/chmod/c'); -assert.equal(fs.statSync('resources/chmod/c').mode & parseInt('4000', 8), parseInt('4000', 8)); -shell.chmod('u-s', 'resources/chmod/c'); - -// Test setgid -shell.chmod('g+s', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('2000', 8), parseInt('2000', 8)); -shell.chmod('g-s', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8)); - -// Test sticky bit -shell.chmod('+t', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('1000', 8), parseInt('1000', 8)); -shell.chmod('-t', 'resources/chmod/file1'); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('777', 8), parseInt('644', 8)); -assert.equal(fs.statSync('resources/chmod/file1').mode & parseInt('1000', 8), 0); - -// Test directories -shell.chmod('a-w', 'resources/chmod/b/a/b'); -assert.equal(fs.statSync('resources/chmod/b/a/b').mode & parseInt('777', 8), parseInt('555', 8)); -shell.chmod('755', 'resources/chmod/b/a/b'); - -// Test recursion -shell.chmod('-R', 'a+w', 'resources/chmod/b'); -assert.equal(fs.statSync('resources/chmod/b/a/b').mode & parseInt('777', 8), parseInt('777', 8)); -shell.chmod('-R', '755', 'resources/chmod/b'); -assert.equal(fs.statSync('resources/chmod/b/a/b').mode & parseInt('777', 8), parseInt('755', 8)); - -// Test symbolic links w/ recursion - WARNING: *nix only -fs.symlinkSync('resources/chmod/b/a', 'resources/chmod/a/b/c/link', 'dir'); -shell.chmod('-R', 'u-w', 'resources/chmod/a/b'); -assert.equal(fs.statSync('resources/chmod/a/b/c').mode & parseInt('700', 8), parseInt('500', 8)); -assert.equal(fs.statSync('resources/chmod/b/a').mode & parseInt('700', 8), parseInt('700', 8)); -shell.chmod('-R', 'u+w', 'resources/chmod/a/b'); -fs.unlinkSync('resources/chmod/a/b/c/link'); - -shell.exit(123); \ No newline at end of file diff --git a/node_modules/shelljs/test/config.js b/node_modules/shelljs/test/config.js deleted file mode 100644 index bd81ec0c..00000000 --- a/node_modules/shelljs/test/config.js +++ /dev/null @@ -1,50 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - child = require('child_process'); - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -// -// config.silent -// - -assert.equal(shell.config.silent, false); // default - -shell.config.silent = true; -assert.equal(shell.config.silent, true); - -shell.config.silent = false; -assert.equal(shell.config.silent, false); - -// -// config.fatal -// - -assert.equal(shell.config.fatal, false); // default - -// -// config.fatal = false -// -shell.mkdir('-p', 'tmp'); -var file = 'tmp/tempscript'+Math.random()+'.js', - script = 'require(\'../../global.js\'); config.silent=true; config.fatal=false; cp("this_file_doesnt_exist", "."); echo("got here");'; -script.to(file); -child.exec('node '+file, function(err, stdout, stderr) { - assert.ok(stdout.match('got here')); - - // - // config.fatal = true - // - shell.mkdir('-p', 'tmp'); - var file = 'tmp/tempscript'+Math.random()+'.js', - script = 'require(\'../../global.js\'); config.silent=true; config.fatal=true; cp("this_file_doesnt_exist", "."); echo("got here");'; - script.to(file); - child.exec('node '+file, function(err, stdout, stderr) { - assert.ok(!stdout.match('got here')); - - shell.exit(123); - }); -}); diff --git a/node_modules/shelljs/test/cp.js b/node_modules/shelljs/test/cp.js deleted file mode 100644 index 39b3ba9d..00000000 --- a/node_modules/shelljs/test/cp.js +++ /dev/null @@ -1,143 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -shell.cp(); -assert.ok(shell.error()); - -shell.cp('file1'); -assert.ok(shell.error()); - -shell.cp('-f'); -assert.ok(shell.error()); - -shell.rm('-rf', 'tmp/*'); -shell.cp('-@', 'resources/file1', 'tmp/file1'); // option not supported, files OK -assert.ok(shell.error()); -assert.equal(fs.existsSync('tmp/file1'), false); - -shell.cp('-Z', 'asdfasdf', 'tmp/file2'); // option not supported, files NOT OK -assert.ok(shell.error()); -assert.equal(fs.existsSync('tmp/file2'), false); - -shell.cp('asdfasdf', 'tmp'); // source does not exist -assert.ok(shell.error()); -assert.equal(numLines(shell.error()), 1); -assert.equal(fs.existsSync('tmp/asdfasdf'), false); - -shell.cp('asdfasdf1', 'asdfasdf2', 'tmp'); // sources do not exist -assert.ok(shell.error()); -assert.equal(numLines(shell.error()), 2); -assert.equal(fs.existsSync('tmp/asdfasdf1'), false); -assert.equal(fs.existsSync('tmp/asdfasdf2'), false); - -shell.cp('asdfasdf1', 'asdfasdf2', 'resources/file1'); // too many sources (dest is file) -assert.ok(shell.error()); - -shell.cp('resources/file1', 'resources/file2'); // dest already exists -assert.ok(shell.error()); - -shell.cp('resources/file1', 'resources/file2', 'tmp/a_file'); // too many sources -assert.ok(shell.error()); -assert.equal(fs.existsSync('tmp/a_file'), false); - -// -// Valids -// - -// simple - to dir -shell.cp('resources/file1', 'tmp'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/file1'), true); - -// simple - to file -shell.cp('resources/file2', 'tmp/file2'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/file2'), true); - -// simple - file list -shell.rm('-rf', 'tmp/*'); -shell.cp('resources/file1', 'resources/file2', 'tmp'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/file1'), true); -assert.equal(fs.existsSync('tmp/file2'), true); - -// simple - file list, array syntax -shell.rm('-rf', 'tmp/*'); -shell.cp(['resources/file1', 'resources/file2'], 'tmp'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/file1'), true); -assert.equal(fs.existsSync('tmp/file2'), true); - -shell.cp('resources/file2', 'tmp/file3'); -assert.equal(fs.existsSync('tmp/file3'), true); -shell.cp('-f', 'resources/file2', 'tmp/file3'); // file exists, but -f specified -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/file3'), true); - -// wildcard -shell.rm('tmp/file1', 'tmp/file2'); -shell.cp('resources/file*', 'tmp'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/file1'), true); -assert.equal(fs.existsSync('tmp/file2'), true); - -//recursive, nothing exists -shell.rm('-rf', 'tmp/*'); -shell.cp('-R', 'resources/cp', 'tmp'); -assert.equal(shell.error(), null); -assert.equal(shell.ls('-R', 'resources/cp') + '', shell.ls('-R', 'tmp/cp') + ''); - -//recursive, nothing exists, source ends in '/' (see Github issue #15) -shell.rm('-rf', 'tmp/*'); -shell.cp('-R', 'resources/cp/', 'tmp/'); -assert.equal(shell.error(), null); -assert.equal(shell.ls('-R', 'resources/cp') + '', shell.ls('-R', 'tmp') + ''); - -//recursive, everything exists, no force flag -shell.rm('-rf', 'tmp/*'); -shell.cp('-R', 'resources/cp', 'tmp'); -shell.cp('-R', 'resources/cp', 'tmp'); -assert.equal(shell.error(), null); // crash test only - -//recursive, everything exists, with force flag -shell.rm('-rf', 'tmp/*'); -shell.cp('-R', 'resources/cp', 'tmp'); -'changing things around'.to('tmp/cp/dir_a/z'); -assert.notEqual(shell.cat('resources/cp/dir_a/z'), shell.cat('tmp/cp/dir_a/z')); // before cp -shell.cp('-Rf', 'resources/cp', 'tmp'); -assert.equal(shell.error(), null); -assert.equal(shell.cat('resources/cp/dir_a/z'), shell.cat('tmp/cp/dir_a/z')); // after cp - -//recursive, creates dest dir since it's only one level deep (see Github issue #44) -shell.rm('-rf', 'tmp/*'); -shell.cp('-r', 'resources/issue44/*', 'tmp/dir2'); -assert.equal(shell.error(), null); -assert.equal(shell.ls('-R', 'resources/issue44') + '', shell.ls('-R', 'tmp/dir2') + ''); -assert.equal(shell.cat('resources/issue44/main.js'), shell.cat('tmp/dir2/main.js')); - -//recursive, does *not* create dest dir since it's too deep (see Github issue #44) -shell.rm('-rf', 'tmp/*'); -shell.cp('-r', 'resources/issue44/*', 'tmp/dir2/dir3'); -assert.ok(shell.error()); -assert.equal(fs.existsSync('tmp/dir2'), false); - -shell.exit(123); diff --git a/node_modules/shelljs/test/dirs.js b/node_modules/shelljs/test/dirs.js deleted file mode 100644 index e9f11e6c..00000000 --- a/node_modules/shelljs/test/dirs.js +++ /dev/null @@ -1,37 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -var root = path.resolve(); - -shell.pushd('resources/pushd'); -shell.pushd('a'); - -var trail = [ - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root -]; - -assert.deepEqual(shell.dirs(), trail); - -// Single items -assert.equal(shell.dirs('+0'), trail[0]); -assert.equal(shell.dirs('+1'), trail[1]); -assert.equal(shell.dirs('+2'), trail[2]); -assert.equal(shell.dirs('-0'), trail[2]); -assert.equal(shell.dirs('-1'), trail[1]); -assert.equal(shell.dirs('-2'), trail[0]); - -// Clearing items -assert.deepEqual(shell.dirs('-c'), []); -assert(!shell.error()); - -shell.exit(123); \ No newline at end of file diff --git a/node_modules/shelljs/test/echo.js b/node_modules/shelljs/test/echo.js deleted file mode 100644 index 82faa51b..00000000 --- a/node_modules/shelljs/test/echo.js +++ /dev/null @@ -1,50 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'), - child = require('child_process'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Valids -// - - -// From here on we use child.exec() to intercept the stdout - - -// simple test with defaults -shell.mkdir('-p', 'tmp'); -var file = 'tmp/tempscript'+Math.random()+'.js', - script = 'require(\'../../global.js\'); echo("-asdf", "111");'; // test '-' bug (see issue #20) -script.to(file); -child.exec('node '+file, function(err, stdout, stderr) { - assert.ok(stdout === '-asdf 111\n' || stdout === '-asdf 111\nundefined\n'); // 'undefined' for v0.4 - - // simple test with silent(true) - shell.mkdir('-p', 'tmp'); - var file = 'tmp/tempscript'+Math.random()+'.js', - script = 'require(\'../../global.js\'); config.silent=true; echo(555);'; - script.to(file); - child.exec('node '+file, function(err, stdout, stderr) { - assert.ok(stdout === '555\n' || stdout === '555\nundefined\n'); // 'undefined' for v0.4 - - theEnd(); - }); -}); - -function theEnd() { - shell.exit(123); -} diff --git a/node_modules/shelljs/test/env.js b/node_modules/shelljs/test/env.js deleted file mode 100644 index 0e041d6a..00000000 --- a/node_modules/shelljs/test/env.js +++ /dev/null @@ -1,19 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'); - -shell.config.silent = true; - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Valids -// - -assert.equal(shell.env['PATH'], process.env['PATH']); - -shell.env['SHELLJS_TEST'] = 'hello world'; -assert.equal(shell.env['SHELLJS_TEST'], process.env['SHELLJS_TEST']); - -shell.exit(123); diff --git a/node_modules/shelljs/test/exec.js b/node_modules/shelljs/test/exec.js deleted file mode 100644 index e7218081..00000000 --- a/node_modules/shelljs/test/exec.js +++ /dev/null @@ -1,109 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'), - util = require('util'), - child = require('child_process'); - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -// -// Invalids -// - -shell.exec(); -assert.ok(shell.error()); - -var result = shell.exec('asdfasdf'); // could not find command -assert.ok(result.code > 0); - - -// -// Valids -// - -// -// sync -// - -// check if stdout goes to output -var result = shell.exec('node -e \"console.log(1234);\"'); -assert.equal(shell.error(), null); -assert.equal(result.code, 0); -assert.ok(result.output === '1234\n' || result.output === '1234\nundefined\n'); // 'undefined' for v0.4 - -// check if stderr goes to output -var result = shell.exec('node -e \"console.error(1234);\"'); -assert.equal(shell.error(), null); -assert.equal(result.code, 0); -assert.ok(result.output === '1234\n' || result.output === '1234\nundefined\n'); // 'undefined' for v0.4 - -// check if stdout + stderr go to output -var result = shell.exec('node -e \"console.error(1234); console.log(666);\"'); -assert.equal(shell.error(), null); -assert.equal(result.code, 0); -assert.ok(result.output === '1234\n666\n' || result.output === '1234\n666\nundefined\n'); // 'undefined' for v0.4 - -// check exit code -var result = shell.exec('node -e \"process.exit(12);\"'); -assert.equal(shell.error(), null); -assert.equal(result.code, 12); - -// interaction with cd -shell.cd('resources/external'); -var result = shell.exec('node node_script.js'); -assert.equal(shell.error(), null); -assert.equal(result.code, 0); -assert.equal(result.output, 'node_script_1234\n'); -shell.cd('../..'); - -// check quotes escaping -var result = shell.exec( util.format('node -e "console.log(%s);"', "\\\"\\'+\\'_\\'+\\'\\\"") ); -assert.equal(shell.error(), null); -assert.equal(result.code, 0); -assert.equal(result.output, "'+'_'+'\n"); - -// -// async -// - -// no callback -var c = shell.exec('node -e \"console.log(1234)\"', {async:true}); -assert.equal(shell.error(), null); -assert.ok('stdout' in c, 'async exec returns child process object'); - -// -// callback as 2nd argument -// -shell.exec('node -e \"console.log(5678);\"', function(code, output) { - assert.equal(code, 0); - assert.ok(output === '5678\n' || output === '5678\nundefined\n'); // 'undefined' for v0.4 - - // - // callback as 3rd argument - // - shell.exec('node -e \"console.log(5566);\"', {async:true}, function(code, output) { - assert.equal(code, 0); - assert.ok(output === '5566\n' || output === '5566\nundefined\n'); // 'undefined' for v0.4 - - // - // callback as 3rd argument (slient:true) - // - shell.exec('node -e \"console.log(5678);\"', {silent:true}, function(code, output) { - assert.equal(code, 0); - assert.ok(output === '5678\n' || output === '5678\nundefined\n'); // 'undefined' for v0.4 - - shell.exit(123); - - }); - - }); - -}); - -assert.equal(shell.error(), null); diff --git a/node_modules/shelljs/test/find.js b/node_modules/shelljs/test/find.js deleted file mode 100644 index d375f869..00000000 --- a/node_modules/shelljs/test/find.js +++ /dev/null @@ -1,56 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -var result = shell.find(); // no paths given -assert.ok(shell.error()); - -// -// Valids -// - -// current path -shell.cd('resources/find'); -var result = shell.find('.'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('.hidden') > -1, true); -assert.equal(result.indexOf('dir1/dir11/a_dir11') > -1, true); -assert.equal(result.length, 11); -shell.cd('../..'); - -// simple path -var result = shell.find('resources/find'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('resources/find/.hidden') > -1, true); -assert.equal(result.indexOf('resources/find/dir1/dir11/a_dir11') > -1, true); -assert.equal(result.length, 11); - -// multiple paths - comma -var result = shell.find('resources/find/dir1', 'resources/find/dir2'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('resources/find/dir1/dir11/a_dir11') > -1, true); -assert.equal(result.indexOf('resources/find/dir2/a_dir1') > -1, true); -assert.equal(result.length, 6); - -// multiple paths - array -var result = shell.find(['resources/find/dir1', 'resources/find/dir2']); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('resources/find/dir1/dir11/a_dir11') > -1, true); -assert.equal(result.indexOf('resources/find/dir2/a_dir1') > -1, true); -assert.equal(result.length, 6); - -shell.exit(123); diff --git a/node_modules/shelljs/test/grep.js b/node_modules/shelljs/test/grep.js deleted file mode 100644 index 71db9820..00000000 --- a/node_modules/shelljs/test/grep.js +++ /dev/null @@ -1,59 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -shell.grep(); -assert.ok(shell.error()); - -shell.grep(/asdf/g); // too few args -assert.ok(shell.error()); - -assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check -shell.grep(/asdf/g, '/asdfasdf'); // no such file -assert.ok(shell.error()); - -// -// Valids -// - -var result = shell.grep('line', 'resources/a.txt'); -assert.equal(shell.error(), null); -assert.equal(result.split('\n').length - 1, 4); - -var result = shell.grep('-v', 'line', 'resources/a.txt'); -assert.equal(shell.error(), null); -assert.equal(result.split('\n').length - 1, 8); - -var result = shell.grep('line one', 'resources/a.txt'); -assert.equal(shell.error(), null); -assert.equal(result, 'This is line one\n'); - -// multiple files -var result = shell.grep(/test/, 'resources/file1.txt', 'resources/file2.txt'); -assert.equal(shell.error(), null); -assert.equal(result, 'test1\ntest2\n'); - -// multiple files, array syntax -var result = shell.grep(/test/, ['resources/file1.txt', 'resources/file2.txt']); -assert.equal(shell.error(), null); -assert.equal(result, 'test1\ntest2\n'); - -shell.exit(123); diff --git a/node_modules/shelljs/test/ls.js b/node_modules/shelljs/test/ls.js deleted file mode 100644 index 5067b7dd..00000000 --- a/node_modules/shelljs/test/ls.js +++ /dev/null @@ -1,202 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check -var result = shell.ls('/asdfasdf'); // no such file or dir -assert.ok(shell.error()); -assert.equal(result.length, 0); - -// -// Valids -// - -var result = shell.ls(); -assert.equal(shell.error(), null); - -var result = shell.ls('/'); -assert.equal(shell.error(), null); - -// no args -shell.cd('resources/ls'); -var result = shell.ls(); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('file1') > -1, true); -assert.equal(result.indexOf('file2') > -1, true); -assert.equal(result.indexOf('file1.js') > -1, true); -assert.equal(result.indexOf('file2.js') > -1, true); -assert.equal(result.indexOf('filename(with)[chars$]^that.must+be-escaped') > -1, true); -assert.equal(result.indexOf('a_dir') > -1, true); -assert.equal(result.length, 6); -shell.cd('../..'); - -// simple arg -var result = shell.ls('resources/ls'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('file1') > -1, true); -assert.equal(result.indexOf('file2') > -1, true); -assert.equal(result.indexOf('file1.js') > -1, true); -assert.equal(result.indexOf('file2.js') > -1, true); -assert.equal(result.indexOf('filename(with)[chars$]^that.must+be-escaped') > -1, true); -assert.equal(result.indexOf('a_dir') > -1, true); -assert.equal(result.length, 6); - -// no args, 'all' option -shell.cd('resources/ls'); -var result = shell.ls('-A'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('file1') > -1, true); -assert.equal(result.indexOf('file2') > -1, true); -assert.equal(result.indexOf('file1.js') > -1, true); -assert.equal(result.indexOf('file2.js') > -1, true); -assert.equal(result.indexOf('filename(with)[chars$]^that.must+be-escaped') > -1, true); -assert.equal(result.indexOf('a_dir') > -1, true); -assert.equal(result.indexOf('.hidden_file') > -1, true); -assert.equal(result.indexOf('.hidden_dir') > -1, true); -assert.equal(result.length, 8); -shell.cd('../..'); - -// no args, 'all' option -shell.cd('resources/ls'); -var result = shell.ls('-a'); // (deprecated) backwards compatibility test -assert.equal(shell.error(), null); -assert.equal(result.indexOf('file1') > -1, true); -assert.equal(result.indexOf('file2') > -1, true); -assert.equal(result.indexOf('file1.js') > -1, true); -assert.equal(result.indexOf('file2.js') > -1, true); -assert.equal(result.indexOf('filename(with)[chars$]^that.must+be-escaped') > -1, true); -assert.equal(result.indexOf('a_dir') > -1, true); -assert.equal(result.indexOf('.hidden_file') > -1, true); -assert.equal(result.indexOf('.hidden_dir') > -1, true); -assert.equal(result.length, 8); -shell.cd('../..'); - -// wildcard, simple -var result = shell.ls('resources/ls/*'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('resources/ls/file1') > -1, true); -assert.equal(result.indexOf('resources/ls/file2') > -1, true); -assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); -assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); -assert.equal(result.indexOf('resources/ls/filename(with)[chars$]^that.must+be-escaped') > -1, true); -assert.equal(result.indexOf('resources/ls/a_dir') > -1, true); -assert.equal(result.length, 6); - -// wildcard, hidden only -var result = shell.ls('resources/ls/.*'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('resources/ls/.hidden_file') > -1, true); -assert.equal(result.indexOf('resources/ls/.hidden_dir') > -1, true); -assert.equal(result.length, 2); - -// wildcard, mid-file -var result = shell.ls('resources/ls/f*le*'); -assert.equal(shell.error(), null); -assert.equal(result.length, 5); -assert.equal(result.indexOf('resources/ls/file1') > -1, true); -assert.equal(result.indexOf('resources/ls/file2') > -1, true); -assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); -assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); -assert.equal(result.indexOf('resources/ls/filename(with)[chars$]^that.must+be-escaped') > -1, true); - -// wildcard, mid-file with dot (should escape dot for regex) -var result = shell.ls('resources/ls/f*le*.js'); -assert.equal(shell.error(), null); -assert.equal(result.length, 2); -assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); -assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); - -// wildcard, should not do partial matches -var result = shell.ls('resources/ls/*.j'); // shouldn't get .js -assert.equal(shell.error(), null); -assert.equal(result.length, 0); - -// wildcard, all files with extension -var result = shell.ls('resources/ls/*.*'); -assert.equal(shell.error(), null); -assert.equal(result.length, 3); -assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); -assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); -assert.equal(result.indexOf('resources/ls/filename(with)[chars$]^that.must+be-escaped') > -1, true); - -// wildcard, with additional path -var result = shell.ls('resources/ls/f*le*.js', 'resources/ls/a_dir'); -assert.equal(shell.error(), null); -assert.equal(result.length, 4); -assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); -assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); -assert.equal(result.indexOf('b_dir') > -1, true); // no wildcard == no path prefix -assert.equal(result.indexOf('nada') > -1, true); // no wildcard == no path prefix - -// wildcard for both paths -var result = shell.ls('resources/ls/f*le*.js', 'resources/ls/a_dir/*'); -assert.equal(shell.error(), null); -assert.equal(result.length, 4); -assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); -assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); -assert.equal(result.indexOf('resources/ls/a_dir/b_dir') > -1, true); -assert.equal(result.indexOf('resources/ls/a_dir/nada') > -1, true); - -// wildcard for both paths, array -var result = shell.ls(['resources/ls/f*le*.js', 'resources/ls/a_dir/*']); -assert.equal(shell.error(), null); -assert.equal(result.length, 4); -assert.equal(result.indexOf('resources/ls/file1.js') > -1, true); -assert.equal(result.indexOf('resources/ls/file2.js') > -1, true); -assert.equal(result.indexOf('resources/ls/a_dir/b_dir') > -1, true); -assert.equal(result.indexOf('resources/ls/a_dir/nada') > -1, true); - -// recursive, no path -shell.cd('resources/ls'); -var result = shell.ls('-R'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('a_dir') > -1, true); -assert.equal(result.indexOf('a_dir/b_dir') > -1, true); -assert.equal(result.indexOf('a_dir/b_dir/z') > -1, true); -assert.equal(result.length, 9); -shell.cd('../..'); - -// recusive, path given -var result = shell.ls('-R', 'resources/ls'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('a_dir') > -1, true); -assert.equal(result.indexOf('a_dir/b_dir') > -1, true); -assert.equal(result.indexOf('a_dir/b_dir/z') > -1, true); -assert.equal(result.length, 9); - -// recusive, path given - 'all' flag -var result = shell.ls('-RA', 'resources/ls'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('a_dir') > -1, true); -assert.equal(result.indexOf('a_dir/b_dir') > -1, true); -assert.equal(result.indexOf('a_dir/b_dir/z') > -1, true); -assert.equal(result.indexOf('a_dir/.hidden_dir/nada') > -1, true); -assert.equal(result.length, 14); - -// recursive, wildcard -var result = shell.ls('-R', 'resources/ls/*'); -assert.equal(shell.error(), null); -assert.equal(result.indexOf('resources/ls/a_dir') > -1, true); -assert.equal(result.indexOf('resources/ls/a_dir/b_dir') > -1, true); -assert.equal(result.indexOf('resources/ls/a_dir/b_dir/z') > -1, true); -assert.equal(result.length, 9); - -shell.exit(123); diff --git a/node_modules/shelljs/test/make.js b/node_modules/shelljs/test/make.js deleted file mode 100644 index 3edbd8ce..00000000 --- a/node_modules/shelljs/test/make.js +++ /dev/null @@ -1,20 +0,0 @@ -var shell = require('..'), - child = require('child_process'), - assert = require('assert'); - -shell.mkdir('-p', 'tmp'); -var file = 'tmp/tempscript'+Math.random()+'.js', - script = 'require(\'../../make.js\');' + - 'target.all=function(){' + - ' echo("first"); '+ - ' cp("this_file_doesnt_exist", ".");' + - ' echo("second");' + - '}'; - -script.to(file); -child.exec('node '+file, function(err, stdout, stderr) { - assert.ok(stdout.match('first')); - assert.ok(!stdout.match('second')); // Make should die on errors, so this should never get echoed - - shell.exit(123); -}); diff --git a/node_modules/shelljs/test/mkdir.js b/node_modules/shelljs/test/mkdir.js deleted file mode 100644 index 1f93422a..00000000 --- a/node_modules/shelljs/test/mkdir.js +++ /dev/null @@ -1,79 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -shell.mkdir(); -assert.ok(shell.error()); - -var mtime = fs.statSync('tmp').mtime.toString(); -shell.mkdir('tmp'); // dir already exists -assert.ok(shell.error()); -assert.equal(fs.statSync('tmp').mtime.toString(), mtime); // didn't mess with dir - -assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check -shell.mkdir('/asdfasdf/asdfasdf'); // root path does not exist -assert.ok(shell.error()); -assert.equal(fs.existsSync('/asdfasdf'), false); - -// -// Valids -// - -assert.equal(fs.existsSync('tmp/t1'), false); -shell.mkdir('tmp/t1'); // simple dir -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/t1'), true); - -assert.equal(fs.existsSync('tmp/t2'), false); -assert.equal(fs.existsSync('tmp/t3'), false); -shell.mkdir('tmp/t2', 'tmp/t3'); // multiple dirs -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/t2'), true); -assert.equal(fs.existsSync('tmp/t3'), true); - -assert.equal(fs.existsSync('tmp/t1'), true); -assert.equal(fs.existsSync('tmp/t4'), false); -shell.mkdir('tmp/t1', 'tmp/t4'); // one dir exists, one doesn't -assert.equal(numLines(shell.error()), 1); -assert.equal(fs.existsSync('tmp/t1'), true); -assert.equal(fs.existsSync('tmp/t4'), true); - -assert.equal(fs.existsSync('tmp/a'), false); -shell.mkdir('-p', 'tmp/a/b/c'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/a/b/c'), true); -shell.rm('-Rf', 'tmp/a'); // revert - -// multiple dirs -shell.mkdir('-p', 'tmp/zzza', 'tmp/zzzb', 'tmp/zzzc'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/zzza'), true); -assert.equal(fs.existsSync('tmp/zzzb'), true); -assert.equal(fs.existsSync('tmp/zzzc'), true); - -// multiple dirs, array syntax -shell.mkdir('-p', ['tmp/yyya', 'tmp/yyyb', 'tmp/yyyc']); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/yyya'), true); -assert.equal(fs.existsSync('tmp/yyyb'), true); -assert.equal(fs.existsSync('tmp/yyyc'), true); - -shell.exit(123); diff --git a/node_modules/shelljs/test/mv.js b/node_modules/shelljs/test/mv.js deleted file mode 100644 index 89bca91e..00000000 --- a/node_modules/shelljs/test/mv.js +++ /dev/null @@ -1,130 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// Prepare tmp/ -shell.cp('resources/*', 'tmp'); - -// -// Invalids -// - -shell.mv(); -assert.ok(shell.error()); - -shell.mv('file1'); -assert.ok(shell.error()); - -shell.mv('-f'); -assert.ok(shell.error()); - -shell.mv('-Z', 'tmp/file1', 'tmp/file1'); // option not supported -assert.ok(shell.error()); -assert.equal(fs.existsSync('tmp/file1'), true); - -shell.mv('asdfasdf', 'tmp'); // source does not exist -assert.ok(shell.error()); -assert.equal(numLines(shell.error()), 1); -assert.equal(fs.existsSync('tmp/asdfasdf'), false); - -shell.mv('asdfasdf1', 'asdfasdf2', 'tmp'); // sources do not exist -assert.ok(shell.error()); -assert.equal(numLines(shell.error()), 2); -assert.equal(fs.existsSync('tmp/asdfasdf1'), false); -assert.equal(fs.existsSync('tmp/asdfasdf2'), false); - -shell.mv('asdfasdf1', 'asdfasdf2', 'tmp/file1'); // too many sources (dest is file) -assert.ok(shell.error()); - -shell.mv('tmp/file1', 'tmp/file2'); // dest already exists -assert.ok(shell.error()); - -shell.mv('tmp/file1', 'tmp/file2', 'tmp/a_file'); // too many sources (exist, but dest is file) -assert.ok(shell.error()); -assert.equal(fs.existsSync('tmp/a_file'), false); - -shell.mv('tmp/file*', 'tmp/file1'); // can't use wildcard when dest is file -assert.ok(shell.error()); -assert.equal(fs.existsSync('tmp/file1'), true); -assert.equal(fs.existsSync('tmp/file2'), true); -assert.equal(fs.existsSync('tmp/file1.js'), true); -assert.equal(fs.existsSync('tmp/file2.js'), true); - -// -// Valids -// - -shell.cd('tmp'); - -// handles self OK -shell.mkdir('tmp2'); -shell.mv('*', 'tmp2'); // has to handle self (tmp2 --> tmp2) without throwing error -assert.ok(shell.error()); // there's an error, but not fatal -assert.equal(fs.existsSync('tmp2/file1'), true); // moved OK -shell.mv('tmp2/*', '.'); // revert -assert.equal(fs.existsSync('file1'), true); // moved OK - -shell.mv('file1', 'file3'); // one source -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('file1'), false); -assert.equal(fs.existsSync('file3'), true); -shell.mv('file3', 'file1'); // revert -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('file1'), true); - -// two sources -shell.rm('-rf', 't'); -shell.mkdir('-p', 't'); -shell.mv('file1', 'file2', 't'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('file1'), false); -assert.equal(fs.existsSync('file2'), false); -assert.equal(fs.existsSync('t/file1'), true); -assert.equal(fs.existsSync('t/file2'), true); -shell.mv('t/*', '.'); // revert -assert.equal(fs.existsSync('file1'), true); -assert.equal(fs.existsSync('file2'), true); - -// two sources, array style -shell.rm('-rf', 't'); -shell.mkdir('-p', 't'); -shell.mv(['file1', 'file2'], 't'); // two sources -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('file1'), false); -assert.equal(fs.existsSync('file2'), false); -assert.equal(fs.existsSync('t/file1'), true); -assert.equal(fs.existsSync('t/file2'), true); -shell.mv('t/*', '.'); // revert -assert.equal(fs.existsSync('file1'), true); -assert.equal(fs.existsSync('file2'), true); - -shell.mv('file*.js', 't'); // wildcard -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('file1.js'), false); -assert.equal(fs.existsSync('file2.js'), false); -assert.equal(fs.existsSync('t/file1.js'), true); -assert.equal(fs.existsSync('t/file2.js'), true); -shell.mv('t/*', '.'); // revert -assert.equal(fs.existsSync('file1.js'), true); -assert.equal(fs.existsSync('file2.js'), true); - -shell.mv('-f', 'file1', 'file2'); // dest exists, but -f given -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('file1'), false); -assert.equal(fs.existsSync('file2'), true); - -shell.exit(123); diff --git a/node_modules/shelljs/test/popd.js b/node_modules/shelljs/test/popd.js deleted file mode 100644 index fd795332..00000000 --- a/node_modules/shelljs/test/popd.js +++ /dev/null @@ -1,118 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -var root = path.resolve(), trail; - -function reset() { - shell.dirs('-c'); - shell.cd(root); -} - -// Valid -shell.pushd('resources/pushd'); -trail = shell.popd(); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ root ]); - -shell.pushd('resources/pushd'); -shell.pushd('a'); -trail = shell.popd(); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd'), - root -]); - -shell.pushd('b'); -trail = shell.popd(); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd'), - root -]); - -shell.pushd('b'); -shell.pushd('c'); -trail = shell.popd(); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd'), - root -]); - -trail = shell.popd(); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd'), - root -]); - -trail = shell.popd(); -assert.equal(shell.error(), null); -assert.equal(trail.length, 1); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ root ]); - -// Valid by index -shell.pushd('resources/pushd'); -trail = shell.popd('+0'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ root ]); - -shell.pushd('resources/pushd'); -trail = shell.popd('+1'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ path.resolve(root, 'resources/pushd') ]); - -reset(); shell.pushd('resources/pushd'); -trail = shell.popd('-0'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ path.resolve(root, 'resources/pushd') ]); - -reset(); shell.pushd('resources/pushd'); -trail = shell.popd('-1'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ root ]); - - -reset(); shell.pushd('resources/pushd'); -trail = shell.popd('-n'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ path.resolve(root, 'resources/pushd') ]); - -// Invalid -trail = shell.popd(); -assert.ok(shell.error('popd: directory stack empty\n')); - -// Test that the root dir is not stored -shell.cd('resources/pushd'); -shell.pushd('b'); -trail = shell.popd(); -assert.equal(shell.error(), null); -assert.equal(trail[0], path.resolve(root, 'resources/pushd')); -assert.equal(process.cwd(), trail[0]); -shell.popd(); -assert.ok(shell.error(), null); - -shell.cd(root); - -shell.exit(123); \ No newline at end of file diff --git a/node_modules/shelljs/test/pushd.js b/node_modules/shelljs/test/pushd.js deleted file mode 100644 index 32089dc2..00000000 --- a/node_modules/shelljs/test/pushd.js +++ /dev/null @@ -1,228 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -var root = path.resolve(), trail; - -function reset() { - shell.dirs('-c'); - shell.cd(root); -} - -// Push valid directories -trail = shell.pushd('resources/pushd'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd'), - root -]); - -trail = shell.pushd('a'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root -]); - -trail = shell.pushd('../b'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root -]); - -trail = shell.pushd('c'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/b/c'), - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root -]); - -// Push stuff around with positive indices -trail = shell.pushd('+0'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/b/c'), - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root -]); - -trail = shell.pushd('+1'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root, - path.resolve(root, 'resources/pushd/b/c') -]); - -trail = shell.pushd('+2'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd'), - root, - path.resolve(root, 'resources/pushd/b/c'), - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a') -]); - -trail = shell.pushd('+3'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root, - path.resolve(root, 'resources/pushd/b/c') -]); - -trail = shell.pushd('+4'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/b/c'), - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root -]); - -// Push stuff around with negative indices -trail = shell.pushd('-0'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - root, - path.resolve(root, 'resources/pushd/b/c'), - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd') -]); - -trail = shell.pushd('-1'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root, - path.resolve(root, 'resources/pushd/b/c'), - path.resolve(root, 'resources/pushd/b') -]); - -trail = shell.pushd('-2'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - root, - path.resolve(root, 'resources/pushd/b/c'), - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd') -]); - -trail = shell.pushd('-3'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/b/c'), - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root -]); - -trail = shell.pushd('-4'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - path.resolve(root, 'resources/pushd/b/c'), - path.resolve(root, 'resources/pushd/b'), - path.resolve(root, 'resources/pushd/a'), - path.resolve(root, 'resources/pushd'), - root -]); - -// Push without changing directory or resolving paths -reset(); trail = shell.pushd('-n', 'resources/pushd'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - root, - 'resources/pushd' -]); - -trail = shell.pushd('-n', 'resources/pushd/a'); -assert.equal(shell.error(), null); -assert.equal(process.cwd(), trail[0]); -assert.deepEqual(trail, [ - root, - 'resources/pushd/a', - 'resources/pushd' -]); - -// Push invalid directory -shell.pushd('does/not/exist'); -assert.equal(shell.error(), 'pushd: no such file or directory: ' + path.resolve('.', 'does/not/exist') + '\n'); -assert.equal(process.cwd(), trail[0]); - -// Push without arguments should swap top two directories when stack length is 2 -reset(); trail = shell.pushd('resources/pushd'); -assert.equal(shell.error(), null); -assert.equal(trail.length, 2); -assert.equal(path.relative(root, trail[0]), 'resources/pushd'); -assert.equal(trail[1], root); -assert.equal(process.cwd(), trail[0]); -trail = shell.pushd(); -assert.equal(shell.error(), null); -assert.equal(trail.length, 2); -assert.equal(trail[0], root); -assert.equal(path.relative(root, trail[1]), 'resources/pushd'); -assert.equal(process.cwd(), trail[0]); - -// Push without arguments should swap top two directories when stack length is > 2 -trail = shell.pushd('resources/pushd/a'); -assert.equal(shell.error(), null); -assert.equal(trail.length, 3); -assert.equal(path.relative(root, trail[0]), 'resources/pushd/a'); -assert.equal(trail[1], root); -assert.equal(path.relative(root, trail[2]), 'resources/pushd'); -assert.equal(process.cwd(), trail[0]); - -trail = shell.pushd(); -assert.equal(shell.error(), null); -assert.equal(trail.length, 3); -assert.equal(trail[0], root); -assert.equal(path.relative(root, trail[1]), 'resources/pushd/a'); -assert.equal(path.relative(root, trail[2]), 'resources/pushd'); -assert.equal(process.cwd(), trail[0]); - -// Push without arguments invalid when stack is empty -reset(); shell.pushd(); -assert.equal(shell.error(), 'pushd: no other directory\n'); - -shell.exit(123); \ No newline at end of file diff --git a/node_modules/shelljs/test/pwd.js b/node_modules/shelljs/test/pwd.js deleted file mode 100644 index d1f563f9..00000000 --- a/node_modules/shelljs/test/pwd.js +++ /dev/null @@ -1,28 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'); - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Valids -// - -var _pwd = shell.pwd(); -assert.equal(shell.error(), null); -assert.equal(_pwd, path.resolve('.')); - -shell.cd('tmp'); -var _pwd = shell.pwd(); -assert.equal(shell.error(), null); -assert.equal(path.basename(_pwd), 'tmp'); - -shell.exit(123); diff --git a/node_modules/shelljs/test/resources/a.txt b/node_modules/shelljs/test/resources/a.txt deleted file mode 100644 index 356ce491..00000000 --- a/node_modules/shelljs/test/resources/a.txt +++ /dev/null @@ -1,11 +0,0 @@ -This is line one -This is line two - -This is line four -. -. -More content here -. -. - -This is line eleven diff --git a/node_modules/shelljs/test/resources/chmod/a/b/c/.npmignore b/node_modules/shelljs/test/resources/chmod/a/b/c/.npmignore deleted file mode 100644 index e69de29b..00000000 diff --git a/node_modules/shelljs/test/resources/chmod/b/a/b/.npmignore b/node_modules/shelljs/test/resources/chmod/b/a/b/.npmignore deleted file mode 100755 index e69de29b..00000000 diff --git a/node_modules/shelljs/test/resources/chmod/c/a/b/.npmignore b/node_modules/shelljs/test/resources/chmod/c/a/b/.npmignore deleted file mode 100644 index e69de29b..00000000 diff --git a/node_modules/shelljs/test/resources/chmod/file1 b/node_modules/shelljs/test/resources/chmod/file1 deleted file mode 100644 index db3f9ca6..00000000 --- a/node_modules/shelljs/test/resources/chmod/file1 +++ /dev/null @@ -1,2 +0,0 @@ -this is test file 1 -default state should be 0644 (rw-r--r--) diff --git a/node_modules/shelljs/test/resources/cp/a b/node_modules/shelljs/test/resources/cp/a deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/cp/a +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/cp/b b/node_modules/shelljs/test/resources/cp/b deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/cp/b +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/cp/dir_a/z b/node_modules/shelljs/test/resources/cp/dir_a/z deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/cp/dir_a/z +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/cp/dir_b/dir_b_a/dir_b_a_a/z b/node_modules/shelljs/test/resources/cp/dir_b/dir_b_a/dir_b_a_a/z deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/cp/dir_b/dir_b_a/dir_b_a_a/z +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/external/node_script.js b/node_modules/shelljs/test/resources/external/node_script.js deleted file mode 100755 index 3b2d24a0..00000000 --- a/node_modules/shelljs/test/resources/external/node_script.js +++ /dev/null @@ -1,2 +0,0 @@ -console.log('node_script_1234'); - diff --git a/node_modules/shelljs/test/resources/file1 b/node_modules/shelljs/test/resources/file1 deleted file mode 100644 index f079749c..00000000 --- a/node_modules/shelljs/test/resources/file1 +++ /dev/null @@ -1 +0,0 @@ -test1 \ No newline at end of file diff --git a/node_modules/shelljs/test/resources/file1.js b/node_modules/shelljs/test/resources/file1.js deleted file mode 100644 index 9daeafb9..00000000 --- a/node_modules/shelljs/test/resources/file1.js +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/node_modules/shelljs/test/resources/file1.txt b/node_modules/shelljs/test/resources/file1.txt deleted file mode 100644 index a5bce3fd..00000000 --- a/node_modules/shelljs/test/resources/file1.txt +++ /dev/null @@ -1 +0,0 @@ -test1 diff --git a/node_modules/shelljs/test/resources/file2 b/node_modules/shelljs/test/resources/file2 deleted file mode 100644 index d606037c..00000000 --- a/node_modules/shelljs/test/resources/file2 +++ /dev/null @@ -1 +0,0 @@ -test2 \ No newline at end of file diff --git a/node_modules/shelljs/test/resources/file2.js b/node_modules/shelljs/test/resources/file2.js deleted file mode 100644 index 9daeafb9..00000000 --- a/node_modules/shelljs/test/resources/file2.js +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/node_modules/shelljs/test/resources/file2.txt b/node_modules/shelljs/test/resources/file2.txt deleted file mode 100644 index 180cf832..00000000 --- a/node_modules/shelljs/test/resources/file2.txt +++ /dev/null @@ -1 +0,0 @@ -test2 diff --git a/node_modules/shelljs/test/resources/find/.hidden b/node_modules/shelljs/test/resources/find/.hidden deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/find/.hidden +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/find/a b/node_modules/shelljs/test/resources/find/a deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/find/a +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/find/b b/node_modules/shelljs/test/resources/find/b deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/find/b +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/find/dir1/a_dir1 b/node_modules/shelljs/test/resources/find/dir1/a_dir1 deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/find/dir1/a_dir1 +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/find/dir1/dir11/a_dir11 b/node_modules/shelljs/test/resources/find/dir1/dir11/a_dir11 deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/find/dir1/dir11/a_dir11 +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/find/dir2/a_dir1 b/node_modules/shelljs/test/resources/find/dir2/a_dir1 deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/find/dir2/a_dir1 +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/issue44/main.js b/node_modules/shelljs/test/resources/issue44/main.js deleted file mode 100644 index d800886d..00000000 --- a/node_modules/shelljs/test/resources/issue44/main.js +++ /dev/null @@ -1 +0,0 @@ -123 \ No newline at end of file diff --git a/node_modules/shelljs/test/resources/ls/.hidden_dir/nada b/node_modules/shelljs/test/resources/ls/.hidden_dir/nada deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/ls/.hidden_dir/nada +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/ls/.hidden_file b/node_modules/shelljs/test/resources/ls/.hidden_file deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/ls/.hidden_file +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/ls/a_dir/.hidden_dir/nada b/node_modules/shelljs/test/resources/ls/a_dir/.hidden_dir/nada deleted file mode 100644 index 5fedf572..00000000 --- a/node_modules/shelljs/test/resources/ls/a_dir/.hidden_dir/nada +++ /dev/null @@ -1 +0,0 @@ -nada \ No newline at end of file diff --git a/node_modules/shelljs/test/resources/ls/a_dir/b_dir/z b/node_modules/shelljs/test/resources/ls/a_dir/b_dir/z deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/ls/a_dir/b_dir/z +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/ls/a_dir/nada b/node_modules/shelljs/test/resources/ls/a_dir/nada deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/ls/a_dir/nada +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/ls/file1 b/node_modules/shelljs/test/resources/ls/file1 deleted file mode 100644 index 9daeafb9..00000000 --- a/node_modules/shelljs/test/resources/ls/file1 +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/node_modules/shelljs/test/resources/ls/file1.js b/node_modules/shelljs/test/resources/ls/file1.js deleted file mode 100644 index 9daeafb9..00000000 --- a/node_modules/shelljs/test/resources/ls/file1.js +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/node_modules/shelljs/test/resources/ls/file2 b/node_modules/shelljs/test/resources/ls/file2 deleted file mode 100644 index 9daeafb9..00000000 --- a/node_modules/shelljs/test/resources/ls/file2 +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/node_modules/shelljs/test/resources/ls/file2.js b/node_modules/shelljs/test/resources/ls/file2.js deleted file mode 100644 index 9daeafb9..00000000 --- a/node_modules/shelljs/test/resources/ls/file2.js +++ /dev/null @@ -1 +0,0 @@ -test diff --git a/node_modules/shelljs/test/resources/ls/filename(with)[chars$]^that.must+be-escaped b/node_modules/shelljs/test/resources/ls/filename(with)[chars$]^that.must+be-escaped deleted file mode 100644 index 8bd6648e..00000000 --- a/node_modules/shelljs/test/resources/ls/filename(with)[chars$]^that.must+be-escaped +++ /dev/null @@ -1 +0,0 @@ -asdf diff --git a/node_modules/shelljs/test/resources/pushd/a/dummy b/node_modules/shelljs/test/resources/pushd/a/dummy deleted file mode 100644 index 72e12a96..00000000 --- a/node_modules/shelljs/test/resources/pushd/a/dummy +++ /dev/null @@ -1 +0,0 @@ -meh \ No newline at end of file diff --git a/node_modules/shelljs/test/resources/pushd/b/c/dummy b/node_modules/shelljs/test/resources/pushd/b/c/dummy deleted file mode 100644 index 72e12a96..00000000 --- a/node_modules/shelljs/test/resources/pushd/b/c/dummy +++ /dev/null @@ -1 +0,0 @@ -meh \ No newline at end of file diff --git a/node_modules/shelljs/test/rm.js b/node_modules/shelljs/test/rm.js deleted file mode 100644 index 61182a11..00000000 --- a/node_modules/shelljs/test/rm.js +++ /dev/null @@ -1,183 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -shell.rm(); -assert.ok(shell.error()); - -shell.rm('asdfasdf'); // file does not exist -assert.ok(shell.error()); - -shell.rm('-f'); // no file -assert.ok(shell.error()); - -shell.rm('-@', 'resources/file1'); // invalid option -assert.ok(shell.error()); -assert.equal(fs.existsSync('resources/file1'), true); - -// -// Valids -// - -// file does not exist, but -f specified -shell.rm('-f', 'asdfasdf'); -assert.equal(shell.error(), null); - -// simple rm -shell.cp('-f', 'resources/file1', 'tmp/file1'); -assert.equal(fs.existsSync('tmp/file1'), true); -shell.rm('tmp/file1'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/file1'), false); - -// recursive dir removal - small-caps '-r' -shell.mkdir('-p', 'tmp/a/b/c'); -assert.equal(fs.existsSync('tmp/a/b/c'), true); -shell.rm('-rf', 'tmp/a'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/a'), false); - -// recursive dir removal - capital '-R' -shell.mkdir('-p', 'tmp/a/b/c'); -assert.equal(fs.existsSync('tmp/a/b/c'), true); -shell.rm('-Rf', 'tmp/a'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/a'), false); - -// recursive dir removal - absolute path -shell.mkdir('-p', 'tmp/a/b/c'); -assert.equal(fs.existsSync('tmp/a/b/c'), true); -shell.rm('-Rf', path.resolve('./tmp/a')); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/a'), false); - -// wildcard -shell.cp('-f', 'resources/file*', 'tmp'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/file1'), true); -assert.equal(fs.existsSync('tmp/file2'), true); -assert.equal(fs.existsSync('tmp/file1.js'), true); -assert.equal(fs.existsSync('tmp/file2.js'), true); -shell.rm('tmp/file*'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync('tmp/file1'), false); -assert.equal(fs.existsSync('tmp/file2'), false); -assert.equal(fs.existsSync('tmp/file1.js'), false); -assert.equal(fs.existsSync('tmp/file2.js'), false); - -// recursive dir removal -shell.mkdir('-p', 'tmp/a/b/c'); -shell.mkdir('-p', 'tmp/b'); -shell.mkdir('-p', 'tmp/c'); -shell.mkdir('-p', 'tmp/.hidden'); -assert.equal(fs.existsSync('tmp/a/b/c'), true); -assert.equal(fs.existsSync('tmp/b'), true); -assert.equal(fs.existsSync('tmp/c'), true); -assert.equal(fs.existsSync('tmp/.hidden'), true); -shell.rm('-rf', 'tmp/*'); -assert.equal(shell.error(), null); -var contents = fs.readdirSync('tmp'); -assert.equal(contents.length, 1); -assert.equal(contents[0], '.hidden'); // shouldn't remove hiddden if no .* given - -// recursive dir removal -shell.mkdir('-p', 'tmp/a/b/c'); -shell.mkdir('-p', 'tmp/b'); -shell.mkdir('-p', 'tmp/c'); -shell.mkdir('-p', 'tmp/.hidden'); -assert.equal(fs.existsSync('tmp/a/b/c'), true); -assert.equal(fs.existsSync('tmp/b'), true); -assert.equal(fs.existsSync('tmp/c'), true); -assert.equal(fs.existsSync('tmp/.hidden'), true); -shell.rm('-rf', 'tmp/*', 'tmp/.*'); -assert.equal(shell.error(), null); -var contents = fs.readdirSync('tmp'); -assert.equal(contents.length, 0); - -// recursive dir removal - array-syntax -shell.mkdir('-p', 'tmp/a/b/c'); -shell.mkdir('-p', 'tmp/b'); -shell.mkdir('-p', 'tmp/c'); -shell.mkdir('-p', 'tmp/.hidden'); -assert.equal(fs.existsSync('tmp/a/b/c'), true); -assert.equal(fs.existsSync('tmp/b'), true); -assert.equal(fs.existsSync('tmp/c'), true); -assert.equal(fs.existsSync('tmp/.hidden'), true); -shell.rm('-rf', ['tmp/*', 'tmp/.*']); -assert.equal(shell.error(), null); -var contents = fs.readdirSync('tmp'); -assert.equal(contents.length, 0); - -// removal of a read-only file (unforced) -shell.mkdir('-p', 'tmp/readonly'); -'asdf'.to('tmp/readonly/file1'); -fs.chmodSync('tmp/readonly/file1', '0444'); // -r--r--r-- -shell.rm('tmp/readonly/file1'); -assert.equal(fs.existsSync('tmp/readonly/file1'), true); // bash's rm always asks before removing read-only files - // here we just assume "no" - -// removal of a read-only file (forced) -shell.mkdir('-p', 'tmp/readonly'); -'asdf'.to('tmp/readonly/file2'); -fs.chmodSync('tmp/readonly/file2', '0444'); // -r--r--r-- -shell.rm('-f', 'tmp/readonly/file2'); -assert.equal(fs.existsSync('tmp/readonly/file2'), false); - -// removal of a tree containing read-only files (unforced) -shell.mkdir('-p', 'tmp/tree2'); -'asdf'.to('tmp/tree2/file1'); -'asdf'.to('tmp/tree2/file2'); -fs.chmodSync('tmp/tree2/file1', '0444'); // -r--r--r-- -shell.rm('-r', 'tmp/tree2'); -assert.equal(fs.existsSync('tmp/tree2/file1'), true); -assert.equal(fs.existsSync('tmp/tree2/file2'), false); - -// removal of a tree containing read-only files (forced) -shell.mkdir('-p', 'tmp/tree'); -'asdf'.to('tmp/tree/file1'); -'asdf'.to('tmp/tree/file2'); -fs.chmodSync('tmp/tree/file1', '0444'); // -r--r--r-- -shell.rm('-rf', 'tmp/tree'); -assert.equal(fs.existsSync('tmp/tree'), false); - -// removal of a sub-tree containing read-only and hidden files - rm('dir/*') -shell.mkdir('-p', 'tmp/tree3'); -shell.mkdir('-p', 'tmp/tree3/subtree'); -shell.mkdir('-p', 'tmp/tree3/.hidden'); -'asdf'.to('tmp/tree3/subtree/file'); -'asdf'.to('tmp/tree3/.hidden/file'); -'asdf'.to('tmp/tree3/file'); -fs.chmodSync('tmp/tree3/file', '0444'); // -r--r--r-- -fs.chmodSync('tmp/tree3/subtree/file', '0444'); // -r--r--r-- -fs.chmodSync('tmp/tree3/.hidden/file', '0444'); // -r--r--r-- -shell.rm('-rf', 'tmp/tree3/*', 'tmp/tree3/.*'); // erase dir contents -assert.equal(shell.ls('tmp/tree3').length, 0); - -// removal of a sub-tree containing read-only and hidden files - rm('dir') -shell.mkdir('-p', 'tmp/tree4'); -shell.mkdir('-p', 'tmp/tree4/subtree'); -shell.mkdir('-p', 'tmp/tree4/.hidden'); -'asdf'.to('tmp/tree4/subtree/file'); -'asdf'.to('tmp/tree4/.hidden/file'); -'asdf'.to('tmp/tree4/file'); -fs.chmodSync('tmp/tree4/file', '0444'); // -r--r--r-- -fs.chmodSync('tmp/tree4/subtree/file', '0444'); // -r--r--r-- -fs.chmodSync('tmp/tree4/.hidden/file', '0444'); // -r--r--r-- -shell.rm('-rf', 'tmp/tree4'); // erase dir contents -assert.equal(fs.existsSync('tmp/tree4'), false); - -shell.exit(123); diff --git a/node_modules/shelljs/test/sed.js b/node_modules/shelljs/test/sed.js deleted file mode 100644 index d3d66b11..00000000 --- a/node_modules/shelljs/test/sed.js +++ /dev/null @@ -1,58 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -shell.sed(); -assert.ok(shell.error()); - -shell.sed(/asdf/g); // too few args -assert.ok(shell.error()); - -shell.sed(/asdf/g, 'nada'); // too few args -assert.ok(shell.error()); - -assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check -shell.sed(/asdf/g, 'nada', '/asdfasdf'); // no such file -assert.ok(shell.error()); - -// -// Valids -// - -shell.cp('-f', 'resources/file1', 'tmp/file1'); -var result = shell.sed('test1', 'hello', 'tmp/file1'); // search string -assert.equal(shell.error(), null); -assert.equal(result, 'hello'); - -var result = shell.sed(/test1/, 'hello', 'tmp/file1'); // search regex -assert.equal(shell.error(), null); -assert.equal(result, 'hello'); - -var result = shell.sed(/test1/, 1234, 'tmp/file1'); // numeric replacement -assert.equal(shell.error(), null); -assert.equal(result, '1234'); - -var result = shell.sed('-i', /test1/, 'hello', 'tmp/file1'); -assert.equal(shell.error(), null); -assert.equal(result, 'hello'); -assert.equal(shell.cat('tmp/file1'), 'hello'); - -shell.exit(123); diff --git a/node_modules/shelljs/test/tempdir.js b/node_modules/shelljs/test/tempdir.js deleted file mode 100644 index 704ca561..00000000 --- a/node_modules/shelljs/test/tempdir.js +++ /dev/null @@ -1,27 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Valids -// - -var tmp = shell.tempdir(); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync(tmp), true); - -shell.exit(123); diff --git a/node_modules/shelljs/test/test.js b/node_modules/shelljs/test/test.js deleted file mode 100644 index a824edb3..00000000 --- a/node_modules/shelljs/test/test.js +++ /dev/null @@ -1,91 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -var result = shell.test(); // no expression given -assert.ok(shell.error()); - -var result = shell.test('asdf'); // bad expression -assert.ok(shell.error()); - -var result = shell.test('f', 'resources/file1'); // bad expression -assert.ok(shell.error()); - -var result = shell.test('-f'); // no file -assert.ok(shell.error()); - -// -// Valids -// - -//exists -var result = shell.test('-e', 'resources/file1'); -assert.equal(shell.error(), null); -assert.equal(result, true);//true - -var result = shell.test('-e', 'resources/404'); -assert.equal(shell.error(), null); -assert.equal(result, false); - -//directory -var result = shell.test('-d', 'resources'); -assert.equal(shell.error(), null); -assert.equal(result, true);//true - -var result = shell.test('-f', 'resources'); -assert.equal(shell.error(), null); -assert.equal(result, false); - -var result = shell.test('-L', 'resources'); -assert.equal(shell.error(), null); -assert.equal(result, false); - -//file -var result = shell.test('-d', 'resources/file1'); -assert.equal(shell.error(), null); -assert.equal(result, false); - -var result = shell.test('-f', 'resources/file1'); -assert.equal(shell.error(), null); -assert.equal(result, true);//true - -var result = shell.test('-L', 'resources/file1'); -assert.equal(shell.error(), null); -assert.equal(result, false); - -//link -var result = shell.test('-d', 'resources/link'); -assert.equal(shell.error(), null); -assert.equal(result, false); - -var result = shell.test('-f', 'resources/link'); -assert.equal(shell.error(), null); -assert.equal(result, true);//true - -var result = shell.test('-L', 'resources/link'); -assert.equal(shell.error(), null); -assert.equal(result, true);//true - -var result = shell.test('-L', 'resources/badlink'); -assert.equal(shell.error(), null); -assert.equal(result, true);//true - -var result = shell.test('-L', 'resources/404'); -assert.equal(shell.error(), null); -assert.equal(result, false);//false - -shell.exit(123); diff --git a/node_modules/shelljs/test/to.js b/node_modules/shelljs/test/to.js deleted file mode 100644 index 2e1253db..00000000 --- a/node_modules/shelljs/test/to.js +++ /dev/null @@ -1,39 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -'hello world'.to(); -assert.ok(shell.error()); - -assert.equal(fs.existsSync('/asdfasdf'), false); // sanity check -'hello world'.to('/asdfasdf/file'); -assert.ok(shell.error()); - -// -// Valids -// - -'hello world'.to('tmp/to1'); -var result = shell.cat('tmp/to1'); -assert.equal(shell.error(), null); -assert.equal(result, 'hello world'); - -shell.exit(123); diff --git a/node_modules/shelljs/test/which.js b/node_modules/shelljs/test/which.js deleted file mode 100644 index ac9a04d5..00000000 --- a/node_modules/shelljs/test/which.js +++ /dev/null @@ -1,38 +0,0 @@ -var shell = require('..'); - -var assert = require('assert'), - path = require('path'), - fs = require('fs'); - -// Node shims for < v0.7 -fs.existsSync = fs.existsSync || path.existsSync; - -shell.config.silent = true; - -function numLines(str) { - return typeof str === 'string' ? str.match(/\n/g).length : 0; -} - -shell.rm('-rf', 'tmp'); -shell.mkdir('tmp'); - -// -// Invalids -// - -shell.which(); -assert.ok(shell.error()); - -var result = shell.which('asdfasdfasdfasdfasdf'); // what are the odds... -assert.equal(shell.error(), null); -assert.equal(result, null); - -// -// Valids -// - -var result = shell.which('node'); -assert.equal(shell.error(), null); -assert.equal(fs.existsSync(result), true); - -shell.exit(123); diff --git a/node_modules/underscore/.npmignore b/node_modules/underscore/.npmignore deleted file mode 100644 index 4e5886de..00000000 --- a/node_modules/underscore/.npmignore +++ /dev/null @@ -1,4 +0,0 @@ -test/ -Rakefile -docs/ -raw/ diff --git a/node_modules/underscore/.travis.yml b/node_modules/underscore/.travis.yml deleted file mode 100644 index 99dc7712..00000000 --- a/node_modules/underscore/.travis.yml +++ /dev/null @@ -1,5 +0,0 @@ -language: node_js -node_js: - - 0.8 -notifications: - email: false diff --git a/node_modules/underscore/CNAME b/node_modules/underscore/CNAME deleted file mode 100644 index a007e65c..00000000 --- a/node_modules/underscore/CNAME +++ /dev/null @@ -1 +0,0 @@ -underscorejs.org diff --git a/node_modules/underscore/CONTRIBUTING.md b/node_modules/underscore/CONTRIBUTING.md deleted file mode 100644 index de5d5626..00000000 --- a/node_modules/underscore/CONTRIBUTING.md +++ /dev/null @@ -1,9 +0,0 @@ -## How to contribute to Underscore.js - -* Before you open a ticket or send a pull request, [search](https://github.com/documentcloud/underscore/issues) for previous discussions about the same feature or issue. Add to the earlier ticket if you find one. - -* Before sending a pull request for a feature, be sure to have [tests](http://underscorejs.org/test/). - -* Use the same coding style as the rest of the [codebase](https://github.com/documentcloud/underscore/blob/master/underscore.js). - -* In your pull request, do not add documentation or re-build the minified `underscore-min.js` file. We'll do those things before cutting a new release. diff --git a/node_modules/underscore/LICENSE b/node_modules/underscore/LICENSE deleted file mode 100644 index 0d8dbe40..00000000 --- a/node_modules/underscore/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2009-2013 Jeremy Ashkenas, DocumentCloud - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/underscore/README.md b/node_modules/underscore/README.md deleted file mode 100644 index b1f3e50a..00000000 --- a/node_modules/underscore/README.md +++ /dev/null @@ -1,19 +0,0 @@ - __ - /\ \ __ - __ __ ___ \_\ \ __ _ __ ____ ___ ___ _ __ __ /\_\ ____ - /\ \/\ \ /' _ `\ /'_ \ /'__`\/\ __\/ ,__\ / ___\ / __`\/\ __\/'__`\ \/\ \ /',__\ - \ \ \_\ \/\ \/\ \/\ \ \ \/\ __/\ \ \//\__, `\/\ \__//\ \ \ \ \ \//\ __/ __ \ \ \/\__, `\ - \ \____/\ \_\ \_\ \___,_\ \____\\ \_\\/\____/\ \____\ \____/\ \_\\ \____\/\_\ _\ \ \/\____/ - \/___/ \/_/\/_/\/__,_ /\/____/ \/_/ \/___/ \/____/\/___/ \/_/ \/____/\/_//\ \_\ \/___/ - \ \____/ - \/___/ - -Underscore.js is a utility-belt library for JavaScript that provides -support for the usual functional suspects (each, map, reduce, filter...) -without extending any core JavaScript objects. - -For Docs, License, Tests, and pre-packed downloads, see: -http://underscorejs.org - -Many thanks to our contributors: -https://github.com/documentcloud/underscore/contributors diff --git a/node_modules/underscore/favicon.ico b/node_modules/underscore/favicon.ico deleted file mode 100644 index 03049683..00000000 Binary files a/node_modules/underscore/favicon.ico and /dev/null differ diff --git a/node_modules/underscore/index.html b/node_modules/underscore/index.html deleted file mode 100644 index 8c5793ab..00000000 --- a/node_modules/underscore/index.html +++ /dev/null @@ -1,2467 +0,0 @@ - - - - - - - - - Underscore.js - - - - - - -
- -

- -

- -

- Underscore is a - utility-belt library for JavaScript that provides a lot of the - functional programming support that you would expect in - Prototype.js - (or Ruby), - but without extending any of the built-in JavaScript objects. It's the - tie to go along with jQuery's tux, - and Backbone.js's suspenders. -

- -

- Underscore provides 80-odd functions that support both the usual - functional suspects: map, select, invoke — - as well as more specialized helpers: function binding, javascript - templating, deep equality testing, and so on. It delegates to built-in - functions, if present, so modern browsers will use the - native implementations of forEach, map, reduce, - filter, every, some and indexOf. -

- -

- A complete Test & Benchmark Suite - is included for your perusal. -

- -

- You may also read through the annotated source code. -

- -

- The project is - hosted on GitHub. - You can report bugs and discuss features on the - issues page, - on Freenode in the #documentcloud channel, - or send tweets to @documentcloud. -

- -

- Underscore is an open-source component of DocumentCloud. -

- -

Downloads (Right-click, and use "Save As")

- - - - - - - - - - - - - - - - - -
Development Version (1.4.4)40kb, Uncompressed with Plentiful Comments
Production Version (1.4.4)4kb, Minified and Gzipped
Edge VersionUnreleased, current master, use at your own risk
- -
- -

Collection Functions (Arrays or Objects)

- -

- each_.each(list, iterator, [context]) - Alias: forEach -
- Iterates over a list of elements, yielding each in turn to an iterator - function. The iterator is bound to the context object, if one is - passed. Each invocation of iterator is called with three arguments: - (element, index, list). If list is a JavaScript object, iterator's - arguments will be (value, key, list). Delegates to the native - forEach function if it exists. -

-
-_.each([1, 2, 3], alert);
-=> alerts each number in turn...
-_.each({one : 1, two : 2, three : 3}, alert);
-=> alerts each number value in turn...
- -

- map_.map(list, iterator, [context]) - Alias: collect -
- Produces a new array of values by mapping each value in list - through a transformation function (iterator). If the native map method - exists, it will be used instead. If list is a JavaScript object, - iterator's arguments will be (value, key, list). -

-
-_.map([1, 2, 3], function(num){ return num * 3; });
-=> [3, 6, 9]
-_.map({one : 1, two : 2, three : 3}, function(num, key){ return num * 3; });
-=> [3, 6, 9]
- -

- reduce_.reduce(list, iterator, memo, [context]) - Aliases: inject, foldl -
- Also known as inject and foldl, reduce boils down a - list of values into a single value. Memo is the initial state - of the reduction, and each successive step of it should be returned by - iterator. The iterator is passed four arguments: the memo, - then the value and index (or key) of the iteration, - and finally a reference to the entire list. -

-
-var sum = _.reduce([1, 2, 3], function(memo, num){ return memo + num; }, 0);
-=> 6
-
- -

- reduceRight_.reduceRight(list, iterator, memo, [context]) - Alias: foldr -
- The right-associative version of reduce. Delegates to the - JavaScript 1.8 version of reduceRight, if it exists. Foldr - is not as useful in JavaScript as it would be in a language with lazy - evaluation. -

-
-var list = [[0, 1], [2, 3], [4, 5]];
-var flat = _.reduceRight(list, function(a, b) { return a.concat(b); }, []);
-=> [4, 5, 2, 3, 0, 1]
-
- -

- find_.find(list, iterator, [context]) - Alias: detect -
- Looks through each value in the list, returning the first one that - passes a truth test (iterator). The function returns as - soon as it finds an acceptable element, and doesn't traverse the - entire list. -

-
-var even = _.find([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
-=> 2
-
- -

- filter_.filter(list, iterator, [context]) - Alias: select -
- Looks through each value in the list, returning an array of all - the values that pass a truth test (iterator). Delegates to the - native filter method, if it exists. -

-
-var evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
-=> [2, 4, 6]
-
- -

- where_.where(list, properties) -
- Looks through each value in the list, returning an array of all - the values that contain all of the key-value pairs listed in properties. -

-
-_.where(listOfPlays, {author: "Shakespeare", year: 1611});
-=> [{title: "Cymbeline", author: "Shakespeare", year: 1611},
-    {title: "The Tempest", author: "Shakespeare", year: 1611}]
-
- -

- findWhere_.findWhere(list, properties) -
- Looks through the list and returns the first value that matches - all of the key-value pairs listed in properties. -

-
-_.findWhere(publicServicePulitzers, {newsroom: "The New York Times"});
-=> {year: 1918, newsroom: "The New York Times",
-  reason: "For its public service in publishing in full so many official reports,
-  documents and speeches by European statesmen relating to the progress and
-  conduct of the war."}
-
- -

- reject_.reject(list, iterator, [context]) -
- Returns the values in list without the elements that the truth - test (iterator) passes. The opposite of filter. -

-
-var odds = _.reject([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
-=> [1, 3, 5]
-
- -

- every_.every(list, iterator, [context]) - Alias: all -
- Returns true if all of the values in the list pass the iterator - truth test. Delegates to the native method every, if present. -

-
-_.every([true, 1, null, 'yes'], _.identity);
-=> false
-
- -

- some_.some(list, [iterator], [context]) - Alias: any -
- Returns true if any of the values in the list pass the - iterator truth test. Short-circuits and stops traversing the list - if a true element is found. Delegates to the native method some, - if present. -

-
-_.some([null, 0, 'yes', false]);
-=> true
-
- -

- contains_.contains(list, value) - Alias: include -
- Returns true if the value is present in the list. - Uses indexOf internally, if list is an Array. -

-
-_.contains([1, 2, 3], 3);
-=> true
-
- -

- invoke_.invoke(list, methodName, [*arguments]) -
- Calls the method named by methodName on each value in the list. - Any extra arguments passed to invoke will be forwarded on to the - method invocation. -

-
-_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
-=> [[1, 5, 7], [1, 2, 3]]
-
- -

- pluck_.pluck(list, propertyName) -
- A convenient version of what is perhaps the most common use-case for - map: extracting a list of property values. -

-
-var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
-_.pluck(stooges, 'name');
-=> ["moe", "larry", "curly"]
-
- -

- max_.max(list, [iterator], [context]) -
- Returns the maximum value in list. If iterator is passed, - it will be used on each value to generate the criterion by which the - value is ranked. -

-
-var stooges = [{name : 'moe', age : 40}, {name : 'larry', age : 50}, {name : 'curly', age : 60}];
-_.max(stooges, function(stooge){ return stooge.age; });
-=> {name : 'curly', age : 60};
-
- -

- min_.min(list, [iterator], [context]) -
- Returns the minimum value in list. If iterator is passed, - it will be used on each value to generate the criterion by which the - value is ranked. -

-
-var numbers = [10, 5, 100, 2, 1000];
-_.min(numbers);
-=> 2
-
- -

- sortBy_.sortBy(list, iterator, [context]) -
- Returns a sorted copy of list, ranked in ascending order by the - results of running each value through iterator. Iterator may - also be the string name of the property to sort by (eg. length). -

-
-_.sortBy([1, 2, 3, 4, 5, 6], function(num){ return Math.sin(num); });
-=> [5, 4, 6, 3, 1, 2]
-
- -

- groupBy_.groupBy(list, iterator, [context]) -
- Splits a collection into sets, grouped by the result of running each - value through iterator. If iterator is a string instead of - a function, groups by the property named by iterator on each of - the values. -

-
-_.groupBy([1.3, 2.1, 2.4], function(num){ return Math.floor(num); });
-=> {1: [1.3], 2: [2.1, 2.4]}
-
-_.groupBy(['one', 'two', 'three'], 'length');
-=> {3: ["one", "two"], 5: ["three"]}
-
- -

- countBy_.countBy(list, iterator, [context]) -
- Sorts a list into groups and returns a count for the number of objects - in each group. - Similar to groupBy, but instead of returning a list of values, - returns a count for the number of values in that group. -

-
-_.countBy([1, 2, 3, 4, 5], function(num) {
-  return num % 2 == 0 ? 'even' : 'odd';
-});
-=> {odd: 3, even: 2}
-
- -

- shuffle_.shuffle(list) -
- Returns a shuffled copy of the list, using a version of the - Fisher-Yates shuffle. -

-
-_.shuffle([1, 2, 3, 4, 5, 6]);
-=> [4, 1, 6, 3, 5, 2]
-
- -

- toArray_.toArray(list) -
- Converts the list (anything that can be iterated over), into a - real Array. Useful for transmuting the arguments object. -

-
-(function(){ return _.toArray(arguments).slice(1); })(1, 2, 3, 4);
-=> [2, 3, 4]
-
- -

- size_.size(list) -
- Return the number of values in the list. -

-
-_.size({one : 1, two : 2, three : 3});
-=> 3
-
- -

Array Functions

- -

- - Note: All array functions will also work on the arguments object. - However, Underscore functions are not designed to work on "sparse" arrays. - -

- -

- first_.first(array, [n]) - Alias: head, take -
- Returns the first element of an array. Passing n will - return the first n elements of the array. -

-
-_.first([5, 4, 3, 2, 1]);
-=> 5
-
- -

- initial_.initial(array, [n]) -
- Returns everything but the last entry of the array. Especially useful on - the arguments object. Pass n to exclude the last n elements - from the result. -

-
-_.initial([5, 4, 3, 2, 1]);
-=> [5, 4, 3, 2]
-
- -

- last_.last(array, [n]) -
- Returns the last element of an array. Passing n will return - the last n elements of the array. -

-
-_.last([5, 4, 3, 2, 1]);
-=> 1
-
- -

- rest_.rest(array, [index]) - Alias: tail, drop -
- Returns the rest of the elements in an array. Pass an index - to return the values of the array from that index onward. -

-
-_.rest([5, 4, 3, 2, 1]);
-=> [4, 3, 2, 1]
-
- -

- compact_.compact(array) -
- Returns a copy of the array with all falsy values removed. - In JavaScript, false, null, 0, "", - undefined and NaN are all falsy. -

-
-_.compact([0, 1, false, 2, '', 3]);
-=> [1, 2, 3]
-
- -

- flatten_.flatten(array, [shallow]) -
- Flattens a nested array (the nesting can be to any depth). If you - pass shallow, the array will only be flattened a single level. -

-
-_.flatten([1, [2], [3, [[4]]]]);
-=> [1, 2, 3, 4];
-
-_.flatten([1, [2], [3, [[4]]]], true);
-=> [1, 2, 3, [[4]]];
-
- -

- without_.without(array, [*values]) -
- Returns a copy of the array with all instances of the values - removed. -

-
-_.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
-=> [2, 3, 4]
-
- -

- union_.union(*arrays) -
- Computes the union of the passed-in arrays: the list of unique items, - in order, that are present in one or more of the arrays. -

-
-_.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
-=> [1, 2, 3, 101, 10]
-
- -

- intersection_.intersection(*arrays) -
- Computes the list of values that are the intersection of all the arrays. - Each value in the result is present in each of the arrays. -

-
-_.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
-=> [1, 2]
-
- -

- difference_.difference(array, *others) -
- Similar to without, but returns the values from array that - are not present in the other arrays. -

-
-_.difference([1, 2, 3, 4, 5], [5, 2, 10]);
-=> [1, 3, 4]
-
- -

- uniq_.uniq(array, [isSorted], [iterator]) - Alias: unique -
- Produces a duplicate-free version of the array, using === to test - object equality. If you know in advance that the array is sorted, - passing true for isSorted will run a much faster algorithm. - If you want to compute unique items based on a transformation, pass an - iterator function. -

-
-_.uniq([1, 2, 1, 3, 1, 4]);
-=> [1, 2, 3, 4]
-
- -

- zip_.zip(*arrays) -
- Merges together the values of each of the arrays with the - values at the corresponding position. Useful when you have separate - data sources that are coordinated through matching array indexes. - If you're working with a matrix of nested arrays, zip.apply - can transpose the matrix in a similar fashion. -

-
-_.zip(['moe', 'larry', 'curly'], [30, 40, 50], [true, false, false]);
-=> [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]
-
- -

- object_.object(list, [values]) -
- Converts arrays into objects. Pass either a single list of - [key, value] pairs, or a list of keys, and a list of values. -

-
-_.object(['moe', 'larry', 'curly'], [30, 40, 50]);
-=> {moe: 30, larry: 40, curly: 50}
-
-_.object([['moe', 30], ['larry', 40], ['curly', 50]]);
-=> {moe: 30, larry: 40, curly: 50}
-
- -

- indexOf_.indexOf(array, value, [isSorted]) -
- Returns the index at which value can be found in the array, - or -1 if value is not present in the array. Uses the native - indexOf function unless it's missing. If you're working with a - large array, and you know that the array is already sorted, pass true - for isSorted to use a faster binary search ... or, pass a number as - the third argument in order to look for the first matching value in the - array after the given index. -

-
-_.indexOf([1, 2, 3], 2);
-=> 1
-
- -

- lastIndexOf_.lastIndexOf(array, value, [fromIndex]) -
- Returns the index of the last occurrence of value in the array, - or -1 if value is not present. Uses the native lastIndexOf - function if possible. Pass fromIndex to start your search at a - given index. -

-
-_.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
-=> 4
-
- -

- sortedIndex_.sortedIndex(list, value, [iterator], [context]) -
- Uses a binary search to determine the index at which the value - should be inserted into the list in order to maintain the list's - sorted order. If an iterator is passed, it will be used to compute - the sort ranking of each value, including the value you pass. -

-
-_.sortedIndex([10, 20, 30, 40, 50], 35);
-=> 3
-
- -

- range_.range([start], stop, [step]) -
- A function to create flexibly-numbered lists of integers, handy for - each and map loops. start, if omitted, defaults - to 0; step defaults to 1. Returns a list of integers - from start to stop, incremented (or decremented) by step, - exclusive. -

-
-_.range(10);
-=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
-_.range(1, 11);
-=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
-_.range(0, 30, 5);
-=> [0, 5, 10, 15, 20, 25]
-_.range(0, -10, -1);
-=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
-_.range(0);
-=> []
-
- -

Function (uh, ahem) Functions

- -

- bind_.bind(function, object, [*arguments]) -
- Bind a function to an object, meaning that whenever - the function is called, the value of this will be the object. - Optionally, pass arguments to the function to pre-fill them, - also known as partial application. -

-
-var func = function(greeting){ return greeting + ': ' + this.name };
-func = _.bind(func, {name : 'moe'}, 'hi');
-func();
-=> 'hi: moe'
-
- -

- bindAll_.bindAll(object, [*methodNames]) -
- Binds a number of methods on the object, specified by - methodNames, to be run in the context of that object whenever they - are invoked. Very handy for binding functions that are going to be used - as event handlers, which would otherwise be invoked with a fairly useless - this. If no methodNames are provided, all of the object's - function properties will be bound to it. -

-
-var buttonView = {
-  label   : 'underscore',
-  onClick : function(){ alert('clicked: ' + this.label); },
-  onHover : function(){ console.log('hovering: ' + this.label); }
-};
-_.bindAll(buttonView);
-jQuery('#underscore_button').bind('click', buttonView.onClick);
-=> When the button is clicked, this.label will have the correct value...
-
- -

- partial_.partial(function, [*arguments]) -
- Partially apply a function by filling in any number of its arguments, - without changing its dynamic this value. A close cousin - of bind. -

-
-var add = function(a, b) { return a + b; };
-add5 = _.partial(add, 5);
-add5(10);
-=> 15
-
- -

- memoize_.memoize(function, [hashFunction]) -
- Memoizes a given function by caching the computed result. Useful - for speeding up slow-running computations. If passed an optional - hashFunction, it will be used to compute the hash key for storing - the result, based on the arguments to the original function. The default - hashFunction just uses the first argument to the memoized function - as the key. -

-
-var fibonacci = _.memoize(function(n) {
-  return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2);
-});
-
- -

- delay_.delay(function, wait, [*arguments]) -
- Much like setTimeout, invokes function after wait - milliseconds. If you pass the optional arguments, they will be - forwarded on to the function when it is invoked. -

-
-var log = _.bind(console.log, console);
-_.delay(log, 1000, 'logged later');
-=> 'logged later' // Appears after one second.
-
- -

- defer_.defer(function, [*arguments]) -
- Defers invoking the function until the current call stack has cleared, - similar to using setTimeout with a delay of 0. Useful for performing - expensive computations or HTML rendering in chunks without blocking the UI thread - from updating. If you pass the optional arguments, they will be - forwarded on to the function when it is invoked. -

-
-_.defer(function(){ alert('deferred'); });
-// Returns from the function before the alert runs.
-
- -

- throttle_.throttle(function, wait) -
- Creates and returns a new, throttled version of the passed function, - that, when invoked repeatedly, will only actually call the original function - at most once per every wait - milliseconds. Useful for rate-limiting events that occur faster than you - can keep up with. -

-
-var throttled = _.throttle(updatePosition, 100);
-$(window).scroll(throttled);
-
- -

- debounce_.debounce(function, wait, [immediate]) -
- Creates and returns a new debounced version of the passed function that - will postpone its execution until after - wait milliseconds have elapsed since the last time it - was invoked. Useful for implementing behavior that should only happen - after the input has stopped arriving. For example: rendering a - preview of a Markdown comment, recalculating a layout after the window - has stopped being resized, and so on. -

- -

- Pass true for the immediate parameter to cause - debounce to trigger the function on the leading instead of the - trailing edge of the wait interval. Useful in circumstances like - preventing accidental double-clicks on a "submit" button from firing a - second time. -

- -
-var lazyLayout = _.debounce(calculateLayout, 300);
-$(window).resize(lazyLayout);
-
- -

- once_.once(function) -
- Creates a version of the function that can only be called one time. - Repeated calls to the modified function will have no effect, returning - the value from the original call. Useful for initialization functions, - instead of having to set a boolean flag and then check it later. -

-
-var initialize = _.once(createApplication);
-initialize();
-initialize();
-// Application is only created once.
-
- -

- after_.after(count, function) -
- Creates a version of the function that will only be run after first - being called count times. Useful for grouping asynchronous responses, - where you want to be sure that all the async calls have finished, before - proceeding. -

-
-var renderNotes = _.after(notes.length, render);
-_.each(notes, function(note) {
-  note.asyncSave({success: renderNotes});
-});
-// renderNotes is run once, after all notes have saved.
-
- -

- wrap_.wrap(function, wrapper) -
- Wraps the first function inside of the wrapper function, - passing it as the first argument. This allows the wrapper to - execute code before and after the function runs, adjust the arguments, - and execute it conditionally. -

-
-var hello = function(name) { return "hello: " + name; };
-hello = _.wrap(hello, function(func) {
-  return "before, " + func("moe") + ", after";
-});
-hello();
-=> 'before, hello: moe, after'
-
- -

- compose_.compose(*functions) -
- Returns the composition of a list of functions, where each function - consumes the return value of the function that follows. In math terms, - composing the functions f(), g(), and h() produces - f(g(h())). -

-
-var greet    = function(name){ return "hi: " + name; };
-var exclaim  = function(statement){ return statement + "!"; };
-var welcome = _.compose(exclaim, greet);
-welcome('moe');
-=> 'hi: moe!'
-
- -

Object Functions

- -

- keys_.keys(object) -
- Retrieve all the names of the object's properties. -

-
-_.keys({one : 1, two : 2, three : 3});
-=> ["one", "two", "three"]
-
- -

- values_.values(object) -
- Return all of the values of the object's properties. -

-
-_.values({one : 1, two : 2, three : 3});
-=> [1, 2, 3]
-
- -

- pairs_.pairs(object) -
- Convert an object into a list of [key, value] pairs. -

-
-_.pairs({one: 1, two: 2, three: 3});
-=> [["one", 1], ["two", 2], ["three", 3]]
-
- -

- invert_.invert(object) -
- Returns a copy of the object where the keys have become the values - and the values the keys. For this to work, all of your object's values - should be unique and string serializable. -

-
-_.invert({Moe: "Moses", Larry: "Louis", Curly: "Jerome"});
-=> {Moses: "Moe", Louis: "Larry", Jerome: "Curly"};
-
- -

- functions_.functions(object) - Alias: methods -
- Returns a sorted list of the names of every method in an object — - that is to say, the name of every function property of the object. -

-
-_.functions(_);
-=> ["all", "any", "bind", "bindAll", "clone", "compact", "compose" ...
-
- -

- extend_.extend(destination, *sources) -
- Copy all of the properties in the source objects over to the - destination object, and return the destination object. - It's in-order, so the last source will override properties of the same - name in previous arguments. -

-
-_.extend({name : 'moe'}, {age : 50});
-=> {name : 'moe', age : 50}
-
- -

- pick_.pick(object, *keys) -
- Return a copy of the object, filtered to only have values for - the whitelisted keys (or array of valid keys). -

-
-_.pick({name : 'moe', age: 50, userid : 'moe1'}, 'name', 'age');
-=> {name : 'moe', age : 50}
-
- -

- omit_.omit(object, *keys) -
- Return a copy of the object, filtered to omit the blacklisted - keys (or array of keys). -

-
-_.omit({name : 'moe', age : 50, userid : 'moe1'}, 'userid');
-=> {name : 'moe', age : 50}
-
- -

- defaults_.defaults(object, *defaults) -
- Fill in null and undefined properties in object with values from the - defaults objects, and return the object. As soon as the - property is filled, further defaults will have no effect. -

-
-var iceCream = {flavor : "chocolate"};
-_.defaults(iceCream, {flavor : "vanilla", sprinkles : "lots"});
-=> {flavor : "chocolate", sprinkles : "lots"}
-
- -

- clone_.clone(object) -
- Create a shallow-copied clone of the object. Any nested objects - or arrays will be copied by reference, not duplicated. -

-
-_.clone({name : 'moe'});
-=> {name : 'moe'};
-
- -

- tap_.tap(object, interceptor) -
- Invokes interceptor with the object, and then returns object. - The primary purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain. -

-
-_.chain([1,2,3,200])
-  .filter(function(num) { return num % 2 == 0; })
-  .tap(alert)
-  .map(function(num) { return num * num })
-  .value();
-=> // [2, 200] (alerted)
-=> [4, 40000]
-
- -

- has_.has(object, key) -
- Does the object contain the given key? Identical to - object.hasOwnProperty(key), but uses a safe reference to the - hasOwnProperty function, in case it's been - overridden accidentally. -

-
-_.has({a: 1, b: 2, c: 3}, "b");
-=> true
-
- -

- isEqual_.isEqual(object, other) -
- Performs an optimized deep comparison between the two objects, to determine - if they should be considered equal. -

-
-var moe   = {name : 'moe', luckyNumbers : [13, 27, 34]};
-var clone = {name : 'moe', luckyNumbers : [13, 27, 34]};
-moe == clone;
-=> false
-_.isEqual(moe, clone);
-=> true
-
- -

- isEmpty_.isEmpty(object) -
- Returns true if object contains no values. -

-
-_.isEmpty([1, 2, 3]);
-=> false
-_.isEmpty({});
-=> true
-
- -

- isElement_.isElement(object) -
- Returns true if object is a DOM element. -

-
-_.isElement(jQuery('body')[0]);
-=> true
-
- -

- isArray_.isArray(object) -
- Returns true if object is an Array. -

-
-(function(){ return _.isArray(arguments); })();
-=> false
-_.isArray([1,2,3]);
-=> true
-
- -

- isObject_.isObject(value) -
- Returns true if value is an Object. Note that JavaScript - arrays and functions are objects, while (normal) strings and numbers are not. -

-
-_.isObject({});
-=> true
-_.isObject(1);
-=> false
-
- -

- isArguments_.isArguments(object) -
- Returns true if object is an Arguments object. -

-
-(function(){ return _.isArguments(arguments); })(1, 2, 3);
-=> true
-_.isArguments([1,2,3]);
-=> false
-
- -

- isFunction_.isFunction(object) -
- Returns true if object is a Function. -

-
-_.isFunction(alert);
-=> true
-
- -

- isString_.isString(object) -
- Returns true if object is a String. -

-
-_.isString("moe");
-=> true
-
- -

- isNumber_.isNumber(object) -
- Returns true if object is a Number (including NaN). -

-
-_.isNumber(8.4 * 5);
-=> true
-
- -

- isFinite_.isFinite(object) -
- Returns true if object is a finite Number. -

-
-_.isFinite(-101);
-=> true
-
-_.isFinite(-Infinity);
-=> false
-
- -

- isBoolean_.isBoolean(object) -
- Returns true if object is either true or false. -

-
-_.isBoolean(null);
-=> false
-
- -

- isDate_.isDate(object) -
- Returns true if object is a Date. -

-
-_.isDate(new Date());
-=> true
-
- -

- isRegExp_.isRegExp(object) -
- Returns true if object is a RegExp. -

-
-_.isRegExp(/moe/);
-=> true
-
- -

- isNaN_.isNaN(object) -
- Returns true if object is NaN.
Note: this is not - the same as the native isNaN function, which will also return - true if the variable is undefined. -

-
-_.isNaN(NaN);
-=> true
-isNaN(undefined);
-=> true
-_.isNaN(undefined);
-=> false
-
- -

- isNull_.isNull(object) -
- Returns true if the value of object is null. -

-
-_.isNull(null);
-=> true
-_.isNull(undefined);
-=> false
-
- -

- isUndefined_.isUndefined(value) -
- Returns true if value is undefined. -

-
-_.isUndefined(window.missingVariable);
-=> true
-
- -

Utility Functions

- -

- noConflict_.noConflict() -
- Give control of the "_" variable back to its previous owner. Returns - a reference to the Underscore object. -

-
-var underscore = _.noConflict();
- -

- identity_.identity(value) -
- Returns the same value that is used as the argument. In math: - f(x) = x
- This function looks useless, but is used throughout Underscore as - a default iterator. -

-
-var moe = {name : 'moe'};
-moe === _.identity(moe);
-=> true
- -

- times_.times(n, iterator, [context]) -
- Invokes the given iterator function n times. Each invocation of - iterator is called with an index argument. -
- Note: this example uses the chaining syntax. -

-
-_(3).times(function(n){ genie.grantWishNumber(n); });
- -

- random_.random(min, max) -
- Returns a random integer between min and max, inclusive. - If you only pass one argument, it will return a number between 0 - and that number. -

-
-_.random(0, 100);
-=> 42
- -

- mixin_.mixin(object) -
- Allows you to extend Underscore with your own utility functions. Pass - a hash of {name: function} definitions to have your functions - added to the Underscore object, as well as the OOP wrapper. -

-
-_.mixin({
-  capitalize : function(string) {
-    return string.charAt(0).toUpperCase() + string.substring(1).toLowerCase();
-  }
-});
-_("fabio").capitalize();
-=> "Fabio"
-
- -

- uniqueId_.uniqueId([prefix]) -
- Generate a globally-unique id for client-side models or DOM elements - that need one. If prefix is passed, the id will be appended to it. -

-
-_.uniqueId('contact_');
-=> 'contact_104'
- -

- escape_.escape(string) -
- Escapes a string for insertion into HTML, replacing - &, <, >, ", ', and / characters. -

-
-_.escape('Curly, Larry & Moe');
-=> "Curly, Larry &amp; Moe"
- -

- unescape_.unescape(string) -
- The opposite of escape, replaces - &amp;, &lt;, &gt;, - &quot;, &#x27;, and &#x2F; - with their unescaped counterparts. -

-
-_.unescape('Curly, Larry &amp; Moe');
-=> "Curly, Larry & Moe"
- -

- result_.result(object, property) -
- If the value of the named property is a function then invoke it; otherwise, return it. -

-
-var object = {cheese: 'crumpets', stuff: function(){ return 'nonsense'; }};
-_.result(object, 'cheese');
-=> "crumpets"
-_.result(object, 'stuff');
-=> "nonsense"
- -

- template_.template(templateString, [data], [settings]) -
- Compiles JavaScript templates into functions that can be evaluated - for rendering. Useful for rendering complicated bits of HTML from JSON - data sources. Template functions can both interpolate variables, using - <%= … %>, as well as execute arbitrary JavaScript code, with - <% … %>. If you wish to interpolate a value, and have - it be HTML-escaped, use <%- … %> When you evaluate a template function, pass in a - data object that has properties corresponding to the template's free - variables. If you're writing a one-off, you can pass the data - object as the second parameter to template in order to render - immediately instead of returning a template function. The settings argument - should be a hash containing any _.templateSettings that should be overridden. -

- -
-var compiled = _.template("hello: <%= name %>");
-compiled({name : 'moe'});
-=> "hello: moe"
-
-var list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>";
-_.template(list, {people : ['moe', 'curly', 'larry']});
-=> "<li>moe</li><li>curly</li><li>larry</li>"
-
-var template = _.template("<b><%- value %></b>");
-template({value : '<script>'});
-=> "<b>&lt;script&gt;</b>"
- -

- You can also use print from within JavaScript code. This is - sometimes more convenient than using <%= ... %>. -

- -
-var compiled = _.template("<% print('Hello ' + epithet); %>");
-compiled({epithet: "stooge"});
-=> "Hello stooge."
- -

- If ERB-style delimiters aren't your cup of tea, you can change Underscore's - template settings to use different symbols to set off interpolated code. - Define an interpolate regex to match expressions that should be - interpolated verbatim, an escape regex to match expressions that should - be inserted after being HTML escaped, and an evaluate regex to match - expressions that should be evaluated without insertion into the resulting - string. You may define or omit any combination of the three. - For example, to perform - Mustache.js - style templating: -

- -
-_.templateSettings = {
-  interpolate : /\{\{(.+?)\}\}/g
-};
-
-var template = _.template("Hello {{ name }}!");
-template({name : "Mustache"});
-=> "Hello Mustache!"
- -

- By default, template places the values from your data in the local scope - via the with statement. However, you can specify a single variable name - with the variable setting. This can significantly improve the speed - at which a template is able to render. -

- -
-_.template("Using 'with': <%= data.answer %>", {answer: 'no'}, {variable: 'data'});
-=> "Using 'with': no"
- -

- Precompiling your templates can be a big help when debugging errors you can't - reproduce. This is because precompiled templates can provide line numbers and - a stack trace, something that is not possible when compiling templates on the client. - The source property is available on the compiled template - function for easy precompilation. -

- -
<script>
-  JST.project = <%= _.template(jstText).source %>;
-</script>
- - -

Chaining

- -

- You can use Underscore in either an object-oriented or a functional style, - depending on your preference. The following two lines of code are - identical ways to double a list of numbers. -

- -
-_.map([1, 2, 3], function(n){ return n * 2; });
-_([1, 2, 3]).map(function(n){ return n * 2; });
- -

- Calling chain will cause all future method calls to return - wrapped objects. When you've finished the computation, use - value to retrieve the final value. Here's an example of chaining - together a map/flatten/reduce, in order to get the word count of - every word in a song. -

- -
-var lyrics = [
-  {line : 1, words : "I'm a lumberjack and I'm okay"},
-  {line : 2, words : "I sleep all night and I work all day"},
-  {line : 3, words : "He's a lumberjack and he's okay"},
-  {line : 4, words : "He sleeps all night and he works all day"}
-];
-
-_.chain(lyrics)
-  .map(function(line) { return line.words.split(' '); })
-  .flatten()
-  .reduce(function(counts, word) {
-    counts[word] = (counts[word] || 0) + 1;
-    return counts;
-  }, {})
-  .value();
-
-=> {lumberjack : 2, all : 4, night : 2 ... }
- -

- In addition, the - Array prototype's methods - are proxied through the chained Underscore object, so you can slip a - reverse or a push into your chain, and continue to - modify the array. -

- -

- chain_.chain(obj) -
- Returns a wrapped object. Calling methods on this object will continue - to return wrapped objects until value is used. -

-
-var stooges = [{name : 'curly', age : 25}, {name : 'moe', age : 21}, {name : 'larry', age : 23}];
-var youngest = _.chain(stooges)
-  .sortBy(function(stooge){ return stooge.age; })
-  .map(function(stooge){ return stooge.name + ' is ' + stooge.age; })
-  .first()
-  .value();
-=> "moe is 21"
-
- -

- value_(obj).value() -
- Extracts the value of a wrapped object. -

-
-_([1, 2, 3]).value();
-=> [1, 2, 3]
-
- - - -

- The Underscore documentation is also available in - Simplified Chinese. -

- -

- Underscore.lua, - a Lua port of the functions that are applicable in both languages. - Includes OOP-wrapping and chaining. - (source) -

- -

- Underscore.m, an Objective-C port - of many of the Underscore.js functions, using a syntax that encourages - chaining. - (source) -

- -

- _.m, an alternative - Objective-C port that tries to stick a little closer to the original - Underscore.js API. - (source) -

- -

- Underscore.php, - a PHP port of the functions that are applicable in both languages. - Includes OOP-wrapping and chaining. - (source) -

- -

- Underscore-perl, - a Perl port of many of the Underscore.js functions, - aimed at on Perl hashes and arrays. - (source) -

- -

- Underscore.cfc, - a Coldfusion port of many of the Underscore.js functions. - (source) -

- -

- Underscore.string, - an Underscore extension that adds functions for string-manipulation: - trim, startsWith, contains, capitalize, - reverse, sprintf, and more. -

- -

- Ruby's Enumerable module. -

- -

- Prototype.js, which provides - JavaScript with collection functions in the manner closest to Ruby's Enumerable. -

- -

- Oliver Steele's - Functional JavaScript, - which includes comprehensive higher-order function support as well as string lambdas. -

- -

- Michael Aufreiter's Data.js, - a data manipulation + persistence library for JavaScript. -

- -

- Python's itertools. -

- -

Change Log

- -

- 1.4.4Jan. 30, 2013Diff
-

    -
  • - Added _.findWhere, for finding the first element in a list - that matches a particular set of keys and values. -
  • -
  • - Added _.partial, for partially applying a function without - changing its dynamic reference to this. -
  • -
  • - Simplified bind by removing some edge cases involving - constructor functions. In short: don't _.bind your - constructors. -
  • -
  • - A minor optimization to invoke. -
  • -
  • - Fix bug in the minified version due to the minifier incorrectly - optimizing-away isFunction. -
  • -
-

- -

- 1.4.3Dec. 4, 2012Diff
-

    -
  • - Improved Underscore compatibility with Adobe's JS engine that can be - used to script Illustrator, Photoshop, and friends. -
  • -
  • - Added a default _.identity iterator to countBy and - groupBy. -
  • -
  • - The uniq function can now take array, iterator, context - as the argument list. -
  • -
  • - The times function now returns the mapped array of iterator - results. -
  • -
  • - Simplified and fixed bugs in throttle. -
  • -
-

- -

- 1.4.2Oct. 1, 2012Diff
-

    -
  • - For backwards compatibility, returned to pre-1.4.0 behavior when - passing null to iteration functions. They now become no-ops - again. -
  • -
-

- -

- 1.4.1Oct. 1, 2012Diff
-

    -
  • - Fixed a 1.4.0 regression in the lastIndexOf function. -
  • -
-

- -

- 1.4.0Sept. 27, 2012Diff
-

    -
  • - Added a pairs function, for turning a JavaScript object - into [key, value] pairs ... as well as an object - function, for converting an array of [key, value] pairs - into an object. -
  • -
  • - Added a countBy function, for counting the number of objects - in a list that match a certain criteria. -
  • -
  • - Added an invert function, for performing a simple inversion - of the keys and values in an object. -
  • -
  • - Added a where function, for easy cases of filtering a list - for objects with specific values. -
  • -
  • - Added an omit function, for filtering an object to remove - certain keys. -
  • -
  • - Added a random function, to return a random number in a - given range. -
  • -
  • - _.debounce'd functions now return their last updated value, - just like _.throttle'd functions do. -
  • -
  • - The sortBy function now runs a stable sort algorithm. -
  • -
  • - Added the optional fromIndex option to indexOf and - lastIndexOf. -
  • -
  • - "Sparse" arrays are no longer supported in Underscore iteration - functions. Use a for loop instead (or better yet, an object). -
  • -
  • - The min and max functions may now be called on - very large arrays. -
  • -
  • - Interpolation in templates now represents null and - undefined as the empty string. -
  • -
  • - Underscore iteration functions no longer accept null values - as a no-op argument. You'll get an early error instead. -
  • -
  • - A number of edge-cases fixes and tweaks, which you can spot in the - diff. - Depending on how you're using Underscore, 1.4.0 may be more - backwards-incompatible than usual — please test when you upgrade. -
  • -
-

- -

- 1.3.3April 10, 2012
-

    -
  • - Many improvements to _.template, which now provides the - source of the template function as a property, for potentially - even more efficient pre-compilation on the server-side. You may now - also set the variable option when creating a template, - which will cause your passed-in data to be made available under the - variable you named, instead of using a with statement — - significantly improving the speed of rendering the template. -
  • -
  • - Added the pick function, which allows you to filter an - object literal with a whitelist of allowed property names. -
  • -
  • - Added the result function, for convenience when working - with APIs that allow either functions or raw properties. -
  • -
  • - Added the isFinite function, because sometimes knowing that - a value is a number just ain't quite enough. -
  • -
  • - The sortBy function may now also be passed the string name - of a property to use as the sort order on each object. -
  • -
  • - Fixed uniq to work with sparse arrays. -
  • -
  • - The difference function now performs a shallow flatten - instead of a deep one when computing array differences. -
  • -
  • - The debounce function now takes an immediate - parameter, which will cause the callback to fire on the leading - instead of the trailing edge. -
  • -
-

- -

- 1.3.1Jan. 23, 2012
-

    -
  • - Added an _.has function, as a safer way to use hasOwnProperty. -
  • -
  • - Added _.collect as an alias for _.map. Smalltalkers, rejoice. -
  • -
  • - Reverted an old change so that _.extend will correctly copy - over keys with undefined values again. -
  • -
  • - Bugfix to stop escaping slashes within interpolations in _.template. -
  • -
-

- -

- 1.3.0Jan. 11, 2012
-

    -
  • - Removed AMD (RequireJS) support from Underscore. If you'd like to use - Underscore with RequireJS, you can load it as a normal script, wrap - or patch your copy, or download a forked version. -
  • -
-

- -

- 1.2.4Jan. 4, 2012
-

    -
  • - You now can (and probably should, as it's simpler) - write _.chain(list) - instead of _(list).chain(). -
  • -
  • - Fix for escaped characters in Underscore templates, and for supporting - customizations of _.templateSettings that only define one or - two of the required regexes. -
  • -
  • - Fix for passing an array as the first argument to an _.wrap'd function. -
  • -
  • - Improved compatibility with ClojureScript, which adds a call - function to String.prototype. -
  • -
-

- -

- 1.2.3Dec. 7, 2011
-

    -
  • - Dynamic scope is now preserved for compiled _.template functions, - so you can use the value of this if you like. -
  • -
  • - Sparse array support of _.indexOf, _.lastIndexOf. -
  • -
  • - Both _.reduce and _.reduceRight can now be passed an - explicitly undefined value. (There's no reason why you'd - want to do this.) -
  • -
-

- -

- 1.2.2Nov. 14, 2011
-

    -
  • - Continued tweaks to _.isEqual semantics. Now JS primitives are - considered equivalent to their wrapped versions, and arrays are compared - by their numeric properties only (#351). -
  • -
  • - _.escape no longer tries to be smart about not double-escaping - already-escaped HTML entities. Now it just escapes regardless (#350). -
  • -
  • - In _.template, you may now leave semicolons out of evaluated - statements if you wish: <% }) %> (#369). -
  • -
  • - _.after(callback, 0) will now trigger the callback immediately, - making "after" easier to use with asynchronous APIs (#366). -
  • -
-

- -

- 1.2.1Oct. 24, 2011
-

    -
  • - Several important bug fixes for _.isEqual, which should now - do better on mutated Arrays, and on non-Array objects with - length properties. (#329) -
  • -
  • - jrburke contributed Underscore exporting for AMD module loaders, - and tonylukasavage for Appcelerator Titanium. - (#335, #338) -
  • -
  • - You can now _.groupBy(list, 'property') as a shortcut for - grouping values by a particular common property. -
  • -
  • - _.throttle'd functions now fire immediately upon invocation, - and are rate-limited thereafter (#170, #266). -
  • -
  • - Most of the _.is[Type] checks no longer ducktype. -
  • -
  • - The _.bind function now also works on constructors, a-la - ES5 ... but you would never want to use _.bind on a - constructor function. -
  • -
  • - _.clone no longer wraps non-object types in Objects. -
  • -
  • - _.find and _.filter are now the preferred names for - _.detect and _.select. -
  • -
-

- -

- 1.2.0Oct. 5, 2011
-

    -
  • - The _.isEqual function now - supports true deep equality comparisons, with checks for cyclic structures, - thanks to Kit Cambridge. -
  • -
  • - Underscore templates now support HTML escaping interpolations, using - <%- ... %> syntax. -
  • -
  • - Ryan Tenney contributed _.shuffle, which uses a modified - Fisher-Yates to give you a shuffled copy of an array. -
  • -
  • - _.uniq can now be passed an optional iterator, to determine by - what criteria an object should be considered unique. -
  • -
  • - _.last now takes an optional argument which will return the last - N elements of the list. -
  • -
  • - A new _.initial function was added, as a mirror of _.rest, - which returns all the initial values of a list (except the last N). -
  • -
-

- -

- 1.1.7July 13, 2011
- Added _.groupBy, which aggregates a collection into groups of like items. - Added _.union and _.difference, to complement the - (re-named) _.intersection. - Various improvements for support of sparse arrays. - _.toArray now returns a clone, if directly passed an array. - _.functions now also returns the names of functions that are present - in the prototype chain. -

- -

- 1.1.6April 18, 2011
- Added _.after, which will return a function that only runs after - first being called a specified number of times. - _.invoke can now take a direct function reference. - _.every now requires an iterator function to be passed, which - mirrors the ECMA5 API. - _.extend no longer copies keys when the value is undefined. - _.bind now errors when trying to bind an undefined value. -

- -

- 1.1.5Mar 20, 2011
- Added an _.defaults function, for use merging together JS objects - representing default options. - Added an _.once function, for manufacturing functions that should - only ever execute a single time. - _.bind now delegates to the native ECMAScript 5 version, - where available. - _.keys now throws an error when used on non-Object values, as in - ECMAScript 5. - Fixed a bug with _.keys when used over sparse arrays. -

- -

- 1.1.4Jan 9, 2011
- Improved compliance with ES5's Array methods when passing null - as a value. _.wrap now correctly sets this for the - wrapped function. _.indexOf now takes an optional flag for - finding the insertion index in an array that is guaranteed to already - be sorted. Avoiding the use of .callee, to allow _.isArray - to work properly in ES5's strict mode. -

- -

- 1.1.3Dec 1, 2010
- In CommonJS, Underscore may now be required with just:
- var _ = require("underscore"). - Added _.throttle and _.debounce functions. - Removed _.breakLoop, in favor of an ECMA5-style un-break-able - each implementation — this removes the try/catch, and you'll now have - better stack traces for exceptions that are thrown within an Underscore iterator. - Improved the isType family of functions for better interoperability - with Internet Explorer host objects. - _.template now correctly escapes backslashes in templates. - Improved _.reduce compatibility with the ECMA5 version: - if you don't pass an initial value, the first item in the collection is used. - _.each no longer returns the iterated collection, for improved - consistency with ES5's forEach. -

- -

- 1.1.2
- Fixed _.contains, which was mistakenly pointing at - _.intersect instead of _.include, like it should - have been. Added _.unique as an alias for _.uniq. -

- -

- 1.1.1
- Improved the speed of _.template, and its handling of multiline - interpolations. Ryan Tenney contributed optimizations to many Underscore - functions. An annotated version of the source code is now available. -

- -

- 1.1.0
- The method signature of _.reduce has been changed to match - the ECMAScript 5 signature, instead of the Ruby/Prototype.js version. - This is a backwards-incompatible change. _.template may now be - called with no arguments, and preserves whitespace. _.contains - is a new alias for _.include. -

- -

- 1.0.4
- Andri Möll contributed the _.memoize - function, which can be used to speed up expensive repeated computations - by caching the results. -

- -

- 1.0.3
- Patch that makes _.isEqual return false if any property - of the compared object has a NaN value. Technically the correct - thing to do, but of questionable semantics. Watch out for NaN comparisons. -

- -

- 1.0.2
- Fixes _.isArguments in recent versions of Opera, which have - arguments objects as real Arrays. -

- -

- 1.0.1
- Bugfix for _.isEqual, when comparing two objects with the same - number of undefined keys, but with different names. -

- -

- 1.0.0
- Things have been stable for many months now, so Underscore is now - considered to be out of beta, at 1.0. Improvements since 0.6 - include _.isBoolean, and the ability to have _.extend - take multiple source objects. -

- -

- 0.6.0
- Major release. Incorporates a number of - Mile Frawley's refactors for - safer duck-typing on collection functions, and cleaner internals. A new - _.mixin method that allows you to extend Underscore with utility - functions of your own. Added _.times, which works the same as in - Ruby or Prototype.js. Native support for ECMAScript 5's Array.isArray, - and Object.keys. -

- -

- 0.5.8
- Fixed Underscore's collection functions to work on - NodeLists and - HTMLCollections - once more, thanks to - Justin Tulloss. -

- -

- 0.5.7
- A safer implementation of _.isArguments, and a - faster _.isNumber,
thanks to - Jed Schmidt. -

- -

- 0.5.6
- Customizable delimiters for _.template, contributed by - Noah Sloan. -

- -

- 0.5.5
- Fix for a bug in MobileSafari's OOP-wrapper, with the arguments object. -

- -

- 0.5.4
- Fix for multiple single quotes within a template string for - _.template. See: - Rick Strahl's blog post. -

- -

- 0.5.2
- New implementations of isArray, isDate, isFunction, - isNumber, isRegExp, and isString, thanks to - a suggestion from - Robert Kieffer. - Instead of doing Object#toString - comparisons, they now check for expected properties, which is less safe, - but more than an order of magnitude faster. Most other Underscore - functions saw minor speed improvements as a result. - Evgeniy Dolzhenko - contributed _.tap, - similar to Ruby 1.9's, - which is handy for injecting side effects (like logging) into chained calls. -

- -

- 0.5.1
- Added an _.isArguments function. Lots of little safety checks - and optimizations contributed by - Noah Sloan and - Andri Möll. -

- -

- 0.5.0
- [API Changes] _.bindAll now takes the context object as - its first parameter. If no method names are passed, all of the context - object's methods are bound to it, enabling chaining and easier binding. - _.functions now takes a single argument and returns the names - of its Function properties. Calling _.functions(_) will get you - the previous behavior. - Added _.isRegExp so that isEqual can now test for RegExp equality. - All of the "is" functions have been shrunk down into a single definition. - Karl Guertin contributed patches. -

- -

- 0.4.7
- Added isDate, isNaN, and isNull, for completeness. - Optimizations for isEqual when checking equality between Arrays - or Dates. _.keys is now 25%–2X faster (depending on your - browser) which speeds up the functions that rely on it, such as _.each. -

- -

- 0.4.6
- Added the range function, a port of the - Python - function of the same name, for generating flexibly-numbered lists - of integers. Original patch contributed by - Kirill Ishanov. -

- -

- 0.4.5
- Added rest for Arrays and arguments objects, and aliased - first as head, and rest as tail, - thanks to Luke Sutton's patches. - Added tests ensuring that all Underscore Array functions also work on - arguments objects. -

- -

- 0.4.4
- Added isString, and isNumber, for consistency. Fixed - _.isEqual(NaN, NaN) to return true (which is debatable). -

- -

- 0.4.3
- Started using the native StopIteration object in browsers that support it. - Fixed Underscore setup for CommonJS environments. -

- -

- 0.4.2
- Renamed the unwrapping function to value, for clarity. -

- -

- 0.4.1
- Chained Underscore objects now support the Array prototype methods, so - that you can perform the full range of operations on a wrapped array - without having to break your chain. Added a breakLoop method - to break in the middle of any Underscore iteration. Added an - isEmpty function that works on arrays and objects. -

- -

- 0.4.0
- All Underscore functions can now be called in an object-oriented style, - like so: _([1, 2, 3]).map(...);. Original patch provided by - Marc-André Cournoyer. - Wrapped objects can be chained through multiple - method invocations. A functions method - was added, providing a sorted list of all the functions in Underscore. -

- -

- 0.3.3
- Added the JavaScript 1.8 function reduceRight. Aliased it - as foldr, and aliased reduce as foldl. -

- -

- 0.3.2
- Now runs on stock Rhino - interpreters with: load("underscore.js"). - Added identity as a utility function. -

- -

- 0.3.1
- All iterators are now passed in the original collection as their third - argument, the same as JavaScript 1.6's forEach. Iterating over - objects is now called with (value, key, collection), for details - see _.each. -

- -

- 0.3.0
- Added Dmitry Baranovskiy's - comprehensive optimizations, merged in - Kris Kowal's patches to make Underscore - CommonJS and - Narwhal compliant. -

- -

- 0.2.0
- Added compose and lastIndexOf, renamed inject to - reduce, added aliases for inject, filter, - every, some, and forEach. -

- -

- 0.1.1
- Added noConflict, so that the "Underscore" object can be assigned to - other variables. -

- -

- 0.1.0
- Initial release of Underscore.js. -

- -

- - A DocumentCloud Project - -

- -
- -
- - - - - - diff --git a/node_modules/underscore/index.js b/node_modules/underscore/index.js deleted file mode 100644 index 2cf0ca5b..00000000 --- a/node_modules/underscore/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('./underscore'); diff --git a/node_modules/underscore/package.json b/node_modules/underscore/package.json deleted file mode 100644 index f4711373..00000000 --- a/node_modules/underscore/package.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "name": "underscore", - "description": "JavaScript's functional programming helper library.", - "homepage": "http://underscorejs.org", - "keywords": [ - "util", - "functional", - "server", - "client", - "browser" - ], - "author": { - "name": "Jeremy Ashkenas", - "email": "jeremy@documentcloud.org" - }, - "repository": { - "type": "git", - "url": "git://github.com/documentcloud/underscore.git" - }, - "main": "underscore.js", - "version": "1.4.4", - "devDependencies": { - "phantomjs": "0.2.2" - }, - "scripts": { - "test": "phantomjs test/vendor/runner.js test/index.html?noglobals=true" - }, - "readme": " __\n /\\ \\ __\n __ __ ___ \\_\\ \\ __ _ __ ____ ___ ___ _ __ __ /\\_\\ ____\n /\\ \\/\\ \\ /' _ `\\ /'_ \\ /'__`\\/\\ __\\/ ,__\\ / ___\\ / __`\\/\\ __\\/'__`\\ \\/\\ \\ /',__\\\n \\ \\ \\_\\ \\/\\ \\/\\ \\/\\ \\ \\ \\/\\ __/\\ \\ \\//\\__, `\\/\\ \\__//\\ \\ \\ \\ \\ \\//\\ __/ __ \\ \\ \\/\\__, `\\\n \\ \\____/\\ \\_\\ \\_\\ \\___,_\\ \\____\\\\ \\_\\\\/\\____/\\ \\____\\ \\____/\\ \\_\\\\ \\____\\/\\_\\ _\\ \\ \\/\\____/\n \\/___/ \\/_/\\/_/\\/__,_ /\\/____/ \\/_/ \\/___/ \\/____/\\/___/ \\/_/ \\/____/\\/_//\\ \\_\\ \\/___/\n \\ \\____/\n \\/___/\n\nUnderscore.js is a utility-belt library for JavaScript that provides\nsupport for the usual functional suspects (each, map, reduce, filter...)\nwithout extending any core JavaScript objects.\n\nFor Docs, License, Tests, and pre-packed downloads, see:\nhttp://underscorejs.org\n\nMany thanks to our contributors:\nhttps://github.com/documentcloud/underscore/contributors\n", - "readmeFilename": "README.md", - "_id": "underscore@1.4.4", - "_from": "underscore@" -} diff --git a/node_modules/underscore/underscore-min.js b/node_modules/underscore/underscore-min.js deleted file mode 100644 index c1d9d3ae..00000000 --- a/node_modules/underscore/underscore-min.js +++ /dev/null @@ -1 +0,0 @@ -(function(){var n=this,t=n._,r={},e=Array.prototype,u=Object.prototype,i=Function.prototype,a=e.push,o=e.slice,c=e.concat,l=u.toString,f=u.hasOwnProperty,s=e.forEach,p=e.map,h=e.reduce,v=e.reduceRight,d=e.filter,g=e.every,m=e.some,y=e.indexOf,b=e.lastIndexOf,x=Array.isArray,_=Object.keys,j=i.bind,w=function(n){return n instanceof w?n:this instanceof w?(this._wrapped=n,void 0):new w(n)};"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=w),exports._=w):n._=w,w.VERSION="1.4.4";var A=w.each=w.forEach=function(n,t,e){if(null!=n)if(s&&n.forEach===s)n.forEach(t,e);else if(n.length===+n.length){for(var u=0,i=n.length;i>u;u++)if(t.call(e,n[u],u,n)===r)return}else for(var a in n)if(w.has(n,a)&&t.call(e,n[a],a,n)===r)return};w.map=w.collect=function(n,t,r){var e=[];return null==n?e:p&&n.map===p?n.map(t,r):(A(n,function(n,u,i){e[e.length]=t.call(r,n,u,i)}),e)};var O="Reduce of empty array with no initial value";w.reduce=w.foldl=w.inject=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),h&&n.reduce===h)return e&&(t=w.bind(t,e)),u?n.reduce(t,r):n.reduce(t);if(A(n,function(n,i,a){u?r=t.call(e,r,n,i,a):(r=n,u=!0)}),!u)throw new TypeError(O);return r},w.reduceRight=w.foldr=function(n,t,r,e){var u=arguments.length>2;if(null==n&&(n=[]),v&&n.reduceRight===v)return e&&(t=w.bind(t,e)),u?n.reduceRight(t,r):n.reduceRight(t);var i=n.length;if(i!==+i){var a=w.keys(n);i=a.length}if(A(n,function(o,c,l){c=a?a[--i]:--i,u?r=t.call(e,r,n[c],c,l):(r=n[c],u=!0)}),!u)throw new TypeError(O);return r},w.find=w.detect=function(n,t,r){var e;return E(n,function(n,u,i){return t.call(r,n,u,i)?(e=n,!0):void 0}),e},w.filter=w.select=function(n,t,r){var e=[];return null==n?e:d&&n.filter===d?n.filter(t,r):(A(n,function(n,u,i){t.call(r,n,u,i)&&(e[e.length]=n)}),e)},w.reject=function(n,t,r){return w.filter(n,function(n,e,u){return!t.call(r,n,e,u)},r)},w.every=w.all=function(n,t,e){t||(t=w.identity);var u=!0;return null==n?u:g&&n.every===g?n.every(t,e):(A(n,function(n,i,a){return(u=u&&t.call(e,n,i,a))?void 0:r}),!!u)};var E=w.some=w.any=function(n,t,e){t||(t=w.identity);var u=!1;return null==n?u:m&&n.some===m?n.some(t,e):(A(n,function(n,i,a){return u||(u=t.call(e,n,i,a))?r:void 0}),!!u)};w.contains=w.include=function(n,t){return null==n?!1:y&&n.indexOf===y?n.indexOf(t)!=-1:E(n,function(n){return n===t})},w.invoke=function(n,t){var r=o.call(arguments,2),e=w.isFunction(t);return w.map(n,function(n){return(e?t:n[t]).apply(n,r)})},w.pluck=function(n,t){return w.map(n,function(n){return n[t]})},w.where=function(n,t,r){return w.isEmpty(t)?r?null:[]:w[r?"find":"filter"](n,function(n){for(var r in t)if(t[r]!==n[r])return!1;return!0})},w.findWhere=function(n,t){return w.where(n,t,!0)},w.max=function(n,t,r){if(!t&&w.isArray(n)&&n[0]===+n[0]&&65535>n.length)return Math.max.apply(Math,n);if(!t&&w.isEmpty(n))return-1/0;var e={computed:-1/0,value:-1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;a>=e.computed&&(e={value:n,computed:a})}),e.value},w.min=function(n,t,r){if(!t&&w.isArray(n)&&n[0]===+n[0]&&65535>n.length)return Math.min.apply(Math,n);if(!t&&w.isEmpty(n))return 1/0;var e={computed:1/0,value:1/0};return A(n,function(n,u,i){var a=t?t.call(r,n,u,i):n;e.computed>a&&(e={value:n,computed:a})}),e.value},w.shuffle=function(n){var t,r=0,e=[];return A(n,function(n){t=w.random(r++),e[r-1]=e[t],e[t]=n}),e};var k=function(n){return w.isFunction(n)?n:function(t){return t[n]}};w.sortBy=function(n,t,r){var e=k(t);return w.pluck(w.map(n,function(n,t,u){return{value:n,index:t,criteria:e.call(r,n,t,u)}}).sort(function(n,t){var r=n.criteria,e=t.criteria;if(r!==e){if(r>e||r===void 0)return 1;if(e>r||e===void 0)return-1}return n.indexi;){var o=i+a>>>1;u>r.call(e,n[o])?i=o+1:a=o}return i},w.toArray=function(n){return n?w.isArray(n)?o.call(n):n.length===+n.length?w.map(n,w.identity):w.values(n):[]},w.size=function(n){return null==n?0:n.length===+n.length?n.length:w.keys(n).length},w.first=w.head=w.take=function(n,t,r){return null==n?void 0:null==t||r?n[0]:o.call(n,0,t)},w.initial=function(n,t,r){return o.call(n,0,n.length-(null==t||r?1:t))},w.last=function(n,t,r){return null==n?void 0:null==t||r?n[n.length-1]:o.call(n,Math.max(n.length-t,0))},w.rest=w.tail=w.drop=function(n,t,r){return o.call(n,null==t||r?1:t)},w.compact=function(n){return w.filter(n,w.identity)};var R=function(n,t,r){return A(n,function(n){w.isArray(n)?t?a.apply(r,n):R(n,t,r):r.push(n)}),r};w.flatten=function(n,t){return R(n,t,[])},w.without=function(n){return w.difference(n,o.call(arguments,1))},w.uniq=w.unique=function(n,t,r,e){w.isFunction(t)&&(e=r,r=t,t=!1);var u=r?w.map(n,r,e):n,i=[],a=[];return A(u,function(r,e){(t?e&&a[a.length-1]===r:w.contains(a,r))||(a.push(r),i.push(n[e]))}),i},w.union=function(){return w.uniq(c.apply(e,arguments))},w.intersection=function(n){var t=o.call(arguments,1);return w.filter(w.uniq(n),function(n){return w.every(t,function(t){return w.indexOf(t,n)>=0})})},w.difference=function(n){var t=c.apply(e,o.call(arguments,1));return w.filter(n,function(n){return!w.contains(t,n)})},w.zip=function(){for(var n=o.call(arguments),t=w.max(w.pluck(n,"length")),r=Array(t),e=0;t>e;e++)r[e]=w.pluck(n,""+e);return r},w.object=function(n,t){if(null==n)return{};for(var r={},e=0,u=n.length;u>e;e++)t?r[n[e]]=t[e]:r[n[e][0]]=n[e][1];return r},w.indexOf=function(n,t,r){if(null==n)return-1;var e=0,u=n.length;if(r){if("number"!=typeof r)return e=w.sortedIndex(n,t),n[e]===t?e:-1;e=0>r?Math.max(0,u+r):r}if(y&&n.indexOf===y)return n.indexOf(t,r);for(;u>e;e++)if(n[e]===t)return e;return-1},w.lastIndexOf=function(n,t,r){if(null==n)return-1;var e=null!=r;if(b&&n.lastIndexOf===b)return e?n.lastIndexOf(t,r):n.lastIndexOf(t);for(var u=e?r:n.length;u--;)if(n[u]===t)return u;return-1},w.range=function(n,t,r){1>=arguments.length&&(t=n||0,n=0),r=arguments[2]||1;for(var e=Math.max(Math.ceil((t-n)/r),0),u=0,i=Array(e);e>u;)i[u++]=n,n+=r;return i},w.bind=function(n,t){if(n.bind===j&&j)return j.apply(n,o.call(arguments,1));var r=o.call(arguments,2);return function(){return n.apply(t,r.concat(o.call(arguments)))}},w.partial=function(n){var t=o.call(arguments,1);return function(){return n.apply(this,t.concat(o.call(arguments)))}},w.bindAll=function(n){var t=o.call(arguments,1);return 0===t.length&&(t=w.functions(n)),A(t,function(t){n[t]=w.bind(n[t],n)}),n},w.memoize=function(n,t){var r={};return t||(t=w.identity),function(){var e=t.apply(this,arguments);return w.has(r,e)?r[e]:r[e]=n.apply(this,arguments)}},w.delay=function(n,t){var r=o.call(arguments,2);return setTimeout(function(){return n.apply(null,r)},t)},w.defer=function(n){return w.delay.apply(w,[n,1].concat(o.call(arguments,1)))},w.throttle=function(n,t){var r,e,u,i,a=0,o=function(){a=new Date,u=null,i=n.apply(r,e)};return function(){var c=new Date,l=t-(c-a);return r=this,e=arguments,0>=l?(clearTimeout(u),u=null,a=c,i=n.apply(r,e)):u||(u=setTimeout(o,l)),i}},w.debounce=function(n,t,r){var e,u;return function(){var i=this,a=arguments,o=function(){e=null,r||(u=n.apply(i,a))},c=r&&!e;return clearTimeout(e),e=setTimeout(o,t),c&&(u=n.apply(i,a)),u}},w.once=function(n){var t,r=!1;return function(){return r?t:(r=!0,t=n.apply(this,arguments),n=null,t)}},w.wrap=function(n,t){return function(){var r=[n];return a.apply(r,arguments),t.apply(this,r)}},w.compose=function(){var n=arguments;return function(){for(var t=arguments,r=n.length-1;r>=0;r--)t=[n[r].apply(this,t)];return t[0]}},w.after=function(n,t){return 0>=n?t():function(){return 1>--n?t.apply(this,arguments):void 0}},w.keys=_||function(n){if(n!==Object(n))throw new TypeError("Invalid object");var t=[];for(var r in n)w.has(n,r)&&(t[t.length]=r);return t},w.values=function(n){var t=[];for(var r in n)w.has(n,r)&&t.push(n[r]);return t},w.pairs=function(n){var t=[];for(var r in n)w.has(n,r)&&t.push([r,n[r]]);return t},w.invert=function(n){var t={};for(var r in n)w.has(n,r)&&(t[n[r]]=r);return t},w.functions=w.methods=function(n){var t=[];for(var r in n)w.isFunction(n[r])&&t.push(r);return t.sort()},w.extend=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)n[r]=t[r]}),n},w.pick=function(n){var t={},r=c.apply(e,o.call(arguments,1));return A(r,function(r){r in n&&(t[r]=n[r])}),t},w.omit=function(n){var t={},r=c.apply(e,o.call(arguments,1));for(var u in n)w.contains(r,u)||(t[u]=n[u]);return t},w.defaults=function(n){return A(o.call(arguments,1),function(t){if(t)for(var r in t)null==n[r]&&(n[r]=t[r])}),n},w.clone=function(n){return w.isObject(n)?w.isArray(n)?n.slice():w.extend({},n):n},w.tap=function(n,t){return t(n),n};var I=function(n,t,r,e){if(n===t)return 0!==n||1/n==1/t;if(null==n||null==t)return n===t;n instanceof w&&(n=n._wrapped),t instanceof w&&(t=t._wrapped);var u=l.call(n);if(u!=l.call(t))return!1;switch(u){case"[object String]":return n==t+"";case"[object Number]":return n!=+n?t!=+t:0==n?1/n==1/t:n==+t;case"[object Date]":case"[object Boolean]":return+n==+t;case"[object RegExp]":return n.source==t.source&&n.global==t.global&&n.multiline==t.multiline&&n.ignoreCase==t.ignoreCase}if("object"!=typeof n||"object"!=typeof t)return!1;for(var i=r.length;i--;)if(r[i]==n)return e[i]==t;r.push(n),e.push(t);var a=0,o=!0;if("[object Array]"==u){if(a=n.length,o=a==t.length)for(;a--&&(o=I(n[a],t[a],r,e)););}else{var c=n.constructor,f=t.constructor;if(c!==f&&!(w.isFunction(c)&&c instanceof c&&w.isFunction(f)&&f instanceof f))return!1;for(var s in n)if(w.has(n,s)&&(a++,!(o=w.has(t,s)&&I(n[s],t[s],r,e))))break;if(o){for(s in t)if(w.has(t,s)&&!a--)break;o=!a}}return r.pop(),e.pop(),o};w.isEqual=function(n,t){return I(n,t,[],[])},w.isEmpty=function(n){if(null==n)return!0;if(w.isArray(n)||w.isString(n))return 0===n.length;for(var t in n)if(w.has(n,t))return!1;return!0},w.isElement=function(n){return!(!n||1!==n.nodeType)},w.isArray=x||function(n){return"[object Array]"==l.call(n)},w.isObject=function(n){return n===Object(n)},A(["Arguments","Function","String","Number","Date","RegExp"],function(n){w["is"+n]=function(t){return l.call(t)=="[object "+n+"]"}}),w.isArguments(arguments)||(w.isArguments=function(n){return!(!n||!w.has(n,"callee"))}),"function"!=typeof/./&&(w.isFunction=function(n){return"function"==typeof n}),w.isFinite=function(n){return isFinite(n)&&!isNaN(parseFloat(n))},w.isNaN=function(n){return w.isNumber(n)&&n!=+n},w.isBoolean=function(n){return n===!0||n===!1||"[object Boolean]"==l.call(n)},w.isNull=function(n){return null===n},w.isUndefined=function(n){return n===void 0},w.has=function(n,t){return f.call(n,t)},w.noConflict=function(){return n._=t,this},w.identity=function(n){return n},w.times=function(n,t,r){for(var e=Array(n),u=0;n>u;u++)e[u]=t.call(r,u);return e},w.random=function(n,t){return null==t&&(t=n,n=0),n+Math.floor(Math.random()*(t-n+1))};var M={escape:{"&":"&","<":"<",">":">",'"':""","'":"'","/":"/"}};M.unescape=w.invert(M.escape);var S={escape:RegExp("["+w.keys(M.escape).join("")+"]","g"),unescape:RegExp("("+w.keys(M.unescape).join("|")+")","g")};w.each(["escape","unescape"],function(n){w[n]=function(t){return null==t?"":(""+t).replace(S[n],function(t){return M[n][t]})}}),w.result=function(n,t){if(null==n)return null;var r=n[t];return w.isFunction(r)?r.call(n):r},w.mixin=function(n){A(w.functions(n),function(t){var r=w[t]=n[t];w.prototype[t]=function(){var n=[this._wrapped];return a.apply(n,arguments),D.call(this,r.apply(w,n))}})};var N=0;w.uniqueId=function(n){var t=++N+"";return n?n+t:t},w.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var T=/(.)^/,q={"'":"'","\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},B=/\\|'|\r|\n|\t|\u2028|\u2029/g;w.template=function(n,t,r){var e;r=w.defaults({},r,w.templateSettings);var u=RegExp([(r.escape||T).source,(r.interpolate||T).source,(r.evaluate||T).source].join("|")+"|$","g"),i=0,a="__p+='";n.replace(u,function(t,r,e,u,o){return a+=n.slice(i,o).replace(B,function(n){return"\\"+q[n]}),r&&(a+="'+\n((__t=("+r+"))==null?'':_.escape(__t))+\n'"),e&&(a+="'+\n((__t=("+e+"))==null?'':__t)+\n'"),u&&(a+="';\n"+u+"\n__p+='"),i=o+t.length,t}),a+="';\n",r.variable||(a="with(obj||{}){\n"+a+"}\n"),a="var __t,__p='',__j=Array.prototype.join,"+"print=function(){__p+=__j.call(arguments,'');};\n"+a+"return __p;\n";try{e=Function(r.variable||"obj","_",a)}catch(o){throw o.source=a,o}if(t)return e(t,w);var c=function(n){return e.call(this,n,w)};return c.source="function("+(r.variable||"obj")+"){\n"+a+"}",c},w.chain=function(n){return w(n).chain()};var D=function(n){return this._chain?w(n).chain():n};w.mixin(w),A(["pop","push","reverse","shift","sort","splice","unshift"],function(n){var t=e[n];w.prototype[n]=function(){var r=this._wrapped;return t.apply(r,arguments),"shift"!=n&&"splice"!=n||0!==r.length||delete r[0],D.call(this,r)}}),A(["concat","join","slice"],function(n){var t=e[n];w.prototype[n]=function(){return D.call(this,t.apply(this._wrapped,arguments))}}),w.extend(w.prototype,{chain:function(){return this._chain=!0,this},value:function(){return this._wrapped}})}).call(this); \ No newline at end of file diff --git a/node_modules/underscore/underscore.js b/node_modules/underscore/underscore.js deleted file mode 100644 index a12f0d96..00000000 --- a/node_modules/underscore/underscore.js +++ /dev/null @@ -1,1226 +0,0 @@ -// Underscore.js 1.4.4 -// http://underscorejs.org -// (c) 2009-2013 Jeremy Ashkenas, DocumentCloud Inc. -// Underscore may be freely distributed under the MIT license. - -(function() { - - // Baseline setup - // -------------- - - // Establish the root object, `window` in the browser, or `global` on the server. - var root = this; - - // Save the previous value of the `_` variable. - var previousUnderscore = root._; - - // Establish the object that gets returned to break out of a loop iteration. - var breaker = {}; - - // Save bytes in the minified (but not gzipped) version: - var ArrayProto = Array.prototype, ObjProto = Object.prototype, FuncProto = Function.prototype; - - // Create quick reference variables for speed access to core prototypes. - var push = ArrayProto.push, - slice = ArrayProto.slice, - concat = ArrayProto.concat, - toString = ObjProto.toString, - hasOwnProperty = ObjProto.hasOwnProperty; - - // All **ECMAScript 5** native function implementations that we hope to use - // are declared here. - var - nativeForEach = ArrayProto.forEach, - nativeMap = ArrayProto.map, - nativeReduce = ArrayProto.reduce, - nativeReduceRight = ArrayProto.reduceRight, - nativeFilter = ArrayProto.filter, - nativeEvery = ArrayProto.every, - nativeSome = ArrayProto.some, - nativeIndexOf = ArrayProto.indexOf, - nativeLastIndexOf = ArrayProto.lastIndexOf, - nativeIsArray = Array.isArray, - nativeKeys = Object.keys, - nativeBind = FuncProto.bind; - - // Create a safe reference to the Underscore object for use below. - var _ = function(obj) { - if (obj instanceof _) return obj; - if (!(this instanceof _)) return new _(obj); - this._wrapped = obj; - }; - - // Export the Underscore object for **Node.js**, with - // backwards-compatibility for the old `require()` API. If we're in - // the browser, add `_` as a global object via a string identifier, - // for Closure Compiler "advanced" mode. - if (typeof exports !== 'undefined') { - if (typeof module !== 'undefined' && module.exports) { - exports = module.exports = _; - } - exports._ = _; - } else { - root._ = _; - } - - // Current version. - _.VERSION = '1.4.4'; - - // Collection Functions - // -------------------- - - // The cornerstone, an `each` implementation, aka `forEach`. - // Handles objects with the built-in `forEach`, arrays, and raw objects. - // Delegates to **ECMAScript 5**'s native `forEach` if available. - var each = _.each = _.forEach = function(obj, iterator, context) { - if (obj == null) return; - if (nativeForEach && obj.forEach === nativeForEach) { - obj.forEach(iterator, context); - } else if (obj.length === +obj.length) { - for (var i = 0, l = obj.length; i < l; i++) { - if (iterator.call(context, obj[i], i, obj) === breaker) return; - } - } else { - for (var key in obj) { - if (_.has(obj, key)) { - if (iterator.call(context, obj[key], key, obj) === breaker) return; - } - } - } - }; - - // Return the results of applying the iterator to each element. - // Delegates to **ECMAScript 5**'s native `map` if available. - _.map = _.collect = function(obj, iterator, context) { - var results = []; - if (obj == null) return results; - if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); - each(obj, function(value, index, list) { - results[results.length] = iterator.call(context, value, index, list); - }); - return results; - }; - - var reduceError = 'Reduce of empty array with no initial value'; - - // **Reduce** builds up a single result from a list of values, aka `inject`, - // or `foldl`. Delegates to **ECMAScript 5**'s native `reduce` if available. - _.reduce = _.foldl = _.inject = function(obj, iterator, memo, context) { - var initial = arguments.length > 2; - if (obj == null) obj = []; - if (nativeReduce && obj.reduce === nativeReduce) { - if (context) iterator = _.bind(iterator, context); - return initial ? obj.reduce(iterator, memo) : obj.reduce(iterator); - } - each(obj, function(value, index, list) { - if (!initial) { - memo = value; - initial = true; - } else { - memo = iterator.call(context, memo, value, index, list); - } - }); - if (!initial) throw new TypeError(reduceError); - return memo; - }; - - // The right-associative version of reduce, also known as `foldr`. - // Delegates to **ECMAScript 5**'s native `reduceRight` if available. - _.reduceRight = _.foldr = function(obj, iterator, memo, context) { - var initial = arguments.length > 2; - if (obj == null) obj = []; - if (nativeReduceRight && obj.reduceRight === nativeReduceRight) { - if (context) iterator = _.bind(iterator, context); - return initial ? obj.reduceRight(iterator, memo) : obj.reduceRight(iterator); - } - var length = obj.length; - if (length !== +length) { - var keys = _.keys(obj); - length = keys.length; - } - each(obj, function(value, index, list) { - index = keys ? keys[--length] : --length; - if (!initial) { - memo = obj[index]; - initial = true; - } else { - memo = iterator.call(context, memo, obj[index], index, list); - } - }); - if (!initial) throw new TypeError(reduceError); - return memo; - }; - - // Return the first value which passes a truth test. Aliased as `detect`. - _.find = _.detect = function(obj, iterator, context) { - var result; - any(obj, function(value, index, list) { - if (iterator.call(context, value, index, list)) { - result = value; - return true; - } - }); - return result; - }; - - // Return all the elements that pass a truth test. - // Delegates to **ECMAScript 5**'s native `filter` if available. - // Aliased as `select`. - _.filter = _.select = function(obj, iterator, context) { - var results = []; - if (obj == null) return results; - if (nativeFilter && obj.filter === nativeFilter) return obj.filter(iterator, context); - each(obj, function(value, index, list) { - if (iterator.call(context, value, index, list)) results[results.length] = value; - }); - return results; - }; - - // Return all the elements for which a truth test fails. - _.reject = function(obj, iterator, context) { - return _.filter(obj, function(value, index, list) { - return !iterator.call(context, value, index, list); - }, context); - }; - - // Determine whether all of the elements match a truth test. - // Delegates to **ECMAScript 5**'s native `every` if available. - // Aliased as `all`. - _.every = _.all = function(obj, iterator, context) { - iterator || (iterator = _.identity); - var result = true; - if (obj == null) return result; - if (nativeEvery && obj.every === nativeEvery) return obj.every(iterator, context); - each(obj, function(value, index, list) { - if (!(result = result && iterator.call(context, value, index, list))) return breaker; - }); - return !!result; - }; - - // Determine if at least one element in the object matches a truth test. - // Delegates to **ECMAScript 5**'s native `some` if available. - // Aliased as `any`. - var any = _.some = _.any = function(obj, iterator, context) { - iterator || (iterator = _.identity); - var result = false; - if (obj == null) return result; - if (nativeSome && obj.some === nativeSome) return obj.some(iterator, context); - each(obj, function(value, index, list) { - if (result || (result = iterator.call(context, value, index, list))) return breaker; - }); - return !!result; - }; - - // Determine if the array or object contains a given value (using `===`). - // Aliased as `include`. - _.contains = _.include = function(obj, target) { - if (obj == null) return false; - if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1; - return any(obj, function(value) { - return value === target; - }); - }; - - // Invoke a method (with arguments) on every item in a collection. - _.invoke = function(obj, method) { - var args = slice.call(arguments, 2); - var isFunc = _.isFunction(method); - return _.map(obj, function(value) { - return (isFunc ? method : value[method]).apply(value, args); - }); - }; - - // Convenience version of a common use case of `map`: fetching a property. - _.pluck = function(obj, key) { - return _.map(obj, function(value){ return value[key]; }); - }; - - // Convenience version of a common use case of `filter`: selecting only objects - // containing specific `key:value` pairs. - _.where = function(obj, attrs, first) { - if (_.isEmpty(attrs)) return first ? null : []; - return _[first ? 'find' : 'filter'](obj, function(value) { - for (var key in attrs) { - if (attrs[key] !== value[key]) return false; - } - return true; - }); - }; - - // Convenience version of a common use case of `find`: getting the first object - // containing specific `key:value` pairs. - _.findWhere = function(obj, attrs) { - return _.where(obj, attrs, true); - }; - - // Return the maximum element or (element-based computation). - // Can't optimize arrays of integers longer than 65,535 elements. - // See: https://bugs.webkit.org/show_bug.cgi?id=80797 - _.max = function(obj, iterator, context) { - if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) { - return Math.max.apply(Math, obj); - } - if (!iterator && _.isEmpty(obj)) return -Infinity; - var result = {computed : -Infinity, value: -Infinity}; - each(obj, function(value, index, list) { - var computed = iterator ? iterator.call(context, value, index, list) : value; - computed >= result.computed && (result = {value : value, computed : computed}); - }); - return result.value; - }; - - // Return the minimum element (or element-based computation). - _.min = function(obj, iterator, context) { - if (!iterator && _.isArray(obj) && obj[0] === +obj[0] && obj.length < 65535) { - return Math.min.apply(Math, obj); - } - if (!iterator && _.isEmpty(obj)) return Infinity; - var result = {computed : Infinity, value: Infinity}; - each(obj, function(value, index, list) { - var computed = iterator ? iterator.call(context, value, index, list) : value; - computed < result.computed && (result = {value : value, computed : computed}); - }); - return result.value; - }; - - // Shuffle an array. - _.shuffle = function(obj) { - var rand; - var index = 0; - var shuffled = []; - each(obj, function(value) { - rand = _.random(index++); - shuffled[index - 1] = shuffled[rand]; - shuffled[rand] = value; - }); - return shuffled; - }; - - // An internal function to generate lookup iterators. - var lookupIterator = function(value) { - return _.isFunction(value) ? value : function(obj){ return obj[value]; }; - }; - - // Sort the object's values by a criterion produced by an iterator. - _.sortBy = function(obj, value, context) { - var iterator = lookupIterator(value); - return _.pluck(_.map(obj, function(value, index, list) { - return { - value : value, - index : index, - criteria : iterator.call(context, value, index, list) - }; - }).sort(function(left, right) { - var a = left.criteria; - var b = right.criteria; - if (a !== b) { - if (a > b || a === void 0) return 1; - if (a < b || b === void 0) return -1; - } - return left.index < right.index ? -1 : 1; - }), 'value'); - }; - - // An internal function used for aggregate "group by" operations. - var group = function(obj, value, context, behavior) { - var result = {}; - var iterator = lookupIterator(value || _.identity); - each(obj, function(value, index) { - var key = iterator.call(context, value, index, obj); - behavior(result, key, value); - }); - return result; - }; - - // Groups the object's values by a criterion. Pass either a string attribute - // to group by, or a function that returns the criterion. - _.groupBy = function(obj, value, context) { - return group(obj, value, context, function(result, key, value) { - (_.has(result, key) ? result[key] : (result[key] = [])).push(value); - }); - }; - - // Counts instances of an object that group by a certain criterion. Pass - // either a string attribute to count by, or a function that returns the - // criterion. - _.countBy = function(obj, value, context) { - return group(obj, value, context, function(result, key) { - if (!_.has(result, key)) result[key] = 0; - result[key]++; - }); - }; - - // Use a comparator function to figure out the smallest index at which - // an object should be inserted so as to maintain order. Uses binary search. - _.sortedIndex = function(array, obj, iterator, context) { - iterator = iterator == null ? _.identity : lookupIterator(iterator); - var value = iterator.call(context, obj); - var low = 0, high = array.length; - while (low < high) { - var mid = (low + high) >>> 1; - iterator.call(context, array[mid]) < value ? low = mid + 1 : high = mid; - } - return low; - }; - - // Safely convert anything iterable into a real, live array. - _.toArray = function(obj) { - if (!obj) return []; - if (_.isArray(obj)) return slice.call(obj); - if (obj.length === +obj.length) return _.map(obj, _.identity); - return _.values(obj); - }; - - // Return the number of elements in an object. - _.size = function(obj) { - if (obj == null) return 0; - return (obj.length === +obj.length) ? obj.length : _.keys(obj).length; - }; - - // Array Functions - // --------------- - - // Get the first element of an array. Passing **n** will return the first N - // values in the array. Aliased as `head` and `take`. The **guard** check - // allows it to work with `_.map`. - _.first = _.head = _.take = function(array, n, guard) { - if (array == null) return void 0; - return (n != null) && !guard ? slice.call(array, 0, n) : array[0]; - }; - - // Returns everything but the last entry of the array. Especially useful on - // the arguments object. Passing **n** will return all the values in - // the array, excluding the last N. The **guard** check allows it to work with - // `_.map`. - _.initial = function(array, n, guard) { - return slice.call(array, 0, array.length - ((n == null) || guard ? 1 : n)); - }; - - // Get the last element of an array. Passing **n** will return the last N - // values in the array. The **guard** check allows it to work with `_.map`. - _.last = function(array, n, guard) { - if (array == null) return void 0; - if ((n != null) && !guard) { - return slice.call(array, Math.max(array.length - n, 0)); - } else { - return array[array.length - 1]; - } - }; - - // Returns everything but the first entry of the array. Aliased as `tail` and `drop`. - // Especially useful on the arguments object. Passing an **n** will return - // the rest N values in the array. The **guard** - // check allows it to work with `_.map`. - _.rest = _.tail = _.drop = function(array, n, guard) { - return slice.call(array, (n == null) || guard ? 1 : n); - }; - - // Trim out all falsy values from an array. - _.compact = function(array) { - return _.filter(array, _.identity); - }; - - // Internal implementation of a recursive `flatten` function. - var flatten = function(input, shallow, output) { - each(input, function(value) { - if (_.isArray(value)) { - shallow ? push.apply(output, value) : flatten(value, shallow, output); - } else { - output.push(value); - } - }); - return output; - }; - - // Return a completely flattened version of an array. - _.flatten = function(array, shallow) { - return flatten(array, shallow, []); - }; - - // Return a version of the array that does not contain the specified value(s). - _.without = function(array) { - return _.difference(array, slice.call(arguments, 1)); - }; - - // Produce a duplicate-free version of the array. If the array has already - // been sorted, you have the option of using a faster algorithm. - // Aliased as `unique`. - _.uniq = _.unique = function(array, isSorted, iterator, context) { - if (_.isFunction(isSorted)) { - context = iterator; - iterator = isSorted; - isSorted = false; - } - var initial = iterator ? _.map(array, iterator, context) : array; - var results = []; - var seen = []; - each(initial, function(value, index) { - if (isSorted ? (!index || seen[seen.length - 1] !== value) : !_.contains(seen, value)) { - seen.push(value); - results.push(array[index]); - } - }); - return results; - }; - - // Produce an array that contains the union: each distinct element from all of - // the passed-in arrays. - _.union = function() { - return _.uniq(concat.apply(ArrayProto, arguments)); - }; - - // Produce an array that contains every item shared between all the - // passed-in arrays. - _.intersection = function(array) { - var rest = slice.call(arguments, 1); - return _.filter(_.uniq(array), function(item) { - return _.every(rest, function(other) { - return _.indexOf(other, item) >= 0; - }); - }); - }; - - // Take the difference between one array and a number of other arrays. - // Only the elements present in just the first array will remain. - _.difference = function(array) { - var rest = concat.apply(ArrayProto, slice.call(arguments, 1)); - return _.filter(array, function(value){ return !_.contains(rest, value); }); - }; - - // Zip together multiple lists into a single array -- elements that share - // an index go together. - _.zip = function() { - var args = slice.call(arguments); - var length = _.max(_.pluck(args, 'length')); - var results = new Array(length); - for (var i = 0; i < length; i++) { - results[i] = _.pluck(args, "" + i); - } - return results; - }; - - // Converts lists into objects. Pass either a single array of `[key, value]` - // pairs, or two parallel arrays of the same length -- one of keys, and one of - // the corresponding values. - _.object = function(list, values) { - if (list == null) return {}; - var result = {}; - for (var i = 0, l = list.length; i < l; i++) { - if (values) { - result[list[i]] = values[i]; - } else { - result[list[i][0]] = list[i][1]; - } - } - return result; - }; - - // If the browser doesn't supply us with indexOf (I'm looking at you, **MSIE**), - // we need this function. Return the position of the first occurrence of an - // item in an array, or -1 if the item is not included in the array. - // Delegates to **ECMAScript 5**'s native `indexOf` if available. - // If the array is large and already in sort order, pass `true` - // for **isSorted** to use binary search. - _.indexOf = function(array, item, isSorted) { - if (array == null) return -1; - var i = 0, l = array.length; - if (isSorted) { - if (typeof isSorted == 'number') { - i = (isSorted < 0 ? Math.max(0, l + isSorted) : isSorted); - } else { - i = _.sortedIndex(array, item); - return array[i] === item ? i : -1; - } - } - if (nativeIndexOf && array.indexOf === nativeIndexOf) return array.indexOf(item, isSorted); - for (; i < l; i++) if (array[i] === item) return i; - return -1; - }; - - // Delegates to **ECMAScript 5**'s native `lastIndexOf` if available. - _.lastIndexOf = function(array, item, from) { - if (array == null) return -1; - var hasIndex = from != null; - if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) { - return hasIndex ? array.lastIndexOf(item, from) : array.lastIndexOf(item); - } - var i = (hasIndex ? from : array.length); - while (i--) if (array[i] === item) return i; - return -1; - }; - - // Generate an integer Array containing an arithmetic progression. A port of - // the native Python `range()` function. See - // [the Python documentation](http://docs.python.org/library/functions.html#range). - _.range = function(start, stop, step) { - if (arguments.length <= 1) { - stop = start || 0; - start = 0; - } - step = arguments[2] || 1; - - var len = Math.max(Math.ceil((stop - start) / step), 0); - var idx = 0; - var range = new Array(len); - - while(idx < len) { - range[idx++] = start; - start += step; - } - - return range; - }; - - // Function (ahem) Functions - // ------------------ - - // Create a function bound to a given object (assigning `this`, and arguments, - // optionally). Delegates to **ECMAScript 5**'s native `Function.bind` if - // available. - _.bind = function(func, context) { - if (func.bind === nativeBind && nativeBind) return nativeBind.apply(func, slice.call(arguments, 1)); - var args = slice.call(arguments, 2); - return function() { - return func.apply(context, args.concat(slice.call(arguments))); - }; - }; - - // Partially apply a function by creating a version that has had some of its - // arguments pre-filled, without changing its dynamic `this` context. - _.partial = function(func) { - var args = slice.call(arguments, 1); - return function() { - return func.apply(this, args.concat(slice.call(arguments))); - }; - }; - - // Bind all of an object's methods to that object. Useful for ensuring that - // all callbacks defined on an object belong to it. - _.bindAll = function(obj) { - var funcs = slice.call(arguments, 1); - if (funcs.length === 0) funcs = _.functions(obj); - each(funcs, function(f) { obj[f] = _.bind(obj[f], obj); }); - return obj; - }; - - // Memoize an expensive function by storing its results. - _.memoize = function(func, hasher) { - var memo = {}; - hasher || (hasher = _.identity); - return function() { - var key = hasher.apply(this, arguments); - return _.has(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments)); - }; - }; - - // Delays a function for the given number of milliseconds, and then calls - // it with the arguments supplied. - _.delay = function(func, wait) { - var args = slice.call(arguments, 2); - return setTimeout(function(){ return func.apply(null, args); }, wait); - }; - - // Defers a function, scheduling it to run after the current call stack has - // cleared. - _.defer = function(func) { - return _.delay.apply(_, [func, 1].concat(slice.call(arguments, 1))); - }; - - // Returns a function, that, when invoked, will only be triggered at most once - // during a given window of time. - _.throttle = function(func, wait) { - var context, args, timeout, result; - var previous = 0; - var later = function() { - previous = new Date; - timeout = null; - result = func.apply(context, args); - }; - return function() { - var now = new Date; - var remaining = wait - (now - previous); - context = this; - args = arguments; - if (remaining <= 0) { - clearTimeout(timeout); - timeout = null; - previous = now; - result = func.apply(context, args); - } else if (!timeout) { - timeout = setTimeout(later, remaining); - } - return result; - }; - }; - - // Returns a function, that, as long as it continues to be invoked, will not - // be triggered. The function will be called after it stops being called for - // N milliseconds. If `immediate` is passed, trigger the function on the - // leading edge, instead of the trailing. - _.debounce = function(func, wait, immediate) { - var timeout, result; - return function() { - var context = this, args = arguments; - var later = function() { - timeout = null; - if (!immediate) result = func.apply(context, args); - }; - var callNow = immediate && !timeout; - clearTimeout(timeout); - timeout = setTimeout(later, wait); - if (callNow) result = func.apply(context, args); - return result; - }; - }; - - // Returns a function that will be executed at most one time, no matter how - // often you call it. Useful for lazy initialization. - _.once = function(func) { - var ran = false, memo; - return function() { - if (ran) return memo; - ran = true; - memo = func.apply(this, arguments); - func = null; - return memo; - }; - }; - - // Returns the first function passed as an argument to the second, - // allowing you to adjust arguments, run code before and after, and - // conditionally execute the original function. - _.wrap = function(func, wrapper) { - return function() { - var args = [func]; - push.apply(args, arguments); - return wrapper.apply(this, args); - }; - }; - - // Returns a function that is the composition of a list of functions, each - // consuming the return value of the function that follows. - _.compose = function() { - var funcs = arguments; - return function() { - var args = arguments; - for (var i = funcs.length - 1; i >= 0; i--) { - args = [funcs[i].apply(this, args)]; - } - return args[0]; - }; - }; - - // Returns a function that will only be executed after being called N times. - _.after = function(times, func) { - if (times <= 0) return func(); - return function() { - if (--times < 1) { - return func.apply(this, arguments); - } - }; - }; - - // Object Functions - // ---------------- - - // Retrieve the names of an object's properties. - // Delegates to **ECMAScript 5**'s native `Object.keys` - _.keys = nativeKeys || function(obj) { - if (obj !== Object(obj)) throw new TypeError('Invalid object'); - var keys = []; - for (var key in obj) if (_.has(obj, key)) keys[keys.length] = key; - return keys; - }; - - // Retrieve the values of an object's properties. - _.values = function(obj) { - var values = []; - for (var key in obj) if (_.has(obj, key)) values.push(obj[key]); - return values; - }; - - // Convert an object into a list of `[key, value]` pairs. - _.pairs = function(obj) { - var pairs = []; - for (var key in obj) if (_.has(obj, key)) pairs.push([key, obj[key]]); - return pairs; - }; - - // Invert the keys and values of an object. The values must be serializable. - _.invert = function(obj) { - var result = {}; - for (var key in obj) if (_.has(obj, key)) result[obj[key]] = key; - return result; - }; - - // Return a sorted list of the function names available on the object. - // Aliased as `methods` - _.functions = _.methods = function(obj) { - var names = []; - for (var key in obj) { - if (_.isFunction(obj[key])) names.push(key); - } - return names.sort(); - }; - - // Extend a given object with all the properties in passed-in object(s). - _.extend = function(obj) { - each(slice.call(arguments, 1), function(source) { - if (source) { - for (var prop in source) { - obj[prop] = source[prop]; - } - } - }); - return obj; - }; - - // Return a copy of the object only containing the whitelisted properties. - _.pick = function(obj) { - var copy = {}; - var keys = concat.apply(ArrayProto, slice.call(arguments, 1)); - each(keys, function(key) { - if (key in obj) copy[key] = obj[key]; - }); - return copy; - }; - - // Return a copy of the object without the blacklisted properties. - _.omit = function(obj) { - var copy = {}; - var keys = concat.apply(ArrayProto, slice.call(arguments, 1)); - for (var key in obj) { - if (!_.contains(keys, key)) copy[key] = obj[key]; - } - return copy; - }; - - // Fill in a given object with default properties. - _.defaults = function(obj) { - each(slice.call(arguments, 1), function(source) { - if (source) { - for (var prop in source) { - if (obj[prop] == null) obj[prop] = source[prop]; - } - } - }); - return obj; - }; - - // Create a (shallow-cloned) duplicate of an object. - _.clone = function(obj) { - if (!_.isObject(obj)) return obj; - return _.isArray(obj) ? obj.slice() : _.extend({}, obj); - }; - - // Invokes interceptor with the obj, and then returns obj. - // The primary purpose of this method is to "tap into" a method chain, in - // order to perform operations on intermediate results within the chain. - _.tap = function(obj, interceptor) { - interceptor(obj); - return obj; - }; - - // Internal recursive comparison function for `isEqual`. - var eq = function(a, b, aStack, bStack) { - // Identical objects are equal. `0 === -0`, but they aren't identical. - // See the Harmony `egal` proposal: http://wiki.ecmascript.org/doku.php?id=harmony:egal. - if (a === b) return a !== 0 || 1 / a == 1 / b; - // A strict comparison is necessary because `null == undefined`. - if (a == null || b == null) return a === b; - // Unwrap any wrapped objects. - if (a instanceof _) a = a._wrapped; - if (b instanceof _) b = b._wrapped; - // Compare `[[Class]]` names. - var className = toString.call(a); - if (className != toString.call(b)) return false; - switch (className) { - // Strings, numbers, dates, and booleans are compared by value. - case '[object String]': - // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is - // equivalent to `new String("5")`. - return a == String(b); - case '[object Number]': - // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for - // other numeric values. - return a != +a ? b != +b : (a == 0 ? 1 / a == 1 / b : a == +b); - case '[object Date]': - case '[object Boolean]': - // Coerce dates and booleans to numeric primitive values. Dates are compared by their - // millisecond representations. Note that invalid dates with millisecond representations - // of `NaN` are not equivalent. - return +a == +b; - // RegExps are compared by their source patterns and flags. - case '[object RegExp]': - return a.source == b.source && - a.global == b.global && - a.multiline == b.multiline && - a.ignoreCase == b.ignoreCase; - } - if (typeof a != 'object' || typeof b != 'object') return false; - // Assume equality for cyclic structures. The algorithm for detecting cyclic - // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. - var length = aStack.length; - while (length--) { - // Linear search. Performance is inversely proportional to the number of - // unique nested structures. - if (aStack[length] == a) return bStack[length] == b; - } - // Add the first object to the stack of traversed objects. - aStack.push(a); - bStack.push(b); - var size = 0, result = true; - // Recursively compare objects and arrays. - if (className == '[object Array]') { - // Compare array lengths to determine if a deep comparison is necessary. - size = a.length; - result = size == b.length; - if (result) { - // Deep compare the contents, ignoring non-numeric properties. - while (size--) { - if (!(result = eq(a[size], b[size], aStack, bStack))) break; - } - } - } else { - // Objects with different constructors are not equivalent, but `Object`s - // from different frames are. - var aCtor = a.constructor, bCtor = b.constructor; - if (aCtor !== bCtor && !(_.isFunction(aCtor) && (aCtor instanceof aCtor) && - _.isFunction(bCtor) && (bCtor instanceof bCtor))) { - return false; - } - // Deep compare objects. - for (var key in a) { - if (_.has(a, key)) { - // Count the expected number of properties. - size++; - // Deep compare each member. - if (!(result = _.has(b, key) && eq(a[key], b[key], aStack, bStack))) break; - } - } - // Ensure that both objects contain the same number of properties. - if (result) { - for (key in b) { - if (_.has(b, key) && !(size--)) break; - } - result = !size; - } - } - // Remove the first object from the stack of traversed objects. - aStack.pop(); - bStack.pop(); - return result; - }; - - // Perform a deep comparison to check if two objects are equal. - _.isEqual = function(a, b) { - return eq(a, b, [], []); - }; - - // Is a given array, string, or object empty? - // An "empty" object has no enumerable own-properties. - _.isEmpty = function(obj) { - if (obj == null) return true; - if (_.isArray(obj) || _.isString(obj)) return obj.length === 0; - for (var key in obj) if (_.has(obj, key)) return false; - return true; - }; - - // Is a given value a DOM element? - _.isElement = function(obj) { - return !!(obj && obj.nodeType === 1); - }; - - // Is a given value an array? - // Delegates to ECMA5's native Array.isArray - _.isArray = nativeIsArray || function(obj) { - return toString.call(obj) == '[object Array]'; - }; - - // Is a given variable an object? - _.isObject = function(obj) { - return obj === Object(obj); - }; - - // Add some isType methods: isArguments, isFunction, isString, isNumber, isDate, isRegExp. - each(['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp'], function(name) { - _['is' + name] = function(obj) { - return toString.call(obj) == '[object ' + name + ']'; - }; - }); - - // Define a fallback version of the method in browsers (ahem, IE), where - // there isn't any inspectable "Arguments" type. - if (!_.isArguments(arguments)) { - _.isArguments = function(obj) { - return !!(obj && _.has(obj, 'callee')); - }; - } - - // Optimize `isFunction` if appropriate. - if (typeof (/./) !== 'function') { - _.isFunction = function(obj) { - return typeof obj === 'function'; - }; - } - - // Is a given object a finite number? - _.isFinite = function(obj) { - return isFinite(obj) && !isNaN(parseFloat(obj)); - }; - - // Is the given value `NaN`? (NaN is the only number which does not equal itself). - _.isNaN = function(obj) { - return _.isNumber(obj) && obj != +obj; - }; - - // Is a given value a boolean? - _.isBoolean = function(obj) { - return obj === true || obj === false || toString.call(obj) == '[object Boolean]'; - }; - - // Is a given value equal to null? - _.isNull = function(obj) { - return obj === null; - }; - - // Is a given variable undefined? - _.isUndefined = function(obj) { - return obj === void 0; - }; - - // Shortcut function for checking if an object has a given property directly - // on itself (in other words, not on a prototype). - _.has = function(obj, key) { - return hasOwnProperty.call(obj, key); - }; - - // Utility Functions - // ----------------- - - // Run Underscore.js in *noConflict* mode, returning the `_` variable to its - // previous owner. Returns a reference to the Underscore object. - _.noConflict = function() { - root._ = previousUnderscore; - return this; - }; - - // Keep the identity function around for default iterators. - _.identity = function(value) { - return value; - }; - - // Run a function **n** times. - _.times = function(n, iterator, context) { - var accum = Array(n); - for (var i = 0; i < n; i++) accum[i] = iterator.call(context, i); - return accum; - }; - - // Return a random integer between min and max (inclusive). - _.random = function(min, max) { - if (max == null) { - max = min; - min = 0; - } - return min + Math.floor(Math.random() * (max - min + 1)); - }; - - // List of HTML entities for escaping. - var entityMap = { - escape: { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''', - '/': '/' - } - }; - entityMap.unescape = _.invert(entityMap.escape); - - // Regexes containing the keys and values listed immediately above. - var entityRegexes = { - escape: new RegExp('[' + _.keys(entityMap.escape).join('') + ']', 'g'), - unescape: new RegExp('(' + _.keys(entityMap.unescape).join('|') + ')', 'g') - }; - - // Functions for escaping and unescaping strings to/from HTML interpolation. - _.each(['escape', 'unescape'], function(method) { - _[method] = function(string) { - if (string == null) return ''; - return ('' + string).replace(entityRegexes[method], function(match) { - return entityMap[method][match]; - }); - }; - }); - - // If the value of the named property is a function then invoke it; - // otherwise, return it. - _.result = function(object, property) { - if (object == null) return null; - var value = object[property]; - return _.isFunction(value) ? value.call(object) : value; - }; - - // Add your own custom functions to the Underscore object. - _.mixin = function(obj) { - each(_.functions(obj), function(name){ - var func = _[name] = obj[name]; - _.prototype[name] = function() { - var args = [this._wrapped]; - push.apply(args, arguments); - return result.call(this, func.apply(_, args)); - }; - }); - }; - - // Generate a unique integer id (unique within the entire client session). - // Useful for temporary DOM ids. - var idCounter = 0; - _.uniqueId = function(prefix) { - var id = ++idCounter + ''; - return prefix ? prefix + id : id; - }; - - // By default, Underscore uses ERB-style template delimiters, change the - // following template settings to use alternative delimiters. - _.templateSettings = { - evaluate : /<%([\s\S]+?)%>/g, - interpolate : /<%=([\s\S]+?)%>/g, - escape : /<%-([\s\S]+?)%>/g - }; - - // When customizing `templateSettings`, if you don't want to define an - // interpolation, evaluation or escaping regex, we need one that is - // guaranteed not to match. - var noMatch = /(.)^/; - - // Certain characters need to be escaped so that they can be put into a - // string literal. - var escapes = { - "'": "'", - '\\': '\\', - '\r': 'r', - '\n': 'n', - '\t': 't', - '\u2028': 'u2028', - '\u2029': 'u2029' - }; - - var escaper = /\\|'|\r|\n|\t|\u2028|\u2029/g; - - // JavaScript micro-templating, similar to John Resig's implementation. - // Underscore templating handles arbitrary delimiters, preserves whitespace, - // and correctly escapes quotes within interpolated code. - _.template = function(text, data, settings) { - var render; - settings = _.defaults({}, settings, _.templateSettings); - - // Combine delimiters into one regular expression via alternation. - var matcher = new RegExp([ - (settings.escape || noMatch).source, - (settings.interpolate || noMatch).source, - (settings.evaluate || noMatch).source - ].join('|') + '|$', 'g'); - - // Compile the template source, escaping string literals appropriately. - var index = 0; - var source = "__p+='"; - text.replace(matcher, function(match, escape, interpolate, evaluate, offset) { - source += text.slice(index, offset) - .replace(escaper, function(match) { return '\\' + escapes[match]; }); - - if (escape) { - source += "'+\n((__t=(" + escape + "))==null?'':_.escape(__t))+\n'"; - } - if (interpolate) { - source += "'+\n((__t=(" + interpolate + "))==null?'':__t)+\n'"; - } - if (evaluate) { - source += "';\n" + evaluate + "\n__p+='"; - } - index = offset + match.length; - return match; - }); - source += "';\n"; - - // If a variable is not specified, place data values in local scope. - if (!settings.variable) source = 'with(obj||{}){\n' + source + '}\n'; - - source = "var __t,__p='',__j=Array.prototype.join," + - "print=function(){__p+=__j.call(arguments,'');};\n" + - source + "return __p;\n"; - - try { - render = new Function(settings.variable || 'obj', '_', source); - } catch (e) { - e.source = source; - throw e; - } - - if (data) return render(data, _); - var template = function(data) { - return render.call(this, data, _); - }; - - // Provide the compiled function source as a convenience for precompilation. - template.source = 'function(' + (settings.variable || 'obj') + '){\n' + source + '}'; - - return template; - }; - - // Add a "chain" function, which will delegate to the wrapper. - _.chain = function(obj) { - return _(obj).chain(); - }; - - // OOP - // --------------- - // If Underscore is called as a function, it returns a wrapped object that - // can be used OO-style. This wrapper holds altered versions of all the - // underscore functions. Wrapped objects may be chained. - - // Helper function to continue chaining intermediate results. - var result = function(obj) { - return this._chain ? _(obj).chain() : obj; - }; - - // Add all of the Underscore functions to the wrapper object. - _.mixin(_); - - // Add all mutator Array functions to the wrapper. - each(['pop', 'push', 'reverse', 'shift', 'sort', 'splice', 'unshift'], function(name) { - var method = ArrayProto[name]; - _.prototype[name] = function() { - var obj = this._wrapped; - method.apply(obj, arguments); - if ((name == 'shift' || name == 'splice') && obj.length === 0) delete obj[0]; - return result.call(this, obj); - }; - }); - - // Add all accessor Array functions to the wrapper. - each(['concat', 'join', 'slice'], function(name) { - var method = ArrayProto[name]; - _.prototype[name] = function() { - return result.call(this, method.apply(this._wrapped, arguments)); - }; - }); - - _.extend(_.prototype, { - - // Start chaining a wrapped Underscore object. - chain: function() { - this._chain = true; - return this; - }, - - // Extracts the result from a wrapped and chained object. - value: function() { - return this._wrapped; - } - - }); - -}).call(this); diff --git a/package.json b/package.json index 0f48605f..baf679c3 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "asteroid", "version": "0.0.1", "scripts": { - "test": "mocha" + "test": "mocha -R spec" }, "dependencies": { "debug": "latest", diff --git a/test/app.test.js b/test/app.test.js index d3fc6219..f5bea4b7 100644 --- a/test/app.test.js +++ b/test/app.test.js @@ -1,17 +1,37 @@ -var asteroid = require('../'); +describe('app', function() { -describe('app', function(){ - var app; - - beforeEach(function () { - app = asteroid(); + describe('app.model(Model)', function() { + it("Expose a `Model` to remote clients.", function(done) { + /* example - + var memory = asteroid.createDataSource({connector: 'memory'}); + var Color = memory.defineModel({name: String}); + app.model(Color); + app.use(asteroid.rest()); + + + */ + done(new Error('test not implemented')); + }); }); - - describe('asteroid.createModel(name, properties, settings)', function(){ - var User = asteroid.createModel('user', { - first: String, - last: String, - age: Number + + describe('app.models()', function() { + it("Get the app's exposed models.", function(done) { + /* example - + var models = app.models(); + + models.forEach(function (Model) { + console.log(Model.name); // color + }); + + var Color = asteroid.createModel({name: 'string'}); + var red = new Color({name: 'red'}); + var User = asteroid.createModel('user', { + first: String, + last: String, + age: Number + }); + */ + done(new Error('test not implemented')); }); }); }); \ No newline at end of file diff --git a/test/asteroid.test.js b/test/asteroid.test.js new file mode 100644 index 00000000..d9d1625f --- /dev/null +++ b/test/asteroid.test.js @@ -0,0 +1,46 @@ +describe('asteroid', function() { + + describe('asteroid.remoteMethod(Model, fn, [options]);', function() { + it("Expose a remote method.", function(done) { + /* example - + Product.stats = function(fn) { + myApi.getStats('products', fn); + } + + asteroid.remoteMethod( + Product, + Product.stats, + { + returns: {arg: 'stats', type: 'array'}, + http: {path: '/info', verb: 'get'} + } + ); + // examples + {arg: 'myArg', type: 'number'} + [ + {arg: 'arg1', type: 'number', required: true}, + {arg: 'arg2', type: 'array'} + ] + User.before('save', function(user, next) { + console.log('about to save', user); + + next(); + }); + + User.before('delete', function(user, next) { + // prevent all delete calls + next(new Error('deleting is disabled')); + }); + User.beforeRemote('save', function(ctx, user, next) { + if(ctx.user.id === user.id) { + next(); + } else { + next(new Error('must be logged in to update')) + } + }); + + */ + done(new Error('test not implemented')); + }); + }); +}); \ No newline at end of file diff --git a/test/data-source.test.js b/test/data-source.test.js new file mode 100644 index 00000000..b93a7c3f --- /dev/null +++ b/test/data-source.test.js @@ -0,0 +1,137 @@ +describe('DataSource', function() { + + describe('dataSource.createModel(name, options, settings)', function() { + it("Define a model and attach it to a `DataSource`.", function(done) { + /* example - + var Color = oracle.createModel('color', {name: String}); + */ + done(new Error('test not implemented')); + }); + }); + + describe('dataSource.discover(options, fn)', function() { + it("Discover an object containing properties and settings for an existing data source.", function(done) { + /* example - + oracle.discover({owner: 'MYORG'}, function(err, tables) { + var productSchema = tables.PRODUCTS; + var ProductModel = oracle.createModel('product', productSchema.properties, productSchema.settings); + }); + + */ + done(new Error('test not implemented')); + }); + }); + + describe('dataSource.discoverSync(options)', function() { + it("Synchronously discover an object containing properties and settings for an existing data source tables or collections.", function(done) { + /* example - + var tables = oracle.discover({owner: 'MYORG'}); + var productSchema = tables.PRODUCTS; + var ProductModel = oracle.createModel('product', productSchema.properties, productSchema.settings); + + */ + done(new Error('test not implemented')); + }); + }); + + describe('dataSource.discoverModels(options, fn) ', function() { + it("Discover a set of models based on tables or collections in a data source.", function(done) { + /* example - + oracle.discoverModels({owner: 'MYORG'}, function(err, models) { + var ProductModel = models.Product; + }); + + + */ + done(new Error('test not implemented')); + }); + }); + + describe('dataSource.discoverModelsSync(options)', function() { + it("Synchronously Discover a set of models based on tables or collections in a data source.", function(done) { + /* example - + var models = oracle.discoverModels({owner: 'MYORG'}); + var ProductModel = models.Product; + */ + done(new Error('test not implemented')); + }); + }); + + describe('dataSource.enable(operation)', function() { + it("Enable a data source operation", function(done) { + /* example - + // all rest data source operations are + // disabled by default + var rest = asteroid.createDataSource({ + connector: require('asteroid-rest'), + url: 'http://maps.googleapis.com/maps/api' + enableAll: true + }); + + // enable an operation + twitter.enable('find'); + + // enable remote access + twitter.enableRemote('find') + + */ + done(new Error('test not implemented')); + }); + }); + + describe('dataSource.disable(operation)', function() { + it("Disable a data source operation", function(done) { + /* example - + // all rest data source operations are + // disabled by default + var oracle = asteroid.createDataSource({ + connector: require('asteroid-oracle'), + host: '...', + ... + }); + // disable an operation completely + oracle.disable('destroyAll'); + + // or only disable it as a remote method + oracle.disableRemote('destroyAll'); + */ + done(new Error('test not implemented')); + }); + }); + + describe('dataSource.operations()', function() { + it("List the enabled and disabled operations.", function(done) { + /* example - + console.log(oracle.operations()); + + { + find: { + allowRemote: true, + accepts: [...], + returns: [...] + enabled: true + }, + ... + } + var memory = asteroid.createDataSource({ + connector: require('asteroid-memory') + }); + + { + "dependencies": { + "asteroid-oracle": "latest" + } + } + var CoffeeShop = asteroid.createModel('coffee-shop', { + location: 'GeoPoint' + }); + CoffeeShop.attach(oracle); + var here = new GeoPoint({lat: 10.32424, long: 5.84978}); + CoffeeShop.all({where: {location: {near: here}}}, function(err, nearbyShops) { + console.info(nearbyShops); // [CoffeeShop, ...] + }); + */ + done(new Error('test not implemented')); + }); + }); +}); \ No newline at end of file diff --git a/test/geo-point.test.js b/test/geo-point.test.js new file mode 100644 index 00000000..0fd64ed6 --- /dev/null +++ b/test/geo-point.test.js @@ -0,0 +1,41 @@ +describe('GeoPoint', function() { + + describe('geoPoint.distanceTo(geoPoint, options)', function() { + it("Get the distance to another `GeoPoint`.", function(done) { + /* example - + var here = new GeoPoint({lat: 10, long: 10}); + var there = new GeoPoint({lat: 5, long: 5}); + console.log(here.distanceTo(there, {type: 'miles'})); // 438 + */ + done(new Error('test not implemented')); + }); + }); + + describe('GeoPoint.distanceBetween(a, b, options)', function() { + it("Get the distance between two points.", function(done) { + /* example - + GeoPoint.distanceBetween(here, there, {type: 'miles'}) // 438 + */ + done(new Error('test not implemented')); + }); + }); + + describe('geoPoint.lat', function() { + it("The latitude point in degrees", function(done) { + done(new Error('test not implemented')); + }); + }); + + describe('geoPoint.long', function() { + it("The longitude point in degrees", function(done) { + /* example - + app.use(asteroid.rest()); + + + app.use(asteroid.sio); + + */ + done(new Error('test not implemented')); + }); + }); +}); \ No newline at end of file diff --git a/test/model.test.js b/test/model.test.js index 449b3979..5a0434fe 100644 --- a/test/model.test.js +++ b/test/model.test.js @@ -1,19 +1,318 @@ -var asteroid = require('../'); +describe('Model', function() { -describe('app', function(){ - var app; - - beforeEach(function () { - app = asteroid(); + describe('Model.validatesPresenceOf(properties...)', function() { + it("Require a model to include a property to be considered valid.", function(done) { + /* example - + User.validatesPresenceOf('first', 'last', 'age'); + */ + done(new Error('test not implemented')); + }); }); - - describe('.model(Model)', function(){ - it('should expose a Model to remote clients', function() { - var memory = asteroid.createDataSource({adapter: 'memory'}); - var Color = memory.defineModel({name: String}); - app.model(Color); - assert(app.models()[0] === MyModel, 'should add MyModel to the app models'); + describe('Model.validatesLengthOf(property, options)', function() { + it("Require a property length to be within a specified range.", function(done) { + /* example - + User.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}}); + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.validatesInclusionOf(property, options)', function() { + it("Require a value for `property` to be in the specified array.", function(done) { + /* example - + User.validatesInclusionOf('gender', {in: ['male', 'female']}); + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.validatesExclusionOf(property, options)', function() { + it("Require a value for `property` to not exist in the specified array.", function(done) { + /* example - + User.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']}); + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.validatesNumericalityOf(property, options)', function() { + it("Require a value for `property` to be a specific type of `Number`.", function(done) { + /* example - + User.validatesNumericalityOf('age', {int: true}); + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.validatesUniquenessOf(property, options)', function() { + it("Ensure the value for `property` is unique.", function(done) { + /* example - + User.validatesUniquenessOf('email', {message: 'email is not unique'}); + */ + done(new Error('test not implemented')); + }); + }); + + describe('myModel.isValid()', function() { + it("Validate the model instance.", function(done) { + /* example - + user.isValid(function (valid) { + if (!valid) { + user.errors // hash of errors {attr: [errmessage, errmessage, ...], attr: ...} + } + }); + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.attachTo(dataSource)', function() { + it("Attach a model to a [DataSource](#data-source)", function(done) { + /* example - + var oracle = asteroid.createDataSource({ + connector: 'oracle', + host: '111.22.333.44', + database: 'MYDB', + username: 'username', + password: 'password' + }); + User.attachTo(oracle); + + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.create([data], [callback])', function() { + it("Create an instance of Model with given data and save to the attached data source.", function(done) { + /* example - + User.create({first: 'Joe', last: 'Bob'}, function(err, user) { + console.log(user instanceof User); // true + }); + */ + done(new Error('test not implemented')); + }); + }); + + describe('model.save([options], [callback])', function() { + it("Save an instance of a Model to the attached data source.", function(done) { + /* example - + var joe = new User({first: 'Joe', last: 'Bob'}); + joe.save(function(err, user) { + if(user.errors) { + console.log(user.errors); + } else { + console.log(user.id); + } + }); + */ + done(new Error('test not implemented')); + }); + }); + + describe('model.updateAttributes(data, [callback])', function() { + it("Save specified attributes to the attached data source.", function(done) { + /* example - + + user.updateAttributes({ + first: 'updatedFirst', + name: 'updatedLast' + }, fn); + */ + done(new Error('test not implemented')); + }); + }); + + describe('model.upsert(data, callback)', function() { + it("Update when record with id=data.id found, insert otherwise", function(done) { + /* example - + + */ + done(new Error('test not implemented')); + }); + }); + + describe('model.destroy([callback])', function() { + it("Remove a model from the attached data source.", function(done) { + /* example - + model.destroy(function(err) { + // model instance destroyed + }); + + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.destroyAll(callback)', function() { + it("Delete all Model instances from data source", function(done) { + done(new Error('test not implemented')); + }); + }); + + describe('Model.find(id, callback)', function() { + it("Find instance by id.", function(done) { + /* example - + User.find(23, function(err, user) { + console.info(user.id); // 23 + }); + User.all({where: {age: {gt: 21}}, order: 'age DESC', limit: 10, skip: 10}) + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.count([query], callback)', function() { + it("Query count of Model instances in data source", function(done) { + /* example - + User.count({approved: true}, function(err, count) { + console.log(count); // 2081 + }); + User.login = function (username, password, fn) { + var passwordHash = hashPassword(password); + this.findOne({username: username}, function (err, user) { + var failErr = new Error('login failed'); + + if(err) { + fn(err); + } else if(!user) { + fn(failErr); + } else if(user.password === passwordHash) { + MySessionModel.create({userId: user.id}, function (err, session) { + fn(null, session.id); + }); + } else { + fn(failErr); + } + }); + } + + asteroid.remoteMethod( + User, + User.login, + { + accepts: [ + {arg: 'username', type: 'string', required: true}, + {arg: 'password', type: 'string', required: true} + ], + returns: {arg: 'sessionId', type: 'any'}, + http: {path: '/sign-in'} + } + ); + + User.prototype.logout = function (fn) { + MySessionModel.destroyAll({userId: this.id}, fn); + } + + asteroid.remoteMethod(User, User.prototype.logout); + */ + done(new Error('test not implemented')); + }); + }); + + describe('ctx.me', function() { + it("The id of the user calling the method remotely", function(done) { + done(new Error('test not implemented')); + }); + }); + + describe('ctx.req', function() { + it("The express ServerRequest object", function(done) { + done(new Error('test not implemented')); + }); + }); + + describe('ctx.res', function() { + it("The express ServerResponse object", function(done) { + /* example - + + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.hasMany(Model)', function() { + it("Define a one to many relationship.", function(done) { + /* example - + // by referencing model + Book.hasMany(Chapter); + // specify the name + Book.hasMany('chapters', {model: Chapter}); + + Book.create(function(err, book) { + // using 'chapters' scope for build: + var c = book.chapters.build({name: 'Chapter 1'}); + + // same as: + c = new Chapter({name: 'Chapter 1', bookId: book.id}); + + // using 'chapters' scope for create: + book.chapters.create(); + + // same as: + Chapter.create({bookId: book.id}); + // using scope for querying: + book.chapters(function(err, chapters) { + // all chapters with bookId = book.id + }); + + book.chapters({where: {name: 'test'}}, function(err, chapters) { + // all chapters with bookId = book.id and name = 'test' + }); + }); + + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.hasAndBelongsToMany()', function() { + it("TODO: implement / document", function(done) { + /* example - + + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.availableHooks()', function() { + it("Return a list of available hooks.", function(done) { + /* example - + console.log(User.availableHooks()); // ['save', ...] + + */ + done(new Error('test not implemented')); + }); + }); + + describe('Model.availableMethods()', function() { + it("Returns the currently available api of a model as well as descriptions of any modified behavior or methods from attached data sources.", function(done) { + /* example - + User.attachTo(oracle); + console.log(User.availableMethods()); + + { + 'User.all': { + accepts: [{arg: 'filter', type: 'object', description: '...'}], + returns: [{arg: 'users', type: ['User']}] + }, + 'User.find': { + accepts: [{arg: 'id', type: 'any'}], + returns: [{arg: 'items', type: 'User'}] + }, + ... + } + var oracle = asteroid.createDataSource({ + connector: 'oracle', + host: '111.22.333.44', + database: 'MYDB', + username: 'username', + password: 'password' + }); + + */ + done(new Error('test not implemented')); }); }); }); \ No newline at end of file diff --git a/test/support.js b/test/support.js index 2a007e24..f24f62da 100644 --- a/test/support.js +++ b/test/support.js @@ -2,4 +2,12 @@ * asteroid test setup and support. */ -assert = require('assert'); \ No newline at end of file +assert = require('assert'); +asteroid = require('../'); +memoryConnector = require('asteroid-memory'); + +beforeEach(function () { + app = asteroid(); + EmptyModel = asteroid.createModel(); + memory = asteroid.createDataSource({connector: memoryConnector}); +}) \ No newline at end of file