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

cli-engine-command

Package Overview
Dependencies
Maintainers
3
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-engine-command - npm Package Compare versions

Comparing version 9.0.3 to 10.0.0-ts.0

lib/color.d.ts

73

lib/color.js

@@ -1,45 +0,30 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const supports = require("supports-color");
const chalk_1 = require("chalk");
const ansiStyles = require("ansi-styles");
exports.CustomColors = {
supports,
// map gray -> dim because it's not solarized compatible
gray: chalk_1.default.dim,
grey: chalk_1.default.dim,
attachment: chalk_1.default.cyan,
addon: chalk_1.default.yellow,
configVar: chalk_1.default.green,
release: chalk_1.default.blue.bold,
cmd: chalk_1.default.cyan.bold,
app: (s) => exports.color.heroku(`⬢ ${s}`),
heroku: (s) => {
if (!exports.color.supports)
return s;
let has256 = exports.color.supports.has256 || (process.env.TERM || '').indexOf('256') !== -1;
return has256 ? '\u001b[38;5;104m' + s + ansiStyles.reset.open : chalk_1.default.magenta(s);
},
};
exports.color = new Proxy(chalk_1.default, {
get: (chalk, name) => {
if (exports.CustomColors[name])
return exports.CustomColors[name];
return chalk[name];
},
});
exports.color = exports.CustomColors = undefined;
var _supportsColor = require('supports-color');
var _supportsColor2 = _interopRequireDefault(_supportsColor);
var _chalk = require('chalk');
var _chalk2 = _interopRequireDefault(_chalk);
var _ansiStyles = require('ansi-styles');
var _ansiStyles2 = _interopRequireDefault(_ansiStyles);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const CustomColors = exports.CustomColors = {
supports: _supportsColor2.default,
// map gray -> dim because it's not solarized compatible
gray: s => _chalk2.default.dim(s),
grey: s => _chalk2.default.dim(s),
attachment: s => _chalk2.default.cyan(s),
addon: s => _chalk2.default.yellow(s),
configVar: s => _chalk2.default.green(s),
release: s => _chalk2.default.blue.bold(s),
cmd: s => _chalk2.default.cyan.bold(s),
app: s => CustomColors.heroku(`⬢ ${s}`),
heroku: s => {
if (!CustomColors.supports) return s;
let has256 = CustomColors.supports.has256 || (process.env.TERM || '').indexOf('256') !== -1;
return has256 ? '\u001b[38;5;104m' + s + _ansiStyles2.default.reset.open : _chalk2.default.magenta(s);
}
};
const color = exports.color = new Proxy(_chalk2.default, {
get: (chalk, name) => {
if (CustomColors[name]) return CustomColors[name];
return chalk[name];
}
});

@@ -1,119 +0,90 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _parser = require('./parser');
var _parser2 = _interopRequireDefault(_parser);
var _package = require('../package.json');
var _package2 = _interopRequireDefault(_package);
var _cliEngineConfig = require('cli-engine-config');
var _httpCall = require('http-call');
var _httpCall2 = _interopRequireDefault(_httpCall);
var _help = require('./help');
var _help2 = _interopRequireDefault(_help);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// eslint-disable-line
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// import Parser, { type OutputFlags, type OutputArgs, type InputFlags } from './parser' // eslint-disable-line
const pjson = require('../package.json');
const cli_engine_config_1 = require("cli-engine-config");
const http_call_1 = require("http-call");
const help_1 = require("./help");
const cli_flags_1 = require("cli-flags");
class Command {
static get id() {
let cmd = [];
if (this.topic) cmd.push(this.topic);
if (this.command) cmd.push(this.command);
return cmd.join(':');
}
/**
* instantiate and run the command setting {mock: true} in the config (shorthand method)
*/
static async mock(...argv) {
argv.unshift('argv0', 'cmd');
return this.run({ argv, mock: true });
}
/**
* instantiate and run the command
*/
static async run(config) {
const cmd = new this({ config });
try {
await cmd.init();
await cmd.run();
await cmd.out.done();
} catch (err) {
cmd.out.error(err);
constructor(options = {}) {
this.args = {};
this.config = cli_engine_config_1.buildConfig(options.config);
this.argv = this.config.argv;
const { cli } = require('cli-ux');
this.out = this.cli = cli;
this.out.color = require('./color').color;
this.http = http_call_1.HTTP.defaults({
headers: {
'user-agent': `${this.config.name}/${this.config.version} (${this.config.platform}-${this.config.arch}) node-${process.version}`,
},
});
}
return cmd;
}
constructor(options = {}) {
this.flags = {};
this.args = {};
this.config = (0, _cliEngineConfig.buildConfig)(options.config);
this.argv = this.config.argv;
const { cli } = require('cli-ux');
this.out = this.cli = cli;
this.out.color = require('./color').color;
this.http = _httpCall2.default.defaults({
headers: {
'user-agent': `${this.config.name}/${this.config.version} (${this.config.platform}-${this.config.arch}) node-${process.version}`
}
});
}
async init() {
const parser = new _parser2.default({
flags: this.constructor.flags || {},
args: this.constructor.args || [],
variableArgs: this.constructor.variableArgs,
cmd: this
});
const { argv, flags, args } = await parser.parse({ flags: this.flags, argv: this.argv.slice(2) });
this.flags = flags;
this.argv = argv;
this.args = args;
}
// prevent setting things that need to be static
/**
* actual command run code goes here
*/
async run(...rest) {}
get stdout() {
return this.out.stdout.output;
}
get stderr() {
return this.out.stderr.output;
}
static buildHelp(config) {
let help = new _help2.default(config);
return help.command(this);
}
static buildHelpLine(config) {
let help = new _help2.default(config);
return help.commandLine(this);
}
static get id() {
let cmd = [];
if (this.topic)
cmd.push(this.topic);
if (this.command)
cmd.push(this.command);
return cmd.join(':');
}
/**
* instantiate and run the command setting {mock: true} in the config (shorthand method)
*/
static async mock(...argv) {
argv.unshift('argv0', 'cmd');
return this.run({ argv, mock: true });
}
/**
* instantiate and run the command
*/
static async run(config) {
const cmd = new this({ config });
try {
await cmd.init();
await cmd.run();
await cmd.out.done();
}
catch (err) {
cmd.out.error(err);
}
return cmd;
}
get ctor() {
return this.constructor;
}
async init() {
const { argv, flags, args } = await cli_flags_1.parse({
flags: this.ctor.flags || {},
argv: this.argv.slice(2),
args: this.ctor.args || [],
strict: !this.ctor.variableArgs,
});
this.flags = flags;
this.argv = argv;
this.args = args;
}
/**
* actual command run code goes here
*/
async run() { }
get stdout() {
return this.out.stdout.output;
}
get stderr() {
return this.out.stderr.output;
}
static buildHelp(config) {
let help = new help_1.default(config);
return help.command(this);
}
static buildHelpLine(config) {
let help = new help_1.default(config);
return help.commandLine(this);
}
}
exports.default = Command;
Command.aliases = [];
Command.variableArgs = false;
Command.args = [];
Command._version = _package2.default.version;
Command._version = pjson.version;
exports.Command = Command;

@@ -1,97 +0,106 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _screen = require('./screen');
var _color = require('./color');
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const screen_1 = require("cli-ux/lib/screen");
const color_1 = require("./color");
function linewrap(length, s) {
const linewrap = require('@heroku/linewrap');
return linewrap(length, _screen.stdtermwidth, {
skipScheme: 'ansi-color'
})(s).trim();
const linewrap = require('@heroku/linewrap');
return linewrap(length, screen_1.default.stdtermwidth, {
skipScheme: 'ansi-color',
})(s).trim();
}
function renderList(items) {
const S = require('string');
const max = require('lodash.maxby');
let maxLength = max(items, '[0].length')[0].length;
let lines = items.map(i => {
let left = i[0];
let right = i[1];
if (!right) return left;
left = `${S(left).padRight(maxLength)}`;
right = linewrap(maxLength + 2, right);
return `${left} ${right}`;
});
return lines.join('\n');
const S = require('string');
const max = require('lodash.maxby');
let maxLength = max(items, '[0].length')[0].length;
let lines = items.map(i => {
let left = i[0];
let right = i[1];
if (!right)
return left;
left = `${S(left).padRight(maxLength)}`;
right = linewrap(maxLength + 2, right);
return `${left} ${right}`;
});
return lines.join('\n');
}
function buildUsage(command) {
if (command.usage) return command.usage.trim();
let cmd = command.id;
if (!command.args) return cmd.trim();
let args = command.args.map(renderArg);
return `${cmd} ${args.join(' ')}`.trim();
if (command.usage)
return command.usage.trim();
let cmd = command.id;
if (!command.args)
return cmd.trim();
let args = command.args.map(renderArg);
return `${cmd} ${args.join(' ')}`.trim();
}
function renderArg(arg) {
let name = arg.name.toUpperCase();
if (arg.required !== false && arg.optional !== true) return `${name}`;else return `[${name}]`;
let name = arg.name.toUpperCase();
if (arg.required)
return `${name}`;
else
return `[${name}]`;
}
class Help {
constructor(config) {
this.config = config;
}
command(cmd) {
let flags = Object.entries(cmd.flags || {}).filter(([name, flag]) => !flag.hidden);
let args = (cmd.args || []).filter(a => !a.hidden);
let hasFlags = flags.length ? ` ${_color.color.blue('[flags]')}` : '';
let usage = `${_color.color.bold('Usage:')} ${this.config.bin} ${buildUsage(cmd)}${hasFlags}\n`;
return [usage, cmd.description ? `\n${_color.color.bold(cmd.description.trim())}\n` : '', this.renderAliases(cmd.aliases), this.renderArgs(args), this.renderFlags(flags), cmd.help ? `\n${cmd.help.trim()}\n` : ''].join('');
}
commandLine(cmd) {
return [buildUsage(cmd), cmd.description ? _color.color.dim(cmd.description) : null];
}
renderAliases(aliases) {
if (!aliases || !aliases.length) return '';
let a = aliases.map(a => ` $ ${this.config.bin} ${a}`).join('\n');
return `\n${_color.color.blue('Aliases:')}\n${a}\n`;
}
renderArgs(args) {
if (!args.find(f => f.description)) return '';
return '\n' + renderList(args.map(a => {
return [a.name.toUpperCase(), a.description ? _color.color.dim(a.description) : null];
})) + '\n';
}
renderFlags(flags) {
if (!flags.length) return '';
flags.sort((a, b) => {
if (a[1].char && !b[1].char) return -1;
if (b[1].char && !a[1].char) return 1;
if (a[0] < b[0]) return -1;
return b[0] < a[0] ? 1 : 0;
});
return `\n${_color.color.blue('Flags:')}\n` + renderList(flags.map(([name, f]) => {
let label = [];
if (f.char) label.push(`-${f.char}`);
if (name) label.push(` --${name}`);
let usage = f.parse ? ` ${name.toUpperCase()}` : '';
let description = f.description || '';
if (f.required || f.optional === false) description = `(required) ${description}`;
return [` ${label.join(',').trim()}` + usage, description ? _color.color.dim(description) : null];
})) + '\n';
}
constructor(config) {
this.config = config;
}
command(cmd) {
let flags = Object.entries(cmd.flags || {}).filter(([, flag]) => !flag.hidden);
let args = (cmd.args || []).filter(a => !a.hidden);
let hasFlags = flags.length ? ` ${color_1.color.blue('[flags]')}` : '';
let usage = `${color_1.color.bold('Usage:')} ${this.config.bin} ${buildUsage(cmd)}${hasFlags}\n`;
return [
usage,
cmd.description ? `\n${color_1.color.bold(cmd.description.trim())}\n` : '',
this.renderAliases(cmd.aliases),
this.renderArgs(args),
this.renderFlags(flags),
cmd.help ? `\n${cmd.help.trim()}\n` : '',
].join('');
}
commandLine(cmd) {
return [buildUsage(cmd), cmd.description ? color_1.color.dim(cmd.description) : undefined];
}
renderAliases(aliases) {
if (!aliases || !aliases.length)
return '';
let a = aliases.map(a => ` $ ${this.config.bin} ${a}`).join('\n');
return `\n${color_1.color.blue('Aliases:')}\n${a}\n`;
}
renderArgs(args) {
if (!args.find(f => !!f.description))
return '';
return ('\n' +
renderList(args.map(a => {
return [a.name.toUpperCase(), a.description ? color_1.color.dim(a.description) : undefined];
})) +
'\n');
}
renderFlags(flags) {
if (!flags.length)
return '';
flags.sort((a, b) => {
if (a[1].char && !b[1].char)
return -1;
if (b[1].char && !a[1].char)
return 1;
if (a[0] < b[0])
return -1;
return b[0] < a[0] ? 1 : 0;
});
return (`\n${color_1.color.blue('Flags:')}\n` +
renderList(flags.map(([name, f]) => {
let label = [];
if (f.char)
label.push(`-${f.char}`);
if (name)
label.push(` --${name}`);
let usage = f.type === 'option' ? ` ${name.toUpperCase()}` : '';
let description = f.description || '';
if (f.required)
description = `(required) ${description}`;
return [` ${label.join(',').trim()}` + usage, description ? color_1.color.dim(description) : undefined];
})) +
'\n');
}
}
exports.default = Help;
exports.default = Help;

@@ -1,40 +0,9 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _command = require('./command');
Object.defineProperty(exports, 'default', {
enumerable: true,
get: function () {
return _interopRequireDefault(_command).default;
}
});
Object.defineProperty(exports, 'Command', {
enumerable: true,
get: function () {
return _interopRequireDefault(_command).default;
}
});
var _topic = require('./topic');
Object.defineProperty(exports, 'Topic', {
enumerable: true,
get: function () {
return _interopRequireDefault(_topic).default;
}
});
var _flags = require('./flags');
Object.defineProperty(exports, 'flags', {
enumerable: true,
get: function () {
return _flags.flags;
}
});
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var command_1 = require("./command");
exports.default = command_1.Command;
exports.Command = command_1.Command;
var topic_1 = require("./topic");
exports.Topic = topic_1.Topic;
var cli_flags_1 = require("cli-flags");
exports.flags = cli_flags_1.flags;

@@ -1,16 +0,13 @@

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
class Topic {
constructor(commands) {
this.commands = commands;
}
static get id() {
return this.topic;
}
}
exports.default = Topic;
Topic.hidden = false;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Topic = (_a = class Topic {
constructor(commands) {
this.commands = commands;
}
static get id() {
return this.topic;
}
},
_a.hidden = false,
_a);
var _a;
{
"name": "cli-engine-command",
"description": "base CLI command for cli-engine",
"version": "9.0.3",
"author": "Jeff Dickey @dickeyxxx",
"version": "10.0.0-ts.0",
"author": "Jeff Dickey @jdxcode",
"bugs": "https://github.com/heroku/cli-engine-command/issues",

@@ -11,31 +11,30 @@ "dependencies": {

"cardinal": "1.x",
"chalk": "^2.1.0",
"chalk": "2.3.0",
"cli-flags": "1.0.16",
"cli-ux": "^2.0.4",
"fs-extra": "^4.0.2",
"http-call": "^3.0.2",
"http-call": "^4.0.0",
"lodash.maxby": "^4.6.0",
"moment": "^2.18.1",
"moment": "^2.19.3",
"string": "3.x",
"supports-color": "^4.4.0"
"supports-color": "^5.0.1"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-jest": "^21.2.0",
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"babel-plugin-transform-class-properties": "6.24.1",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.0",
"babel-plugin-transform-flow-strip-types": "6.22.0",
"cli-engine-config": "^3.3.1",
"flow-bin": "^0.55.0",
"flow-copy-source": "^1.2.1",
"flow-typed": "^2.1.5",
"@types/ansi-styles": "2.0.30",
"@types/chalk": "2.2.0",
"@types/jest": "21.1.8",
"@types/nock": "8.2.1",
"@types/node": "8.0.53",
"@types/supports-color": "3.1.0",
"cli-engine-config": "4.0.1-ts.19",
"del-cli": "1.1.0",
"husky": "^0.14.3",
"jest": "^21.2.1",
"jest-junit": "^3.0.0",
"lint-staged": "^4.2.3",
"nock": "^9.0.21",
"nodemon": "^1.12.1",
"prettier": "^1.7.1",
"rimraf": "2.6.2",
"std-mocks": "1.0.1"
"lint-staged": "^6.0.0",
"nock": "^9.1.3",
"prettier": "^1.8.2",
"std-mocks": "1.0.1",
"ts-jest": "21.2.4",
"ts-node": "3.3.0",
"typescript": "2.6.2"
},

@@ -49,6 +48,2 @@ "engines": {

"homepage": "https://github.com/heroku/cli-engine-command",
"jest": {
"testEnvironment": "node",
"setupTestFrameworkScriptFile": "./test/init.js"
},
"keywords": [

@@ -59,23 +54,15 @@ "heroku",

"license": "ISC",
"lint-staged": {
"src/**/*.js": [
"prettier --write",
"git add"
]
},
"main": "lib/index.js",
"peerDependencies": {
"cli-engine-config": "^3.0.0"
"cli-engine-config": "^4.0.0"
},
"repository": "heroku/cli-engine-command",
"scripts": {
"build": "babel src -d lib --ignore '*.test.js'",
"clean": "rimraf lib",
"copy-flow": "flow-copy-source -v -i '**/*.test.js' src lib",
"posttest": "prettier -l 'src/**/*.js' && flow",
"posttest": "prettier -l 'src/**/*.ts'",
"precommit": "lint-staged",
"prepare": "npm run clean && npm run build && npm run copy-flow",
"test": "jest",
"watch": "nodemon -e js -i lib --exec \"npm run prepare\""
}
"prepare": "del-cli lib && tsc && del-cli \"lib/**/*.test.+(d.ts|js)\"",
"pretest": "tsc",
"test": "jest"
},
"types": "./lib/index.d.ts"
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc