From e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d Mon Sep 17 00:00:00 2001 From: Piotr Russ Date: Mon, 16 Nov 2020 00:10:28 +0100 Subject: api, login, auth --- node_modules/npm-run-all/LICENSE | 22 ++ node_modules/npm-run-all/README.md | 91 +++++++ node_modules/npm-run-all/bin/common/bootstrap.js | 51 ++++ .../npm-run-all/bin/common/parse-cli-args.js | 251 ++++++++++++++++++ node_modules/npm-run-all/bin/common/version.js | 25 ++ node_modules/npm-run-all/bin/npm-run-all/help.js | 71 +++++ node_modules/npm-run-all/bin/npm-run-all/index.js | 13 + node_modules/npm-run-all/bin/npm-run-all/main.js | 77 ++++++ node_modules/npm-run-all/bin/run-p/help.js | 66 +++++ node_modules/npm-run-all/bin/run-p/index.js | 13 + node_modules/npm-run-all/bin/run-p/main.js | 74 ++++++ node_modules/npm-run-all/bin/run-s/help.js | 60 +++++ node_modules/npm-run-all/bin/run-s/index.js | 13 + node_modules/npm-run-all/bin/run-s/main.js | 71 +++++ node_modules/npm-run-all/docs/node-api.md | 117 +++++++++ node_modules/npm-run-all/docs/npm-run-all.md | 192 ++++++++++++++ node_modules/npm-run-all/docs/run-p.md | 156 +++++++++++ node_modules/npm-run-all/docs/run-s.md | 147 +++++++++++ node_modules/npm-run-all/lib/create-header.js | 48 ++++ .../lib/create-prefix-transform-stream.js | 89 +++++++ node_modules/npm-run-all/lib/index.js | 287 +++++++++++++++++++++ node_modules/npm-run-all/lib/match-tasks.js | 128 +++++++++ node_modules/npm-run-all/lib/npm-run-all-error.js | 47 ++++ node_modules/npm-run-all/lib/read-package-json.js | 31 +++ node_modules/npm-run-all/lib/run-task.js | 206 +++++++++++++++ node_modules/npm-run-all/lib/run-tasks.js | 177 +++++++++++++ node_modules/npm-run-all/lib/spawn-posix.js | 64 +++++ node_modules/npm-run-all/lib/spawn-win32.js | 50 ++++ node_modules/npm-run-all/lib/spawn.js | 20 ++ node_modules/npm-run-all/package.json | 108 ++++++++ 30 files changed, 2765 insertions(+) create mode 100644 node_modules/npm-run-all/LICENSE create mode 100644 node_modules/npm-run-all/README.md create mode 100644 node_modules/npm-run-all/bin/common/bootstrap.js create mode 100644 node_modules/npm-run-all/bin/common/parse-cli-args.js create mode 100644 node_modules/npm-run-all/bin/common/version.js create mode 100644 node_modules/npm-run-all/bin/npm-run-all/help.js create mode 100755 node_modules/npm-run-all/bin/npm-run-all/index.js create mode 100644 node_modules/npm-run-all/bin/npm-run-all/main.js create mode 100644 node_modules/npm-run-all/bin/run-p/help.js create mode 100755 node_modules/npm-run-all/bin/run-p/index.js create mode 100644 node_modules/npm-run-all/bin/run-p/main.js create mode 100644 node_modules/npm-run-all/bin/run-s/help.js create mode 100755 node_modules/npm-run-all/bin/run-s/index.js create mode 100644 node_modules/npm-run-all/bin/run-s/main.js create mode 100644 node_modules/npm-run-all/docs/node-api.md create mode 100644 node_modules/npm-run-all/docs/npm-run-all.md create mode 100644 node_modules/npm-run-all/docs/run-p.md create mode 100644 node_modules/npm-run-all/docs/run-s.md create mode 100644 node_modules/npm-run-all/lib/create-header.js create mode 100644 node_modules/npm-run-all/lib/create-prefix-transform-stream.js create mode 100644 node_modules/npm-run-all/lib/index.js create mode 100644 node_modules/npm-run-all/lib/match-tasks.js create mode 100644 node_modules/npm-run-all/lib/npm-run-all-error.js create mode 100644 node_modules/npm-run-all/lib/read-package-json.js create mode 100644 node_modules/npm-run-all/lib/run-task.js create mode 100644 node_modules/npm-run-all/lib/run-tasks.js create mode 100644 node_modules/npm-run-all/lib/spawn-posix.js create mode 100644 node_modules/npm-run-all/lib/spawn-win32.js create mode 100644 node_modules/npm-run-all/lib/spawn.js create mode 100644 node_modules/npm-run-all/package.json (limited to 'node_modules/npm-run-all') diff --git a/node_modules/npm-run-all/LICENSE b/node_modules/npm-run-all/LICENSE new file mode 100644 index 0000000..c39e694 --- /dev/null +++ b/node_modules/npm-run-all/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Toru Nagashima + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/node_modules/npm-run-all/README.md b/node_modules/npm-run-all/README.md new file mode 100644 index 0000000..b80d787 --- /dev/null +++ b/node_modules/npm-run-all/README.md @@ -0,0 +1,91 @@ +| index | [npm-run-all] | [run-s] | [run-p] | [Node API] | +|-------|---------------|---------|---------|------------| + +# npm-run-all + +[![npm version](https://img.shields.io/npm/v/npm-run-all.svg)](https://www.npmjs.com/package/npm-run-all) +[![Downloads/month](https://img.shields.io/npm/dm/npm-run-all.svg)](http://www.npmtrends.com/npm-run-all) +[![Build Status](https://travis-ci.org/mysticatea/npm-run-all.svg?branch=master)](https://travis-ci.org/mysticatea/npm-run-all) +[![Build status](https://ci.appveyor.com/api/projects/status/v0owd44q1r7hceir/branch/master?svg=true)](https://ci.appveyor.com/project/mysticatea/npm-run-all/branch/master) +[![Coverage Status](https://codecov.io/gh/mysticatea/eslint-plugin-node/branch/master/graph/badge.svg)](https://codecov.io/gh/mysticatea/npm-run-all) +[![Dependency Status](https://david-dm.org/mysticatea/npm-run-all.svg)](https://david-dm.org/mysticatea/npm-run-all) + +A CLI tool to run multiple npm-scripts in parallel or sequential. + +## ⤴️ Motivation + +- **Simplify.** The official `npm run-script` command cannot run multiple scripts, so if we want to run multiple scripts, it's redundant a bit. Let's shorten it by glob-like patterns.
+ Before: `npm run clean && npm run build:css && npm run build:js && npm run build:html`
+ After: `npm-run-all clean build:*` +- **Cross platform.** We sometimes use `&` to run multiple command in parallel, but `cmd.exe` (`npm run-script` uses it by default) does not support the `&`. Half of Node.js users are using it on Windows, so the use of `&` might block contributions. `npm-run-all --parallel` works well on Windows as well. + +## 💿 Installation + +```bash +$ npm install npm-run-all --save-dev +# or +$ yarn add npm-run-all --dev +``` + +- It requires `Node@>=4`. + +## 📖 Usage + +### CLI Commands + +This `npm-run-all` package provides 3 CLI commands. + +- [npm-run-all] +- [run-s] +- [run-p] + +The main command is [npm-run-all]. +We can make complex plans with [npm-run-all] command. + +Both [run-s] and [run-p] are shorthand commands. +[run-s] is for sequential, [run-p] is for parallel. +We can make simple plans with those commands. + +#### Yarn Compatibility + +If a script is invoked with Yarn, `npm-run-all` will correctly use Yarn to execute the plan's child scripts. + +### Node API + +This `npm-run-all` package provides Node API. + +- [Node API] + +## 📰 Changelog + +- https://github.com/mysticatea/npm-run-all/releases + +## 🍻 Contributing + +Welcome♡ + +### Bug Reports or Feature Requests + +Please use GitHub Issues. + +### Correct Documents + +Please use GitHub Pull Requests. + +I'm not familiar with English, so I especially thank you for documents' corrections. + +### Implementing + +Please use GitHub Pull Requests. + +There are some npm-scripts to help developments. + +- **npm test** - Run tests and collect coverage. +- **npm run clean** - Delete temporary files. +- **npm run lint** - Run ESLint. +- **npm run watch** - Run tests (not collect coverage) on every file change. + +[npm-run-all]: docs/npm-run-all.md +[run-s]: docs/run-s.md +[run-p]: docs/run-p.md +[Node API]: docs/node-api.md diff --git a/node_modules/npm-run-all/bin/common/bootstrap.js b/node_modules/npm-run-all/bin/common/bootstrap.js new file mode 100644 index 0000000..e73b093 --- /dev/null +++ b/node_modules/npm-run-all/bin/common/bootstrap.js @@ -0,0 +1,51 @@ +/** + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ +/*eslint-disable no-process-exit */ + +module.exports = function bootstrap(name) { + const argv = process.argv.slice(2) + + switch (argv[0]) { + case undefined: + case "-h": + case "--help": + return require(`../${name}/help`)(process.stdout) + + case "-v": + case "--version": + return require("./version")(process.stdout) + + default: + // https://github.com/mysticatea/npm-run-all/issues/105 + // Avoid MaxListenersExceededWarnings. + process.stdout.setMaxListeners(0) + process.stderr.setMaxListeners(0) + process.stdin.setMaxListeners(0) + + // Main + return require(`../${name}/main`)( + argv, + process.stdout, + process.stderr + ).then( + () => { + // I'm not sure why, but maybe the process never exits + // on Git Bash (MINGW64) + process.exit(0) + }, + () => { + process.exit(1) + } + ) + } +} + +/*eslint-enable */ diff --git a/node_modules/npm-run-all/bin/common/parse-cli-args.js b/node_modules/npm-run-all/bin/common/parse-cli-args.js new file mode 100644 index 0000000..7f056fc --- /dev/null +++ b/node_modules/npm-run-all/bin/common/parse-cli-args.js @@ -0,0 +1,251 @@ +/** + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +/*eslint-disable no-process-env */ + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +const OVERWRITE_OPTION = /^--([^:]+?):([^=]+?)(?:=(.+))?$/ +const CONFIG_OPTION = /^--([^=]+?)(?:=(.+))$/ +const PACKAGE_CONFIG_PATTERN = /^npm_package_config_(.+)$/ +const CONCAT_OPTIONS = /^-[clnprs]+$/ + +/** + * Overwrites a specified package config. + * + * @param {object} config - A config object to be overwritten. + * @param {string} packageName - A package name to overwrite. + * @param {string} variable - A variable name to overwrite. + * @param {string} value - A new value to overwrite. + * @returns {void} + */ +function overwriteConfig(config, packageName, variable, value) { + const scope = config[packageName] || (config[packageName] = {}) + scope[variable] = value +} + +/** + * Creates a package config object. + * This checks `process.env` and creates the default value. + * + * @returns {object} Created config object. + */ +function createPackageConfig() { + const retv = {} + const packageName = process.env.npm_package_name + if (!packageName) { + return retv + } + + for (const key of Object.keys(process.env)) { + const m = PACKAGE_CONFIG_PATTERN.exec(key) + if (m != null) { + overwriteConfig(retv, packageName, m[1], process.env[key]) + } + } + + return retv +} + +/** + * Adds a new group into a given list. + * + * @param {object[]} groups - A group list to add. + * @param {object} initialValues - A key-value map for the default of new value. + * @returns {void} + */ +function addGroup(groups, initialValues) { + groups.push(Object.assign( + { parallel: false, patterns: [] }, + initialValues || {} + )) +} + +/** + * ArgumentSet is values of parsed CLI arguments. + * This class provides the getter to get the last group. + */ +class ArgumentSet { + /** + * @param {object} initialValues - A key-value map for the default of new value. + * @param {object} options - A key-value map for the options. + */ + constructor(initialValues, options) { + this.config = {} + this.continueOnError = false + this.groups = [] + this.maxParallel = 0 + this.npmPath = null + this.packageConfig = createPackageConfig() + this.printLabel = false + this.printName = false + this.race = false + this.rest = [] + this.silent = process.env.npm_config_loglevel === "silent" + this.singleMode = Boolean(options && options.singleMode) + + addGroup(this.groups, initialValues) + } + + /** + * Gets the last group. + */ + get lastGroup() { + return this.groups[this.groups.length - 1] + } + + /** + * Gets "parallel" flag. + */ + get parallel() { + return this.groups.some(g => g.parallel) + } +} + +/** + * Parses CLI arguments. + * + * @param {ArgumentSet} set - The parsed CLI arguments. + * @param {string[]} args - CLI arguments. + * @returns {ArgumentSet} set itself. + */ +function parseCLIArgsCore(set, args) { // eslint-disable-line complexity + LOOP: + for (let i = 0; i < args.length; ++i) { + const arg = args[i] + + switch (arg) { + case "--": + set.rest = args.slice(1 + i) + break LOOP + + case "--color": + case "--no-color": + // do nothing. + break + + case "-c": + case "--continue-on-error": + set.continueOnError = true + break + + case "-l": + case "--print-label": + set.printLabel = true + break + + case "-n": + case "--print-name": + set.printName = true + break + + case "-r": + case "--race": + set.race = true + break + + case "--silent": + set.silent = true + break + + case "--max-parallel": + set.maxParallel = parseInt(args[++i], 10) + if (!Number.isFinite(set.maxParallel) || set.maxParallel <= 0) { + throw new Error(`Invalid Option: --max-parallel ${args[i]}`) + } + break + + case "-s": + case "--sequential": + case "--serial": + if (set.singleMode && arg === "-s") { + set.silent = true + break + } + if (set.singleMode) { + throw new Error(`Invalid Option: ${arg}`) + } + addGroup(set.groups) + break + + case "--aggregate-output": + set.aggregateOutput = true + break + + case "-p": + case "--parallel": + if (set.singleMode) { + throw new Error(`Invalid Option: ${arg}`) + } + addGroup(set.groups, { parallel: true }) + break + + case "--npm-path": + set.npmPath = args[++i] || null + break + + default: { + let matched = null + if ((matched = OVERWRITE_OPTION.exec(arg))) { + overwriteConfig( + set.packageConfig, + matched[1], + matched[2], + matched[3] || args[++i] + ) + } + else if ((matched = CONFIG_OPTION.exec(arg))) { + set.config[matched[1]] = matched[2] + } + else if (CONCAT_OPTIONS.test(arg)) { + parseCLIArgsCore( + set, + arg.slice(1).split("").map(c => `-${c}`) + ) + } + else if (arg[0] === "-") { + throw new Error(`Invalid Option: ${arg}`) + } + else { + set.lastGroup.patterns.push(arg) + } + + break + } + } + } + + if (!set.parallel && set.aggregateOutput) { + throw new Error("Invalid Option: --aggregate-output (without parallel)") + } + if (!set.parallel && set.race) { + const race = args.indexOf("--race") !== -1 ? "--race" : "-r" + throw new Error(`Invalid Option: ${race} (without parallel)`) + } + if (!set.parallel && set.maxParallel !== 0) { + throw new Error("Invalid Option: --max-parallel (without parallel)") + } + + return set +} + +/** + * Parses CLI arguments. + * + * @param {string[]} args - CLI arguments. + * @param {object} initialValues - A key-value map for the default of new value. + * @param {object} options - A key-value map for the options. + * @param {boolean} options.singleMode - The flag to be single group mode. + * @returns {ArgumentSet} The parsed CLI arguments. + */ +module.exports = function parseCLIArgs(args, initialValues, options) { + return parseCLIArgsCore(new ArgumentSet(initialValues, options), args) +} + +/*eslint-enable */ diff --git a/node_modules/npm-run-all/bin/common/version.js b/node_modules/npm-run-all/bin/common/version.js new file mode 100644 index 0000000..06afb8f --- /dev/null +++ b/node_modules/npm-run-all/bin/common/version.js @@ -0,0 +1,25 @@ +/** + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Print a version text. + * + * @param {stream.Writable} output - A writable stream to print. + * @returns {Promise} Always a fulfilled promise. + * @private + */ +module.exports = function printVersion(output) { + const version = require("../../package.json").version + + output.write(`v${version}\n`) + + return Promise.resolve(null) +} diff --git a/node_modules/npm-run-all/bin/npm-run-all/help.js b/node_modules/npm-run-all/bin/npm-run-all/help.js new file mode 100644 index 0000000..0300bfe --- /dev/null +++ b/node_modules/npm-run-all/bin/npm-run-all/help.js @@ -0,0 +1,71 @@ +/** + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Print a help text. + * + * @param {stream.Writable} output - A writable stream to print. + * @returns {Promise} Always a fulfilled promise. + * @private + */ +module.exports = function printHelp(output) { + output.write(` +Usage: + $ npm-run-all [--help | -h | --version | -v] + $ npm-run-all [tasks] [OPTIONS] + + Run given npm-scripts in parallel or sequential. + + : A list of npm-scripts' names and Glob-like patterns. + +Options: + --aggregate-output - - - Avoid interleaving output by delaying printing of + each command's output until it has finished. + -c, --continue-on-error - Set the flag to continue executing + other/subsequent tasks even if a task threw an + error. 'npm-run-all' itself will exit with + non-zero code if one or more tasks threw error(s) + --max-parallel - Set the maximum number of parallelism. Default is + unlimited. + --npm-path - - - Set the path to npm. Default is the value of + environment variable npm_execpath. + If the variable is not defined, then it's "npm". + In this case, the "npm" command must be found in + environment variable PATH. + -l, --print-label - - - - Set the flag to print the task name as a prefix + on each line of output. Tools in tasks may stop + coloring their output if this option was given. + -n, --print-name - - - - Set the flag to print the task name before + running each task. + -p, --parallel - Run a group of tasks in parallel. + e.g. 'npm-run-all -p foo bar' is similar to + 'npm run foo & npm run bar'. + -r, --race - - - - - - - Set the flag to kill all tasks when a task + finished with zero. This option is valid only + with 'parallel' option. + -s, --sequential - Run a group of tasks sequentially. + --serial e.g. 'npm-run-all -s foo bar' is similar to + 'npm run foo && npm run bar'. + '--serial' is a synonym of '--sequential'. + --silent - - - - - - - - Set 'silent' to the log level of npm. + +Examples: + $ npm-run-all --serial clean lint build:** + $ npm-run-all --parallel watch:** + $ npm-run-all clean lint --parallel "build:** -- --watch" + $ npm-run-all -l -p start-server start-browser start-electron + +See Also: + https://github.com/mysticatea/npm-run-all#readme +`) + + return Promise.resolve(null) +} diff --git a/node_modules/npm-run-all/bin/npm-run-all/index.js b/node_modules/npm-run-all/bin/npm-run-all/index.js new file mode 100755 index 0000000..b405238 --- /dev/null +++ b/node_modules/npm-run-all/bin/npm-run-all/index.js @@ -0,0 +1,13 @@ +#!/usr/bin/env node +/** + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Main +//------------------------------------------------------------------------------ + +require("../common/bootstrap")("npm-run-all") diff --git a/node_modules/npm-run-all/bin/npm-run-all/main.js b/node_modules/npm-run-all/bin/npm-run-all/main.js new file mode 100644 index 0000000..2782468 --- /dev/null +++ b/node_modules/npm-run-all/bin/npm-run-all/main.js @@ -0,0 +1,77 @@ +/** + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const runAll = require("../../lib") +const parseCLIArgs = require("../common/parse-cli-args") + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Parses arguments, then run specified npm-scripts. + * + * @param {string[]} args - Arguments to parse. + * @param {stream.Writable} stdout - A writable stream to print logs. + * @param {stream.Writable} stderr - A writable stream to print errors. + * @returns {Promise} A promise which comes to be fulfilled when all npm-scripts are completed. + * @private + */ +module.exports = function npmRunAll(args, stdout, stderr) { + try { + const stdin = process.stdin + const argv = parseCLIArgs(args) + + const promise = argv.groups.reduce( + (prev, group) => { + if (group.patterns.length === 0) { + return prev + } + return prev.then(() => runAll( + group.patterns, + { + stdout, + stderr, + stdin, + parallel: group.parallel, + maxParallel: group.parallel ? argv.maxParallel : 1, + continueOnError: argv.continueOnError, + printLabel: argv.printLabel, + printName: argv.printName, + config: argv.config, + packageConfig: argv.packageConfig, + silent: argv.silent, + arguments: argv.rest, + race: group.parallel && argv.race, + npmPath: argv.npmPath, + aggregateOutput: group.parallel && argv.aggregateOutput, + } + )) + }, + Promise.resolve(null) + ) + + if (!argv.silent) { + promise.catch(err => { + //eslint-disable-next-line no-console + console.error("ERROR:", err.message) + }) + } + + return promise + } + catch (err) { + //eslint-disable-next-line no-console + console.error("ERROR:", err.message) + + return Promise.reject(err) + } +} diff --git a/node_modules/npm-run-all/bin/run-p/help.js b/node_modules/npm-run-all/bin/run-p/help.js new file mode 100644 index 0000000..873568f --- /dev/null +++ b/node_modules/npm-run-all/bin/run-p/help.js @@ -0,0 +1,66 @@ +/** + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Print a help text. + * + * @param {stream.Writable} output - A writable stream to print. + * @returns {Promise} Always a fulfilled promise. + * @private + */ +module.exports = function printHelp(output) { + output.write(` +Usage: + $ run-p [--help | -h | --version | -v] + $ run-p [OPTIONS] + + Run given npm-scripts in parallel. + + : A list of npm-scripts' names and Glob-like patterns. + +Options: + --aggregate-output - - - Avoid interleaving output by delaying printing of + each command's output until it has finished. + -c, --continue-on-error - Set the flag to continue executing other tasks + even if a task threw an error. 'run-p' itself + will exit with non-zero code if one or more tasks + threw error(s). + --max-parallel - Set the maximum number of parallelism. Default is + unlimited. + --npm-path - - - Set the path to npm. Default is the value of + environment variable npm_execpath. + If the variable is not defined, then it's "npm." + In this case, the "npm" command must be found in + environment variable PATH. + -l, --print-label - - - - Set the flag to print the task name as a prefix + on each line of output. Tools in tasks may stop + coloring their output if this option was given. + -n, --print-name - - - - Set the flag to print the task name before + running each task. + -r, --race - - - - - - - Set the flag to kill all tasks when a task + finished with zero. + -s, --silent - - - - - - Set 'silent' to the log level of npm. + + Shorthand aliases can be combined. + For example, '-clns' equals to '-c -l -n -s'. + +Examples: + $ run-p watch:** + $ run-p --print-label "build:** -- --watch" + $ run-p -sl "build:** -- --watch" + $ run-p start-server start-browser start-electron + +See Also: + https://github.com/mysticatea/npm-run-all#readme +`) + + return Promise.resolve(null) +} diff --git a/node_modules/npm-run-all/bin/run-p/index.js b/node_modules/npm-run-all/bin/run-p/index.js new file mode 100755 index 0000000..b7ca754 --- /dev/null +++ b/node_modules/npm-run-all/bin/run-p/index.js @@ -0,0 +1,13 @@ +#!/usr/bin/env node +/** + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Main +//------------------------------------------------------------------------------ + +require("../common/bootstrap")("run-p") diff --git a/node_modules/npm-run-all/bin/run-p/main.js b/node_modules/npm-run-all/bin/run-p/main.js new file mode 100644 index 0000000..e44f2f2 --- /dev/null +++ b/node_modules/npm-run-all/bin/run-p/main.js @@ -0,0 +1,74 @@ +/** + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const runAll = require("../../lib") +const parseCLIArgs = require("../common/parse-cli-args") + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Parses arguments, then run specified npm-scripts. + * + * @param {string[]} args - Arguments to parse. + * @param {stream.Writable} stdout - A writable stream to print logs. + * @param {stream.Writable} stderr - A writable stream to print errors. + * @returns {Promise} A promise which comes to be fulfilled when all npm-scripts are completed. + * @private + */ +module.exports = function npmRunAll(args, stdout, stderr) { + try { + const stdin = process.stdin + const argv = parseCLIArgs(args, { parallel: true }, { singleMode: true }) + const group = argv.lastGroup + + if (group.patterns.length === 0) { + return Promise.resolve(null) + } + + const promise = runAll( + group.patterns, + { + stdout, + stderr, + stdin, + parallel: group.parallel, + maxParallel: argv.maxParallel, + continueOnError: argv.continueOnError, + printLabel: argv.printLabel, + printName: argv.printName, + config: argv.config, + packageConfig: argv.packageConfig, + silent: argv.silent, + arguments: argv.rest, + race: argv.race, + npmPath: argv.npmPath, + aggregateOutput: argv.aggregateOutput, + } + ) + + if (!argv.silent) { + promise.catch(err => { + //eslint-disable-next-line no-console + console.error("ERROR:", err.message) + }) + } + + return promise + } + catch (err) { + //eslint-disable-next-line no-console + console.error("ERROR:", err.message) + + return Promise.reject(err) + } +} diff --git a/node_modules/npm-run-all/bin/run-s/help.js b/node_modules/npm-run-all/bin/run-s/help.js new file mode 100644 index 0000000..6dfa6a1 --- /dev/null +++ b/node_modules/npm-run-all/bin/run-s/help.js @@ -0,0 +1,60 @@ +/** + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Print a help text. + * + * @param {stream.Writable} output - A writable stream to print. + * @returns {Promise} Always a fulfilled promise. + * @private + */ +module.exports = function printHelp(output) { + output.write(` +Usage: + $ run-s [--help | -h | --version | -v] + $ run-s [OPTIONS] + + Run given npm-scripts sequentially. + + : A list of npm-scripts' names and Glob-like patterns. + +Options: + -c, --continue-on-error - Set the flag to continue executing subsequent + tasks even if a task threw an error. 'run-s' + itself will exit with non-zero code if one or + more tasks threw error(s). + --npm-path - - - Set the path to npm. Default is the value of + environment variable npm_execpath. + If the variable is not defined, then it's "npm." + In this case, the "npm" command must be found in + environment variable PATH. + -l, --print-label - - - - Set the flag to print the task name as a prefix + on each line of output. Tools in tasks may stop + coloring their output if this option was given. + -n, --print-name - - - - Set the flag to print the task name before + running each task. + -s, --silent - - - - - - Set 'silent' to the log level of npm. + + Shorthand aliases can be combined. + For example, '-clns' equals to '-c -l -n -s'. + +Examples: + $ run-s build:** + $ run-s lint clean build:** + $ run-s --silent --print-name lint clean build:** + $ run-s -sn lint clean build:** + +See Also: + https://github.com/mysticatea/npm-run-all#readme +`) + + return Promise.resolve(null) +} diff --git a/node_modules/npm-run-all/bin/run-s/index.js b/node_modules/npm-run-all/bin/run-s/index.js new file mode 100755 index 0000000..f3cf012 --- /dev/null +++ b/node_modules/npm-run-all/bin/run-s/index.js @@ -0,0 +1,13 @@ +#!/usr/bin/env node +/** + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Main +//------------------------------------------------------------------------------ + +require("../common/bootstrap")("run-s") diff --git a/node_modules/npm-run-all/bin/run-s/main.js b/node_modules/npm-run-all/bin/run-s/main.js new file mode 100644 index 0000000..d1bd6da --- /dev/null +++ b/node_modules/npm-run-all/bin/run-s/main.js @@ -0,0 +1,71 @@ +/** + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const runAll = require("../../lib") +const parseCLIArgs = require("../common/parse-cli-args") + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Parses arguments, then run specified npm-scripts. + * + * @param {string[]} args - Arguments to parse. + * @param {stream.Writable} stdout - A writable stream to print logs. + * @param {stream.Writable} stderr - A writable stream to print errors. + * @returns {Promise} A promise which comes to be fulfilled when all npm-scripts are completed. + * @private + */ +module.exports = function npmRunAll(args, stdout, stderr) { + try { + const stdin = process.stdin + const argv = parseCLIArgs(args, { parallel: false }, { singleMode: true }) + const group = argv.lastGroup + + if (group.patterns.length === 0) { + return Promise.resolve(null) + } + + const promise = runAll( + group.patterns, + { + stdout, + stderr, + stdin, + parallel: group.parallel, + continueOnError: argv.continueOnError, + printLabel: argv.printLabel, + printName: argv.printName, + config: argv.config, + packageConfig: argv.packageConfig, + silent: argv.silent, + arguments: argv.rest, + npmPath: argv.npmPath, + } + ) + + if (!argv.silent) { + promise.catch(err => { + //eslint-disable-next-line no-console + console.error("ERROR:", err.message) + }) + } + + return promise + } + catch (err) { + //eslint-disable-next-line no-console + console.error("ERROR:", err.message) + + return Promise.reject(err) + } +} diff --git a/node_modules/npm-run-all/docs/node-api.md b/node_modules/npm-run-all/docs/node-api.md new file mode 100644 index 0000000..37530e1 --- /dev/null +++ b/node_modules/npm-run-all/docs/node-api.md @@ -0,0 +1,117 @@ +| [index](../README.md) | [npm-run-all](npm-run-all.md) | [run-s](run-s.md) | [run-p](run-p.md) | Node API | +|-----------------------|-------------------------------|-------------------|-------------------|----------| + +# Node API + +A Node module to run given npm-scripts in parallel or sequential. + +```js +const runAll = require("npm-run-all"); + +runAll(["clean", "lint", "build:*"], {parallel: false}) + .then(() => { + console.log("done!"); + }) + .catch(err => { + console.log("failed!"); + }); + +runAll(["build:* -- --watch"], {parallel: true}) + .then(() => { + console.log("done!"); + }) + .catch(err => { + console.log("failed!"); + }); +``` + +## runAll + +``` +let promise = runAll(patterns, options); +``` + +Run npm-scripts. + +- **patterns** `string|string[]` -- Glob-like patterns for script names. +- **options** `object` + - **options.aggregateOutput** `boolean` -- + The flag to avoid interleaving output by delaying printing of each command's output until it has finished. + This option is valid only with `options.parallel` option. + Default is `false`. + - **options.arguments** `string[]` -- + An argument list to replace argument placeholders (such as `{1}`, `{2}`). If pattern text has `{1}`, it's replaced by `options.arguments[0]`. + Default is an empty array. + - **options.continueOnError** `boolean` -- + The flag to continue executing other/subsequent scripts even if a script threw an error. + Returned `Promise` object will be rejected if one or more scripts threw error(s). + Default is `false`. + - **options.parallel** `boolean` -- + The flag to run scripts in parallel. + Default is `false`. + - **options.maxParallel** `number` -- + The maximum number of parallelism. + This option is valid only with `options.parallel` option. + Default is `Number.POSITIVE_INFINITY`. + - **options.npmPath** `string` -- + The path to npm. + Default is `process.env.npm_execpath` or `"npm"`. + - **options.packageConfig** `object|null` -- + The map-like object to overwrite package configs. + Keys are package names. + Every value is a map-like object (Pairs of variable name and value). + e.g. `{"npm-run-all": {"test": 777, "test2": 333}}` + Default is `null`. + - **options.printLabel** `boolean` -- + Set the flag to print the task name as a prefix on each line of output. + Tools in scripts may stop coloring their output if this option is given. + Default is `false`. + - **options.printName** `boolean` -- + Set the flag to print the task name before running each task. + Default is `false`. + - **options.race** `boolean` -- + Set the flag to kill all npm-scripts when a npm-script finished with zero. + This option is valid only with `options.parallel` option. + Default is `false`. + - **options.silent** `boolean` -- + The flag to set `silent` to the log level of npm. + Default is `false`. + - **options.stdin** `stream.Readable|null` -- + The readable stream to send to the stdin of npm-scripts. + Default is nothing. + Set `process.stdin` in order to send from stdin. + - **options.stdout** `stream.Writable|null` -- + The writable stream to receive from the stdout of npm-scripts. + Default is nothing. + Set `process.stdout` in order to print to stdout. + - **options.stderr** `stream.Writable|null` -- + The writable stream to receive from the stderr of npm-scripts + Default is nothing. + Set `process.stderr` in order to print to stderr. + - **options.taskList** `string[]|null` -- + The string array of all script names. + If this is `null`, it reads from `package.json` in the current directory. + Default is `null`. + +`runAll` returns a promise that will becomes *fulfilled* when all scripts are completed. +The promise will become *rejected* when any of the scripts exit with a non-zero code. + +The promise gives `results` to the fulfilled handler. +`results` is an array of objects which have 2 properties: `name` and `code`. +The `name` property is the name of a npm-script. +The `code` property is the exit code of the npm-script. If the npm-script was not executed, the `code` property is `undefined`. + +```js +runAll(["clean", "lint", "build"]) + .then(results => { + console.log(`${results[0].name}: ${results[0].code}`); // clean: 0 + console.log(`${results[1].name}: ${results[1].code}`); // lint: 0 + console.log(`${results[2].name}: ${results[2].code}`); // build: 0 + }); +``` + +## About MaxListenersExceededWarning + +- If you use `options.stdin`, `options.stdout`, or `options.stderr` in parallel mode, please configure max listeners by [emitter.setMaxListeners(n)](https://nodejs.org/api/events.html#events_emitter_setmaxlisteners_n) properly. +- If you don't use those options and `process.stdXXX.isTTY` is `false`, please configure max listeners of the `process.stdXXX` properly. In that case, `npm-run-all` uses piping to connect to child processes.
+ On the other hand, if `process.stdXXX.isTTY` is `true`, `npm-run-all` uses `inherit` option, so the configuration is unnecessary. diff --git a/node_modules/npm-run-all/docs/npm-run-all.md b/node_modules/npm-run-all/docs/npm-run-all.md new file mode 100644 index 0000000..c6f1aaa --- /dev/null +++ b/node_modules/npm-run-all/docs/npm-run-all.md @@ -0,0 +1,192 @@ +| [index](../README.md) | npm-run-all | [run-s](run-s.md) | [run-p](run-p.md) | [Node API](node-api.md) | +|-----------------------|-------------|-------------------|-------------------|-------------------------| + +# `npm-run-all` command + +``` +Usage: + $ npm-run-all [--help | -h | --version | -v] + $ npm-run-all [tasks] [OPTIONS] + + Run given npm-scripts in parallel or sequential. + + : A list of npm-scripts' names and Glob-like patterns. + +Options: + --aggregate-output - - - Avoid interleaving output by delaying printing of + each command's output until it has finished. + -c, --continue-on-error - Set the flag to continue executing + other/subsequent tasks even if a task threw an + error. 'npm-run-all' itself will exit with + non-zero code if one or more tasks threw error(s) + --max-parallel - Set the maximum number of parallelism. Default is + unlimited. + --npm-path - - - Set the path to npm. Default is the value of + environment variable npm_execpath. + If the variable is not defined, then it's "npm." + In this case, the "npm" command must be found in + environment variable PATH. + -l, --print-label - - - - Set the flag to print the task name as a prefix + on each line of output. Tools in tasks may stop + coloring their output if this option was given. + -n, --print-name - - - - Set the flag to print the task name before + running each task. + -p, --parallel - Run a group of tasks in parallel. + e.g. 'npm-run-all -p foo bar' is similar to + 'npm run foo & npm run bar'. + -r, --race - - - - - - - Set the flag to kill all tasks when a task + finished with zero. This option is valid only + with 'parallel' option. + -s, --sequential - Run a group of tasks sequentially. + --serial e.g. 'npm-run-all -s foo bar' is similar to + 'npm run foo && npm run bar'. + '--serial' is a synonym of '--sequential'. + --silent - - - - - - - - Set 'silent' to the log level of npm. + +Examples: + $ npm-run-all --serial clean lint build:** + $ npm-run-all --parallel watch:** + $ npm-run-all clean lint --parallel "build:** -- --watch" + $ npm-run-all -l -p start-server start-browser start-electron +``` + +### npm-scripts + +It's `"scripts"` field of `package.json`. +For example: + +```json +{ + "scripts": { + "clean": "rimraf dist", + "lint": "eslint src", + "build": "babel src -o lib" + } +} +``` + +We can run a script with `npm run` command. +On the other hand, this `npm-run-all` command runs multiple scripts in parallel or sequential. + +### Run scripts sequentially + +``` +$ npm-run-all clean lint build +``` + +This is same as `npm run clean && npm run lint && npm run build`. + +**Note:** If a script exited with non zero code, the following scripts are not run. +If `--continue-on-error` option is given, this behavior will be disabled. + +### Run scripts in parallel + +``` +$ npm-run-all --parallel lint build +``` + +This is similar to `npm run lint & npm run build`. + +**Note1:** If a script exited with a non-zero code, the other scripts and those descendant processes are killed with `SIGTERM` (On Windows, with `taskkill.exe /F /T`). +If `--continue-on-error` option is given, this behavior will be disabled. + +**Note2:** `&` operator does not work on Windows' `cmd.exe`. But `npm-run-all --parallel` works fine there. + +### Run a mix of sequential and parallel scripts + +``` +$ npm-run-all clean lint --parallel watch:html watch:js +``` + +1. First, this runs `clean` and `lint` sequentially / serially. +2. Next, runs `watch:html` and `watch:js` in parallel. + +``` +$ npm-run-all a b --parallel c d --sequential e f --parallel g h i +``` +or + +``` +$ npm-run-all a b --parallel c d --serial e f --parallel g h i +``` + +1. First, runs `a` and `b` sequentially / serially. +2. Second, runs `c` and `d` in parallel. +3. Third, runs `e` and `f` sequentially / serially. +4. Lastly, runs `g`, `h`, and `i` in parallel. + +### Glob-like pattern matching for script names + +We can use [glob]-like patterns to specify npm-scripts. +The difference is one -- the separator is `:` instead of `/`. + +``` +$ npm-run-all --parallel watch:* +``` + +In this case, runs sub scripts of `watch`. For example: `watch:html`, `watch:js`. +But, doesn't run sub-sub scripts. For example: `watch:js:index`. + +``` +$ npm-run-all --parallel watch:** +``` + +If we use a globstar `**`, runs both sub scripts and sub-sub scripts. + +`npm-run-all` reads the actual npm-script list from `package.json` in the current directory, then filters the scripts by glob-like patterns, then runs those. + +### Run with arguments + +We can enclose a script name or a pattern in quotes to use arguments. +The following 2 commands are similar. + +``` +$ npm-run-all --parallel "build:* -- --watch" +$ npm run build:aaa -- --watch & npm run build:bbb -- --watch +``` + +When we use a pattern, arguments are forwarded to every matched script. + +### Argument placeholders + +We can use placeholders to give the arguments preceded by `--` to scripts. + +``` +$ npm-run-all build "start-server -- --port {1}" -- 8080 +``` + +This is useful to pass through arguments from `npm run` command. + +```json +{ + "scripts": { + "start": "npm-run-all build \"start-server -- --port {1}\" --" + } +} +``` + +``` +$ npm run start 8080 + +> example@0.0.0 start /path/to/package.json +> npm-run-all build "start-server -- --port {1}" -- "8080" +``` + +There are the following placeholders: + +- `{1}`, `{2}`, ... -- An argument. `{1}` is the 1st argument. `{2}` is the 2nd. +- `{@}` -- All arguments. +- `{*}` -- All arguments as combined. + +Those are similar to [Shell Parameters](http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters). But please note arguments are enclosed by double quotes automatically (similar to npm). + +### Known Limitations + +- If `--print-label` option is given, some tools in scripts might stop coloring their output. + Because some coloring library (e.g. [chalk]) will stop coloring if `process.stdout` is not a TTY. + `npm-run-all` changes the `process.stdout` of child processes to a pipe in order to add labels to the head of each line if `--print-label` option is given.
+ For example, [eslint] stops coloring under `npm-run-all --print-label`. But [eslint] has `--color` option to force coloring, we can use it. For anything [chalk] based you can set the environment variable `FORCE_COLOR=1` to produce colored output anyway. + +[glob]: https://www.npmjs.com/package/glob#glob-primer +[chalk]: https://www.npmjs.com/package/chalk +[eslint]: https://www.npmjs.com/package/eslint diff --git a/node_modules/npm-run-all/docs/run-p.md b/node_modules/npm-run-all/docs/run-p.md new file mode 100644 index 0000000..ce9d309 --- /dev/null +++ b/node_modules/npm-run-all/docs/run-p.md @@ -0,0 +1,156 @@ +| [index](../README.md) | [npm-run-all](npm-run-all.md) | [run-s](run-s.md) | run-p | [Node API](node-api.md) | +|-----------------------|-------------------------------|-------------------|-------|-------------------------| + +# `run-p` command + +A CLI command to run given npm-scripts in parallel. +This command is the shorthand of `npm-run-all -p`. + +``` +Usage: + $ run-p [--help | -h | --version | -v] + $ run-p [OPTIONS] + + Run given npm-scripts in parallel. + + : A list of npm-scripts' names and Glob-like patterns. + +Options: + --aggregate-output - - - Avoid interleaving output by delaying printing of + each command's output until it has finished. + -c, --continue-on-error - Set the flag to continue executing other tasks + even if a task threw an error. 'run-p' itself + will exit with non-zero code if one or more tasks + threw error(s). + --max-parallel - Set the maximum number of parallelism. Default is + unlimited. + --npm-path - - - Set the path to npm. Default is the value of + environment variable npm_execpath. + If the variable is not defined, then it's "npm." + In this case, the "npm" command must be found in + environment variable PATH. + -l, --print-label - - - - Set the flag to print the task name as a prefix + on each line of output. Tools in tasks may stop + coloring their output if this option was given. + -n, --print-name - - - - Set the flag to print the task name before + running each task. + -r, --race - - - - - - - Set the flag to kill all tasks when a task + finished with zero. + -s, --silent - - - - - - Set 'silent' to the log level of npm. + + Shorthand aliases can be combined. + For example, '-clns' equals to '-c -l -n -s'. + +Examples: + $ run-p watch:** + $ run-p --print-label "build:** -- --watch" + $ run-p -l "build:** -- --watch" + $ run-p start-server start-browser start-electron +``` + +### npm-scripts + +It's `"scripts"` field of `package.json`. +For example: + +```json +{ + "scripts": { + "clean": "rimraf dist", + "lint": "eslint src", + "build": "babel src -o lib" + } +} +``` + +We can run a script with `npm run` command. +On the other hand, this `run-p` command runs multiple scripts in parallel. + +The following 2 commands are similar. +The `run-p` command is shorter and **available on Windows**. + +``` +$ run-p lint build +$ npm run lint & npm run build +``` + +**Note1:** If a script exited with a non-zero code, the other scripts and those descendant processes are killed with `SIGTERM` (On Windows, with `taskkill.exe /F /T`). +If `--continue-on-error` option is given, this behavior will be disabled. + +**Note2:** `&` operator does not work on Windows' `cmd.exe`. But `run-p` works fine there. + +### Glob-like pattern matching for script names + +We can use [glob]-like patterns to specify npm-scripts. +The difference is one -- the separator is `:` instead of `/`. + +``` +$ run-p watch:* +``` + +In this case, runs sub scripts of `watch`. For example: `watch:html`, `watch:js`. +But, doesn't run sub-sub scripts. For example: `watch:js:index`. + +``` +$ run-p watch:** +``` + +If we use a globstar `**`, runs both sub scripts and sub-sub scripts. + +`run-p` reads the actual npm-script list from `package.json` in the current directory, then filters the scripts by glob-like patterns, then runs those. + +### Run with arguments + +We can enclose a script name or a pattern in quotes to use arguments. +The following 2 commands are similar. + +``` +$ run-p "build:* -- --watch" +$ npm run build:aaa -- --watch & npm run build:bbb -- --watch +``` + +When we use a pattern, arguments are forwarded to every matched script. + +### Argument placeholders + +We can use placeholders to give the arguments preceded by `--` to scripts. + +``` +$ run-p "start-server -- --port {1}" -- 8080 +``` + +This is useful to pass through arguments from `npm run` command. + +```json +{ + "scripts": { + "start": "run-p \"start-server -- --port {1}\" --" + } +} +``` + +``` +$ npm run start 8080 + +> example@0.0.0 start /path/to/package.json +> run-p "start-server -- --port {1}" -- "8080" +``` + +There are the following placeholders: + +- `{1}`, `{2}`, ... -- An argument. `{1}` is the 1st argument. `{2}` is the 2nd. +- `{@}` -- All arguments. +- `{*}` -- All arguments as combined. + +Those are similar to [Shell Parameters](http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters). But please note arguments are enclosed by double quotes automatically (similar to npm). + +### Known Limitations + +- If `--print-label` option is given, some tools in scripts might stop coloring their output. + Because some coloring library (e.g. [chalk]) will stop coloring if `process.stdout` is not a TTY. + `run-p` changes the `process.stdout` of child processes to a pipe in order to add labels to the head of each line if `--print-label` option is given.
+ For example, [eslint] stops coloring under `run-p --print-label`. But [eslint] has `--color` option to force coloring, we can use it. + +[glob]: https://www.npmjs.com/package/glob#glob-primer +[chalk]: https://www.npmjs.com/package/chalk +[eslint]: https://www.npmjs.com/package/eslint diff --git a/node_modules/npm-run-all/docs/run-s.md b/node_modules/npm-run-all/docs/run-s.md new file mode 100644 index 0000000..cf62681 --- /dev/null +++ b/node_modules/npm-run-all/docs/run-s.md @@ -0,0 +1,147 @@ +| [index](../README.md) | [npm-run-all](npm-run-all.md) | run-s | [run-p](run-p.md) | [Node API](node-api.md) | +|-----------------------|-------------------------------|-------|-------------------|-------------------------| + +# `run-s` command + +A CLI command to run given npm-scripts sequentially. +This command is the shorthand of `npm-run-all -s`. + +``` +Usage: + $ run-s [--help | -h | --version | -v] + $ run-s [OPTIONS] + + Run given npm-scripts sequentially. + + : A list of npm-scripts' names and Glob-like patterns. + +Options: + -c, --continue-on-error - Set the flag to continue executing subsequent + tasks even if a task threw an error. 'run-s' + itself will exit with non-zero code if one or + more tasks threw error(s). + --npm-path - - - Set the path to npm. Default is the value of + environment variable npm_execpath. + If the variable is not defined, then it's "npm." + In this case, the "npm" command must be found in + environment variable PATH. + -l, --print-label - - - - Set the flag to print the task name as a prefix + on each line of output. Tools in tasks may stop + coloring their output if this option was given. + -n, --print-name - - - - Set the flag to print the task name before + running each task. + -s, --silent - - - - - - Set 'silent' to the log level of npm. + + Shorthand aliases can be combined. + For example, '-clns' equals to '-c -l -n -s'. + +Examples: + $ run-s build:** + $ run-s lint clean build:** + $ run-s --silent --print-name lint clean build:** + $ run-s -sn lint clean build:** +``` + +### npm-scripts + +It's `"scripts"` field of `package.json`. +For example: + +```json +{ + "scripts": { + "clean": "rimraf dist", + "lint": "eslint src", + "build": "babel src -o lib" + } +} +``` + +We can run a script with `npm run` command. +On the other hand, this `run-s` command runs multiple scripts sequentially. + +The following 2 commands are the same. +The `run-s` command is shorter. + +``` +$ run-s clean lint build +$ npm run clean && npm run lint && npm run build +``` + +**Note:** If a script exited with a non-zero code, the following scripts are not run. + +### Glob-like pattern matching for script names + +We can use [glob]-like patterns to specify npm-scripts. +The difference is one -- the separator is `:` instead of `/`. + +``` +$ run-s build:* +``` + +In this case, runs sub scripts of `build`. For example: `build:html`, `build:js`. +But, doesn't run sub-sub scripts. For example: `build:js:index`. + +``` +$ run-s build:** +``` + +If we use a globstar `**`, runs both sub scripts and sub-sub scripts. + +`run-s` reads the actual npm-script list from `package.json` in the current directory, then filters the scripts by glob-like patterns, then runs those. + +### Run with arguments + +We can enclose a script name or a pattern in quotes to use arguments. +The following 2 commands are the same. + +``` +$ run-s start:server "delay 3000" start:client +$ npm run start:server && npm run delay 3000 && npm run start:client +``` + +When we use a pattern, arguments are forwarded to every matched script. + +### Argument placeholders + +We can use placeholders to give the arguments preceded by `--` to scripts. + +``` +$ run-s build "start-server -- --port {1}" -- 8080 +``` + +This is useful to pass through arguments from `npm run` command. + +```json +{ + "scripts": { + "start": "run-s build \"start-server -- --port {1}\" --" + } +} +``` + +``` +$ npm run start 8080 + +> example@0.0.0 start /path/to/package.json +> run-s build "start-server -- --port {1}" -- "8080" +``` + +There are the following placeholders: + +- `{1}`, `{2}`, ... -- An argument. `{1}` is the 1st argument. `{2}` is the 2nd. +- `{@}` -- All arguments. +- `{*}` -- All arguments as combined. + +Those are similar to [Shell Parameters](http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters). But please note arguments are enclosed by double quotes automatically (similar to npm). + +### Known Limitations + +- If `--print-label` option is given, some tools in scripts might stop coloring their output. + Because some coloring library (e.g. [chalk]) will stop coloring if `process.stdout` is not a TTY. + `run-s` changes the `process.stdout` of child processes to a pipe in order to add labels to the head of each line if `--print-label` option is given.
+ For example, [eslint] stops coloring under `run-s --print-label`. But [eslint] has `--color` option to force coloring, we can use it. + +[glob]: https://www.npmjs.com/package/glob#glob-primer +[chalk]: https://www.npmjs.com/package/chalk +[eslint]: https://www.npmjs.com/package/eslint diff --git a/node_modules/npm-run-all/lib/create-header.js b/node_modules/npm-run-all/lib/create-header.js new file mode 100644 index 0000000..cdf52df --- /dev/null +++ b/node_modules/npm-run-all/lib/create-header.js @@ -0,0 +1,48 @@ +/** + * @module create-header + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const ansiStyles = require("ansi-styles") + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Creates the header text for a given task. + * + * @param {string} nameAndArgs - A task name and arguments. + * @param {object} packageInfo - A package.json's information. + * @param {object} packageInfo.body - A package.json's JSON object. + * @param {string} packageInfo.path - A package.json's file path. + * @param {boolean} isTTY - The flag to color the header. + * @returns {string} The header of a given task. + */ +module.exports = function createHeader(nameAndArgs, packageInfo, isTTY) { + if (!packageInfo) { + return `\n> ${nameAndArgs}\n\n` + } + + const index = nameAndArgs.indexOf(" ") + const name = (index === -1) ? nameAndArgs : nameAndArgs.slice(0, index) + const args = (index === -1) ? "" : nameAndArgs.slice(index + 1) + const packageName = packageInfo.body.name + const packageVersion = packageInfo.body.version + const scriptBody = packageInfo.body.scripts[name] + const packagePath = packageInfo.path + const color = isTTY ? ansiStyles.gray : { open: "", close: "" } + + return ` +${color.open}> ${packageName}@${packageVersion} ${name} ${packagePath}${color.close} +${color.open}> ${scriptBody} ${args}${color.close} + +` +} diff --git a/node_modules/npm-run-all/lib/create-prefix-transform-stream.js b/node_modules/npm-run-all/lib/create-prefix-transform-stream.js new file mode 100644 index 0000000..cb2c360 --- /dev/null +++ b/node_modules/npm-run-all/lib/create-prefix-transform-stream.js @@ -0,0 +1,89 @@ +/** + * @module create-prefix-transform-stream + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const stream = require("stream") + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +const ALL_BR = /\n/g + +/** + * The transform stream to insert a specific prefix. + * + * Several streams can exist for the same output stream. + * This stream will insert the prefix if the last output came from other instance. + * To do that, this stream is using a shared state object. + * + * @private + */ +class PrefixTransform extends stream.Transform { + /** + * @param {string} prefix - A prefix text to be inserted. + * @param {object} state - A state object. + * @param {string} state.lastPrefix - The last prefix which is printed. + * @param {boolean} state.lastIsLinebreak -The flag to check whether the last output is a line break or not. + */ + constructor(prefix, state) { + super() + + this.prefix = prefix + this.state = state + } + + /** + * Transforms the output chunk. + * + * @param {string|Buffer} chunk - A chunk to be transformed. + * @param {string} _encoding - The encoding of the chunk. + * @param {function} callback - A callback function that is called when done. + * @returns {void} + */ + _transform(chunk, _encoding, callback) { + const prefix = this.prefix + const nPrefix = `\n${prefix}` + const state = this.state + const firstPrefix = + state.lastIsLinebreak ? prefix : + (state.lastPrefix !== prefix) ? "\n" : + /* otherwise */ "" + const prefixed = `${firstPrefix}${chunk}`.replace(ALL_BR, nPrefix) + const index = prefixed.indexOf(prefix, Math.max(0, prefixed.length - prefix.length)) + + state.lastPrefix = prefix + state.lastIsLinebreak = (index !== -1) + + callback(null, (index !== -1) ? prefixed.slice(0, index) : prefixed) + } +} + +//------------------------------------------------------------------------------ +// Public API +//------------------------------------------------------------------------------ + +/** + * Create a transform stream to insert the specific prefix. + * + * Several streams can exist for the same output stream. + * This stream will insert the prefix if the last output came from other instance. + * To do that, this stream is using a shared state object. + * + * @param {string} prefix - A prefix text to be inserted. + * @param {object} state - A state object. + * @param {string} state.lastPrefix - The last prefix which is printed. + * @param {boolean} state.lastIsLinebreak -The flag to check whether the last output is a line break or not. + * @returns {stream.Transform} The created transform stream. + */ +module.exports = function createPrefixTransform(prefix, state) { + return new PrefixTransform(prefix, state) +} diff --git a/node_modules/npm-run-all/lib/index.js b/node_modules/npm-run-all/lib/index.js new file mode 100644 index 0000000..e36a605 --- /dev/null +++ b/node_modules/npm-run-all/lib/index.js @@ -0,0 +1,287 @@ +/** + * @module index + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const shellQuote = require("shell-quote") +const matchTasks = require("./match-tasks") +const readPackageJson = require("./read-package-json") +const runTasks = require("./run-tasks") + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +const ARGS_PATTERN = /\{(!)?([*@]|\d+)([^}]+)?}/g + +/** + * Converts a given value to an array. + * + * @param {string|string[]|null|undefined} x - A value to convert. + * @returns {string[]} An array. + */ +function toArray(x) { + if (x == null) { + return [] + } + return Array.isArray(x) ? x : [x] +} + +/** + * Replaces argument placeholders (such as `{1}`) by arguments. + * + * @param {string[]} patterns - Patterns to replace. + * @param {string[]} args - Arguments to replace. + * @returns {string[]} replaced + */ +function applyArguments(patterns, args) { + const defaults = Object.create(null) + + return patterns.map(pattern => pattern.replace(ARGS_PATTERN, (whole, indirectionMark, id, options) => { + if (indirectionMark != null) { + throw Error(`Invalid Placeholder: ${whole}`) + } + if (id === "@") { + return shellQuote.quote(args) + } + if (id === "*") { + return shellQuote.quote([args.join(" ")]) + } + + const position = parseInt(id, 10) + if (position >= 1 && position <= args.length) { + return shellQuote.quote([args[position - 1]]) + } + + // Address default values + if (options != null) { + const prefix = options.slice(0, 2) + + if (prefix === ":=") { + defaults[id] = shellQuote.quote([options.slice(2)]) + return defaults[id] + } + if (prefix === ":-") { + return shellQuote.quote([options.slice(2)]) + } + + throw Error(`Invalid Placeholder: ${whole}`) + } + if (defaults[id] != null) { + return defaults[id] + } + + return "" + })) +} + +/** + * Parse patterns. + * In parsing process, it replaces argument placeholders (such as `{1}`) by arguments. + * + * @param {string|string[]} patternOrPatterns - Patterns to run. + * A pattern is a npm-script name or a Glob-like pattern. + * @param {string[]} args - Arguments to replace placeholders. + * @returns {string[]} Parsed patterns. + */ +function parsePatterns(patternOrPatterns, args) { + const patterns = toArray(patternOrPatterns) + const hasPlaceholder = patterns.some(pattern => ARGS_PATTERN.test(pattern)) + + return hasPlaceholder ? applyArguments(patterns, args) : patterns +} + +/** + * Converts a given config object to an `--:=` style option array. + * + * @param {object|null} config - + * A map-like object to overwrite package configs. + * Keys are package names. + * Every value is a map-like object (Pairs of variable name and value). + * @returns {string[]} `--:=` style options. + */ +function toOverwriteOptions(config) { + const options = [] + + for (const packageName of Object.keys(config)) { + const packageConfig = config[packageName] + + for (const variableName of Object.keys(packageConfig)) { + const value = packageConfig[variableName] + + options.push(`--${packageName}:${variableName}=${value}`) + } + } + + return options +} + +/** + * Converts a given config object to an `--a=b` style option array. + * + * @param {object|null} config - + * A map-like object to set configs. + * @returns {string[]} `--a=b` style options. + */ +function toConfigOptions(config) { + return Object.keys(config).map(key => `--${key}=${config[key]}`) +} + +/** + * Gets the maximum length. + * + * @param {number} length - The current maximum length. + * @param {string} name - A name. + * @returns {number} The maximum length. + */ +function maxLength(length, name) { + return Math.max(name.length, length) +} + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Runs npm-scripts which are matched with given patterns. + * + * @param {string|string[]} patternOrPatterns - Patterns to run. + * A pattern is a npm-script name or a Glob-like pattern. + * @param {object|undefined} [options] Optional. + * @param {boolean} options.parallel - + * If this is `true`, run scripts in parallel. + * Otherwise, run scripts in sequencial. + * Default is `false`. + * @param {stream.Readable|null} options.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. + * Default is `null`. + * @param {stream.Writable|null} options.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. + * Default is `null`. + * @param {stream.Writable|null} options.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. + * Default is `null`. + * @param {string[]} options.taskList - + * Actual name list of npm-scripts. + * This function search npm-script names in this list. + * If this is `null`, this function reads `package.json` of current directly. + * @param {object|null} options.packageConfig - + * A map-like object to overwrite package configs. + * Keys are package names. + * Every value is a map-like object (Pairs of variable name and value). + * e.g. `{"npm-run-all": {"test": 777}}` + * Default is `null`. + * @param {boolean} options.silent - + * The flag to set `silent` to the log level of npm. + * Default is `false`. + * @param {boolean} options.continueOnError - + * The flag to ignore errors. + * Default is `false`. + * @param {boolean} options.printLabel - + * The flag to print task names at the head of each line. + * Default is `false`. + * @param {boolean} options.printName - + * The flag to print task names before running each task. + * Default is `false`. + * @param {number} options.maxParallel - + * The maximum number of parallelism. + * Default is unlimited. + * @param {string} options.npmPath - + * The path to npm. + * Default is `process.env.npm_execpath`. + * @returns {Promise} + * A promise object which becomes fullfilled when all npm-scripts are completed. + */ +module.exports = function npmRunAll(patternOrPatterns, options) { //eslint-disable-line complexity + const stdin = (options && options.stdin) || null + const stdout = (options && options.stdout) || null + const stderr = (options && options.stderr) || null + const taskList = (options && options.taskList) || null + const config = (options && options.config) || null + const packageConfig = (options && options.packageConfig) || null + const args = (options && options.arguments) || [] + const parallel = Boolean(options && options.parallel) + const silent = Boolean(options && options.silent) + const continueOnError = Boolean(options && options.continueOnError) + const printLabel = Boolean(options && options.printLabel) + const printName = Boolean(options && options.printName) + const race = Boolean(options && options.race) + const maxParallel = parallel ? ((options && options.maxParallel) || 0) : 1 + const aggregateOutput = Boolean(options && options.aggregateOutput) + const npmPath = options && options.npmPath + try { + const patterns = parsePatterns(patternOrPatterns, args) + if (patterns.length === 0) { + return Promise.resolve(null) + } + if (taskList != null && Array.isArray(taskList) === false) { + throw new Error("Invalid options.taskList") + } + if (typeof maxParallel !== "number" || !(maxParallel >= 0)) { + throw new Error("Invalid options.maxParallel") + } + if (!parallel && aggregateOutput) { + throw new Error("Invalid options.aggregateOutput; It requires options.parallel") + } + if (!parallel && race) { + throw new Error("Invalid options.race; It requires options.parallel") + } + + const prefixOptions = [].concat( + silent ? ["--silent"] : [], + packageConfig ? toOverwriteOptions(packageConfig) : [], + config ? toConfigOptions(config) : [] + ) + + return Promise.resolve() + .then(() => { + if (taskList != null) { + return { taskList, packageInfo: null } + } + return readPackageJson() + }) + .then(x => { + const tasks = matchTasks(x.taskList, patterns) + const labelWidth = tasks.reduce(maxLength, 0) + + return runTasks(tasks, { + stdin, + stdout, + stderr, + prefixOptions, + continueOnError, + labelState: { + enabled: printLabel, + width: labelWidth, + lastPrefix: null, + lastIsLinebreak: true, + }, + printName, + packageInfo: x.packageInfo, + race, + maxParallel, + npmPath, + aggregateOutput, + }) + }) + } + catch (err) { + return Promise.reject(new Error(err.message)) + } +} diff --git a/node_modules/npm-run-all/lib/match-tasks.js b/node_modules/npm-run-all/lib/match-tasks.js new file mode 100644 index 0000000..e3adb95 --- /dev/null +++ b/node_modules/npm-run-all/lib/match-tasks.js @@ -0,0 +1,128 @@ +/** + * @module match-tasks + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const Minimatch = require("minimatch").Minimatch + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +const COLON_OR_SLASH = /[:/]/g +const CONVERT_MAP = { ":": "/", "/": ":" } + +/** + * Swaps ":" and "/", in order to use ":" as the separator in minimatch. + * + * @param {string} s - A text to swap. + * @returns {string} The text which was swapped. + */ +function swapColonAndSlash(s) { + return s.replace(COLON_OR_SLASH, (matched) => CONVERT_MAP[matched]) +} + +/** + * Creates a filter from user-specified pattern text. + * + * The task name is the part until the first space. + * The rest part is the arguments for this task. + * + * @param {string} pattern - A pattern to create filter. + * @returns {{match: function, task: string, args: string}} The filter object of the pattern. + */ +function createFilter(pattern) { + const trimmed = pattern.trim() + const spacePos = trimmed.indexOf(" ") + const task = spacePos < 0 ? trimmed : trimmed.slice(0, spacePos) + const args = spacePos < 0 ? "" : trimmed.slice(spacePos) + const matcher = new Minimatch(swapColonAndSlash(task), { nonegate: true }) + const match = matcher.match.bind(matcher) + + return { match, task, args } +} + +/** + * The set to remove overlapped task. + */ +class TaskSet { + /** + * Creates a instance. + */ + constructor() { + this.result = [] + this.sourceMap = Object.create(null) + } + + /** + * Adds a command (a pattern) into this set if it's not overlapped. + * "Overlapped" is meaning that the command was added from a different source. + * + * @param {string} command - A pattern text to add. + * @param {string} source - A task name to check. + * @returns {void} + */ + add(command, source) { + const sourceList = this.sourceMap[command] || (this.sourceMap[command] = []) + if (sourceList.length === 0 || sourceList.indexOf(source) !== -1) { + this.result.push(command) + } + sourceList.push(source) + } +} + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Enumerates tasks which matches with given patterns. + * + * @param {string[]} taskList - A list of actual task names. + * @param {string[]} patterns - Pattern texts to match. + * @returns {string[]} Tasks which matches with the patterns. + * @private + */ +module.exports = function matchTasks(taskList, patterns) { + const filters = patterns.map(createFilter) + const candidates = taskList.map(swapColonAndSlash) + const taskSet = new TaskSet() + const unknownSet = Object.create(null) + + // Take tasks while keep the order of patterns. + for (const filter of filters) { + let found = false + + for (const candidate of candidates) { + if (filter.match(candidate)) { + found = true + taskSet.add( + swapColonAndSlash(candidate) + filter.args, + filter.task + ) + } + } + + // Built-in tasks should be allowed. + if (!found && (filter.task === "restart" || filter.task === "env")) { + taskSet.add(filter.task + filter.args, filter.task) + found = true + } + if (!found) { + unknownSet[filter.task] = true + } + } + + const unknownTasks = Object.keys(unknownSet) + if (unknownTasks.length > 0) { + throw new Error(`Task not found: "${unknownTasks.join("\", ")}"`) + } + return taskSet.result +} diff --git a/node_modules/npm-run-all/lib/npm-run-all-error.js b/node_modules/npm-run-all/lib/npm-run-all-error.js new file mode 100644 index 0000000..af08b09 --- /dev/null +++ b/node_modules/npm-run-all/lib/npm-run-all-error.js @@ -0,0 +1,47 @@ +/** + * @module npm-run-all-error + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Error object with some additional info. + */ +module.exports = class NpmRunAllError extends Error { + /** + * Constructor. + * + * @param {{name: string, code: number}} causeResult - + * The result item of the npm-script which causes an error. + * @param {Array.<{name: string, code: (number|undefined)}>} allResults - + * All result items of npm-scripts. + */ + constructor(causeResult, allResults) { + super(`"${causeResult.task}" exited with ${causeResult.code}.`) + + /** + * The name of a npm-script which exited with a non-zero code. + * @type {string} + */ + this.name = causeResult.name + + /** + * The code of a npm-script which exited with a non-zero code. + * This can be `undefined`. + * @type {number} + */ + this.code = causeResult.code + + /** + * All result items of npm-scripts. + * @type {Array.<{name: string, code: (number|undefined)}>} + */ + this.results = allResults + } +} diff --git a/node_modules/npm-run-all/lib/read-package-json.js b/node_modules/npm-run-all/lib/read-package-json.js new file mode 100644 index 0000000..1497ebf --- /dev/null +++ b/node_modules/npm-run-all/lib/read-package-json.js @@ -0,0 +1,31 @@ +/** + * @module read-package-json + * @author Toru Nagashima + * @copyright 2016 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const joinPath = require("path").join +const readPkg = require("read-pkg") + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Reads the package.json in the current directory. + * + * @returns {object} package.json's information. + */ +module.exports = function readPackageJson() { + const path = joinPath(process.cwd(), "package.json") + return readPkg(path).then(body => ({ + taskList: Object.keys(body.scripts || {}), + packageInfo: { path, body }, + })) +} diff --git a/node_modules/npm-run-all/lib/run-task.js b/node_modules/npm-run-all/lib/run-task.js new file mode 100644 index 0000000..8cabc03 --- /dev/null +++ b/node_modules/npm-run-all/lib/run-task.js @@ -0,0 +1,206 @@ +/** + * @module run-task + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const path = require("path") +const chalk = require("chalk") +const parseArgs = require("shell-quote").parse +const padEnd = require("string.prototype.padend") +const createHeader = require("./create-header") +const createPrefixTransform = require("./create-prefix-transform-stream") +const spawn = require("./spawn") + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +const colors = [chalk.cyan, chalk.green, chalk.magenta, chalk.yellow, chalk.red] + +let colorIndex = 0 +const taskNamesToColors = new Map() + +/** + * Select a color from given task name. + * + * @param {string} taskName - The task name. + * @returns {function} A colorize function that provided by `chalk` + */ +function selectColor(taskName) { + let color = taskNamesToColors.get(taskName) + if (!color) { + color = colors[colorIndex] + colorIndex = (colorIndex + 1) % colors.length + taskNamesToColors.set(taskName, color) + } + return color +} + +/** + * Wraps stdout/stderr with a transform stream to add the task name as prefix. + * + * @param {string} taskName - The task name. + * @param {stream.Writable} source - An output stream to be wrapped. + * @param {object} labelState - An label state for the transform stream. + * @returns {stream.Writable} `source` or the created wrapped stream. + */ +function wrapLabeling(taskName, source, labelState) { + if (source == null || !labelState.enabled) { + return source + } + + const label = padEnd(taskName, labelState.width) + const color = source.isTTY ? selectColor(taskName) : (x) => x + const prefix = color(`[${label}] `) + const stream = createPrefixTransform(prefix, labelState) + + stream.pipe(source) + + return stream +} + +/** + * Converts a given stream to an option for `child_process.spawn`. + * + * @param {stream.Readable|stream.Writable|null} stream - An original stream to convert. + * @param {process.stdin|process.stdout|process.stderr} std - A standard stream for this option. + * @returns {string|stream.Readable|stream.Writable} An option for `child_process.spawn`. + */ +function detectStreamKind(stream, std) { + return ( + stream == null ? "ignore" : + // `|| !std.isTTY` is needed for the workaround of https://github.com/nodejs/node/issues/5620 + stream !== std || !std.isTTY ? "pipe" : + /* else */ stream + ) +} + +/** + * Ensure the output of shell-quote's `parse()` is acceptable input to npm-cli. + * + * The `parse()` method of shell-quote sometimes returns special objects in its + * output array, e.g. if it thinks some elements should be globbed. But npm-cli + * only accepts strings and will throw an error otherwise. + * + * See https://github.com/substack/node-shell-quote#parsecmd-env + * + * @param {object|string} arg - Item in the output of shell-quote's `parse()`. + * @returns {string} A valid argument for npm-cli. + */ +function cleanTaskArg(arg) { + return arg.pattern || arg.op || arg +} + +//------------------------------------------------------------------------------ +// Interface +//------------------------------------------------------------------------------ + +/** + * Run a npm-script of a given name. + * The return value is a promise which has an extra method: `abort()`. + * The `abort()` kills the child process to run the npm-script. + * + * @param {string} task - A npm-script name to run. + * @param {object} options - An option object. + * @param {stream.Readable|null} options.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} options.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} options.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[]} options.prefixOptions - + * An array of options which are inserted before the task name. + * @param {object} options.labelState - A state object for printing labels. + * @param {boolean} options.printName - The flag to print task names before running each task. + * @returns {Promise} + * A promise object which becomes fullfilled when the npm-script is completed. + * This promise object has an extra method: `abort()`. + * @private + */ +module.exports = function runTask(task, options) { + let cp = null + const promise = new Promise((resolve, reject) => { + const stdin = options.stdin + const stdout = wrapLabeling(task, options.stdout, options.labelState) + const stderr = wrapLabeling(task, options.stderr, options.labelState) + const stdinKind = detectStreamKind(stdin, process.stdin) + const stdoutKind = detectStreamKind(stdout, process.stdout) + const stderrKind = detectStreamKind(stderr, process.stderr) + const spawnOptions = { stdio: [stdinKind, stdoutKind, stderrKind] } + + // Print task name. + if (options.printName && stdout != null) { + stdout.write(createHeader( + task, + options.packageInfo, + options.stdout.isTTY + )) + } + + // Execute. + const npmPath = options.npmPath || process.env.npm_execpath //eslint-disable-line no-process-env + const npmPathIsJs = typeof npmPath === "string" && /\.m?js/.test(path.extname(npmPath)) + const execPath = (npmPathIsJs ? process.execPath : npmPath || "npm") + const isYarn = path.basename(npmPath || "npm").startsWith("yarn") + const spawnArgs = ["run"] + + if (npmPathIsJs) { + spawnArgs.unshift(npmPath) + } + if (!isYarn) { + Array.prototype.push.apply(spawnArgs, options.prefixOptions) + } + else if (options.prefixOptions.indexOf("--silent") !== -1) { + spawnArgs.push("--silent") + } + Array.prototype.push.apply(spawnArgs, parseArgs(task).map(cleanTaskArg)) + + cp = spawn(execPath, spawnArgs, spawnOptions) + + // Piping stdio. + if (stdinKind === "pipe") { + stdin.pipe(cp.stdin) + } + if (stdoutKind === "pipe") { + cp.stdout.pipe(stdout, { end: false }) + } + if (stderrKind === "pipe") { + cp.stderr.pipe(stderr, { end: false }) + } + + // Register + cp.on("error", (err) => { + cp = null + reject(err) + }) + cp.on("close", (code) => { + cp = null + resolve({ task, code }) + }) + }) + + promise.abort = function abort() { + if (cp != null) { + cp.kill() + cp = null + } + } + + return promise +} diff --git a/node_modules/npm-run-all/lib/run-tasks.js b/node_modules/npm-run-all/lib/run-tasks.js new file mode 100644 index 0000000..64a4506 --- /dev/null +++ b/node_modules/npm-run-all/lib/run-tasks.js @@ -0,0 +1,177 @@ +/** + * @module run-tasks-in-parallel + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const MemoryStream = require("memorystream") +const NpmRunAllError = require("./npm-run-all-error") +const runTask = require("./run-task") + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +/** + * Remove the given value from the array. + * @template T + * @param {T[]} array - The array to remove. + * @param {T} x - The item to be removed. + * @returns {void} + */ +function remove(array, x) { + const index = array.indexOf(x) + if (index !== -1) { + array.splice(index, 1) + } +} + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Run npm-scripts of given names in parallel. + * + * If a npm-script exited with a non-zero code, this aborts other all npm-scripts. + * + * @param {string} tasks - A list of npm-script name to run in parallel. + * @param {object} options - An option object. + * @returns {Promise} A promise object which becomes fullfilled when all npm-scripts are completed. + * @private + */ +module.exports = function runTasks(tasks, options) { + return new Promise((resolve, reject) => { + if (tasks.length === 0) { + resolve([]) + return + } + + const results = tasks.map(task => ({ name: task, code: undefined })) + const queue = tasks.map((task, index) => ({ name: task, index })) + const promises = [] + let error = null + let aborted = false + + /** + * Done. + * @returns {void} + */ + function done() { + if (error == null) { + resolve(results) + } + else { + reject(error) + } + } + + /** + * Aborts all tasks. + * @returns {void} + */ + function abort() { + if (aborted) { + return + } + aborted = true + + if (promises.length === 0) { + done() + } + else { + for (const p of promises) { + p.abort() + } + Promise.all(promises).then(done, reject) + } + } + + /** + * Runs a next task. + * @returns {void} + */ + function next() { + if (aborted) { + return + } + if (queue.length === 0) { + if (promises.length === 0) { + done() + } + return + } + + const originalOutputStream = options.stdout + const optionsClone = Object.assign({}, options) + const writer = new MemoryStream(null, { + readable: false, + }) + + if (options.aggregateOutput) { + optionsClone.stdout = writer + } + + const task = queue.shift() + const promise = runTask(task.name, optionsClone) + + promises.push(promise) + promise.then( + (result) => { + remove(promises, promise) + if (aborted) { + return + } + + if (options.aggregateOutput) { + originalOutputStream.write(writer.toString()) + } + + // Save the result. + results[task.index].code = result.code + + // Aborts all tasks if it's an error. + if (result.code) { + error = new NpmRunAllError(result, results) + if (!options.continueOnError) { + abort() + return + } + } + + // Aborts all tasks if options.race is true. + if (options.race && !result.code) { + abort() + return + } + + // Call the next task. + next() + }, + (thisError) => { + remove(promises, promise) + if (!options.continueOnError || options.race) { + error = thisError + abort() + return + } + next() + } + ) + } + + const max = options.maxParallel + const end = (typeof max === "number" && max > 0) + ? Math.min(tasks.length, max) + : tasks.length + for (let i = 0; i < end; ++i) { + next() + } + }) +} diff --git a/node_modules/npm-run-all/lib/spawn-posix.js b/node_modules/npm-run-all/lib/spawn-posix.js new file mode 100644 index 0000000..604bfef --- /dev/null +++ b/node_modules/npm-run-all/lib/spawn-posix.js @@ -0,0 +1,64 @@ +/** + * @module spawn-posix + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const crossSpawn = require("cross-spawn") +const getDescendentProcessInfo = require("pidtree") + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +/** + * Kills the new process and its sub processes. + * @this ChildProcess + * @returns {void} + */ +function kill() { + getDescendentProcessInfo(this.pid, { root: true }, (err, pids) => { + if (err) { + return + } + + for (const pid of pids) { + try { + process.kill(pid) + } + catch (_err) { + // ignore. + } + } + }) +} + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Launches a new process with the given command. + * This is almost same as `child_process.spawn`. + * + * This returns a `ChildProcess` instance. + * `kill` method of the instance kills the new process and its sub processes. + * + * @param {string} command - The command to run. + * @param {string[]} args - List of string arguments. + * @param {object} options - Options. + * @returns {ChildProcess} A ChildProcess instance of new process. + * @private + */ +module.exports = function spawn(command, args, options) { + const child = crossSpawn(command, args, options) + child.kill = kill + + return child +} diff --git a/node_modules/npm-run-all/lib/spawn-win32.js b/node_modules/npm-run-all/lib/spawn-win32.js new file mode 100644 index 0000000..3743a1d --- /dev/null +++ b/node_modules/npm-run-all/lib/spawn-win32.js @@ -0,0 +1,50 @@ +/** + * @module spawn-win32 + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Requirements +//------------------------------------------------------------------------------ + +const crossSpawn = require("cross-spawn") + +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +/** + * Kills the new process and its sub processes forcibly. + * @this ChildProcess + * @returns {void} + */ +function kill() { + crossSpawn("taskkill", ["/F", "/T", "/PID", this.pid]) +} + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Launches a new process with the given command. + * This is almost same as `child_process.spawn`. + * + * This returns a `ChildProcess` instance. + * `kill` method of the instance kills the new process and its sub processes forcibly. + * + * @param {string} command - The command to run. + * @param {string[]} args - List of string arguments. + * @param {object} options - Options. + * @returns {ChildProcess} A ChildProcess instance of new process. + * @private + */ +module.exports = function spawn(command, args, options) { + const child = crossSpawn(command, args, options) + child.kill = kill + + return child +} diff --git a/node_modules/npm-run-all/lib/spawn.js b/node_modules/npm-run-all/lib/spawn.js new file mode 100644 index 0000000..1392817 --- /dev/null +++ b/node_modules/npm-run-all/lib/spawn.js @@ -0,0 +1,20 @@ +/** + * @module spawn + * @author Toru Nagashima + * @copyright 2015 Toru Nagashima. All rights reserved. + * See LICENSE file in root directory for full license. + */ +"use strict" + +//------------------------------------------------------------------------------ +// Public Interface +//------------------------------------------------------------------------------ + +/** + * Launches a new process with the given command. + * This is {@link ./spawn-posix.js:spawn} or {@link ./spawn-win32.js:spawn} + * @private + */ +module.exports = require( + process.platform === "win32" ? "./spawn-win32" : "./spawn-posix" +) diff --git a/node_modules/npm-run-all/package.json b/node_modules/npm-run-all/package.json new file mode 100644 index 0000000..1862460 --- /dev/null +++ b/node_modules/npm-run-all/package.json @@ -0,0 +1,108 @@ +{ + "_from": "npm-run-all@^4.1.5", + "_id": "npm-run-all@4.1.5", + "_inBundle": false, + "_integrity": "sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==", + "_location": "/npm-run-all", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "npm-run-all@^4.1.5", + "name": "npm-run-all", + "escapedName": "npm-run-all", + "rawSpec": "^4.1.5", + "saveSpec": null, + "fetchSpec": "^4.1.5" + }, + "_requiredBy": [ + "/" + ], + "_resolved": "https://registry.npmjs.org/npm-run-all/-/npm-run-all-4.1.5.tgz", + "_shasum": "04476202a15ee0e2e214080861bff12a51d98fba", + "_spec": "npm-run-all@^4.1.5", + "_where": "/home/pruss/Dev/3-minute-website", + "author": { + "name": "Toru Nagashima" + }, + "bin": { + "run-p": "bin/run-p/index.js", + "run-s": "bin/run-s/index.js", + "npm-run-all": "bin/npm-run-all/index.js" + }, + "bugs": { + "url": "https://github.com/mysticatea/npm-run-all/issues" + }, + "bundleDependencies": false, + "dependencies": { + "ansi-styles": "^3.2.1", + "chalk": "^2.4.1", + "cross-spawn": "^6.0.5", + "memorystream": "^0.3.1", + "minimatch": "^3.0.4", + "pidtree": "^0.3.0", + "read-pkg": "^3.0.0", + "shell-quote": "^1.6.1", + "string.prototype.padend": "^3.0.0" + }, + "deprecated": false, + "description": "A CLI tool to run multiple npm-scripts in parallel or sequential.", + "devDependencies": { + "@types/node": "^4.9.1", + "babel-plugin-transform-async-to-generator": "^6.24.1", + "babel-preset-power-assert": "^2.0.0", + "babel-register": "^6.26.0", + "codecov": "^3.1.0", + "eslint": "^4.19.1", + "eslint-config-mysticatea": "^12.0.0", + "fs-extra": "^7.0.1", + "mocha": "^5.2.0", + "nyc": "^11.9.0", + "p-queue": "^2.4.2", + "power-assert": "^1.6.1", + "rimraf": "^2.6.2", + "yarn": "^1.12.3" + }, + "engines": { + "node": ">= 4" + }, + "files": [ + "bin", + "lib", + "docs" + ], + "homepage": "https://github.com/mysticatea/npm-run-all", + "keywords": [ + "cli", + "command", + "commandline", + "tool", + "npm", + "npm-scripts", + "run", + "sequential", + "serial", + "parallel", + "task" + ], + "license": "MIT", + "main": "lib/index.js", + "name": "npm-run-all", + "repository": { + "type": "git", + "url": "git+https://github.com/mysticatea/npm-run-all.git" + }, + "scripts": { + "_mocha": "mocha \"test/*.js\" --timeout 120000", + "clean": "rimraf .nyc_output coverage jsdoc \"test-workspace/{build,test.txt}\"", + "codecov": "nyc report -r lcovonly && codecov", + "docs": "jsdoc -c jsdoc.json", + "lint": "eslint bin lib scripts test \"test-workspace/tasks/*.js\"", + "postversion": "git push && git push --tags", + "pretest": "node scripts/make-slink.js && npm run lint", + "preversion": "npm test", + "test": "nyc --require babel-register npm run _mocha", + "watch": "npm run _mocha -- --require babel-register --watch --growl" + }, + "version": "4.1.5" +} -- cgit v1.2.3