Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

boost

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

boost - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

66

lib/CLI.js

@@ -15,10 +15,2 @@ 'use strict';

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _fs = require('fs');

@@ -53,7 +45,5 @@

};*/
class CLI {
var CLI = function () {
function CLI(packagePath /*: string*/) {
(0, _classCallCheck3.default)(this, CLI);
constructor(packagePath /*: string*/) {
if (!packagePath) {

@@ -63,6 +53,6 @@ throw new Error('Path to local `package.json` is required.');

var pkg = JSON.parse(_fs2.default.readFileSync(packagePath, 'utf8'));
var name = pkg.name,
version = pkg.version,
description = pkg.description;
const pkg = JSON.parse(_fs2.default.readFileSync(packagePath, 'utf8'));
const name = pkg.name,
version = pkg.version,
description = pkg.description;

@@ -75,33 +65,25 @@

// Auto-setup commander
this.app.version(version).description(description).usage(name + ' [options]');
this.app.version(version).description(description).usage(`${name} [options]`);
}
(0, _createClass3.default)(CLI, [{
key: 'options',
value: function options(_options /*: Options*/) /*: this*/ {
var _this = this;
options(options /*: Options*/) /*: this*/ {
(0, _keys2.default)((0, _extends3.default)({
'-c, --config <path>': 'Path to configuration file'
}, options)).forEach((flags /*: string*/) => {
const option = options[flags];
(0, _keys2.default)((0, _extends3.default)({
'-c, --config <path>': 'Path to configuration file'
}, _options)).forEach(function (flags /*: string*/) {
var option = _options[flags];
if (typeof option === 'string') {
this.app.option(flags, _chalk2.default.green(option));
} else {
this.app.option(flags, _chalk2.default.green(option.description), option.parser || option.defaultValue, option.defaultValue);
}
});
if (typeof option === 'string') {
_this.app.option(flags, _chalk2.default.green(option));
} else {
_this.app.option(flags, _chalk2.default.green(option.description), option.parser || option.defaultValue, option.defaultValue);
}
});
return this;
}
return this;
}
}, {
key: 'run',
value: function run() {
this.app.parse(process.argv);
}
}]);
return CLI;
}();
run() {
this.app.parse(process.argv);
}
}
exports.default = CLI;

@@ -8,6 +8,2 @@ 'use strict';

var _CLI = require('./CLI');
var _CLI2 = _interopRequireDefault(_CLI);
var _Pipeline = require('./Pipeline');

@@ -23,9 +19,11 @@

/**
* @copyright 2017, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
// import CLI from './CLI';
exports.Pipeline = _Pipeline2.default;
exports.Routine = _Routine2.default; /**
* @copyright 2017, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
exports.default = _CLI2.default;
exports.Routine = _Routine2.default;
// export default CLI;

@@ -7,26 +7,18 @@ 'use strict';

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
var _promise = require('babel-runtime/core-js/promise');
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
var _promise2 = _interopRequireDefault(_promise);
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _chalk = require('chalk');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _chalk2 = _interopRequireDefault(_chalk);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _readline = require('readline');
var _createClass3 = _interopRequireDefault(_createClass2);
var _readline2 = _interopRequireDefault(_readline);
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
var _Routine = require('./Routine');
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
var _Routine2 = _interopRequireDefault(_Routine);
var _inherits2 = require('babel-runtime/helpers/inherits');
var _inherits3 = _interopRequireDefault(_inherits2);
var _Routine2 = require('./Routine');
var _Routine3 = _interopRequireDefault(_Routine2);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -40,14 +32,14 @@

var Pipeline = function (_Routine) {
(0, _inherits3.default)(Pipeline, _Routine);
class Pipeline extends _Routine2.default {
function Pipeline(name /*: string*/) {
var config /*: RoutineConfig*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
(0, _classCallCheck3.default)(this, Pipeline);
constructor(name /*: string*/, config /*: RoutineConfig*/ = {}) {
super(name, config);
// Inherit global config as well
var _this = (0, _possibleConstructorReturn3.default)(this, (Pipeline.__proto__ || (0, _getPrototypeOf2.default)(Pipeline)).call(this, name, config));
this.globalConfig = config;
_this.globalConfig = config;
return _this;
this.console = _readline2.default.createInterface({
input: process.stdin,
output: process.stdout
});
}

@@ -60,25 +52,34 @@

*/
execute(initialValue /*: Result<*>*/ = null) /*: ResultPromise<*>*/ {
return this.serializeSubroutines(initialValue);
}
/**
* Request input from the console.
*/
askQuestion(question /*: string*/) /*: Promise<string>*/ {
return new _promise2.default((resolve /*: (string) => void*/) => {
this.console.question(_chalk2.default.magenta(question), (answer /*: string*/) => {
resolve(answer);
this.console.close();
});
});
}
(0, _createClass3.default)(Pipeline, [{
key: 'execute',
value: function execute() /*: ResultPromise<*>*/ {
var initialValue /*: Result<*>*/ = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
/**
* Output a message to the console.
*/
log(message /*: string*/) /*: this*/ {
this.console.write(message);
return this.serializeSubroutines(initialValue);
}
return this;
}
/**
* Add a routine using different terminology.
*/
}, {
key: 'phase',
value: function phase() /*: this*/ {
return this.chain.apply(this, arguments);
}
}]);
return Pipeline;
}(_Routine3.default);
/**
* Output a title for the current routing phase.
*/
logTitle(step /*: string*/, message /*: string*/) /*: this*/ {
return this.log(`${_chalk2.default.gray(`[${step}]`)} ${_chalk2.default.reset(message)}`);
}
}
exports.default = Pipeline;

@@ -15,18 +15,2 @@ 'use strict';

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 _readline = require('readline');
var _readline2 = _interopRequireDefault(_readline);
var _merge = require('lodash/merge');

@@ -40,18 +24,14 @@

var _executeSequentially = require('./executeSequentially');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _executeSequentially2 = _interopRequireDefault(_executeSequentially);
/**
* @copyright 2017, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*:: import type { RoutineConfig, Result, ResultPromise, ResultAccumulator, Task } from './types';*/
class Routine {
/*:: import type { RoutineConfig, Result, ResultPromise, Task } from './types';*/ /**
* @copyright 2017, Miles Johnson
* @license https://opensource.org/licenses/MIT
* @flow
*/
var Routine = function () {
function Routine(name /*: string*/) {
var defaultConfig /*: RoutineConfig*/ = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
(0, _classCallCheck3.default)(this, Routine);
constructor(name /*: string*/, defaultConfig /*: RoutineConfig*/ = {}) {
this.config = {};

@@ -62,2 +42,6 @@ this.globalConfig = {};

this.executeSubroutine = (value /*: Result<*>*/, routine /*: Routine*/) /*: ResultPromise<*>*/ => this.wrapPromise(routine.execute(value));
this.executeTask = (value /*: Result<*>*/, task /*: Task<*>*/) /*: ResultPromise<*>*/ => this.wrapPromise(task.call(this, value));
if (!name || typeof name !== 'string') {

@@ -68,178 +52,101 @@ throw new TypeError('Routine name must be a valid string.');

this.config = (0, _extends3.default)({}, defaultConfig);
this.globalConfig = {};
this.name = name;
this.subroutines = [];
this.console = _readline2.default.createInterface({
input: process.stdin,
output: process.stdout
});
}
/**
* Request input from the console.
* Configure the routine after it has been instantiated.
*/
configure(parentConfig /*: RoutineConfig*/, globalConfig /*: RoutineConfig*/) /*: this*/ {
this.globalConfig = globalConfig;
const config = parentConfig[this.name];
(0, _createClass3.default)(Routine, [{
key: 'askQuestion',
value: function askQuestion(question /*: string*/) /*: Promise<string>*/ {
var _this = this;
return new _promise2.default(function (resolve /*: (string) => void*/) {
_this.console.question(_chalk2.default.magenta(question), function (answer /*: string*/) {
resolve(answer);
_this.console.close();
});
});
if ((0, _isObject2.default)(config)) {
// $FlowIssue Flow cannot introspect from isObject
(0, _merge2.default)(this.config, config);
}
/**
* Add a new subroutine within this routine.
*/
return this;
}
}, {
key: 'chain',
value: function chain() /*: this*/ {
var _this2 = this;
/**
* Execute the current routine and return a new value.
* This method *must* be overridden in a subclass.
*/
execute(value /*: Result<*>*/) /*: ResultPromise<*>*/ {
return this.wrapPromise(value);
}
for (var _len = arguments.length, routines = Array(_len), _key = 0; _key < _len; _key++) {
routines[_key] = arguments[_key];
}
/**
* Execute a subroutine wih the provided value.
*/
routines.forEach(function (routine /*: Routine*/) {
if (routine instanceof Routine) {
_this2.subroutines.push(routine.configure(_this2.config, _this2.globalConfig));
} else {
throw new TypeError('Routine must be an instance of `Routine`.');
}
});
return this;
}
/**
* Execute a task, a method in the current routine, or a function,
* with the provided value.
*/
/**
* Configure the routine after it has been instantiated.
*/
}, {
key: 'configure',
value: function configure(parentConfig /*: RoutineConfig*/, globalConfig /*: RoutineConfig*/) /*: this*/ {
this.globalConfig = globalConfig;
/**
* Execute subroutines in parralel with a value being passed to each subroutine.
* A combination promise will be returned as the result.
*/
parallelizeSubroutines(value /*: Result<*>*/) /*: ResultPromise<*>*/ {
return _promise2.default.all(this.subroutines.map(routine => this.executeSubroutine(value, routine)));
}
var config = parentConfig[this.name];
/**
* Execute tasks in parralel with a value being passed to each task.
* A combination promise will be returned as the result.
*/
parallelizeTasks(value /*: Result<*>*/, tasks /*: Task<*>[]*/) /*: ResultPromise<*>*/ {
return _promise2.default.all(tasks.map(task => this.executeTask(value, task)));
}
if ((0, _isObject2.default)(config)) {
// $FlowIssue Flow cannot introspect from isObject
(0, _merge2.default)(this.config, config);
/**
* Add a new subroutine within this routine.
*/
pipe(...routines /*: Routine[]*/) /*: this*/ {
routines.forEach((routine /*: Routine*/) => {
if (routine instanceof Routine) {
this.subroutines.push(routine.configure(this.config, this.globalConfig));
} else {
throw new TypeError('Routine must be an instance of `Routine`.');
}
});
return this;
}
return this;
}
/**
* Execute the current routine and return a new value.
* This method *must* be overridden in a subclass.
*/
/**
* Execute processes in sequential order with the output of each
* task being passed to the next promise in the chain. Utilize the
* `accumulator` function to execute the list of processes.
*/
serialize /*:: <T>*/(initialValue /*: Result<*>*/, items /*: T[]*/, accumulator /*: ResultAccumulator<*, T>*/) /*: ResultPromise<*>*/ {
return items.reduce((promise /*: ResultPromise<*>*/, item /*: T*/) => promise.then((value /*: Result<*>*/) => accumulator(value, item)), _promise2.default.resolve(initialValue));
}
}, {
key: 'execute',
value: function execute(value /*: Result<*>*/) /*: Result<*>*/ {
return value;
}
/**
* Execute subroutines in sequential (serial) order.
*/
serializeSubroutines(value /*: Result<*>*/) /*: ResultPromise<*>*/ {
return this.serialize(value, this.subroutines, this.executeSubroutine);
}
/**
* Execute a subroutine wih the provided value.
*/
/**
* Execute tasks in sequential (serial) order.
*/
serializeTasks(value /*: Result<*>*/, tasks /*: Task<*>[]*/) /*: ResultPromise<*>*/ {
return this.serialize(value, tasks, this.executeTask);
}
}, {
key: 'executeSubroutine',
value: function executeSubroutine(value /*: Result<*>*/, routine /*: Routine*/) /*: Result<*>*/ {
return routine.execute(value);
}
/**
* Execute a task (a method in the current routine) with the provided value.
*/
}, {
key: 'executeTask',
value: function executeTask(value /*: Result<*>*/, task /*: Task<*>*/) /*: Result<*>*/ {
return task.call(this, value);
}
/**
* Output a message to the console.
*/
}, {
key: 'log',
value: function log(message /*: string*/) /*: this*/ {
this.console.write(message);
return this;
}
/**
* Output a title for the current routing phase.
*/
}, {
key: 'logTitle',
value: function logTitle(step /*: string*/, message /*: string*/) /*: this*/ {
return this.log(_chalk2.default.gray('[' + step + ']') + ' ' + _chalk2.default.reset(message));
}
/**
* Execute subroutines in parralel with a value being passed to each subroutine.
* A combination promise will be returned as the result.
*/
}, {
key: 'parallelizeSubroutines',
value: function parallelizeSubroutines(value /*: Result<*>*/) /*: ResultPromise<*>*/ {
var _this3 = this;
return _promise2.default.all(this.subroutines.map(function (routine) {
return _this3.executeSubroutine(value, routine);
}));
}
/**
* Execute tasks in parralel with a value being passed to each task.
* A combination promise will be returned as the result.
*/
}, {
key: 'parallelizeTasks',
value: function parallelizeTasks(value /*: Result<*>*/, tasks /*: Task<*>[]*/) /*: ResultPromise<*>*/ {
var _this4 = this;
return _promise2.default.all(tasks.map(function (task) {
return _this4.executeTask(value, task);
}));
}
/**
* Execute subroutines in sequential (serial) order.
*/
}, {
key: 'serializeSubroutines',
value: function serializeSubroutines(value /*: Result<*>*/) /*: ResultPromise<*>*/ {
return (0, _executeSequentially2.default)(value, this.subroutines, this.executeSubroutine);
}
/**
* Execute tasks in sequential (serial) order.
*/
}, {
key: 'serializeTasks',
value: function serializeTasks(value /*: Result<*>*/, tasks /*: Task<*>[]*/) /*: ResultPromise<*>*/ {
return (0, _executeSequentially2.default)(value, tasks, this.executeTask);
}
}]);
return Routine;
}();
/**
* Wrap a value in a promise if it has not already been.
*/
wrapPromise(value /*: Result<*>*/) /*: ResultPromise<*>*/ {
return value instanceof _promise2.default ? value : _promise2.default.resolve(value);
}
}
exports.default = Routine;

@@ -15,2 +15,3 @@ "use strict";

/*:: export type ResultPromise<T> = Promise<Result<T>>;*/
/*:: export type ResultAccumulator<T1, T2> = (value: Result<T1>, item: T2) => ResultPromise<*>;*/
/*:: export type Task<T> = (value: Result<T>) => Result<T> | ResultPromise<T>;*/
{
"name": "boost",
"version": "0.0.5",
"version": "0.0.6",
"description": "Robust pipeline for creating build tools that separate logic into routines and tasks.",

@@ -16,5 +16,6 @@ "keywords": [],

"flow": "flow check",
"mocha": "mocha --opts ./mocha.opts './tests/**/*.test.js'",
"jest": "jest --config ./jest.json",
"coverage": "yarn run jest -- --coverage",
"pretest": "yarn run lint",
"test": "yarn run mocha",
"test": "yarn run jest",
"posttest": "yarn run flow",

@@ -37,3 +38,3 @@ "preversion": "yarn test && yarn run clean && yarn run build"

"dependencies": {
"babel-runtime": "^6.18.0",
"babel-runtime": "^6.23.0",
"chalk": "^1.1.3",

@@ -44,18 +45,20 @@ "commander": "^2.9.0",

"devDependencies": {
"babel-cli": "^6.18.0",
"babel-eslint": "^7.1.0",
"babel-plugin-transform-flow-comments": "^6.17.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-latest": "^6.16.0",
"babel-preset-stage-2": "^6.18.0",
"babel-register": "^6.18.0",
"chai": "^3.5.0",
"eslint": "^3.12.1",
"eslint-config-airbnb-base": "^11.0.0",
"eslint-plugin-flowtype": "^2.25.0",
"babel-cli": "^6.24.0",
"babel-eslint": "^7.2.1",
"babel-jest": "^19.0.0",
"babel-plugin-transform-flow-comments": "^6.22.0",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.3.2",
"babel-preset-stage-2": "^6.22.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.1.2",
"eslint-plugin-flowtype": "^2.30.4",
"eslint-plugin-import": "^2.2.0",
"flow-bin": "^0.37.0",
"mocha": "^3.1.2",
"rimraf": "^2.5.4"
"flow-bin": "^0.42.0",
"jest": "^19.0.2",
"rimraf": "^2.6.1"
},
"engines": {
"node": "^6.0.0"
}
}

@@ -12,7 +12,7 @@ # Boost v0.0.0

(new Pipeline('babel', require('./.babelrc')))
.phase(new LocateRoutine('locate')) // Glob initial files
.phase(new ResolveRoutine('resolve')) // Resolve dependency lookups
.phase(new TransformRoutine('transform')) // Apply transformations
.phase(new MinifyRoutine('minify')) // Apply minification
.phase(new BundleRoutine('bundle', { // Bundle and or output the files
.pipe(new LocateRoutine('locate')) // Glob initial files
.pipe(new ResolveRoutine('resolve')) // Resolve dependency lookups
.pipe(new TransformRoutine('transform')) // Apply transformations
.pipe(new MinifyRoutine('minify')) // Apply minification
.pipe(new BundleRoutine('bundle', { // Bundle and or output the files
out: './lib',

@@ -19,0 +19,0 @@ }))

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc