Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removing local utils in favor of utilities NPM lib.

  • Loading branch information...
commit a307065895539830010708fbf57c00f1fc0897ed 1 parent 4f5f97d
mde authored
Showing with 13 additions and 96 deletions.
  1. +3 −3 bin/cli.js
  2. +3 −3 lib/loader.js
  3. +7 −90 lib/utils/index.js
View
6 bin/cli.js
@@ -53,9 +53,9 @@ if (!program.preemptiveOption()) {
// Convenience aliases
jake.program = program;
- for (var p in utils) {
- jake[p] = utils[p];
- }
+ utils.mixin(jake, utils);
+ // File utils should be aliased directly on the base namespace
+ utils.mixin(jake, utils.file);
jake.FileList = require(libPath + '/file_list').FileList;
jake.PackageTask = require(libPath + '/package_task').PackageTask;
jake.NpmPublishTask = require(libPath + '/npm_publish_task').NpmPublishTask;
View
6 lib/loader.js
@@ -20,7 +20,7 @@ var path = require('path')
, fs = require('fs')
, existsSync = typeof fs.existsSync == 'function' ?
fs.existsSync : path.existsSync
- , fileUtils = require('./utils/file')
+ , utils = require('utilities')
, Loader;
@@ -60,13 +60,13 @@ Loader = function () {
if (isCoffee) {
CoffeeScript = _requireCoffee();
}
- require(fileUtils.absolutize(jakefile));
+ require(utils.file.absolutize(jakefile));
}
, _loadJakeLibdir = function (d) {
var dirname = d || 'jakelib'
, dirlist;
- dirname = fileUtils.absolutize(dirname);
+ dirname = utils.file.absolutize(dirname);
if (existsSync(dirname)) {
dirlist = fs.readdirSync(dirname);
dirlist.forEach(function (filePath) {
View
97 lib/utils/index.js
@@ -20,52 +20,15 @@
var exec = require('child_process').exec
, spawn = require('child_process').spawn
, EventEmitter = require('events').EventEmitter
- , fileUtils = require('./file')
+ , utils = require('utilities')
, logger = require('./logger')
- , utils
- , Exec
- , _mix, _trim, _truncate;
-
-_mix = function (targ, src, merge, includeProto) {
- for (var p in src) {
- // Don't copy stuff from the prototype
- if (src.hasOwnProperty(p) || includeProto) {
- if (merge &&
- // Assumes the source property is an Object you can
- // actually recurse down into
- (typeof src[p] == 'object') &&
- (src[p] !== null) &&
- !(src[p] instanceof Array)) {
- // Create the source property if it doesn't exist
- // TODO: What if it's something weird like a String or Number?
- if (typeof targ[p] == 'undefined') {
- targ[p] = {};
- }
- _mix(targ[p], src[p], merge, includeProto); // Recurse
- }
- // If it's not a merge-copy, just set and forget
- else {
- targ[p] = src[p];
- }
- }
- }
-};
-
-_trim = function (s) {
- var str = s || '';
- return str.replace(/^\s*|\s*$/g, '');
-};
-
-_truncate = function (s) {
- var str = s ? s.replace(/\n$/, '') : '';
- return str;
-};
+ , Exec;
/**
@name jake
@namespace jake
*/
-utils = new (function () {
+utils.mixin(utils, new (function () {
/**
@name jake.exec
@static
@@ -120,51 +83,7 @@ utils = new (function () {
return objectArray.join(', ');
};
- /*
- * Mix in the properties on an object to another object
- * yam.mixin(target, source, [source,] [source, etc.] [merge-flag]);
- * 'merge' recurses, to merge object sub-properties together instead
- * of just overwriting with the source object.
- */
- this.mixin = (function () {
- return function () {
- var args = Array.prototype.slice.apply(arguments),
- merge = false,
- targ, sources;
- if (args.length > 2) {
- if (typeof args[args.length - 1] == 'boolean') {
- merge = args.pop();
- }
- }
- targ = args.shift();
- sources = args;
- for (var i = 0, ii = sources.length; i < ii; i++) {
- _mix(targ, sources[i], merge);
- }
- return targ;
- };
- }).call(this);
-
- this.enhance = (function () {
- return function () {
- var args = Array.prototype.slice.apply(arguments),
- merge = false,
- targ, sources;
- if (args.length > 2) {
- if (typeof args[args.length - 1] == 'boolean') {
- merge = args.pop();
- }
- }
- targ = args.shift();
- sources = args;
- for (var i = 0, ii = sources.length; i < ii; i++) {
- _mix(targ, sources[i], merge, true);
- }
- return targ;
- };
- }).call(this);
-
-})();
+})());
Exec = function () {
var args
@@ -243,7 +162,7 @@ utils.mixin(Exec.prototype, new (function () {
// Out
sh.stdout.on('data', function (data) {
if (config.printStdout) {
- console.log(_truncate(data.toString()));
+ console.log(utils.string.rtrim(data.toString()));
}
self.emit('stdout', data);
});
@@ -251,7 +170,7 @@ utils.mixin(Exec.prototype, new (function () {
sh.stderr.on('data', function (data) {
var d = data.toString();
if (config.printStderr) {
- console.error(_truncate(d));
+ console.error(utils.string.rtrim(d));
}
self.emit('stderr', data);
// Accumulate the error-data so we can use it as the
@@ -263,7 +182,7 @@ utils.mixin(Exec.prototype, new (function () {
var msg;
if (code != 0) {
msg = errData || 'Process exited with error.';
- msg = _trim(msg);
+ msg = utils.string.trim(msg);
self.emit('error', msg, code);
}
if (code == 0 || !config.breakOnError) {
@@ -292,8 +211,6 @@ utils.mixin(Exec.prototype, new (function () {
utils.Exec = Exec;
utils.logger = logger;
-// Hang all the file utils off this too
-utils.mixin(utils, fileUtils);
module.exports = utils;
Please sign in to comment.
Something went wrong with that request. Please try again.