base-runtimes
Advanced tools
Comparing version 0.1.11 to 0.2.0
156
index.js
@@ -16,14 +16,40 @@ /*! | ||
return function baseRuntimes(app) { | ||
if (!isValidInstance(app)) return; | ||
if (!utils.isValid(app, 'base-runtimes')) return; | ||
var time = new utils.Time(); | ||
var log = utils.log; | ||
this.on('starting', function(build) { | ||
if (!silent(app, build, null)) { | ||
starting(namespace(build)); | ||
// create build context | ||
var ctx = {app: build}; | ||
ctx.key = toKey(namespace(build)); | ||
ctx.event = 'starting'; | ||
time.start(ctx.key); | ||
ctx.time = ''; | ||
ctx.isBuild = true; | ||
ctx.isSilent = silent(app, build, null); | ||
if (app.hasListeners('build')) { | ||
app.emit('build', ctx.event, ctx); | ||
} else if (app.base.hasListeners('build')) { | ||
app.base.emit('build', ctx.event, ctx); | ||
} else if (!ctx.isSilent) { | ||
console.error(log.timestamp, ctx.event, ctx.key, log.red(ctx.time)); | ||
} | ||
}); | ||
this.on('finished', function(build) { | ||
if (!silent(app, build, null)) { | ||
finished(namespace(build)); | ||
this.on('finished', function(build, run) { | ||
// create build context | ||
var ctx = {app: build}; | ||
ctx.key = toKey(namespace(build)); | ||
ctx.time = time.end(ctx.key); | ||
ctx.event = 'finished'; | ||
ctx.isBuild = true; | ||
ctx.isSilent = silent(app, build, null); | ||
if (app.hasListeners('build')) { | ||
app.emit('build', ctx.event, ctx); | ||
} else if (app.base.hasListeners('build')) { | ||
app.base.emit('build', ctx.event, ctx); | ||
} else if (!ctx.isSilent) { | ||
console.error(log.timestamp, ctx.event, ctx.key, log.red(ctx.time)); | ||
} | ||
@@ -33,5 +59,15 @@ }); | ||
this.on('task:starting', function(task) { | ||
if (!silent(app, null, task)) { | ||
if (task.name === 'noop') return; | ||
starting(namespace(app), name(task) + ' task'); | ||
task.key = toKey(namespace(app), name(task) + ' task'); | ||
time.start('task:' + task.key); | ||
task.event = 'starting'; | ||
task.time = ''; | ||
task.isTask = true; | ||
task.isSilent = silent(app, null, task); | ||
if (app.hasListeners('task')) { | ||
app.emit('task', task.event, task); | ||
} else if (app.base.hasListeners('task')) { | ||
app.base.emit('task', task.event, task); | ||
} else if (!task.isSilent) { | ||
console.error(log.timestamp, task.event, task.key, log.red(task.time)); | ||
} | ||
@@ -41,40 +77,65 @@ }); | ||
this.on('task:finished', function(task) { | ||
if (!silent(app, null, task)) { | ||
if (task.name === 'noop') return; | ||
finished(namespace(app), name(task) + ' task'); | ||
task.key = toKey(namespace(app), name(task) + ' task'); | ||
task.time = time.end('task:' + task.key); | ||
task.event = 'finished'; | ||
task.isTask = true; | ||
task.isSilent = silent(app, null, task); | ||
if (app.hasListeners('task')) { | ||
app.emit('task', task.event, task); | ||
} else if (app.base.hasListeners('task')) { | ||
app.base.emit('task', task.event, task); | ||
} else if (!task.isSilent) { | ||
console.error(log.timestamp, task.event, task.key, log.red(task.time)); | ||
} | ||
}); | ||
this.once('done', function() { | ||
utils.timestamp('finished', utils.log.success); | ||
}); | ||
/** | ||
* Handle toggling of verbose and silent modes | ||
*/ | ||
function starting(namespace, name) { | ||
var key = toKey(namespace, name); | ||
time.start(key); | ||
utils.timestamp('starting', key); | ||
} | ||
function silent(app, build, task) { | ||
var opts = utils.extend({}, app.base.options, app.options); | ||
function finished(namespace, name) { | ||
var key = toKey(namespace, name); | ||
var prefix = key ? key + ' ' : ''; | ||
utils.timestamp('finished', prefix + utils.colors.magenta(time.end(key))); | ||
} | ||
if (build && build.options) { | ||
opts = utils.extend({}, opts, build.options); | ||
} | ||
if (task && task.options) { | ||
opts = utils.extend({}, opts, task.options); | ||
} | ||
function silent(app, build, task) { | ||
if (app.options.verbose === true) { | ||
var verbose = opts.verbose; | ||
var silent = opts.silent; | ||
// handle `verbose` first | ||
if (typeof verbose === 'function') { | ||
return verbose(app, build, task); | ||
} | ||
if (verbose === true) { | ||
return false; | ||
} | ||
if (task && app.options.verbose === 'tasks') { | ||
if (task && verbose === 'tasks') { | ||
return false; | ||
} | ||
if (build && app.options.verbose === 'build') { | ||
if (build && verbose === 'build') { | ||
return false; | ||
} | ||
if (app.options.silent === true) { | ||
// if not `verbose`, handle `silent` | ||
if (typeof silent === 'function') { | ||
return silent(app, build, task); | ||
} | ||
if (typeof silent === 'string') { | ||
silent = [silent]; | ||
} | ||
if (build && Array.isArray(silent) && isMatch(silent, build.alias)) { | ||
return true; | ||
} | ||
if (task && task.options.silent === true) { | ||
if (task && Array.isArray(silent) && isMatch(silent, task.name)) { | ||
return true; | ||
} | ||
if (silent === true) { | ||
return true; | ||
} | ||
} | ||
@@ -87,3 +148,3 @@ | ||
function namespace(build) { | ||
return build.env ? build.env.namespace : build.namespace; | ||
return build.env ? build.env.namespace : (build.namespace || build._name); | ||
} | ||
@@ -94,4 +155,5 @@ | ||
if (namespace) { | ||
namespace = stripDefault(namespace); | ||
namespace = formatNamespace(namespace); | ||
} | ||
if (namespace && name) { | ||
@@ -113,17 +175,25 @@ res = utils.colors.bold(utils.colors.cyan(namespace)) + ':' + utils.colors.yellow(name); | ||
function stripDefault(name) { | ||
function isMatch(name, val) { | ||
return utils.mm(val, name).length !== 0; | ||
} | ||
function formatNamespace(name) { | ||
if (name.indexOf('default.') === 0) { | ||
return name.slice('default.'.length); | ||
} | ||
return name; | ||
} | ||
function isValidInstance(app, fn) { | ||
if (!utils.isValid(app)) { | ||
return false; | ||
var segs = name.split('.'); | ||
var len = segs.length; | ||
var idx = -1 | ||
var res = []; | ||
while (++idx < len) { | ||
var next = segs[idx + 1]; | ||
var seg = segs[idx]; | ||
if (next && next === seg) { | ||
continue; | ||
} | ||
res.push(seg); | ||
} | ||
if (utils.isRegistered(app, 'base-runtimes', fn)) { | ||
return false; | ||
} | ||
return true; | ||
return res.join('.'); | ||
} |
{ | ||
"name": "base-runtimes", | ||
"description": "Plugin for adding composer-runtimes to base applications, complementing the base-tasks and base-generators plugins.", | ||
"version": "0.1.11", | ||
"version": "0.2.0", | ||
"homepage": "https://github.com/node-base/base-runtimes", | ||
@@ -14,2 +14,4 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)", | ||
"index.js", | ||
"LICENSE", | ||
"README.md", | ||
"utils.js" | ||
@@ -26,28 +28,39 @@ ], | ||
"extend-shallow": "^2.0.1", | ||
"is-registered": "^0.1.3", | ||
"is-valid-instance": "^0.1.0", | ||
"is-valid-app": "^0.2.0", | ||
"lazy-cache": "^2.0.1", | ||
"log-utils": "^0.1.3", | ||
"log-utils": "^0.1.4", | ||
"micromatch": "^2.3.10", | ||
"time-diff": "^0.3.1" | ||
}, | ||
"devDependencies": { | ||
"base": "^0.8.1", | ||
"base-task": "^0.4.3", | ||
"base": "^0.11.1", | ||
"base-app": "^0.2.6", | ||
"base-task": "^0.6.1", | ||
"gulp-format-md": "^0.1.9", | ||
"mocha": "^2.4.5" | ||
"mocha": "^2.5.3" | ||
}, | ||
"keywords": [ | ||
"api", | ||
"app", | ||
"application", | ||
"base", | ||
"baseplugin", | ||
"building-blocks", | ||
"composer", | ||
"create", | ||
"diff", | ||
"end", | ||
"finish", | ||
"framework", | ||
"generate", | ||
"generator", | ||
"plugin", | ||
"plugins", | ||
"runtimes", | ||
"start", | ||
"task", | ||
"time" | ||
"time", | ||
"tool", | ||
"toolkit", | ||
"tools" | ||
], | ||
@@ -81,3 +94,4 @@ "lintDeps": { | ||
"composer-runtimes", | ||
"verb" | ||
"verb", | ||
"verb-readme-generator" | ||
], | ||
@@ -84,0 +98,0 @@ "lint": { |
@@ -12,5 +12,5 @@ 'use strict'; | ||
require('extend-shallow', 'extend'); | ||
require('is-registered'); | ||
require('is-valid-instance', 'isValid'); | ||
require('is-valid-app', 'isValid'); | ||
require('log-utils', 'log'); | ||
require('micromatch', 'mm'); | ||
require('time-diff', 'Time'); | ||
@@ -17,0 +17,0 @@ require = fn; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
192
8797
5
4
1
0
+ Addedis-valid-app@^0.2.0
+ Addedmicromatch@^2.3.10
+ Addedarr-diff@2.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarray-unique@0.2.1(transitive)
+ Addedbraces@1.8.5(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addedexpand-brackets@0.1.5(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextglob@0.3.2(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.4(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.0(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-number@4.0.0(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedis-valid-app@0.2.1(transitive)
+ Addedis-valid-instance@0.2.0(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.11(transitive)
+ Addedms@2.0.0(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
- Removedis-registered@^0.1.3
- Removedis-valid-instance@^0.1.0
- Removedis-valid-instance@0.1.0(transitive)
Updatedlog-utils@^0.1.4