Comparing version 0.4.6 to 0.4.7
'use strict'; | ||
var debug = require('debug')('base:cli'); | ||
var debug = require('debug')('base:cli:commands'); | ||
var commands = require('./commands'); | ||
@@ -5,0 +5,0 @@ |
'use strict'; | ||
var path = require('path'); | ||
var normalize = require('../config'); | ||
var utils = require('../utils'); | ||
module.exports = function(app) { | ||
return function(val, next) { | ||
if (app.options.verbose) { | ||
console.log('--config is not implemented yet.'); | ||
if (!utils.isObject(val)) { | ||
console.error('config expects an object, cannot set "%s"', val); | ||
process.exit(1); | ||
} | ||
var name = (this.base && this.base.name) || this.constructor.name.toLowerCase(); | ||
var cwd = this.cwd || process.cwd(); | ||
var pkg = utils.pkg.sync(cwd); | ||
if (pkg === null) { | ||
next(new Error('cannot find package.json')); | ||
return; | ||
} | ||
var oldConfig = utils.get(pkg, name) || {}; | ||
val = utils.extend({}, oldConfig, val); | ||
pkg[name] = normalize(this, val, oldConfig); | ||
this.set('cache.pkg', pkg); | ||
var pkgPath = path.resolve(cwd, 'package.json'); | ||
utils.writeJson.sync(pkgPath, pkg); | ||
next(); | ||
}; | ||
}; |
'use strict'; | ||
var path = require('path'); | ||
/** | ||
@@ -16,2 +18,5 @@ * Set the current working directory. | ||
return function(val, next) { | ||
val = path.resolve(val); | ||
app.cwd = val; | ||
if (typeof app.option === 'function') { | ||
@@ -18,0 +23,0 @@ app.option('cwd', val); |
'use strict'; | ||
var path = require('path'); | ||
var utils = require('../utils'); | ||
module.exports = function(app) { | ||
return function(val, next) { | ||
if (typeof app.store === 'undefined') { | ||
next(); | ||
return function(obj, next) { | ||
if (!utils.isObject(obj)) { | ||
cb(new Error('save expects an object, cannot set "%s"', obj)); | ||
return; | ||
} | ||
app.store.set(val); | ||
var name = (this.base && this.base.name) || this.constructor.name.toLowerCase(); | ||
var data = this.store.data; | ||
if (!utils.isObject(data)) { | ||
cb(new Error('the store command requires the base-store plugin to be registered')); | ||
return; | ||
} | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
var val = normalize(key, obj[key]); | ||
var msg; | ||
if (Array.isArray(val)) { | ||
data[key] = data[key] || []; | ||
utils.union(data[key], val); | ||
msg = val.join(', '); | ||
} else if (utils.isObject(val)) { | ||
data[key] = utils.extend({}, data[key], val); | ||
msg = JSON.stringify(data[key]); | ||
} else { | ||
data[key] = val; | ||
msg = val; | ||
} | ||
console.log('global "%s" is now set to "%s"', key, msg); | ||
} | ||
} | ||
this.store.set(data); | ||
next(); | ||
}; | ||
}; | ||
function normalize(key, val) { | ||
var arrayKeys = ['plugins', 'helpers', 'reflinks']; | ||
if (~arrayKeys.indexOf(key)) { | ||
if (typeof val === 'string') { | ||
return [val]; | ||
} | ||
if (utils.isObject(val)) { | ||
for (var key in val) { | ||
if (val.hasOwnProperty(key)) { | ||
var value = val[key]; | ||
if (typeof value === 'boolean') { | ||
return [key]; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return val; | ||
} |
@@ -18,2 +18,3 @@ 'use strict'; | ||
// misc | ||
require('empty-dir'); | ||
require('opn'); | ||
@@ -25,6 +26,12 @@ require('try-open'); | ||
require('kind-of', 'typeOf'); | ||
require('get-value', 'get'); | ||
require('set-value', 'set'); | ||
require('arr-union', 'union'); | ||
require('map-schema', 'Schema'); | ||
// naming | ||
require('namify'); | ||
require('load-pkg', 'pkg'); | ||
require('project-name', 'project'); | ||
require('write-json'); | ||
require = fn; | ||
@@ -41,2 +48,13 @@ | ||
/** | ||
* Cast `val` to an array | ||
* | ||
* @param {String|Array} `val` | ||
* @return {Array} | ||
*/ | ||
utils.arrayify = function(val) { | ||
return val ? (Array.isArray(val) ? val : [val]) : []; | ||
}; | ||
/** | ||
* Return true if a value is an object. | ||
@@ -56,15 +74,6 @@ */ | ||
utils.isEmpty = function(dir, fn) { | ||
var files; | ||
try { | ||
if (!utils.exists(dir)) { | ||
return false; | ||
} | ||
files = fs.readdirSync(dir); | ||
files = files.filter(fn || function(fp) { | ||
return !/\.DS_Store/i.test(fp); | ||
}); | ||
return files.length === 0; | ||
} catch (err) {}; | ||
return true; | ||
utils.isEmpty = function(dir) { | ||
return utils.emptyDir(dir, function(fp) { | ||
return !/\.DS_Store/i.test(fp); | ||
}); | ||
}; | ||
@@ -71,0 +80,0 @@ |
{ | ||
"name": "base-cli", | ||
"description": "Plugin for base-methods that maps built-in methods to CLI args (also supports methods from a few plugins, like 'base-store', 'base-options' and 'base-data'.", | ||
"version": "0.4.6", | ||
"version": "0.4.7", | ||
"homepage": "https://github.com/jonschlinkert/base-cli", | ||
@@ -24,12 +24,19 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"dependencies": { | ||
"arr-union": "^3.0.0", | ||
"base-config": "^0.4.0", | ||
"debug": "^2.2.0", | ||
"empty-dir": "^0.2.0", | ||
"export-files": "^2.1.1", | ||
"extend-shallow": "^2.0.1", | ||
"get-value": "^2.0.3", | ||
"kind-of": "^3.0.2", | ||
"lazy-cache": "^1.0.3", | ||
"load-pkg": "^3.0.1", | ||
"map-schema": "^0.1.1", | ||
"namify": "^0.1.3", | ||
"opn": "^4.0.0", | ||
"project-name": "^0.2.4", | ||
"try-open": "^0.1.0" | ||
"set-value": "^0.3.3", | ||
"try-open": "^0.1.0", | ||
"write-json": "^0.2.2" | ||
}, | ||
@@ -48,3 +55,4 @@ "devDependencies": { | ||
"minimist": "^1.2.0", | ||
"mocha": "*" | ||
"mocha": "*", | ||
"through2": "^2.0.0" | ||
}, | ||
@@ -51,0 +59,0 @@ "keywords": [ |
26374
28
687
17
13
+ Addedarr-union@^3.0.0
+ Addedempty-dir@^0.2.0
+ Addedget-value@^2.0.3
+ Addedload-pkg@^3.0.1
+ Addedmap-schema@^0.1.1
+ Addedset-value@^0.3.3
+ Addedwrite-json@^0.2.2
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedcall-bind-apply-helpers@1.0.2(transitive)
+ Addedcall-bound@1.0.3(transitive)
+ Addedcollection-visit@0.2.3(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addeddunder-proto@1.0.1(transitive)
+ Addedempty-dir@0.2.1(transitive)
+ Addedes-define-property@1.0.1(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedes-object-atoms@1.1.1(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.7(transitive)
+ Addedget-proto@1.0.1(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedgopd@1.2.0(transitive)
+ Addedhas-symbols@1.1.0(transitive)
+ Addedhas-tostringtag@1.0.2(transitive)
+ Addedhas-values@0.1.4(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedis-arguments@1.2.0(transitive)
+ Addedis-date-object@1.1.0(transitive)
+ Addedis-extendable@1.0.1(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedisobject@3.0.1(transitive)
+ Addedlazy-cache@2.0.2(transitive)
+ Addedload-pkg@3.0.1(transitive)
+ Addedmap-schema@0.1.4(transitive)
+ Addedmap-visit@0.1.5(transitive)
+ Addedmath-intrinsics@1.1.0(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addedobject-visit@0.3.4(transitive)
+ Addedomit-empty@0.3.6(transitive)
+ Addedreduce-object@0.1.3(transitive)
+ Addedset-getter@0.1.1(transitive)
+ Addedset-value@0.3.30.4.3(transitive)
+ Addedsort-object-arrays@0.1.1(transitive)
+ Addedto-object-path@0.2.00.3.0(transitive)
+ Addedunion-value@0.2.4(transitive)
+ Addedwrite@0.2.1(transitive)
+ Addedwrite-json@0.2.2(transitive)