preact-material-components
Version:
preact wrapper for "Material Components for the web"
67 lines (60 loc) • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = runTasksInSequencial;
var _runTask = require("./run-task");
var _runTask2 = _interopRequireDefault(_runTask);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var START_PROMISE = Promise.resolve({ code: 0 });
/**
* Throws an error if a given result indicates non-zero exit.
*
* @param {{task: string, code: number}} result - A result object.
* @returns {void}
*/
/**
* @author Toru Nagashima
* @copyright 2015 Toru Nagashima. All rights reserved.
* See LICENSE file in root directory for full license.
*/
function rejectIfNonZeroExit(result) {
if (result.code) {
throw new Error(result.task + ": None-Zero Exit(" + result.code + ");");
}
}
/**
* Run npm-scripts of given names in sequencial.
*
* If a npm-script exited with a non-zero code, this aborts subsequent npm-scripts.
*
* @param {string} tasks - A list of npm-script name to run in sequencial.
* @param {stream.Readable|null} stdin -
* A readable stream to send messages to stdin of child process.
* If this is `null`, ignores it.
* If this is `process.stdin`, inherits it.
* Otherwise, makes a pipe.
* @param {stream.Writable|null} stdout -
* A writable stream to receive messages from stdout of child process.
* If this is `null`, cannot send.
* If this is `process.stdout`, inherits it.
* Otherwise, makes a pipe.
* @param {stream.Writable|null} stderr -
* A writable stream to receive messages from stderr of child process.
* If this is `null`, cannot send.
* If this is `process.stderr`, inherits it.
* Otherwise, makes a pipe.
* @param {string[]} packageConfigOptions -
* `--:=` style options to overwrite package configs.
* @returns {Promise}
* A promise object which becomes fullfilled when all npm-scripts are completed.
* @private
*/
function runTasksInSequencial(tasks, stdin, stdout, stderr, packageConfigOptions) {
return tasks.reduce(function (prev, task) {
return prev.then(function (result) {
rejectIfNonZeroExit(result);
return (0, _runTask2.default)(task, stdin, stdout, stderr, packageConfigOptions);
});
}, START_PROMISE).then(rejectIfNonZeroExit);
}