Comparing version 0.35.1 to 0.36.0
@@ -1,323 +0,193 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _defineProperty2 = require('babel-runtime/helpers/defineProperty'); | ||
var _defineProperty3 = _interopRequireDefault(_defineProperty2); | ||
var _extends3 = require('babel-runtime/helpers/extends'); | ||
var _extends4 = _interopRequireDefault(_extends3); | ||
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray'); | ||
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2); | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _fs = require('fs'); | ||
var _fs2 = _interopRequireDefault(_fs); | ||
var _glob = require('glob'); | ||
var _glob2 = _interopRequireDefault(_glob); | ||
var _path = require('path'); | ||
var _path2 = _interopRequireDefault(_path); | ||
var _json = require('json5'); | ||
var _json2 = _interopRequireDefault(_json); | ||
var _camelCase = require('lodash/camelCase'); | ||
var _camelCase2 = _interopRequireDefault(_camelCase); | ||
var _mergeWith = require('lodash/mergeWith'); | ||
var _mergeWith2 = _interopRequireDefault(_mergeWith); | ||
var _pluralize = require('pluralize'); | ||
var _pluralize2 = _interopRequireDefault(_pluralize); | ||
var _optimal = require('optimal'); | ||
var _optimal2 = _interopRequireDefault(_optimal); | ||
var _formatModuleName = require('./helpers/formatModuleName'); | ||
var _formatModuleName2 = _interopRequireDefault(_formatModuleName); | ||
var _isObject = require('./helpers/isObject'); | ||
var _isObject2 = _interopRequireDefault(_isObject); | ||
var _isEmptyObject = require('./helpers/isEmptyObject'); | ||
var _isEmptyObject2 = _interopRequireDefault(_isEmptyObject); | ||
var _requireModule = require('./helpers/requireModule'); | ||
var _requireModule2 = _interopRequireDefault(_requireModule); | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var ConfigLoader = function () { | ||
function ConfigLoader(tool) { | ||
(0, _classCallCheck3.default)(this, ConfigLoader); | ||
this.parsedFiles = {}; | ||
this.tool = tool; | ||
} | ||
(0, _createClass3.default)(ConfigLoader, [{ | ||
key: 'handleMerge', | ||
value: function handleMerge(target, source) { | ||
if (Array.isArray(target) && Array.isArray(source)) { | ||
return [].concat((0, _toConsumableArray3.default)(new Set([].concat((0, _toConsumableArray3.default)(target), (0, _toConsumableArray3.default)(source))))); | ||
} | ||
return undefined; | ||
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
}, { | ||
key: 'loadConfig', | ||
value: function loadConfig() { | ||
if ((0, _isEmptyObject2.default)(this.package)) { | ||
throw new Error('Cannot load configuration as "package.json" has not been loaded.'); | ||
} | ||
var _tool$options = this.tool.options, | ||
appName = _tool$options.appName, | ||
configBlueprint = _tool$options.configBlueprint, | ||
configFolder = _tool$options.configFolder, | ||
pluginAlias = _tool$options.pluginAlias, | ||
root = _tool$options.root; | ||
var camelName = (0, _camelCase2.default)(appName); | ||
var config = {}; | ||
this.tool.debug('Locating configuration'); | ||
if (this.package[camelName]) { | ||
config = this.package[camelName]; | ||
this.tool.debug('Found in package.json under "' + camelName + '" property'); | ||
if (typeof config === 'string') { | ||
config = { extends: [config] }; | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chalk_1 = __importDefault(require("chalk")); | ||
var fs_1 = __importDefault(require("fs")); | ||
var glob_1 = __importDefault(require("glob")); | ||
var path_1 = __importDefault(require("path")); | ||
var json5_1 = __importDefault(require("json5")); | ||
var camelCase_1 = __importDefault(require("lodash/camelCase")); | ||
var mergeWith_1 = __importDefault(require("lodash/mergeWith")); | ||
var pluralize_1 = __importDefault(require("pluralize")); | ||
var optimal_1 = __importDefault(require("optimal")); | ||
var formatModuleName_1 = __importDefault(require("./helpers/formatModuleName")); | ||
var isObject_1 = __importDefault(require("./helpers/isObject")); | ||
var isEmptyObject_1 = __importDefault(require("./helpers/isEmptyObject")); | ||
var requireModule_1 = __importDefault(require("./helpers/requireModule")); | ||
var constants_1 = require("./constants"); | ||
var ConfigLoader = (function () { | ||
function ConfigLoader(tool) { | ||
this.package = { name: '' }; | ||
this.parsedFiles = {}; | ||
this.debug = tool.createDebugger("config-loader"); | ||
this.tool = tool; | ||
} | ||
ConfigLoader.prototype.handleMerge = function (target, source) { | ||
if (Array.isArray(target) && Array.isArray(source)) { | ||
return Array.from(new Set(target.concat(source))); | ||
} | ||
} else { | ||
var filePaths = _glob2.default.sync(_path2.default.join(root, configFolder, appName + '.{js,json,json5}'), { absolute: true }); | ||
var fileNames = [_path2.default.join(configFolder, appName + '.js'), _path2.default.join(configFolder, appName + '.json'), _path2.default.join(configFolder, appName + '.json5')]; | ||
this.tool.debug('Resolving in order: ' + fileNames.join(', ')); | ||
if (filePaths.length === 0) { | ||
throw new Error('Local configuration file could not be found. ' + ('One of ' + fileNames.join(', ') + ' must exist relative to the project root.')); | ||
} else if (filePaths.length !== 1) { | ||
throw new Error('Multiple "' + appName + '" configuration files found. Only 1 may exist.'); | ||
return undefined; | ||
}; | ||
ConfigLoader.prototype.loadConfig = function () { | ||
if (isEmptyObject_1.default(this.package) || !this.package.name) { | ||
throw new Error('Cannot load configuration as "package.json" has not been loaded.'); | ||
} | ||
var _filePaths = (0, _slicedToArray3.default)(filePaths, 1); | ||
config = _filePaths[0]; | ||
this.tool.debug('Found ' + _path2.default.basename(config)); | ||
} | ||
return new _optimal2.default(this.parseAndExtend(config), (0, _extends4.default)({}, configBlueprint, (0, _defineProperty3.default)({ | ||
debug: (0, _optimal.bool)(), | ||
extends: (0, _optimal.array)((0, _optimal.string)()), | ||
reporter: (0, _optimal.string)().empty(), | ||
silent: (0, _optimal.bool)() | ||
}, (0, _pluralize2.default)(pluginAlias), (0, _optimal.array)((0, _optimal.union)([(0, _optimal.string)(), (0, _optimal.shape)((0, _defineProperty3.default)({}, pluginAlias, (0, _optimal.string)()))])))), { | ||
name: 'ConfigLoader', | ||
unknown: true | ||
}); | ||
} | ||
}, { | ||
key: 'loadPackageJSON', | ||
value: function loadPackageJSON() { | ||
var root = this.tool.options.root; | ||
var filePath = _path2.default.join(root, 'package.json'); | ||
this.tool.debug('Locating package.json in ' + _chalk2.default.cyan(root)); | ||
if (!_fs2.default.existsSync(filePath)) { | ||
throw new Error('Local "package.json" could not be found. ' + 'Please run the command in your project\'s root.'); | ||
} | ||
this.package = new _optimal2.default(this.parseFile(filePath), { | ||
name: (0, _optimal.string)() | ||
}, { | ||
name: 'ConfigLoader', | ||
unknown: true | ||
}); | ||
return this.package; | ||
} | ||
}, { | ||
key: 'parseAndExtend', | ||
value: function parseAndExtend(fileOrConfig) { | ||
var _this = this; | ||
var config = void 0; | ||
var baseDir = ''; | ||
if (typeof fileOrConfig === 'string') { | ||
config = this.parseFile(fileOrConfig); | ||
baseDir = _path2.default.dirname(fileOrConfig); | ||
} else { | ||
config = fileOrConfig; | ||
} | ||
if (!(0, _isObject2.default)(config)) { | ||
throw new Error('Invalid configuration. Must be a plain object.'); | ||
} | ||
var _config = config, | ||
extendPaths = _config.extends; | ||
if (!extendPaths || extendPaths.length === 0) { | ||
return config; | ||
} | ||
var nextConfig = {}; | ||
var resolvedPaths = this.resolveExtendPaths(extendPaths, baseDir); | ||
resolvedPaths.forEach(function (extendPath) { | ||
if (_this.parsedFiles[extendPath]) { | ||
return; | ||
var _a = this.tool.options, appName = _a.appName, configBlueprint = _a.configBlueprint, configFolder = _a.configFolder, pluginAlias = _a.pluginAlias, root = _a.root; | ||
var camelName = camelCase_1.default(appName); | ||
var config = {}; | ||
this.debug('Locating configuration'); | ||
if (this.package[camelName]) { | ||
config = this.package[camelName]; | ||
this.debug('Found in package.json under "%s" property', camelName); | ||
if (typeof config === 'string') { | ||
config = { extends: [config] }; | ||
} | ||
} | ||
if (!_fs2.default.existsSync(extendPath)) { | ||
throw new Error('Preset configuration ' + extendPath + ' does not exist.'); | ||
} else if (!_fs2.default.statSync(extendPath).isFile()) { | ||
throw new Error('Preset configuration ' + extendPath + ' must be a valid file.'); | ||
else { | ||
var filePaths = glob_1.default.sync(path_1.default.join(root, configFolder, appName + ".{js,json,json5}"), { | ||
absolute: true, | ||
}); | ||
var fileNames = [ | ||
path_1.default.join(configFolder, appName + ".js"), | ||
path_1.default.join(configFolder, appName + ".json"), | ||
path_1.default.join(configFolder, appName + ".json5"), | ||
]; | ||
this.debug('Resolving in order: %s', fileNames.join(', ')); | ||
if (filePaths.length === 0) { | ||
throw new Error('Local configuration file could not be found. ' + | ||
("One of " + fileNames.join(', ') + " must exist relative to the project root.")); | ||
} | ||
else if (filePaths.length !== 1) { | ||
throw new Error("Multiple \"" + appName + "\" configuration files found. Only 1 may exist."); | ||
} | ||
config = filePaths[0]; | ||
this.debug('Found %s', path_1.default.basename(String(config))); | ||
} | ||
_this.tool.debug('Extending from file ' + _chalk2.default.cyan(extendPath)); | ||
(0, _mergeWith2.default)(nextConfig, _this.parseAndExtend(extendPath), _this.handleMerge); | ||
}); | ||
config.extends = resolvedPaths; | ||
(0, _mergeWith2.default)(nextConfig, config, this.handleMerge); | ||
return nextConfig; | ||
} | ||
}, { | ||
key: 'parseFile', | ||
value: function parseFile(filePath) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var name = _path2.default.basename(filePath); | ||
var ext = _path2.default.extname(filePath); | ||
var value = void 0; | ||
this.tool.debug('Parsing file ' + _chalk2.default.cyan(filePath)); | ||
if (!_path2.default.isAbsolute(filePath)) { | ||
throw new Error('An absolute file path is required.'); | ||
} | ||
if (ext === '.json' || ext === '.json5') { | ||
value = _json2.default.parse(_fs2.default.readFileSync(filePath, 'utf8')); | ||
} else if (ext === '.js') { | ||
value = (0, _requireModule2.default)(filePath); | ||
if (typeof value === 'function') { | ||
value = value(options); | ||
return optimal_1.default(this.parseAndExtend(config), __assign({}, configBlueprint, (_b = { debug: optimal_1.bool(), extends: optimal_1.array(optimal_1.string()), reporter: optimal_1.string().empty(), silent: optimal_1.bool() }, _b[pluralize_1.default(pluginAlias)] = optimal_1.array(optimal_1.union([optimal_1.string(), optimal_1.shape((_c = {}, _c[pluginAlias] = optimal_1.string(), _c))])), _b)), { | ||
name: 'ConfigLoader', | ||
unknown: true, | ||
}); | ||
var _b, _c; | ||
}; | ||
ConfigLoader.prototype.loadPackageJSON = function () { | ||
var root = this.tool.options.root; | ||
var filePath = path_1.default.join(root, 'package.json'); | ||
this.debug('Locating package.json in %s', chalk_1.default.cyan(root)); | ||
if (!fs_1.default.existsSync(filePath)) { | ||
throw new Error('Local "package.json" could not be found. Please run the command in your project\'s root.'); | ||
} | ||
} else { | ||
throw new Error('Unsupported configuration file format "' + name + '".'); | ||
} | ||
if (!(0, _isObject2.default)(value)) { | ||
throw new Error('Invalid configuration file "' + name + '". Must return an object.'); | ||
} | ||
this.parsedFiles[filePath] = true; | ||
return value; | ||
} | ||
}, { | ||
key: 'resolveExtendPaths', | ||
value: function resolveExtendPaths(extendPaths) { | ||
var _this2 = this; | ||
var baseDir = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ''; | ||
return extendPaths.map(function (extendPath) { | ||
if (typeof extendPath !== 'string') { | ||
throw new TypeError('Invalid `extends` configuration value. Must be an array of strings.'); | ||
this.package = optimal_1.default(this.parseFile(filePath), { | ||
name: optimal_1.string(), | ||
}, { | ||
name: 'ConfigLoader', | ||
unknown: true, | ||
}); | ||
return this.package; | ||
}; | ||
ConfigLoader.prototype.parseAndExtend = function (fileOrConfig) { | ||
var _this = this; | ||
var config; | ||
var baseDir = ''; | ||
if (typeof fileOrConfig === 'string') { | ||
config = this.parseFile(fileOrConfig); | ||
baseDir = path_1.default.dirname(fileOrConfig); | ||
} | ||
var _tool$options2 = _this2.tool.options, | ||
appName = _tool$options2.appName, | ||
scoped = _tool$options2.scoped, | ||
pluginAlias = _tool$options2.pluginAlias, | ||
root = _tool$options2.root; | ||
if (_path2.default.isAbsolute(extendPath)) { | ||
return _path2.default.normalize(extendPath); | ||
} else if (extendPath[0] === '.') { | ||
return _path2.default.resolve(baseDir || root, extendPath); | ||
} else if (extendPath.match(_constants.MODULE_NAME_PATTERN)) { | ||
return _this2.resolveModuleConfigPath(appName, extendPath, true); | ||
} else if (extendPath.match(_constants.PLUGIN_NAME_PATTERN)) { | ||
return _this2.resolveModuleConfigPath(appName, (0, _formatModuleName2.default)(appName, pluginAlias, extendPath, scoped), true); | ||
else { | ||
config = fileOrConfig; | ||
} | ||
throw new Error('Invalid `extends` configuration value "' + extendPath + '".'); | ||
}); | ||
} | ||
}, { | ||
key: 'resolveModuleConfigPath', | ||
value: function resolveModuleConfigPath(appName, moduleName) { | ||
var preset = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
var ext = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'js'; | ||
var fileName = preset ? appName + '.preset.' + ext : appName + '.' + ext; | ||
var configFolder = this.tool.options.configFolder; | ||
return _path2.default.resolve(this.tool.options.root, 'node_modules', moduleName, configFolder, fileName); | ||
} | ||
}]); | ||
return ConfigLoader; | ||
}(); | ||
exports.default = ConfigLoader; | ||
if (!isObject_1.default(config)) { | ||
throw new Error('Invalid configuration. Must be a plain object.'); | ||
} | ||
var extendPaths = config.extends; | ||
if (!extendPaths || extendPaths.length === 0) { | ||
return config; | ||
} | ||
var nextConfig = {}; | ||
var resolvedPaths = this.resolveExtendPaths(extendPaths, baseDir); | ||
resolvedPaths.forEach(function (extendPath) { | ||
if (_this.parsedFiles[extendPath]) { | ||
return; | ||
} | ||
if (!fs_1.default.existsSync(extendPath)) { | ||
throw new Error("Preset configuration " + extendPath + " does not exist."); | ||
} | ||
else if (!fs_1.default.statSync(extendPath).isFile()) { | ||
throw new Error("Preset configuration " + extendPath + " must be a valid file."); | ||
} | ||
_this.debug('Extending from file %s', chalk_1.default.cyan(extendPath)); | ||
mergeWith_1.default(nextConfig, _this.parseAndExtend(extendPath), _this.handleMerge); | ||
}); | ||
config.extends = resolvedPaths; | ||
mergeWith_1.default(nextConfig, config, this.handleMerge); | ||
return nextConfig; | ||
}; | ||
ConfigLoader.prototype.parseFile = function (filePath, options) { | ||
if (options === void 0) { options = {}; } | ||
var name = path_1.default.basename(filePath); | ||
var ext = path_1.default.extname(filePath); | ||
var value = null; | ||
this.debug('Parsing file %s', chalk_1.default.cyan(filePath)); | ||
if (!path_1.default.isAbsolute(filePath)) { | ||
throw new Error('An absolute file path is required.'); | ||
} | ||
if (ext === '.json' || ext === '.json5') { | ||
value = json5_1.default.parse(fs_1.default.readFileSync(filePath, 'utf8')); | ||
} | ||
else if (ext === '.js') { | ||
value = requireModule_1.default(filePath); | ||
if (typeof value === 'function') { | ||
value = value(options); | ||
} | ||
} | ||
else { | ||
throw new Error("Unsupported configuration file format \"" + name + "\"."); | ||
} | ||
if (!isObject_1.default(value)) { | ||
throw new Error("Invalid configuration file \"" + name + "\". Must return an object."); | ||
} | ||
this.parsedFiles[filePath] = true; | ||
return value; | ||
}; | ||
ConfigLoader.prototype.resolveExtendPaths = function (extendPaths, baseDir) { | ||
var _this = this; | ||
if (baseDir === void 0) { baseDir = ''; } | ||
return extendPaths.map(function (extendPath) { | ||
if (typeof extendPath !== 'string') { | ||
throw new TypeError('Invalid `extends` configuration value. Must be an array of strings.'); | ||
} | ||
var _a = _this.tool.options, appName = _a.appName, scoped = _a.scoped, pluginAlias = _a.pluginAlias, root = _a.root; | ||
if (path_1.default.isAbsolute(extendPath)) { | ||
return path_1.default.normalize(extendPath); | ||
} | ||
else if (extendPath[0] === '.') { | ||
return path_1.default.resolve(baseDir || root, extendPath); | ||
} | ||
else if (extendPath.match(constants_1.MODULE_NAME_PATTERN)) { | ||
return _this.resolveModuleConfigPath(appName, extendPath, true); | ||
} | ||
else if (extendPath.match(constants_1.PLUGIN_NAME_PATTERN)) { | ||
return _this.resolveModuleConfigPath(appName, formatModuleName_1.default(appName, pluginAlias, extendPath, scoped), true); | ||
} | ||
throw new Error("Invalid `extends` configuration value \"" + extendPath + "\"."); | ||
}); | ||
}; | ||
ConfigLoader.prototype.resolveModuleConfigPath = function (appName, moduleName, preset, ext) { | ||
if (preset === void 0) { preset = false; } | ||
if (ext === void 0) { ext = 'js'; } | ||
var fileName = preset ? appName + ".preset." + ext : appName + "." + ext; | ||
var configFolder = this.tool.options.configFolder; | ||
return path_1.default.resolve(this.tool.options.root, 'node_modules', moduleName, configFolder, fileName); | ||
}; | ||
return ConfigLoader; | ||
}()); | ||
exports.default = ConfigLoader; |
@@ -1,187 +0,116 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _optimal = require('optimal'); | ||
var _optimal2 = _interopRequireDefault(_optimal); | ||
var _ExitError = require('./ExitError'); | ||
var _ExitError2 = _interopRequireDefault(_ExitError); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var DEBUG_COLORS = ['white', 'cyan', 'blue', 'magenta', 'red', 'yellow', 'green']; /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var Console = function () { | ||
function Console(reporter) { | ||
var _this = this; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
(0, _classCallCheck3.default)(this, Console); | ||
this.debugs = []; | ||
this.debugGroups = []; | ||
this.debugIndex = -1; | ||
this.errors = []; | ||
this.interrupted = false; | ||
this.logs = []; | ||
this.reporter = reporter; | ||
this.options = new _optimal2.default(options, { | ||
debug: (0, _optimal.bool)(), | ||
footer: (0, _optimal.string)().empty(), | ||
header: (0, _optimal.string)().empty(), | ||
silent: (0, _optimal.bool)() | ||
}); | ||
if (process.env.NODE_ENV === 'test') { | ||
return; | ||
} | ||
this.start(); | ||
var signalHandler = function signalHandler() { | ||
if (_this.interrupted) { | ||
_this.exit('Process has been terminated.'); | ||
} else { | ||
_this.log(_chalk2.default.yellow('Press Ctrl+C again to exit.')); | ||
_this.interrupted = true; | ||
} | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
process.on('SIGINT', signalHandler).on('SIGTERM', signalHandler).on('uncaughtException', function (error) { | ||
_this.debug(_chalk2.default.yellow('Uncaught exception detected!')); | ||
_this.exit(error); | ||
}).on('unhandledRejection', function (error) { | ||
_this.debug(_chalk2.default.yellow('Unhandled promise rejection detected!')); | ||
_this.exit(error); | ||
}); | ||
} | ||
(0, _createClass3.default)(Console, [{ | ||
key: 'debug', | ||
value: function debug(message) { | ||
var indent = ' '.repeat(this.debugGroups.length); | ||
this.debugs.push('' + _chalk2.default.gray('[debug]') + indent + ' ' + message); | ||
})(); | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
}, { | ||
key: 'error', | ||
value: function error(message) { | ||
this.errors.push(message); | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chalk_1 = __importDefault(require("chalk")); | ||
var optimal_1 = __importDefault(require("optimal")); | ||
var util_1 = __importDefault(require("util")); | ||
var Emitter_1 = __importDefault(require("./Emitter")); | ||
var ExitError_1 = __importDefault(require("./ExitError")); | ||
var Console = (function (_super) { | ||
__extends(Console, _super); | ||
function Console(reporter, options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = _super.call(this) || this; | ||
_this.errors = []; | ||
_this.interrupted = false; | ||
_this.logs = []; | ||
_this.reporter = reporter; | ||
_this.options = optimal_1.default(options, { | ||
footer: optimal_1.string().empty(), | ||
header: optimal_1.string().empty(), | ||
silent: optimal_1.bool(), | ||
}); | ||
if (process.env.NODE_ENV === 'test') { | ||
return _this; | ||
} | ||
_this.start(); | ||
var signalHandler = function () { | ||
if (_this.interrupted) { | ||
_this.exit('Process has been terminated.'); | ||
} | ||
else { | ||
_this.log(chalk_1.default.yellow('Press Ctrl+C again to exit.')); | ||
_this.interrupted = true; | ||
} | ||
}; | ||
process | ||
.on('SIGINT', signalHandler) | ||
.on('SIGTERM', signalHandler) | ||
.on('uncaughtException', function (error) { | ||
_this.error(chalk_1.default.yellow('Uncaught exception detected!')); | ||
_this.exit(error); | ||
}) | ||
.on('unhandledRejection', function (error) { | ||
_this.error(chalk_1.default.yellow('Unhandled promise rejection detected!')); | ||
_this.exit(error); | ||
}); | ||
return _this; | ||
} | ||
}, { | ||
key: 'exit', | ||
value: function exit(message) { | ||
var code = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
var errorCode = code; | ||
if (message !== null) { | ||
var error = message instanceof Error ? message : new _ExitError2.default(message, code); | ||
if (typeof error.code === 'number') { | ||
errorCode = error.code; | ||
Console.prototype.error = function (message) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
if (this.errors.length === 0) { | ||
this.error(_chalk2.default.red(error.stack || error.message)); | ||
this.errors.push(util_1.default.format.apply(util_1.default, [message].concat(args))); | ||
}; | ||
Console.prototype.exit = function (message, code) { | ||
if (code === void 0) { code = 1; } | ||
var errorCode = code; | ||
if (message !== null) { | ||
var error = message instanceof Error ? message : new ExitError_1.default(message, code); | ||
if (error instanceof ExitError_1.default && typeof error.code === 'number') { | ||
errorCode = error.code; | ||
} | ||
if (this.errors.length === 0) { | ||
this.error(chalk_1.default.red(error.stack || error.message)); | ||
} | ||
} | ||
} | ||
this.stop(); | ||
(errorCode === 0 ? process.stdout : process.stderr).write(this.reporter.render(errorCode), function () { | ||
process.exitCode = errorCode; | ||
}); | ||
} | ||
}, { | ||
key: 'log', | ||
value: function log(message) { | ||
this.logs.push(message); | ||
} | ||
}, { | ||
key: 'start', | ||
value: function start() { | ||
var _this2 = this; | ||
var tasks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var debugs = this.debugs, | ||
errors = this.errors, | ||
logs = this.logs; | ||
this.reporter.start(function () { | ||
return (0, _extends3.default)({}, _this2.options, { | ||
debugs: debugs, | ||
errors: errors, | ||
logs: logs, | ||
tasks: tasks | ||
this.stop(); | ||
(errorCode === 0 ? process.stdout : process.stderr).write(this.reporter.render(errorCode), function () { | ||
process.exitCode = errorCode; | ||
}); | ||
}); | ||
} | ||
}, { | ||
key: 'startDebugGroup', | ||
value: function startDebugGroup(group) { | ||
this.debugIndex += 1; | ||
if (this.debugIndex === DEBUG_COLORS.length) { | ||
this.debugIndex = 0; | ||
} | ||
var color = DEBUG_COLORS[this.debugIndex]; | ||
this.debug(_chalk2.default[color]('[' + group + ']')); | ||
this.debugGroups.push(group); | ||
} | ||
}, { | ||
key: 'stop', | ||
value: function stop() { | ||
this.reporter.stop(); | ||
} | ||
}, { | ||
key: 'stopDebugGroup', | ||
value: function stopDebugGroup() { | ||
var color = DEBUG_COLORS[this.debugIndex]; | ||
var group = this.debugGroups.pop(); | ||
this.debug(_chalk2.default[color]('[/' + group + ']')); | ||
this.debugIndex -= 1; | ||
if (this.debugIndex < 0) { | ||
this.debugIndex = DEBUG_COLORS.length - 1; | ||
} | ||
} | ||
}, { | ||
key: 'update', | ||
value: function update() { | ||
this.reporter.update(); | ||
} | ||
}]); | ||
return Console; | ||
}(); | ||
exports.default = Console; | ||
}; | ||
Console.prototype.log = function (message) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
this.logs.push(util_1.default.format.apply(util_1.default, [message].concat(args))); | ||
}; | ||
Console.prototype.start = function (tasks) { | ||
var _this = this; | ||
if (tasks === void 0) { tasks = []; } | ||
var _a = this, errors = _a.errors, logs = _a.logs; | ||
this.reporter.start(function () { return (__assign({}, _this.options, { errors: errors, | ||
logs: logs, | ||
tasks: tasks })); }); | ||
}; | ||
Console.prototype.stop = function () { | ||
this.reporter.stop(); | ||
}; | ||
Console.prototype.update = function () { | ||
this.reporter.update(); | ||
}; | ||
return Console; | ||
}(Emitter_1.default)); | ||
exports.default = Console; |
@@ -1,27 +0,17 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var APP_NAME_PATTERN = exports.APP_NAME_PATTERN = /^[-a-z.]+$/; /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var MODULE_NAME_PATTERN = exports.MODULE_NAME_PATTERN = /^(@[-a-z]+\/)?[-a-z]+$/; | ||
var PLUGIN_NAME_PATTERN = exports.PLUGIN_NAME_PATTERN = /^[a-z]+:[-a-z]+$/; | ||
var STATUS_PENDING = exports.STATUS_PENDING = 'pending'; | ||
var STATUS_RUNNING = exports.STATUS_RUNNING = 'running'; | ||
var STATUS_SKIPPED = exports.STATUS_SKIPPED = 'skipped'; | ||
var STATUS_PASSED = exports.STATUS_PASSED = 'passed'; | ||
var STATUS_FAILED = exports.STATUS_FAILED = 'failed'; | ||
var DEFAULT_TOOL_CONFIG = exports.DEFAULT_TOOL_CONFIG = { | ||
debug: false, | ||
extends: [], | ||
plugins: [], | ||
reporter: '', | ||
silent: false | ||
}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.APP_NAME_PATTERN = /^[-a-z.]+$/; | ||
exports.MODULE_NAME_PATTERN = /^(@[-a-z]+\/)?[-a-z]+$/; | ||
exports.PLUGIN_NAME_PATTERN = /^[a-z]+:[-a-z]+$/; | ||
exports.STATUS_PENDING = 'pending'; | ||
exports.STATUS_RUNNING = 'running'; | ||
exports.STATUS_SKIPPED = 'skipped'; | ||
exports.STATUS_PASSED = 'passed'; | ||
exports.STATUS_FAILED = 'failed'; | ||
exports.DEFAULT_TOOL_CONFIG = { | ||
debug: false, | ||
extends: [], | ||
plugins: [], | ||
reporter: '', | ||
silent: false, | ||
}; |
@@ -1,156 +0,88 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _Event = require('./Event'); | ||
var _Event2 = _interopRequireDefault(_Event); | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var Emitter = function () { | ||
function Emitter() { | ||
(0, _classCallCheck3.default)(this, Emitter); | ||
this.listeners = {}; | ||
this.namespace = ''; | ||
} | ||
(0, _createClass3.default)(Emitter, [{ | ||
key: 'createEventName', | ||
value: function createEventName(name) { | ||
if (this.namespace && !name.startsWith(this.namespace)) { | ||
return this.namespace + '.' + name; | ||
} | ||
return name; | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Event_1 = __importDefault(require("./Event")); | ||
var constants_1 = require("./constants"); | ||
var Emitter = (function () { | ||
function Emitter() { | ||
this.listeners = {}; | ||
this.namespace = ''; | ||
} | ||
}, { | ||
key: 'emit', | ||
value: function emit(name) { | ||
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var initialValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var event = new _Event2.default(this.createEventName(name), initialValue); | ||
[].concat((0, _toConsumableArray3.default)(this.getListeners(event.name))).some(function (listener) { | ||
listener.apply(undefined, [event].concat((0, _toConsumableArray3.default)(args))); | ||
return event.stopped; | ||
}); | ||
return event; | ||
} | ||
}, { | ||
key: 'emitCascade', | ||
value: function emitCascade(name) { | ||
var args = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var initialValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; | ||
var event = new _Event2.default(this.createEventName(name), initialValue); | ||
var listeners = [].concat((0, _toConsumableArray3.default)(this.getListeners(event.name))); | ||
var index = 0; | ||
if (listeners.length === 0) { | ||
Emitter.prototype.createEventName = function (name) { | ||
if (this.namespace && !name.startsWith(this.namespace)) { | ||
return this.namespace + "." + name; | ||
} | ||
return name; | ||
}; | ||
Emitter.prototype.emit = function (name, args, initialValue) { | ||
if (args === void 0) { args = []; } | ||
if (initialValue === void 0) { initialValue = null; } | ||
var event = new Event_1.default(this.createEventName(name), initialValue); | ||
Array.from(this.getListeners(event.name)).some(function (listener) { | ||
listener.apply(void 0, [event].concat(args)); | ||
return event.stopped; | ||
}); | ||
return event; | ||
} | ||
function next(nextIndex) { | ||
for (var _len = arguments.length, nextEventArguments = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
nextEventArguments[_key - 1] = arguments[_key]; | ||
}; | ||
Emitter.prototype.emitCascade = function (name, args, initialValue) { | ||
if (args === void 0) { args = []; } | ||
if (initialValue === void 0) { initialValue = null; } | ||
var event = new Event_1.default(this.createEventName(name), initialValue); | ||
var listeners = Array.from(this.getListeners(event.name)); | ||
var index = 0; | ||
if (listeners.length === 0) { | ||
return event; | ||
} | ||
index = nextIndex; | ||
var listener = listeners[index]; | ||
if (!listener || event.stopped) { | ||
return; | ||
function next(nextIndex) { | ||
var nextEventArguments = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
nextEventArguments[_i - 1] = arguments[_i]; | ||
} | ||
index = nextIndex; | ||
var listener = listeners[index]; | ||
if (!listener || event.stopped) { | ||
return; | ||
} | ||
event.next = function () { return next.apply(void 0, [index + 1].concat(nextEventArguments)); }; | ||
listener.apply(void 0, [event].concat(nextEventArguments)); | ||
} | ||
event.next = function () { | ||
return next.apply(undefined, [index + 1].concat((0, _toConsumableArray3.default)(nextEventArguments))); | ||
}; | ||
listener.apply(undefined, [event].concat((0, _toConsumableArray3.default)(nextEventArguments))); | ||
} | ||
next.apply(undefined, [0].concat((0, _toConsumableArray3.default)(args))); | ||
return event; | ||
} | ||
}, { | ||
key: 'getEventNames', | ||
value: function getEventNames() { | ||
return Object.keys(this.listeners); | ||
} | ||
}, { | ||
key: 'getListeners', | ||
value: function getListeners(eventName) { | ||
if (!eventName.match(_constants.APP_NAME_PATTERN)) { | ||
throw new Error('Invalid event name "' + eventName + '". ' + 'May only contain dashes, periods, and lowercase characters.'); | ||
} | ||
if (!this.listeners[eventName]) { | ||
this.listeners[eventName] = new Set(); | ||
} | ||
return this.listeners[eventName]; | ||
} | ||
}, { | ||
key: 'off', | ||
value: function off(eventName, listener) { | ||
this.getListeners(eventName).delete(listener); | ||
return this; | ||
} | ||
}, { | ||
key: 'on', | ||
value: function on(eventName, listener) { | ||
if (typeof listener !== 'function') { | ||
throw new TypeError('Invalid event listener for "' + eventName + '", must be a function.'); | ||
} | ||
this.getListeners(eventName).add(listener); | ||
return this; | ||
} | ||
}, { | ||
key: 'setEventNamespace', | ||
value: function setEventNamespace(namespace) { | ||
this.namespace = namespace; | ||
return this; | ||
} | ||
}, { | ||
key: 'removeEventNamespace', | ||
value: function removeEventNamespace() { | ||
this.namespace = ''; | ||
return this; | ||
} | ||
}]); | ||
return Emitter; | ||
}(); | ||
exports.default = Emitter; | ||
next.apply(void 0, [0].concat(args)); | ||
return event; | ||
}; | ||
Emitter.prototype.getEventNames = function () { | ||
return Object.keys(this.listeners); | ||
}; | ||
Emitter.prototype.getListeners = function (eventName) { | ||
if (!eventName.match(constants_1.APP_NAME_PATTERN)) { | ||
throw new Error("Invalid event name \"" + eventName + "\". " + | ||
'May only contain dashes, periods, and lowercase characters.'); | ||
} | ||
if (!this.listeners[eventName]) { | ||
this.listeners[eventName] = new Set(); | ||
} | ||
return this.listeners[eventName]; | ||
}; | ||
Emitter.prototype.off = function (eventName, listener) { | ||
this.getListeners(eventName).delete(listener); | ||
return this; | ||
}; | ||
Emitter.prototype.on = function (eventName, listener) { | ||
if (typeof listener !== 'function') { | ||
throw new TypeError("Invalid event listener for \"" + eventName + "\", must be a function."); | ||
} | ||
this.getListeners(eventName).add(listener); | ||
return this; | ||
}; | ||
Emitter.prototype.setEventNamespace = function (namespace) { | ||
this.namespace = namespace; | ||
return this; | ||
}; | ||
Emitter.prototype.removeEventNamespace = function () { | ||
this.namespace = ''; | ||
return this; | ||
}; | ||
return Emitter; | ||
}()); | ||
exports.default = Emitter; |
@@ -1,46 +0,20 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Event = function () { | ||
function Event(name) { | ||
var value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
(0, _classCallCheck3.default)(this, Event); | ||
this.next = null; | ||
this.stopped = false; | ||
if (!name || typeof name !== 'string') { | ||
throw new Error('A valid event name is required.'); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Event = (function () { | ||
function Event(name, value) { | ||
if (value === void 0) { value = null; } | ||
this.next = null; | ||
this.stopped = false; | ||
if (!name || typeof name !== 'string') { | ||
throw new Error('A valid event name is required.'); | ||
} | ||
this.name = name; | ||
this.time = Date.now(); | ||
this.value = value; | ||
} | ||
this.name = name; | ||
this.time = Date.now(); | ||
this.value = value; | ||
} | ||
(0, _createClass3.default)(Event, [{ | ||
key: 'stop', | ||
value: function stop() { | ||
this.stopped = true; | ||
} | ||
}]); | ||
return Event; | ||
}(); /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
exports.default = Event; | ||
Event.prototype.stop = function () { | ||
this.stopped = true; | ||
}; | ||
return Event; | ||
}()); | ||
exports.default = Event; |
@@ -1,48 +0,27 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var ExitError = function (_Error) { | ||
(0, _inherits3.default)(ExitError, _Error); | ||
function ExitError(message) { | ||
var code = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
(0, _classCallCheck3.default)(this, ExitError); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (ExitError.__proto__ || Object.getPrototypeOf(ExitError)).call(this, message)); | ||
_this.code = code; | ||
_this.name = 'ExitError'; | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(_this, ExitError); | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ExitError = (function (_super) { | ||
__extends(ExitError, _super); | ||
function ExitError(message, code) { | ||
if (code === void 0) { code = 1; } | ||
var _this = _super.call(this, message) || this; | ||
_this.code = code; | ||
_this.name = 'ExitError'; | ||
if (Error.captureStackTrace) { | ||
Error.captureStackTrace(_this, ExitError); | ||
} | ||
return _this; | ||
} | ||
return _this; | ||
} | ||
return ExitError; | ||
}(Error); | ||
exports.default = ExitError; | ||
return ExitError; | ||
}(Error)); | ||
exports.default = ExitError; |
@@ -1,23 +0,14 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function formatModuleName(appName, addonName, name, scoped) { | ||
if (scoped === void 0) { scoped = false; } | ||
var moduleName = name | ||
.toLowerCase() | ||
.replace('plugin:', '') | ||
.replace(addonName + ":", ''); | ||
if (scoped) { | ||
return "@" + appName + "/" + addonName + "-" + moduleName; | ||
} | ||
return appName + "-" + addonName + "-" + moduleName; | ||
} | ||
exports.default = formatModuleName; | ||
/** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
function formatModuleName(appName, addonName, name) { | ||
var scoped = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; | ||
var moduleName = name.toLowerCase().replace('plugin:', '').replace(addonName + ':', ''); | ||
if (scoped) { | ||
return '@' + appName + '/' + addonName + '-' + moduleName; | ||
} | ||
return appName + '-' + addonName + '-' + moduleName; | ||
} |
@@ -1,20 +0,10 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var isObject_1 = __importDefault(require("./isObject")); | ||
function isEmptyObject(value) { | ||
return !value || !isObject_1.default(value) || Object.keys(value).length === 0; | ||
} | ||
exports.default = isEmptyObject; | ||
var _isObject = require('./isObject'); | ||
var _isObject2 = _interopRequireDefault(_isObject); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function isEmptyObject(value) { | ||
return !value || !(0, _isObject2.default)(value) || Object.keys(value).length === 0; | ||
} /** | ||
* @copyright 2016-2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ |
@@ -1,23 +0,6 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
var _typeof3 = _interopRequireDefault(_typeof2); | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function isObject(value) { | ||
return typeof value === 'object' && value !== null && !Array.isArray(value); | ||
} | ||
exports.default = isObject; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* @copyright 2016-2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
function isObject(value) { | ||
return (typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value)) === 'object' && value !== null && !Array.isArray(value); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function requireModule(path) { | ||
var value = require(path); | ||
if (value && value.__esModule) { | ||
value = value.default; | ||
} | ||
return value; | ||
} | ||
exports.default = requireModule; | ||
/** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
function requireModule(path) { | ||
var value = require(path); | ||
if (value && value.__esModule) { | ||
value = value.default; | ||
} | ||
return value; | ||
} |
@@ -1,68 +0,27 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Tool = exports.Routine = exports.Reporter = exports.Plugin = exports.Pipeline = exports.ModuleLoader = exports.Module = exports.ExitError = exports.Event = exports.Emitter = exports.ConfigLoader = undefined; | ||
var _ConfigLoader = require('./ConfigLoader'); | ||
var _ConfigLoader2 = _interopRequireDefault(_ConfigLoader); | ||
var _Emitter = require('./Emitter'); | ||
var _Emitter2 = _interopRequireDefault(_Emitter); | ||
var _Event = require('./Event'); | ||
var _Event2 = _interopRequireDefault(_Event); | ||
var _ExitError = require('./ExitError'); | ||
var _ExitError2 = _interopRequireDefault(_ExitError); | ||
var _Module = require('./Module'); | ||
var _Module2 = _interopRequireDefault(_Module); | ||
var _ModuleLoader = require('./ModuleLoader'); | ||
var _ModuleLoader2 = _interopRequireDefault(_ModuleLoader); | ||
var _Pipeline = require('./Pipeline'); | ||
var _Pipeline2 = _interopRequireDefault(_Pipeline); | ||
var _Plugin = require('./Plugin'); | ||
var _Plugin2 = _interopRequireDefault(_Plugin); | ||
var _Reporter = require('./Reporter'); | ||
var _Reporter2 = _interopRequireDefault(_Reporter); | ||
var _Routine = require('./Routine'); | ||
var _Routine2 = _interopRequireDefault(_Routine); | ||
var _Tool = require('./Tool'); | ||
var _Tool2 = _interopRequireDefault(_Tool); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.ConfigLoader = _ConfigLoader2.default; | ||
exports.Emitter = _Emitter2.default; | ||
exports.Event = _Event2.default; | ||
exports.ExitError = _ExitError2.default; | ||
exports.Module = _Module2.default; | ||
exports.ModuleLoader = _ModuleLoader2.default; | ||
exports.Pipeline = _Pipeline2.default; | ||
exports.Plugin = _Plugin2.default; | ||
exports.Reporter = _Reporter2.default; | ||
exports.Routine = _Routine2.default; | ||
exports.Tool = _Tool2.default; /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var ConfigLoader_1 = __importDefault(require("./ConfigLoader")); | ||
exports.ConfigLoader = ConfigLoader_1.default; | ||
var Emitter_1 = __importDefault(require("./Emitter")); | ||
exports.Emitter = Emitter_1.default; | ||
var Event_1 = __importDefault(require("./Event")); | ||
exports.Event = Event_1.default; | ||
var ExitError_1 = __importDefault(require("./ExitError")); | ||
exports.ExitError = ExitError_1.default; | ||
var Module_1 = __importDefault(require("./Module")); | ||
exports.Module = Module_1.default; | ||
var ModuleLoader_1 = __importDefault(require("./ModuleLoader")); | ||
exports.ModuleLoader = ModuleLoader_1.default; | ||
var Pipeline_1 = __importDefault(require("./Pipeline")); | ||
exports.Pipeline = Pipeline_1.default; | ||
var Plugin_1 = __importDefault(require("./Plugin")); | ||
exports.Plugin = Plugin_1.default; | ||
var Reporter_1 = __importDefault(require("./Reporter")); | ||
exports.Reporter = Reporter_1.default; | ||
var Routine_1 = __importDefault(require("./Routine")); | ||
exports.Routine = Routine_1.default; | ||
var Tool_1 = __importDefault(require("./Tool")); | ||
exports.Tool = Tool_1.default; |
@@ -1,31 +0,20 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var Module = function Module(options) { | ||
(0, _classCallCheck3.default)(this, Module); | ||
this.moduleName = ''; | ||
this.name = ''; | ||
this.options = (0, _extends3.default)({}, options); | ||
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
exports.default = Module; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Module = (function () { | ||
function Module(options) { | ||
if (options === void 0) { options = {}; } | ||
this.moduleName = ''; | ||
this.name = ''; | ||
this.options = __assign({}, options); | ||
} | ||
return Module; | ||
}()); | ||
exports.default = Module; |
@@ -1,176 +0,113 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _path = require('path'); | ||
var _path2 = _interopRequireDefault(_path); | ||
var _upperFirst = require('lodash/upperFirst'); | ||
var _upperFirst2 = _interopRequireDefault(_upperFirst); | ||
var _formatModuleName = require('./helpers/formatModuleName'); | ||
var _formatModuleName2 = _interopRequireDefault(_formatModuleName); | ||
var _isObject = require('./helpers/isObject'); | ||
var _isObject2 = _interopRequireDefault(_isObject); | ||
var _requireModule = require('./helpers/requireModule'); | ||
var _requireModule2 = _interopRequireDefault(_requireModule); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var ModuleLoader = function () { | ||
function ModuleLoader(tool, typeName, classReference) { | ||
(0, _classCallCheck3.default)(this, ModuleLoader); | ||
this.classReference = classReference; | ||
this.tool = tool; | ||
this.typeName = typeName; | ||
this.tool.debug('Using alias ' + _chalk2.default.green(typeName)); | ||
} | ||
(0, _createClass3.default)(ModuleLoader, [{ | ||
key: 'importModule', | ||
value: function importModule(name) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var typeName = this.typeName; | ||
var _tool$options = this.tool.options, | ||
appName = _tool$options.appName, | ||
scoped = _tool$options.scoped; | ||
var modulesToAttempt = []; | ||
var isFilePath = false; | ||
var importedModule = void 0; | ||
var moduleName = void 0; | ||
if (name.match(/^\.|\/|\\|[A-Z]:/)) { | ||
this.tool.debug('Locating ' + typeName + ' from path ' + _chalk2.default.cyan(name)); | ||
modulesToAttempt.push(_path2.default.normalize(name)); | ||
isFilePath = true; | ||
} else { | ||
this.tool.debug('Locating ' + typeName + ' module ' + _chalk2.default.yellow(name)); | ||
modulesToAttempt.push((0, _formatModuleName2.default)(appName, typeName, name, false)); | ||
if (scoped) { | ||
modulesToAttempt.unshift((0, _formatModuleName2.default)(appName, typeName, name, true)); | ||
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chalk_1 = __importDefault(require("chalk")); | ||
var path_1 = __importDefault(require("path")); | ||
var upperFirst_1 = __importDefault(require("lodash/upperFirst")); | ||
var formatModuleName_1 = __importDefault(require("./helpers/formatModuleName")); | ||
var isObject_1 = __importDefault(require("./helpers/isObject")); | ||
var requireModule_1 = __importDefault(require("./helpers/requireModule")); | ||
var ModuleLoader = (function () { | ||
function ModuleLoader(tool, typeName, classReference) { | ||
this.classReference = classReference; | ||
this.debug = tool.createDebugger(typeName + "-loader"); | ||
this.tool = tool; | ||
this.typeName = typeName; | ||
this.debug('Using alias %s', chalk_1.default.green(typeName)); | ||
} | ||
ModuleLoader.prototype.importModule = function (name, options) { | ||
if (options === void 0) { options = {}; } | ||
var typeName = this.typeName; | ||
var _a = this.tool.options, appName = _a.appName, scoped = _a.scoped; | ||
var modulesToAttempt = []; | ||
var isFilePath = false; | ||
var importedModule = null; | ||
var moduleName; | ||
if (name.match(/^\.|\/|\\|[A-Z]:/)) { | ||
this.debug('Locating %s from path %s', typeName, chalk_1.default.cyan(name)); | ||
modulesToAttempt.push(path_1.default.normalize(name)); | ||
isFilePath = true; | ||
} | ||
this.tool.debug('Resolving in order: ' + modulesToAttempt.join(', ')); | ||
} | ||
modulesToAttempt.some(function (modName) { | ||
try { | ||
importedModule = (0, _requireModule2.default)(modName); | ||
moduleName = modName; | ||
return true; | ||
} catch (error) { | ||
return false; | ||
else { | ||
this.debug('Locating %s module %s', typeName, chalk_1.default.yellow(name)); | ||
modulesToAttempt.push(formatModuleName_1.default(appName, typeName, name, false)); | ||
if (scoped) { | ||
modulesToAttempt.unshift(formatModuleName_1.default(appName, typeName, name, true)); | ||
} | ||
this.debug('Resolving in order: %s', modulesToAttempt.join(', ')); | ||
} | ||
}); | ||
if (!importedModule || !moduleName) { | ||
throw new Error('Missing ' + typeName + '. Attempted import in order: ' + modulesToAttempt.join(', ')); | ||
} | ||
if (importedModule instanceof this.classReference) { | ||
throw new TypeError('A ' + typeName + ' class instance was exported from "' + moduleName + '". ' + ((0, _upperFirst2.default)(appName) + ' requires a ' + typeName + ' class definition to be exported.')); | ||
} else if (typeof importedModule !== 'function') { | ||
throw new TypeError('Invalid ' + typeName + ' class definition exported from "' + moduleName + '".'); | ||
} | ||
var ModuleClass = importedModule; | ||
var module = new ModuleClass(options); | ||
if (!(module instanceof this.classReference)) { | ||
throw new TypeError((0, _upperFirst2.default)(typeName) + ' exported from "' + moduleName + '" is invalid.'); | ||
} | ||
if (isFilePath) { | ||
this.tool.debug('Found with ' + _chalk2.default.cyan(moduleName)); | ||
} else { | ||
this.tool.debug('Found with ' + _chalk2.default.yellow(moduleName)); | ||
module.name = name; | ||
module.moduleName = moduleName; | ||
} | ||
return module; | ||
} | ||
}, { | ||
key: 'importModuleFromOptions', | ||
value: function importModuleFromOptions(baseOptions) { | ||
var typeName = this.typeName; | ||
var options = (0, _extends3.default)({}, baseOptions); | ||
var module = options[typeName]; | ||
delete options[typeName]; | ||
if (!module || typeof module !== 'string') { | ||
throw new TypeError('A "' + typeName + '" property must exist when loading through an options object.'); | ||
} | ||
return this.importModule(module, options); | ||
} | ||
}, { | ||
key: 'loadModule', | ||
value: function loadModule(module) { | ||
if (module instanceof this.classReference) { | ||
modulesToAttempt.some(function (modName) { | ||
try { | ||
importedModule = requireModule_1.default(modName); | ||
moduleName = modName; | ||
return true; | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
}); | ||
if (!importedModule || !moduleName) { | ||
throw new Error("Missing " + typeName + ". Attempted import in order: " + modulesToAttempt.join(', ')); | ||
} | ||
if (importedModule instanceof this.classReference) { | ||
throw new TypeError("A " + typeName + " class instance was exported from \"" + moduleName + "\". " + | ||
(upperFirst_1.default(appName) + " requires a " + typeName + " class definition to be exported.")); | ||
} | ||
else if (typeof importedModule !== 'function') { | ||
throw new TypeError("Invalid " + typeName + " class definition exported from \"" + moduleName + "\"."); | ||
} | ||
var ModuleClass = importedModule; | ||
var module = new ModuleClass(options); | ||
if (!(module instanceof this.classReference)) { | ||
throw new TypeError(upperFirst_1.default(typeName) + " exported from \"" + moduleName + "\" is invalid."); | ||
} | ||
if (isFilePath) { | ||
this.debug('Found with %s', chalk_1.default.cyan(moduleName)); | ||
} | ||
else { | ||
this.debug('Found with %s', chalk_1.default.yellow(moduleName)); | ||
module.name = name; | ||
module.moduleName = moduleName; | ||
} | ||
return module; | ||
} else if (typeof module === 'string') { | ||
return this.importModule(module); | ||
} else if ((0, _isObject2.default)(module)) { | ||
return this.importModuleFromOptions(module); | ||
} | ||
throw new TypeError('Invalid ' + this.typeName + '. Must be a class instance or a module that exports a class definition.'); | ||
} | ||
}, { | ||
key: 'loadModules', | ||
value: function loadModules() { | ||
var _this = this; | ||
var modules = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
return modules.map(function (module) { | ||
return _this.loadModule(module); | ||
}); | ||
} | ||
}]); | ||
return ModuleLoader; | ||
}(); | ||
exports.default = ModuleLoader; | ||
}; | ||
ModuleLoader.prototype.importModuleFromOptions = function (baseOptions) { | ||
var typeName = this.typeName; | ||
var options = __assign({}, baseOptions); | ||
var module = options[typeName]; | ||
delete options[typeName]; | ||
if (!module || typeof module !== 'string') { | ||
throw new TypeError("A \"" + typeName + "\" property must exist when loading through an options object."); | ||
} | ||
return this.importModule(module, options); | ||
}; | ||
ModuleLoader.prototype.loadModule = function (module) { | ||
if (module instanceof this.classReference) { | ||
return module; | ||
} | ||
else if (typeof module === 'string') { | ||
return this.importModule(module); | ||
} | ||
else if (isObject_1.default(module)) { | ||
return this.importModuleFromOptions(module); | ||
} | ||
throw new TypeError("Invalid " + this.typeName + ". Must be a class instance or a module that exports a class definition."); | ||
}; | ||
ModuleLoader.prototype.loadModules = function (modules) { | ||
var _this = this; | ||
if (modules === void 0) { modules = []; } | ||
return modules.map(function (module) { return _this.loadModule(module); }); | ||
}; | ||
return ModuleLoader; | ||
}()); | ||
exports.default = ModuleLoader; |
@@ -1,84 +0,50 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _Routine2 = require('./Routine'); | ||
var _Routine3 = _interopRequireDefault(_Routine2); | ||
var _Tool = require('./Tool'); | ||
var _Tool2 = _interopRequireDefault(_Tool); | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Pipeline = function (_Routine) { | ||
(0, _inherits3.default)(Pipeline, _Routine); | ||
function Pipeline(tool) { | ||
(0, _classCallCheck3.default)(this, Pipeline); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (Pipeline.__proto__ || Object.getPrototypeOf(Pipeline)).call(this, 'root', 'Pipeline', tool ? tool.config : (0, _extends3.default)({}, _constants.DEFAULT_TOOL_CONFIG))); | ||
if (tool instanceof _Tool2.default) { | ||
tool.initialize(); | ||
} else { | ||
throw new TypeError('A build `Tool` instance is required to operate the pipeline.'); | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Routine_1 = __importDefault(require("./Routine")); | ||
var Tool_1 = __importDefault(require("./Tool")); | ||
var Pipeline = (function (_super) { | ||
__extends(Pipeline, _super); | ||
function Pipeline(tool) { | ||
var _this = _super.call(this, 'root', 'Pipeline') || this; | ||
if (tool instanceof Tool_1.default) { | ||
tool.initialize(); | ||
} | ||
else { | ||
throw new TypeError('A build `Tool` instance is required to operate the pipeline.'); | ||
} | ||
_this.tool = tool; | ||
_this.tool.debug('Instantiating pipeline'); | ||
return _this; | ||
} | ||
_this.tool = tool; | ||
_this.tool.debug('Instantiating pipeline'); | ||
return _this; | ||
} | ||
(0, _createClass3.default)(Pipeline, [{ | ||
key: 'run', | ||
value: function run(initialValue, context) { | ||
var cli = this.tool.console; | ||
this.tool.debug('Running pipeline'); | ||
this.context = context; | ||
cli.start(this.subroutines); | ||
return this.serializeSubroutines(initialValue).then(function (result) { | ||
cli.exit(null, 0); | ||
}).catch(function (error) { | ||
cli.exit(error, 1); | ||
}); | ||
} | ||
}]); | ||
return Pipeline; | ||
}(_Routine3.default); /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
exports.default = Pipeline; | ||
Pipeline.prototype.run = function (context, initialValue) { | ||
if (initialValue === void 0) { initialValue = null; } | ||
var cli = this.tool.console; | ||
this.tool.debug('Running pipeline'); | ||
this.context = context; | ||
cli.start(this.subroutines); | ||
return this.serializeSubroutines(initialValue) | ||
.then(function (result) { | ||
cli.exit(null, 0); | ||
return result; | ||
}) | ||
.catch(function (error) { | ||
cli.exit(error, 1); | ||
return error; | ||
}); | ||
}; | ||
return Pipeline; | ||
}(Routine_1.default)); | ||
exports.default = Pipeline; |
@@ -1,59 +0,28 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _Module2 = require('./Module'); | ||
var _Module3 = _interopRequireDefault(_Module2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var DEFAULT_PLUGIN_PRIORITY = 100; /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var Plugin = function (_Module) { | ||
(0, _inherits3.default)(Plugin, _Module); | ||
function Plugin() { | ||
var _ref; | ||
var _temp, _this, _ret; | ||
(0, _classCallCheck3.default)(this, Plugin); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var Module_1 = __importDefault(require("./Module")); | ||
exports.DEFAULT_PLUGIN_PRIORITY = 100; | ||
var Plugin = (function (_super) { | ||
__extends(Plugin, _super); | ||
function Plugin() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.priority = exports.DEFAULT_PLUGIN_PRIORITY; | ||
return _this; | ||
} | ||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Plugin.__proto__ || Object.getPrototypeOf(Plugin)).call.apply(_ref, [this].concat(args))), _this), _this.priority = DEFAULT_PLUGIN_PRIORITY, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret); | ||
} | ||
(0, _createClass3.default)(Plugin, [{ | ||
key: 'bootstrap', | ||
value: function bootstrap() {} | ||
}]); | ||
return Plugin; | ||
}(_Module3.default); | ||
exports.default = Plugin; | ||
Plugin.prototype.bootstrap = function () { }; | ||
return Plugin; | ||
}(Module_1.default)); | ||
exports.default = Plugin; |
@@ -1,273 +0,168 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.CURSOR = exports.REFRESH_RATE = undefined; | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _figures = require('figures'); | ||
var _figures2 = _interopRequireDefault(_figures); | ||
var _logUpdate = require('log-update'); | ||
var _logUpdate2 = _interopRequireDefault(_logUpdate); | ||
var _Module2 = require('./Module'); | ||
var _Module3 = _interopRequireDefault(_Module2); | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var REFRESH_RATE = exports.REFRESH_RATE = 100; /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var CURSOR = exports.CURSOR = '\x1B[?25h'; | ||
var Reporter = function (_Module) { | ||
(0, _inherits3.default)(Reporter, _Module); | ||
function Reporter() { | ||
var _ref; | ||
var _temp, _this, _ret; | ||
(0, _classCallCheck3.default)(this, Reporter); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chalk_1 = __importDefault(require("chalk")); | ||
var figures_1 = __importDefault(require("figures")); | ||
var log_update_1 = __importDefault(require("log-update")); | ||
var Module_1 = __importDefault(require("./Module")); | ||
var constants_1 = require("./constants"); | ||
exports.REFRESH_RATE = 100; | ||
exports.CURSOR = '\x1B[?25h'; | ||
var Reporter = (function (_super) { | ||
__extends(Reporter, _super); | ||
function Reporter() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.loader = null; | ||
return _this; | ||
} | ||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = Reporter.__proto__ || Object.getPrototypeOf(Reporter)).call.apply(_ref, [this].concat(args))), _this), _this.loader = null, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret); | ||
} | ||
(0, _createClass3.default)(Reporter, [{ | ||
key: 'indent', | ||
value: function indent(length) { | ||
return ' '.repeat(length); | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
var _this2 = this; | ||
var code = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
if (!this.loader) { | ||
return CURSOR; | ||
} | ||
var _loader = this.loader(), | ||
_loader$debug = _loader.debug, | ||
debug = _loader$debug === undefined ? false : _loader$debug, | ||
_loader$debugs = _loader.debugs, | ||
debugs = _loader$debugs === undefined ? [] : _loader$debugs, | ||
_loader$errors = _loader.errors, | ||
errors = _loader$errors === undefined ? [] : _loader$errors, | ||
_loader$footer = _loader.footer, | ||
footer = _loader$footer === undefined ? '' : _loader$footer, | ||
_loader$header = _loader.header, | ||
header = _loader$header === undefined ? '' : _loader$header, | ||
_loader$logs = _loader.logs, | ||
logs = _loader$logs === undefined ? [] : _loader$logs, | ||
_loader$silent = _loader.silent, | ||
silent = _loader$silent === undefined ? false : _loader$silent, | ||
_loader$tasks = _loader.tasks, | ||
tasks = _loader$tasks === undefined ? [] : _loader$tasks; | ||
var output = []; | ||
var verbose = !silent; | ||
if (header && verbose) { | ||
output.push(header); | ||
} | ||
if (tasks.length > 0 && verbose) { | ||
tasks.forEach(function (task) { | ||
output.push.apply(output, (0, _toConsumableArray3.default)(_this2.renderTask(task, 0))); | ||
}); | ||
} | ||
if (debugs.length > 0 && debug) { | ||
output.push(''); | ||
debugs.forEach(function (log) { | ||
output.push(_this2.renderMessage(log)); | ||
}); | ||
} | ||
var messages = code === 0 ? logs : errors; | ||
if (messages.length > 0) { | ||
if (messages[0] !== '') { | ||
output.push(''); | ||
Reporter.prototype.indent = function (length) { | ||
return ' '.repeat(length); | ||
}; | ||
Reporter.prototype.render = function (code) { | ||
var _this = this; | ||
if (code === void 0) { code = 0; } | ||
if (!this.loader) { | ||
return exports.CURSOR; | ||
} | ||
messages.forEach(function (log) { | ||
output.push(_this2.renderMessage(log)); | ||
}); | ||
if (messages[messages.length - 1] !== '') { | ||
output.push(''); | ||
var _a = this.loader(), _b = _a.errors, errors = _b === void 0 ? [] : _b, _c = _a.footer, footer = _c === void 0 ? '' : _c, _d = _a.header, header = _d === void 0 ? '' : _d, _e = _a.logs, logs = _e === void 0 ? [] : _e, _f = _a.silent, silent = _f === void 0 ? false : _f, _g = _a.tasks, tasks = _g === void 0 ? [] : _g; | ||
var output = []; | ||
var verbose = !silent; | ||
if (header && verbose) { | ||
output.push(header); | ||
} | ||
} | ||
if (footer && verbose) { | ||
output.push(footer); | ||
} | ||
output.push(CURSOR); | ||
return output.join('\n').trim(); | ||
} | ||
}, { | ||
key: 'renderMessage', | ||
value: function renderMessage(message) { | ||
return message; | ||
} | ||
}, { | ||
key: 'renderTask', | ||
value: function renderTask(task) { | ||
var _this3 = this; | ||
var level = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
var suffix = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : ''; | ||
var output = []; | ||
var message = '' + this.indent(level) + this.renderStatus(task) + ' ' + task.title; | ||
if (task.isSkipped()) { | ||
message += ' ' + _chalk2.default.yellow('[skipped]'); | ||
} else if (task.hasFailed()) { | ||
message += ' ' + _chalk2.default.red('[failed]'); | ||
} else if (suffix) { | ||
message += ' ' + suffix; | ||
} | ||
output.push(message); | ||
if (task.subtasks.length > 0) { | ||
var pendingTask = void 0; | ||
var runningTask = void 0; | ||
var failedTask = void 0; | ||
var passed = 0; | ||
task.subtasks.forEach(function (subTask) { | ||
if (subTask.isPending() && !pendingTask) { | ||
pendingTask = subTask; | ||
} else if (subTask.isRunning() && !runningTask) { | ||
runningTask = subTask; | ||
} else if (subTask.hasFailed() && !failedTask) { | ||
failedTask = subTask; | ||
} else if (subTask.hasPassed() || subTask.isSkipped()) { | ||
passed += 1; | ||
} | ||
}); | ||
var activeTask = failedTask || runningTask || pendingTask; | ||
var taskSuffix = _chalk2.default.gray('[' + passed + '/' + task.subtasks.length + ']'); | ||
if (activeTask && (task.isRunning() || failedTask)) { | ||
output.push.apply(output, (0, _toConsumableArray3.default)(this.renderTask(activeTask, level + 1, taskSuffix))); | ||
if (tasks.length > 0 && verbose) { | ||
tasks.forEach(function (task) { | ||
output.push.apply(output, _this.renderTask(task, 0)); | ||
}); | ||
} | ||
} | ||
if (task.statusText) { | ||
output.push('' + this.indent(level + 2) + _chalk2.default.gray(task.statusText)); | ||
} | ||
if (task.subroutines.length > 0) { | ||
task.subroutines.forEach(function (routine) { | ||
output.push.apply(output, (0, _toConsumableArray3.default)(_this3.renderTask(routine, level + 1))); | ||
}); | ||
} | ||
return output; | ||
} | ||
}, { | ||
key: 'renderStatus', | ||
value: function renderStatus(task) { | ||
switch (task.status) { | ||
case _constants.STATUS_PENDING: | ||
return _chalk2.default.gray(_figures2.default.bullet); | ||
case _constants.STATUS_RUNNING: | ||
return _chalk2.default.gray(task.spinner()); | ||
case _constants.STATUS_SKIPPED: | ||
return _chalk2.default.yellow(_figures2.default.circleDotted); | ||
case _constants.STATUS_PASSED: | ||
return _chalk2.default.green(_figures2.default.tick); | ||
case _constants.STATUS_FAILED: | ||
return _chalk2.default.red(_figures2.default.cross); | ||
default: | ||
return ''; | ||
} | ||
} | ||
}, { | ||
key: 'start', | ||
value: function start(loader) { | ||
var _this4 = this; | ||
if (this.instance) { | ||
clearInterval(this.instance); | ||
} | ||
if (!loader || typeof loader !== 'function') { | ||
throw new TypeError('A loader is required to render console output.'); | ||
} | ||
this.loader = loader; | ||
this.instance = setInterval(function () { | ||
_this4.update(); | ||
}, REFRESH_RATE); | ||
} | ||
}, { | ||
key: 'stop', | ||
value: function stop() { | ||
clearInterval(this.instance); | ||
_logUpdate2.default.clear(); | ||
} | ||
}, { | ||
key: 'update', | ||
value: function update() { | ||
var output = this.render(); | ||
if (output) { | ||
(0, _logUpdate2.default)(output); | ||
} | ||
} | ||
}]); | ||
return Reporter; | ||
}(_Module3.default); | ||
exports.default = Reporter; | ||
var messages = code === 0 ? logs : errors; | ||
if (messages.length > 0) { | ||
if (messages[0] !== '') { | ||
output.push(''); | ||
} | ||
messages.forEach(function (log) { | ||
output.push(_this.renderMessage(log)); | ||
}); | ||
if (messages[messages.length - 1] !== '') { | ||
output.push(''); | ||
} | ||
} | ||
if (footer && verbose) { | ||
output.push(footer); | ||
} | ||
output.push(exports.CURSOR); | ||
return output.join('\n').trim(); | ||
}; | ||
Reporter.prototype.renderMessage = function (message) { | ||
return message; | ||
}; | ||
Reporter.prototype.renderTask = function (task, level, suffix) { | ||
var _this = this; | ||
if (level === void 0) { level = 0; } | ||
if (suffix === void 0) { suffix = ''; } | ||
var output = []; | ||
var message = "" + this.indent(level) + this.renderStatus(task) + " " + task.title; | ||
if (task.isSkipped()) { | ||
message += " " + chalk_1.default.yellow('[skipped]'); | ||
} | ||
else if (task.hasFailed()) { | ||
message += " " + chalk_1.default.red('[failed]'); | ||
} | ||
else if (suffix) { | ||
message += " " + suffix; | ||
} | ||
output.push(message); | ||
if (task.subtasks.length > 0) { | ||
var pendingTask_1 = null; | ||
var runningTask_1 = null; | ||
var failedTask_1 = null; | ||
var passed_1 = 0; | ||
task.subtasks.forEach(function (subTask) { | ||
if (subTask.isPending() && !pendingTask_1) { | ||
pendingTask_1 = subTask; | ||
} | ||
else if (subTask.isRunning() && !runningTask_1) { | ||
runningTask_1 = subTask; | ||
} | ||
else if (subTask.hasFailed() && !failedTask_1) { | ||
failedTask_1 = subTask; | ||
} | ||
else if (subTask.hasPassed() || subTask.isSkipped()) { | ||
passed_1 += 1; | ||
} | ||
}); | ||
var activeTask = failedTask_1 || runningTask_1 || pendingTask_1; | ||
var taskSuffix = chalk_1.default.gray("[" + passed_1 + "/" + task.subtasks.length + "]"); | ||
if (activeTask && (task.isRunning() || failedTask_1)) { | ||
output.push.apply(output, this.renderTask(activeTask, level + 1, taskSuffix)); | ||
} | ||
} | ||
if (task.statusText) { | ||
output.push("" + this.indent(level + 2) + chalk_1.default.gray(task.statusText)); | ||
} | ||
if (task.subroutines.length > 0) { | ||
task.subroutines.forEach(function (routine) { | ||
output.push.apply(output, _this.renderTask(routine, level + 1)); | ||
}); | ||
} | ||
return output; | ||
}; | ||
Reporter.prototype.renderStatus = function (task) { | ||
switch (task.status) { | ||
case constants_1.STATUS_PENDING: | ||
return chalk_1.default.gray(figures_1.default.bullet); | ||
case constants_1.STATUS_RUNNING: | ||
return chalk_1.default.gray(task.spinner()); | ||
case constants_1.STATUS_SKIPPED: | ||
return chalk_1.default.yellow(figures_1.default.circleDotted); | ||
case constants_1.STATUS_PASSED: | ||
return chalk_1.default.green(figures_1.default.tick); | ||
case constants_1.STATUS_FAILED: | ||
return chalk_1.default.red(figures_1.default.cross); | ||
default: | ||
return ''; | ||
} | ||
}; | ||
Reporter.prototype.start = function (loader) { | ||
var _this = this; | ||
if (this.instance) { | ||
clearInterval(this.instance); | ||
} | ||
if (!loader || typeof loader !== 'function') { | ||
throw new TypeError('A loader is required to render console output.'); | ||
} | ||
this.loader = loader; | ||
this.instance = setInterval(function () { | ||
_this.update(); | ||
}, exports.REFRESH_RATE); | ||
return this; | ||
}; | ||
Reporter.prototype.stop = function () { | ||
if (this.instance) { | ||
clearInterval(this.instance); | ||
} | ||
log_update_1.default.clear(); | ||
return this; | ||
}; | ||
Reporter.prototype.update = function () { | ||
var output = this.render(); | ||
if (output) { | ||
log_update_1.default(output); | ||
} | ||
return this; | ||
}; | ||
return Reporter; | ||
}(Module_1.default)); | ||
exports.default = Reporter; |
@@ -1,225 +0,139 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _get2 = require('babel-runtime/helpers/get'); | ||
var _get3 = _interopRequireDefault(_get2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _execa = require('execa'); | ||
var _execa2 = _interopRequireDefault(_execa); | ||
var _split = require('split'); | ||
var _split2 = _interopRequireDefault(_split); | ||
var _ExitError = require('./ExitError'); | ||
var _ExitError2 = _interopRequireDefault(_ExitError); | ||
var _Task2 = require('./Task'); | ||
var _Task3 = _interopRequireDefault(_Task2); | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var Routine = function (_Task) { | ||
(0, _inherits3.default)(Routine, _Task); | ||
function Routine(key, title, defaultConfig) { | ||
(0, _classCallCheck3.default)(this, Routine); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (Routine.__proto__ || Object.getPrototypeOf(Routine)).call(this, title, null, defaultConfig)); | ||
_this.exit = false; | ||
_this.key = ''; | ||
_this.executeTask = function (value, task) { | ||
return _this.wrap(task.run(value, _this.context)); | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
if (!key || typeof key !== 'string') { | ||
throw new Error('Routine key must be a valid unique string.'); | ||
})(); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chalk_1 = __importDefault(require("chalk")); | ||
var execa_1 = __importDefault(require("execa")); | ||
var split_1 = __importDefault(require("split")); | ||
var ExitError_1 = __importDefault(require("./ExitError")); | ||
var Task_1 = __importDefault(require("./Task")); | ||
var constants_1 = require("./constants"); | ||
var Routine = (function (_super) { | ||
__extends(Routine, _super); | ||
function Routine(key, title, options) { | ||
if (options === void 0) { options = {}; } | ||
var _this = _super.call(this, title, null, options) || this; | ||
_this.exit = false; | ||
_this.key = ''; | ||
if (!key || typeof key !== 'string') { | ||
throw new Error('Routine key must be a valid unique string.'); | ||
} | ||
_this.key = key; | ||
_this.action = _this.execute.bind(_this); | ||
_this.status = constants_1.STATUS_PENDING; | ||
return _this; | ||
} | ||
_this.key = key; | ||
_this.action = _this.execute.bind(_this); | ||
_this.status = _constants.STATUS_PENDING; | ||
return _this; | ||
} | ||
(0, _createClass3.default)(Routine, [{ | ||
key: 'bootstrap', | ||
value: function bootstrap() {} | ||
}, { | ||
key: 'configure', | ||
value: function configure(parent) { | ||
var _this2 = this; | ||
this.context = parent.context; | ||
this.tool = parent.tool; | ||
this.tool.on('exit', function () { | ||
_this2.exit = true; | ||
}); | ||
this.bootstrap(); | ||
this.tool.debug('Bootstrapping routine ' + _chalk2.default.green(this.key)); | ||
return this; | ||
} | ||
}, { | ||
key: 'execute', | ||
value: function execute(value, context) { | ||
return value; | ||
} | ||
}, { | ||
key: 'executeCommand', | ||
value: function executeCommand(command, args) { | ||
var _this3 = this; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null; | ||
var stream = options.sync ? _execa2.default.sync(command, args, options) : (0, _execa2.default)(command, args, options); | ||
if (!options.sync) { | ||
stream.stdout.pipe((0, _split2.default)()).on('data', function (line) { | ||
if (_this3.status === _constants.STATUS_RUNNING) { | ||
_this3.statusText = line; | ||
} | ||
Routine.prototype.bootstrap = function () { }; | ||
Routine.prototype.configure = function (parent) { | ||
var _this = this; | ||
this.context = parent.context; | ||
this.tool = parent.tool; | ||
this.tool.on('exit', function () { | ||
_this.exit = true; | ||
}); | ||
} | ||
if (typeof callback === 'function') { | ||
callback(stream); | ||
} | ||
return this.wrap(stream); | ||
} | ||
}, { | ||
key: 'parallelizeSubroutines', | ||
value: function parallelizeSubroutines(value) { | ||
var _this4 = this; | ||
return Promise.all(this.subroutines.map(function (routine) { | ||
return _this4.executeTask(value, routine); | ||
})); | ||
} | ||
}, { | ||
key: 'parallelizeTasks', | ||
value: function parallelizeTasks(value) { | ||
var _this5 = this; | ||
return Promise.all(this.subtasks.map(function (task) { | ||
return _this5.executeTask(value, task); | ||
})); | ||
} | ||
}, { | ||
key: 'pipe', | ||
value: function pipe(routine) { | ||
if (routine instanceof Routine) { | ||
this.subroutines.push(routine.configure(this)); | ||
} else { | ||
throw new TypeError('Routines must be an instance of `Routine`.'); | ||
} | ||
return this; | ||
} | ||
}, { | ||
key: 'run', | ||
value: function run(value, context) { | ||
var cli = this.tool.console; | ||
if (this.exit) { | ||
return Promise.reject(new _ExitError2.default('Process has been interrupted.')); | ||
} | ||
this.tool.debug('Executing routine ' + _chalk2.default.green(this.key)); | ||
cli.startDebugGroup(this.key); | ||
return (0, _get3.default)(Routine.prototype.__proto__ || Object.getPrototypeOf(Routine.prototype), 'run', this).call(this, value, context).then(function (result) { | ||
cli.stopDebugGroup(); | ||
cli.update(); | ||
return result; | ||
}).catch(function (error) { | ||
cli.stopDebugGroup(); | ||
cli.update(); | ||
throw error; | ||
}); | ||
} | ||
}, { | ||
key: 'serialize', | ||
value: function serialize(initialValue, items, accumulator) { | ||
return items.reduce(function (promise, item) { | ||
return promise.then(function (value) { | ||
return accumulator(value, item); | ||
this.debug = this.tool.createDebugger('routine', this.key); | ||
this.debug('Bootstrapping routine %s', chalk_1.default.green(this.key)); | ||
this.bootstrap(); | ||
return this; | ||
}; | ||
Routine.prototype.execute = function (context, value) { | ||
if (value === void 0) { value = null; } | ||
return this.wrap(value); | ||
}; | ||
Routine.prototype.executeCommand = function (command, args, options, callback) { | ||
var _this = this; | ||
if (options === void 0) { options = {}; } | ||
if (callback === void 0) { callback = null; } | ||
var stream = options.sync | ||
? execa_1.default.sync(command, args, options) | ||
: execa_1.default(command, args, options); | ||
if (!options.sync) { | ||
var out = stream.stdout; | ||
out.pipe(split_1.default()).on('data', function (line) { | ||
if (_this.status === constants_1.STATUS_RUNNING) { | ||
_this.statusText = line; | ||
} | ||
}); | ||
} | ||
if (typeof callback === 'function') { | ||
callback(stream); | ||
} | ||
return this.wrap(stream); | ||
}; | ||
Routine.prototype.executeTask = function (task, value) { | ||
if (value === void 0) { value = null; } | ||
return this.wrap(task.run(this.context, value)); | ||
}; | ||
Routine.prototype.parallelizeSubroutines = function (value) { | ||
var _this = this; | ||
if (value === void 0) { value = null; } | ||
return Promise.all(this.subroutines.map(function (routine) { return _this.executeTask(routine, value); })); | ||
}; | ||
Routine.prototype.parallelizeTasks = function (value) { | ||
var _this = this; | ||
if (value === void 0) { value = null; } | ||
return Promise.all(this.subtasks.map(function (task) { return _this.executeTask(task, value); })); | ||
}; | ||
Routine.prototype.pipe = function (routine) { | ||
if (routine instanceof Routine) { | ||
this.subroutines.push(routine.configure(this)); | ||
} | ||
else { | ||
throw new TypeError('Routines must be an instance of `Routine`.'); | ||
} | ||
return this; | ||
}; | ||
Routine.prototype.run = function (context, value) { | ||
var _this = this; | ||
if (value === void 0) { value = null; } | ||
if (this.exit) { | ||
return Promise.reject(new ExitError_1.default('Process has been interrupted.')); | ||
} | ||
this.debug('Executing routine %s', chalk_1.default.green(this.key)); | ||
return _super.prototype.run.call(this, context, value) | ||
.then(function (result) { | ||
_this.tool.console.update(); | ||
return result; | ||
}) | ||
.catch(function (error) { | ||
_this.tool.console.update(); | ||
throw error; | ||
}); | ||
}, Promise.resolve(initialValue)); | ||
} | ||
}, { | ||
key: 'serializeSubroutines', | ||
value: function serializeSubroutines(value) { | ||
return this.serialize(value, this.subroutines, this.executeTask); | ||
} | ||
}, { | ||
key: 'serializeTasks', | ||
value: function serializeTasks(value) { | ||
return this.serialize(value, this.subtasks, this.executeTask); | ||
} | ||
}, { | ||
key: 'task', | ||
value: function task(title, action, config) { | ||
if (typeof action !== 'function') { | ||
throw new TypeError('Tasks require an executable function.'); | ||
} | ||
var task = new _Task3.default(title, action.bind(this), config); | ||
this.subtasks.push(task); | ||
return task; | ||
} | ||
}]); | ||
return Routine; | ||
}(_Task3.default); | ||
exports.default = Routine; | ||
}; | ||
Routine.prototype.serialize = function (tasks, initialValue, accumulator) { | ||
if (initialValue === void 0) { initialValue = null; } | ||
return tasks.reduce(function (promise, task) { return promise.then(function (value) { return accumulator(task, value); }); }, Promise.resolve(initialValue)); | ||
}; | ||
Routine.prototype.serializeSubroutines = function (value) { | ||
var _this = this; | ||
if (value === void 0) { value = null; } | ||
return this.serialize(this.subroutines, value, function (task, val) { return _this.executeTask(task, val); }); | ||
}; | ||
Routine.prototype.serializeTasks = function (value) { | ||
var _this = this; | ||
if (value === void 0) { value = null; } | ||
return this.serialize(this.subtasks, value, function (task, val) { return _this.executeTask(task, val); }); | ||
}; | ||
Routine.prototype.task = function (title, action, options) { | ||
if (options === void 0) { options = {}; } | ||
if (typeof action !== 'function') { | ||
throw new TypeError('Tasks require an executable function.'); | ||
} | ||
var task = new Task_1.default(title, action.bind(this), options); | ||
this.subtasks.push(task); | ||
return task; | ||
}; | ||
return Routine; | ||
}(Task_1.default)); | ||
exports.default = Routine; |
220
lib/Task.js
@@ -1,138 +0,86 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _elegantSpinner = require('elegant-spinner'); | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
var Task = function () { | ||
function Task(title) { | ||
var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; | ||
var defaultConfig = arguments[2]; | ||
(0, _classCallCheck3.default)(this, Task); | ||
this.action = null; | ||
this.frame = 0; | ||
this.title = ''; | ||
this.status = _constants.STATUS_PENDING; | ||
this.statusText = ''; | ||
this.subroutines = []; | ||
this.subtasks = []; | ||
if (!title || typeof title !== 'string') { | ||
throw new Error('Tasks require a title.'); | ||
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
if (action !== null && typeof action !== 'function') { | ||
throw new Error('Tasks require an executable function.'); | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var elegant_spinner_1 = require("elegant-spinner"); | ||
var constants_1 = require("./constants"); | ||
var Task = (function () { | ||
function Task(title, action, options) { | ||
if (action === void 0) { action = null; } | ||
if (options === void 0) { options = {}; } | ||
this.action = null; | ||
this.frame = 0; | ||
this.title = ''; | ||
this.status = constants_1.STATUS_PENDING; | ||
this.statusText = ''; | ||
this.subroutines = []; | ||
this.subtasks = []; | ||
if (!title || typeof title !== 'string') { | ||
throw new Error('Tasks require a title.'); | ||
} | ||
if (action !== null && typeof action !== 'function') { | ||
throw new Error('Tasks require an executable function.'); | ||
} | ||
this.action = action; | ||
this.options = __assign({}, options); | ||
this.status = action ? constants_1.STATUS_PENDING : constants_1.STATUS_SKIPPED; | ||
this.title = title; | ||
} | ||
this.action = action; | ||
this.config = (0, _extends3.default)({}, defaultConfig); | ||
this.status = action ? _constants.STATUS_PENDING : _constants.STATUS_SKIPPED; | ||
this.title = title; | ||
} | ||
(0, _createClass3.default)(Task, [{ | ||
key: 'hasFailed', | ||
value: function hasFailed() { | ||
return this.status === _constants.STATUS_FAILED; | ||
} | ||
}, { | ||
key: 'hasPassed', | ||
value: function hasPassed() { | ||
return this.status === _constants.STATUS_PASSED; | ||
} | ||
}, { | ||
key: 'isPending', | ||
value: function isPending() { | ||
return this.status === _constants.STATUS_PENDING; | ||
} | ||
}, { | ||
key: 'isRunning', | ||
value: function isRunning() { | ||
return this.status === _constants.STATUS_RUNNING; | ||
} | ||
}, { | ||
key: 'isSkipped', | ||
value: function isSkipped() { | ||
return this.status === _constants.STATUS_SKIPPED; | ||
} | ||
}, { | ||
key: 'run', | ||
value: function run(initialValue, context) { | ||
var _this = this; | ||
this.context = context; | ||
if (this.isSkipped() || !this.action) { | ||
this.status = _constants.STATUS_SKIPPED; | ||
return Promise.resolve(initialValue); | ||
} | ||
this.status = _constants.STATUS_RUNNING; | ||
return Promise.resolve(initialValue).then(function (value) { | ||
return _this.action(value, context); | ||
}).then(function (result) { | ||
_this.status = _constants.STATUS_PASSED; | ||
_this.statusText = ''; | ||
return result; | ||
}, function (error) { | ||
_this.status = _constants.STATUS_FAILED; | ||
throw error; | ||
}); | ||
} | ||
}, { | ||
key: 'skip', | ||
value: function skip() { | ||
var condition = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true; | ||
if (condition) { | ||
this.status = _constants.STATUS_SKIPPED; | ||
} | ||
return this; | ||
} | ||
}, { | ||
key: 'spinner', | ||
value: function spinner() { | ||
this.frame = ++this.frame % _elegantSpinner.frames.length; | ||
return _elegantSpinner.frames[this.frame]; | ||
} | ||
}, { | ||
key: 'wrap', | ||
value: function wrap(value) { | ||
return value instanceof Promise ? value : Promise.resolve(value); | ||
} | ||
}]); | ||
return Task; | ||
}(); | ||
exports.default = Task; | ||
Task.prototype.hasFailed = function () { | ||
return this.status === constants_1.STATUS_FAILED; | ||
}; | ||
Task.prototype.hasPassed = function () { | ||
return this.status === constants_1.STATUS_PASSED; | ||
}; | ||
Task.prototype.isPending = function () { | ||
return this.status === constants_1.STATUS_PENDING; | ||
}; | ||
Task.prototype.isRunning = function () { | ||
return this.status === constants_1.STATUS_RUNNING; | ||
}; | ||
Task.prototype.isSkipped = function () { | ||
return this.status === constants_1.STATUS_SKIPPED; | ||
}; | ||
Task.prototype.run = function (context, initialValue) { | ||
var _this = this; | ||
if (initialValue === void 0) { initialValue = null; } | ||
this.context = context; | ||
if (this.isSkipped() || !this.action) { | ||
this.status = constants_1.STATUS_SKIPPED; | ||
return Promise.resolve(initialValue); | ||
} | ||
this.status = constants_1.STATUS_RUNNING; | ||
return (Promise.resolve(initialValue) | ||
.then(function (value) { return _this.action(context, value); }) | ||
.then(function (result) { | ||
_this.status = constants_1.STATUS_PASSED; | ||
_this.statusText = ''; | ||
return result; | ||
}, function (error) { | ||
_this.status = constants_1.STATUS_FAILED; | ||
throw error; | ||
})); | ||
}; | ||
Task.prototype.skip = function (condition) { | ||
if (condition === void 0) { condition = true; } | ||
if (condition) { | ||
this.status = constants_1.STATUS_SKIPPED; | ||
} | ||
return this; | ||
}; | ||
Task.prototype.spinner = function () { | ||
this.frame = ++this.frame % elegant_spinner_1.frames.length; | ||
return elegant_spinner_1.frames[this.frame]; | ||
}; | ||
Task.prototype.wrap = function (value) { | ||
return value instanceof Promise ? value : Promise.resolve(value); | ||
}; | ||
return Task; | ||
}()); | ||
exports.default = Task; |
475
lib/Tool.js
@@ -1,290 +0,199 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _extends3 = _interopRequireDefault(_extends2); | ||
var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties'); | ||
var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _chalk = require('chalk'); | ||
var _chalk2 = _interopRequireDefault(_chalk); | ||
var _pluralize = require('pluralize'); | ||
var _pluralize2 = _interopRequireDefault(_pluralize); | ||
var _optimal = require('optimal'); | ||
var _optimal2 = _interopRequireDefault(_optimal); | ||
var _ConfigLoader = require('./ConfigLoader'); | ||
var _ConfigLoader2 = _interopRequireDefault(_ConfigLoader); | ||
var _Console = require('./Console'); | ||
var _Console2 = _interopRequireDefault(_Console); | ||
var _Emitter2 = require('./Emitter'); | ||
var _Emitter3 = _interopRequireDefault(_Emitter2); | ||
var _ModuleLoader = require('./ModuleLoader'); | ||
var _ModuleLoader2 = _interopRequireDefault(_ModuleLoader); | ||
var _Plugin = require('./Plugin'); | ||
var _Plugin2 = _interopRequireDefault(_Plugin); | ||
var _Reporter = require('./Reporter'); | ||
var _Reporter2 = _interopRequireDefault(_Reporter); | ||
var _isEmptyObject = require('./helpers/isEmptyObject'); | ||
var _isEmptyObject2 = _interopRequireDefault(_isEmptyObject); | ||
var _constants = require('./constants'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Tool = function (_Emitter) { | ||
(0, _inherits3.default)(Tool, _Emitter); | ||
function Tool(_ref) { | ||
var argv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var footer = _ref.footer, | ||
header = _ref.header, | ||
options = (0, _objectWithoutProperties3.default)(_ref, ['footer', 'header']); | ||
(0, _classCallCheck3.default)(this, Tool); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (Tool.__proto__ || Object.getPrototypeOf(Tool)).call(this)); | ||
_this.config = (0, _extends3.default)({}, _constants.DEFAULT_TOOL_CONFIG); | ||
_this.initialized = false; | ||
_this.plugins = []; | ||
_this.argv = argv; | ||
_this.options = new _optimal2.default(options, { | ||
appName: (0, _optimal.string)().required(), | ||
configBlueprint: (0, _optimal.object)(), | ||
configFolder: (0, _optimal.string)('./configs'), | ||
extendArgv: (0, _optimal.bool)(true), | ||
pluginAlias: (0, _optimal.string)('plugin'), | ||
root: (0, _optimal.string)(process.cwd()), | ||
scoped: (0, _optimal.bool)() | ||
}, { | ||
name: 'Tool' | ||
}); | ||
_this.console = new _Console2.default(new _Reporter2.default(), { | ||
footer: footer, | ||
header: header | ||
}); | ||
if (process.env.NODE_ENV === 'test') { | ||
return (0, _possibleConstructorReturn3.default)(_this); | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
process.on('exit', function (code) { | ||
_this.emit('exit', [code]); | ||
}); | ||
return _this; | ||
} | ||
(0, _createClass3.default)(Tool, [{ | ||
key: 'debug', | ||
value: function debug(message) { | ||
this.console.debug(message); | ||
return this; | ||
return t; | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0) | ||
t[p[i]] = s[p[i]]; | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var chalk_1 = __importDefault(require("chalk")); | ||
var debug_1 = __importDefault(require("debug")); | ||
var pluralize_1 = __importDefault(require("pluralize")); | ||
var optimal_1 = __importDefault(require("optimal")); | ||
var ConfigLoader_1 = __importDefault(require("./ConfigLoader")); | ||
var Console_1 = __importDefault(require("./Console")); | ||
var Emitter_1 = __importDefault(require("./Emitter")); | ||
var ModuleLoader_1 = __importDefault(require("./ModuleLoader")); | ||
var Plugin_1 = __importDefault(require("./Plugin")); | ||
var Reporter_1 = __importDefault(require("./Reporter")); | ||
var enableDebug_1 = __importDefault(require("./helpers/enableDebug")); | ||
var isEmptyObject_1 = __importDefault(require("./helpers/isEmptyObject")); | ||
var constants_1 = require("./constants"); | ||
var Tool = (function (_super) { | ||
__extends(Tool, _super); | ||
function Tool(_a, argv) { | ||
if (argv === void 0) { argv = []; } | ||
var footer = _a.footer, header = _a.header, options = __rest(_a, ["footer", "header"]); | ||
var _this = _super.call(this) || this; | ||
_this.argv = []; | ||
_this.config = __assign({}, constants_1.DEFAULT_TOOL_CONFIG); | ||
_this.initialized = false; | ||
_this.package = { name: '' }; | ||
_this.plugins = []; | ||
_this.argv = argv; | ||
_this.options = optimal_1.default(options, { | ||
appName: optimal_1.string().required(), | ||
configBlueprint: optimal_1.object(), | ||
configFolder: optimal_1.string('./configs'), | ||
extendArgv: optimal_1.bool(true), | ||
pluginAlias: optimal_1.string('plugin'), | ||
root: optimal_1.string(process.cwd()), | ||
scoped: optimal_1.bool(), | ||
}, { | ||
name: 'Tool', | ||
}); | ||
if (argv.includes('--debug')) { | ||
enableDebug_1.default(_this.options.appName); | ||
} | ||
_this.debug = _this.createDebugger('core'); | ||
_this.console = new Console_1.default(new Reporter_1.default(), { | ||
footer: footer, | ||
header: header, | ||
}); | ||
if (process.env.NODE_ENV === 'test') { | ||
return _this; | ||
} | ||
process.on('exit', function (code) { | ||
_this.emit('exit', [code]); | ||
}); | ||
return _this; | ||
} | ||
}, { | ||
key: 'exit', | ||
value: function exit(message) { | ||
var code = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
this.console.exit(message, code); | ||
return this; | ||
} | ||
}, { | ||
key: 'getPlugin', | ||
value: function getPlugin(name) { | ||
var plugin = this.plugins.find(function (p) { | ||
return p.name === name; | ||
}); | ||
if (!plugin) { | ||
throw new Error('Failed to find ' + this.options.pluginAlias + ' "' + name + '". Have you installed it?'); | ||
} | ||
return plugin; | ||
} | ||
}, { | ||
key: 'initialize', | ||
value: function initialize() { | ||
if (this.initialized) { | ||
Tool.prototype.createDebugger = function () { | ||
var namespaces = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
namespaces[_i] = arguments[_i]; | ||
} | ||
return debug_1.default(this.options.appName + ":" + namespaces.join(':')); | ||
}; | ||
Tool.prototype.exit = function (message, code) { | ||
if (code === void 0) { code = 1; } | ||
this.console.exit(message, code); | ||
return this; | ||
} | ||
var appName = this.options.appName; | ||
this.debug('Initializing ' + _chalk2.default.green(appName)); | ||
this.console.startDebugGroup(appName); | ||
this.loadConfig(); | ||
this.loadPlugins(); | ||
this.loadReporter(); | ||
this.console.stopDebugGroup(); | ||
this.initialized = true; | ||
return this; | ||
} | ||
}, { | ||
key: 'invariant', | ||
value: function invariant(condition, message, pass, fail) { | ||
this.debug(message + ': ' + (condition ? _chalk2.default.green(pass) : _chalk2.default.red(fail))); | ||
return this; | ||
} | ||
}, { | ||
key: 'loadConfig', | ||
value: function loadConfig() { | ||
var _this2 = this; | ||
if (this.initialized) { | ||
}; | ||
Tool.prototype.getPlugin = function (name) { | ||
var plugin = this.plugins.find(function (p) { return p.name === name; }); | ||
if (!plugin) { | ||
throw new Error("Failed to find " + this.options.pluginAlias + " \"" + name + "\". Have you installed it?"); | ||
} | ||
return plugin; | ||
}; | ||
Tool.prototype.initialize = function () { | ||
if (this.initialized) { | ||
return this; | ||
} | ||
var appName = this.options.appName; | ||
this.debug('Initializing %s', chalk_1.default.green(appName)); | ||
this.loadConfig(); | ||
this.loadPlugins(); | ||
this.loadReporter(); | ||
this.initialized = true; | ||
return this; | ||
} | ||
this.console.startDebugGroup('config'); | ||
this.configLoader = new _ConfigLoader2.default(this); | ||
this.package = this.configLoader.loadPackageJSON(); | ||
this.config = this.configLoader.loadConfig(); | ||
if (this.options.extendArgv) { | ||
this.argv.forEach(function (arg) { | ||
if (arg === '--debug' || arg === '--silent') { | ||
var name = arg.slice(2); | ||
_this2.config[name] = true; | ||
_this2.console.options[name] = true; | ||
} | ||
}; | ||
Tool.prototype.invariant = function (condition, message, pass, fail) { | ||
this.debug('%s: %s', message, condition ? chalk_1.default.green(pass) : chalk_1.default.red(fail)); | ||
return this; | ||
}; | ||
Tool.prototype.loadConfig = function () { | ||
var _this = this; | ||
if (this.initialized) { | ||
return this; | ||
} | ||
this.configLoader = new ConfigLoader_1.default(this); | ||
this.package = this.configLoader.loadPackageJSON(); | ||
this.config = this.configLoader.loadConfig(); | ||
if (this.options.extendArgv) { | ||
this.argv.forEach(function (arg) { | ||
if (arg === '--debug' || arg === '--silent') { | ||
var name = arg.slice(2); | ||
_this.config[name] = true; | ||
_this.console.options[name] = true; | ||
} | ||
}); | ||
} | ||
if (this.config.debug) { | ||
enableDebug_1.default(this.options.appName); | ||
} | ||
return this; | ||
}; | ||
Tool.prototype.loadPlugins = function () { | ||
var _this = this; | ||
if (this.initialized) { | ||
return this; | ||
} | ||
var pluginAlias = this.options.pluginAlias; | ||
var pluralPluginAlias = pluralize_1.default(pluginAlias); | ||
if (isEmptyObject_1.default(this.config)) { | ||
throw new Error("Cannot load " + pluralPluginAlias + " as configuration has not been loaded."); | ||
} | ||
var loader = new ModuleLoader_1.default(this, pluginAlias, Plugin_1.default); | ||
this.pluginLoader = loader; | ||
this.plugins = this.pluginLoader.loadModules(this.config[pluralPluginAlias]); | ||
this.plugins.sort(function (a, b) { return a.priority - b.priority; }); | ||
this.plugins.forEach(function (plugin) { | ||
plugin.tool = _this; | ||
plugin.bootstrap(); | ||
}); | ||
} | ||
this.console.stopDebugGroup(); | ||
return this; | ||
} | ||
}, { | ||
key: 'loadPlugins', | ||
value: function loadPlugins() { | ||
var _this3 = this; | ||
if (this.initialized) { | ||
return this; | ||
} | ||
var pluginAlias = this.options.pluginAlias; | ||
var pluralPluginAlias = (0, _pluralize2.default)(pluginAlias); | ||
if ((0, _isEmptyObject2.default)(this.config)) { | ||
throw new Error('Cannot load ' + pluralPluginAlias + ' as configuration has not been loaded.'); | ||
} | ||
this.console.startDebugGroup('plugin'); | ||
this.pluginLoader = new _ModuleLoader2.default(this, pluginAlias, _Plugin2.default); | ||
this.plugins = this.pluginLoader.loadModules(this.config[pluralPluginAlias]); | ||
this.plugins.sort(function (a, b) { | ||
return a.priority - b.priority; | ||
}); | ||
this.plugins.forEach(function (plugin) { | ||
plugin.tool = _this3; | ||
plugin.bootstrap(); | ||
}); | ||
this.console.stopDebugGroup(); | ||
return this; | ||
} | ||
}, { | ||
key: 'loadReporter', | ||
value: function loadReporter() { | ||
if (this.initialized) { | ||
}; | ||
Tool.prototype.loadReporter = function () { | ||
if (this.initialized) { | ||
return this; | ||
} | ||
if (isEmptyObject_1.default(this.config)) { | ||
throw new Error('Cannot load reporter as configuration has not been loaded.'); | ||
} | ||
var reporter = this.config.reporter; | ||
if (reporter) { | ||
var loader = new ModuleLoader_1.default(this, 'reporter', Reporter_1.default); | ||
this.console.reporter = loader.loadModule(reporter); | ||
} | ||
else { | ||
this.debug("Using native " + chalk_1.default.green('boost') + " reporter"); | ||
} | ||
return this; | ||
} | ||
if ((0, _isEmptyObject2.default)(this.config)) { | ||
throw new Error('Cannot load reporter as configuration has not been loaded.'); | ||
} | ||
this.console.startDebugGroup('reporter'); | ||
var reporter = this.config.reporter; | ||
if (reporter) { | ||
this.console.reporter = new _ModuleLoader2.default(this, 'reporter', _Reporter2.default).loadModule(reporter); | ||
} else { | ||
this.debug('Using native ' + _chalk2.default.green('boost') + ' reporter'); | ||
} | ||
this.console.stopDebugGroup(); | ||
return this; | ||
} | ||
}, { | ||
key: 'log', | ||
value: function log(message) { | ||
this.console.log(message); | ||
return this; | ||
} | ||
}, { | ||
key: 'logError', | ||
value: function logError(message) { | ||
this.console.error(message); | ||
return this; | ||
} | ||
}]); | ||
return Tool; | ||
}(_Emitter3.default); /** | ||
* @copyright 2017, Miles Johnson | ||
* @license https://opensource.org/licenses/MIT | ||
* | ||
*/ | ||
exports.default = Tool; | ||
}; | ||
Tool.prototype.log = function (message) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
(_a = this.console).log.apply(_a, [message].concat(args)); | ||
return this; | ||
var _a; | ||
}; | ||
Tool.prototype.logError = function (message) { | ||
var args = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
args[_i - 1] = arguments[_i]; | ||
} | ||
(_a = this.console).error.apply(_a, [message].concat(args)); | ||
return this; | ||
var _a; | ||
}; | ||
return Tool; | ||
}(Emitter_1.default)); | ||
exports.default = Tool; |
@@ -1,1 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
{ | ||
"name": "boost", | ||
"version": "0.35.1", | ||
"version": "0.36.0", | ||
"description": "Robust pipeline for creating build tools that separate logic into routines and tasks.", | ||
"keywords": [], | ||
"main": "./lib/index.js", | ||
"module": "./esm/index.js", | ||
"scripts": { | ||
"babel": "yarn run babel:cjs && yarn run babel:esm", | ||
"babel:cjs": "beemo babel ./src --out-dir ./lib --copy-files --cjs", | ||
"babel:esm": "beemo babel ./src --out-dir ./esm --copy-files --esm", | ||
"babel": "beemo typescript --node", | ||
"build": "yarn run babel && yarn run build:dts", | ||
"build:dts": "beemo run-script generate-dts", | ||
"clean": "rimraf ./{lib,esm}/", | ||
"coverage": "yarn run jest --coverage", | ||
"eslint": "beemo eslint --color --report-unused-disable-directives ./src ./tests", | ||
"flow": "beemo flow check", | ||
"jest": "beemo jest --colors --logHeapUsage", | ||
"posttest": "yarn run flow --silent", | ||
"pretest": "yarn run eslint --silent", | ||
"test": "yarn run jest --silent", | ||
"postversion": "yarn run babel", | ||
"prettier": "beemo prettier --write ./README.md \"./{bin,src,tests}/**/*.js\" \"./*.{md,json}\"" | ||
"eslint": "beemo eslint", | ||
"jest": "beemo jest", | ||
"package": "yarn run clean && yarn run build && yarn test", | ||
"prettier": "beemo prettier", | ||
"pretest": "yarn run type", | ||
"test": "yarn run jest", | ||
"posttest": "yarn run eslint", | ||
"type": "beemo typescript --noEmit", | ||
"prerelease": "yarn run package", | ||
"release": "np --yolo" | ||
}, | ||
@@ -40,2 +42,3 @@ "repository": { | ||
"chalk": "^2.3.2", | ||
"debug": "^3.1.0", | ||
"elegant-spinner": "^1.0.1", | ||
@@ -45,6 +48,6 @@ "execa": "^0.10.0", | ||
"glob": "^7.1.2", | ||
"json5": "^1.0.0", | ||
"json5": "^1.0.1", | ||
"lodash": "^4.17.5", | ||
"log-update": "^2.3.0", | ||
"optimal": "^0.14.0", | ||
"optimal": "^0.17.3", | ||
"pluralize": "^7.0.0", | ||
@@ -54,6 +57,16 @@ "split": "^1.0.1" | ||
"peerDependencies": { | ||
"optimal": "^0.14.0" | ||
"optimal": "^0.16.0" | ||
}, | ||
"devDependencies": { | ||
"@milesj/build-tool-config": "0.67.1", | ||
"@milesj/build-tool-config": "0.78.1", | ||
"@types/chalk": "^2.2.0", | ||
"@types/debug": "^0.0.30", | ||
"@types/execa": "^0.9.0", | ||
"@types/figures": "^2.0.0", | ||
"@types/glob": "^5.0.35", | ||
"@types/json5": "^0.0.29", | ||
"@types/lodash": "^4.14.106", | ||
"@types/log-update": "^2.0.0", | ||
"@types/pluralize": "^0.0.28", | ||
"@types/split": "^0.3.28", | ||
"fs-extra": "^5.0.0" | ||
@@ -66,3 +79,2 @@ }, | ||
"eslint", | ||
"flow", | ||
{ | ||
@@ -74,11 +86,6 @@ "driver": "jest", | ||
}, | ||
"prettier" | ||
], | ||
"flow": { | ||
"libs": [ | ||
"./boost.js.flow", | ||
"./node_modules/optimal/optimal.js.flow" | ||
] | ||
} | ||
"prettier", | ||
"typescript" | ||
] | ||
} | ||
} |
# 🚀 Boost | ||
[![Build Status](https://travis-ci.org/milesj/boost.svg?branch=master)](https://travis-ci.org/milesj/boost) | ||
Create build tools using a robust pipeline that separates logic into routines and tasks. |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
6
4
74861
13
12
28
1775
1
+ Addeddebug@^3.1.0
+ Addeddebug@3.2.7(transitive)
+ Addedms@2.1.3(transitive)
+ Addedoptimal@0.17.3(transitive)
- Removedoptimal@0.14.0(transitive)
Updatedjson5@^1.0.1
Updatedoptimal@^0.17.3