cli-engine-command
Advanced tools
Comparing version 2.3.1 to 3.0.0
@@ -19,6 +19,4 @@ 'use strict'; | ||
var _config = require('./config'); | ||
var _cliEngineConfig = require('cli-engine-config'); | ||
var _config2 = _interopRequireDefault(_config); | ||
var _http = require('./http'); | ||
@@ -30,14 +28,4 @@ | ||
class Command extends _output2.default { | ||
constructor(...args) { | ||
var _temp; | ||
class Command { | ||
return _temp = super(...args), this.http = new _http2.default(this), this.flags = {}, _temp; | ||
} | ||
// static _flags: Flags = [ | ||
// {name: 'debug', hidden: true}, | ||
// {name: 'no-color', hidden: true} | ||
// ] | ||
static get id() { | ||
@@ -48,7 +36,6 @@ return this.command ? `${this.topic}:${this.command}` : this.topic; | ||
/** | ||
* instantiate and run the command setting {mock: true} in the config | ||
* instantiate and run the command setting {mock: true} in the config (shorthand method) | ||
*/ | ||
static async mock(argv = [], options = {}, ...rest) { | ||
options.mock = true; | ||
return this.run(argv, options); | ||
static async mock(...argv) { | ||
return this.run({ argv, mock: true }); | ||
} | ||
@@ -59,6 +46,7 @@ | ||
*/ | ||
static async run(argv = [], options = {}, ...rest) { | ||
let config = new _config2.default(options); | ||
let cmd = new this(config); | ||
cmd.argv = argv; | ||
static async run(options = {}) { | ||
let config = (0, _cliEngineConfig.buildConfig)(options.config); | ||
let output = options.output || new _output2.default({ mock: options.mock, config }); | ||
let cmd = new this({ config, output }); | ||
cmd.argv = options.argv || []; | ||
// if (this.flags.debug) this.config.debug = 1 | ||
@@ -68,6 +56,5 @@ try { | ||
await cmd.run(args); | ||
await cmd.done(); | ||
await cmd.out.done(); | ||
} catch (err) { | ||
if (config.mock) throw err; | ||
cmd.error(err); | ||
cmd.out.error(err); | ||
} | ||
@@ -77,2 +64,10 @@ return cmd; | ||
constructor(options = {}) { | ||
this.flags = {}; | ||
this.config = (0, _cliEngineConfig.buildConfig)(options.config); | ||
this.out = options.output || new _output2.default({ config: this.config }); | ||
this.http = new _http2.default(this.out); | ||
} | ||
async parse() { | ||
@@ -79,0 +74,0 @@ const parser = new _parser2.default({ |
@@ -15,2 +15,4 @@ 'use strict'; | ||
var _cliEngineConfig = require('cli-engine-config'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -37,8 +39,9 @@ | ||
constructor(output) { | ||
constructor(output, config) { | ||
let self = this; | ||
this.out = output; | ||
this.config = (0, _cliEngineConfig.buildConfig)(config || this.out.config); | ||
this.requestOptions = mergeRequestOptions({ | ||
headers: { | ||
'user-agent': `${this.out.config.name}/${this.out.config.version} node-${process.version}` | ||
'user-agent': `${this.config.name}/${this.config.version} node-${process.version}` | ||
} | ||
@@ -45,0 +48,0 @@ }); |
@@ -16,17 +16,2 @@ 'use strict'; | ||
var _config = require('./config'); | ||
Object.defineProperty(exports, 'Config', { | ||
enumerable: true, | ||
get: function () { | ||
return _interopRequireDefault(_config).default; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'ConfigOptions', { | ||
enumerable: true, | ||
get: function () { | ||
return _config.ConfigOptions; | ||
} | ||
}); | ||
var _topic = require('./topic'); | ||
@@ -33,0 +18,0 @@ |
@@ -33,3 +33,3 @@ 'use strict'; | ||
get displaySpinner() { | ||
return !this.out.config.mock && !this.out.config.debug && !!process.stdin.isTTY && !!process.stderr.isTTY && !process.env.CI && process.env.TERM !== 'dumb'; | ||
return !this.out.mock && !this.out.config.debug && !!process.stdin.isTTY && !!process.stderr.isTTY && !process.env.CI && process.env.TERM !== 'dumb'; | ||
} | ||
@@ -36,0 +36,0 @@ |
@@ -34,6 +34,4 @@ 'use strict'; | ||
var _config = require('../config'); | ||
var _cliEngineConfig = require('cli-engine-config'); | ||
var _config2 = _interopRequireDefault(_config); | ||
var _prettyFormat = require('pretty-format'); | ||
@@ -117,3 +115,3 @@ | ||
write(msg) { | ||
if (this.out.config.mock) this.output += msg;else this.stream.write(msg); | ||
if (this.out.mock) this.output += msg;else this.stream.write(msg); | ||
} | ||
@@ -125,3 +123,3 @@ | ||
this.out.action.pause(() => { | ||
if (this.out.config.mock) this.output += msg;else this.stream.write(msg); | ||
if (this.out.mock) this.output += msg;else this.stream.write(msg); | ||
}); | ||
@@ -132,8 +130,11 @@ } | ||
class Output { | ||
constructor(config) { | ||
this.config = config; | ||
constructor(options = {}) { | ||
this.mock = false; | ||
this.mock = options.mock; | ||
this.config = (0, _cliEngineConfig.buildConfig)(options.config); | ||
this.stdout = new StreamOutput(process.stdout, this); | ||
this.stderr = new StreamOutput(process.stderr, this); | ||
this.action = new _action2.default(this); | ||
if (config.mock) _chalk2.default.enabled = CustomColors.supports = false; | ||
if (this.mock) _chalk2.default.enabled = CustomColors.supports = false; | ||
} | ||
@@ -222,6 +223,7 @@ | ||
get errlog() { | ||
return _path2.default.join(this.config.dirs.cache, 'error.log'); | ||
return _path2.default.join(this.config.cacheDir, 'error.log'); | ||
} | ||
error(err, exitCode = 1) { | ||
if (this.mock && typeof err !== 'string') throw err; | ||
try { | ||
@@ -271,3 +273,3 @@ if (typeof err === 'string') err = new Error(err); | ||
if (this.config.debug) console.error(`Exiting with code: ${code}`); | ||
if (this.config.mock) throw new ExitError(code);else process.exit(code); | ||
if (this.mock) throw new ExitError(code);else process.exit(code); | ||
} | ||
@@ -274,0 +276,0 @@ |
{ | ||
"name": "cli-engine-command", | ||
"description": "base CLI command for cli-engine", | ||
"version": "2.3.1", | ||
"version": "3.0.0", | ||
"author": "Jeff Dickey @dickeyxxx", | ||
@@ -11,2 +11,3 @@ "bugs": "https://github.com/heroku/cli-engine-command/issues", | ||
"chalk": "^1.1.3", | ||
"cli-engine-config": "1.0.1", | ||
"fs-extra": "2.1.2", | ||
@@ -34,3 +35,3 @@ "got": "^6.7.1", | ||
"jest-junit": "1.4.0", | ||
"nock": "9.0.11", | ||
"nock": "9.0.13", | ||
"nodemon": "1.11.0", | ||
@@ -37,0 +38,0 @@ "rimraf": "2.6.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
10
135335
13
42
1983
+ Addedcli-engine-config@1.0.1
+ Addedcli-engine-config@1.0.1(transitive)