heroku-cli-command
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -1,72 +0,221 @@ | ||
'use strict' | ||
'use strict'; | ||
const mixins = require('./mixins') | ||
const color = require('./color') | ||
const output = require('./output') | ||
const parse = require('./parse') | ||
const http = require('./http') | ||
const _flags = Symbol('flags') | ||
const _args = Symbol('args') | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
class Command extends mixins.mix(Object).with(color(), output(), parse(), http()) { | ||
constructor (options = {}) { | ||
super(options) | ||
this.options = options | ||
this.argv = options.argv | ||
} | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
/** | ||
* actual command run code goes here | ||
*/ | ||
async run () { | ||
throw new Error('must implement abstract class Command') | ||
} | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
async done () { | ||
await super.done() | ||
} | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
/** | ||
* get whether or not command is in debug mode | ||
* @returns {number} - 0 if not debugging, otherwise current debug level (1 or 2 usually) | ||
*/ | ||
get debugging () { | ||
if (this.flags && this.flags.debug) return this.flags.debug | ||
if (['true', '1'].indexOf((process.env.HEROKU_DEBUG || '').toLowerCase()) !== -1) return 1 | ||
return 0 | ||
} | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
static get id () { | ||
return this.command ? `${this.topic}:${this.command}` : this.topic | ||
} | ||
var _assign = require('babel-runtime/core-js/object/assign'); | ||
static get flags () { | ||
if (!this[_flags]) this[_flags] = [] | ||
return this[_flags] | ||
} | ||
var _assign2 = _interopRequireDefault(_assign); | ||
static set flags (flags) { | ||
if (!this[_flags]) this[_flags] = [] | ||
if (!flags) return | ||
this[_flags] = this[_flags].concat(flags) | ||
} | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
static get args () { | ||
if (!this[_args]) this[_args] = [] | ||
return this[_args] | ||
} | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
static set args (args) { | ||
if (!this[_args]) this[_args] = [] | ||
if (!args) return | ||
this[_args] = this[_args].concat(args) | ||
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray'); | ||
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _get2 = require('babel-runtime/helpers/get'); | ||
var _get3 = _interopRequireDefault(_get2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _http = require('./http'); | ||
var _http2 = _interopRequireDefault(_http); | ||
var _output = require('./output'); | ||
var _output2 = _interopRequireDefault(_output); | ||
var _parser = require('./parser'); | ||
var _parser2 = _interopRequireDefault(_parser); | ||
var _package = require('../package.json'); | ||
var _package2 = _interopRequireDefault(_package); | ||
var _config = require('./config'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var Command = function (_Output) { | ||
(0, _inherits3.default)(Command, _Output); | ||
(0, _createClass3.default)(Command, null, [{ | ||
key: 'id', | ||
get: function get() { | ||
return this.command ? this.topic + ':' + this.command : this.topic; | ||
} | ||
}, { | ||
key: 'flags', | ||
get: function get() { | ||
return this._flags; | ||
}, | ||
set: function set(flags) { | ||
var _flags; | ||
(_flags = this._flags).push.apply(_flags, (0, _toConsumableArray3.default)(flags)); | ||
} | ||
}, { | ||
key: 'args', | ||
get: function get() { | ||
return this._args; | ||
}, | ||
set: function set(args) { | ||
var _args; | ||
(_args = this._args).push.apply(_args, (0, _toConsumableArray3.default)(args)); | ||
} | ||
}]); | ||
function Command() { | ||
var argv = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : []; | ||
var config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
(0, _classCallCheck3.default)(this, Command); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (Command.__proto__ || (0, _getPrototypeOf2.default)(Command)).call(this, (0, _assign2.default)(_config.Default, config))); | ||
_this.argv = argv; | ||
_this.parser = new _parser2.default(_this); | ||
_this.http = (0, _http2.default)(_this); | ||
return _this; | ||
} | ||
} | ||
Command._version = require('../package.json').version | ||
Command.flags = [ | ||
{name: 'debug', char: 'd', hidden: true}, | ||
{name: 'no-color', hidden: true} | ||
] | ||
(0, _createClass3.default)(Command, [{ | ||
key: 'init', | ||
value: function () { | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return this.parser.parse(); | ||
module.exports = Command | ||
case 2: | ||
_context.next = 4; | ||
return (0, _get3.default)(Command.prototype.__proto__ || (0, _getPrototypeOf2.default)(Command.prototype), 'init', this).call(this); | ||
case 4: | ||
this.flags = this.parser.flags; | ||
this.args = this.parser.args; | ||
case 6: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function init() { | ||
return _ref.apply(this, arguments); | ||
} | ||
return init; | ||
}() | ||
/** | ||
* actual command run code goes here | ||
*/ | ||
}, { | ||
key: 'run', | ||
value: function () { | ||
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() { | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
throw new Error('must implement abstract class Command'); | ||
case 1: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
function run() { | ||
return _ref2.apply(this, arguments); | ||
} | ||
return run; | ||
}() | ||
}, { | ||
key: 'done', | ||
value: function () { | ||
var _ref3 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee3() { | ||
return _regenerator2.default.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
_context3.next = 2; | ||
return (0, _get3.default)(Command.prototype.__proto__ || (0, _getPrototypeOf2.default)(Command.prototype), 'done', this).call(this); | ||
case 2: | ||
case 'end': | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
})); | ||
function done() { | ||
return _ref3.apply(this, arguments); | ||
} | ||
return done; | ||
}() | ||
}, { | ||
key: 'debugging', | ||
/** | ||
* get whether or not command is in debug mode | ||
* @returns {number} - 0 if not debugging, otherwise current debug level (1 or 2 usually) | ||
*/ | ||
get: function get() { | ||
if (this.flags && this.flags.debug) return 1; | ||
var HEROKU_DEBUG = process.env.HEROKU_DEBUG; | ||
if (HEROKU_DEBUG === 'true') return 1; | ||
if (HEROKU_DEBUG) return parseInt(HEROKU_DEBUG); | ||
return 0; | ||
} | ||
}]); | ||
return Command; | ||
}(_output2.default); | ||
/* globals | ||
$Shape | ||
Class | ||
*/ | ||
Command._flags = [{ name: 'debug', hidden: true }, { name: 'no-color', hidden: true }]; | ||
Command._args = []; | ||
exports.default = Command; |
167
lib/http.js
@@ -1,48 +0,133 @@ | ||
'use strict' | ||
'use strict'; | ||
const http = Symbol('http') | ||
const util = require('util') | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
function renderHeaders (headers) { | ||
return Object.keys(headers).map(key => { | ||
let value = key.toUpperCase() === 'AUTHORIZATION' ? 'REDACTED' : headers[key] | ||
return ' ' + key + '=' + value | ||
}).join('\n') | ||
} | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
module.exports = () => { | ||
return Base => class HTTP extends Base { | ||
get http () { | ||
if (this[http]) return this[http] | ||
const HTTP = require('http-call') | ||
var _keys2 = _interopRequireDefault(_keys); | ||
this[http] = new HTTP({ | ||
requestMiddleware: module.exports.requestMiddleware.bind(this), | ||
responseMiddleware: module.exports.responseMiddleware.bind(this), | ||
headers: { | ||
'user-agent': `heroku-cli/${this.options.version}` | ||
} | ||
}) | ||
return this[http] | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _get2 = require('babel-runtime/helpers/get'); | ||
var _get3 = _interopRequireDefault(_get2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _util = require('util'); | ||
var _util2 = _interopRequireDefault(_util); | ||
var _httpCall = require('http-call'); | ||
var _httpCall2 = _interopRequireDefault(_httpCall); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = function (cmd) { | ||
return function (_http) { | ||
(0, _inherits3.default)(HTTP, _http); | ||
function HTTP() { | ||
var _ref; | ||
var _temp, _this, _ret; | ||
(0, _classCallCheck3.default)(this, HTTP); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return _ret = (_temp = (_this = (0, _possibleConstructorReturn3.default)(this, (_ref = HTTP.__proto__ || (0, _getPrototypeOf2.default)(HTTP)).call.apply(_ref, [this].concat(args))), _this), _this.headers = { | ||
'user-agent': cmd.config.name + '/' + cmd.config.version + ' node-' + process.version | ||
}, _temp), (0, _possibleConstructorReturn3.default)(_this, _ret); | ||
} | ||
} | ||
} | ||
module.exports.requestMiddleware = function (options) { | ||
if (!this.debugging) return | ||
this.error(`--> ${options.method} ${options.host}${options.path}`) | ||
if (this.debugging > 1) { | ||
this.error(renderHeaders(options.headers)) | ||
// if (body) this.error(`--- BODY\n${util.inspect(body)}\n---`) | ||
} | ||
} | ||
(0, _createClass3.default)(HTTP, [{ | ||
key: 'request', | ||
value: function () { | ||
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
this.logRequest(); | ||
_context.next = 3; | ||
return (0, _get3.default)(HTTP.prototype.__proto__ || (0, _getPrototypeOf2.default)(HTTP.prototype), 'request', this).call(this); | ||
module.exports.responseMiddleware = function ({response, body, options}) { | ||
if (!this.debugging) return | ||
let url = `${response.req._headers.host}${response.req.path}` | ||
this.error(`<-- ${response.req.method} ${url} ${response.statusCode}`) | ||
if (this.debugging > 1) { | ||
this.error(renderHeaders(response.headers)) | ||
if (!options.raw) this.error(`--- BODY\n${util.inspect(body)}\n---`) | ||
} | ||
} | ||
case 3: | ||
this.logResponse(); | ||
case 4: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function request() { | ||
return _ref2.apply(this, arguments); | ||
} | ||
return request; | ||
}() | ||
}, { | ||
key: 'renderHeaders', | ||
value: function renderHeaders(headers) { | ||
return (0, _keys2.default)(headers).map(function (key) { | ||
var value = key.toUpperCase() === 'AUTHORIZATION' ? 'REDACTED' : headers[key]; | ||
return ' ' + key + '=' + value; | ||
}).join('\n'); | ||
} | ||
}, { | ||
key: 'logRequest', | ||
value: function logRequest() { | ||
if (!this.debugging) return; | ||
cmd.error('--> ' + this.method + ' ' + this.url); | ||
if (cmd.debugging > 1) { | ||
cmd.error(this.renderHeaders(this.headers)); | ||
// if (body) this.error(`--- BODY\n${util.inspect(body)}\n---`) | ||
} | ||
} | ||
}, { | ||
key: 'logResponse', | ||
value: function logResponse() { | ||
if (!this.debugging) return; | ||
cmd.error('<-- ' + this.method + ' ' + this.url + ' ' + this.response.statusCode); | ||
if (cmd.debugging > 1) { | ||
cmd.error(this.renderHeaders(this.response.headers)); | ||
if (this.body) cmd.error('--- BODY\n' + _util2.default.inspect(this.body) + '\n---'); | ||
} | ||
} | ||
}]); | ||
return HTTP; | ||
}(_httpCall2.default); | ||
}; |
@@ -1,38 +0,164 @@ | ||
'use strict' | ||
'use strict'; | ||
const Command = require('./command') | ||
const mixins = require('./mixins') | ||
const app = require('./mixins/app') | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
const api = superclass => class extends superclass { | ||
async init () { | ||
await super.init() | ||
let password = process.env.HEROKU_API_KEY | ||
if (!password) { | ||
const netrc = require('netrc')() | ||
const host = netrc['api.heroku.com'] | ||
if (host) password = host.password | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _get2 = require('babel-runtime/helpers/get'); | ||
var _get3 = _interopRequireDefault(_get2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _command = require('./command'); | ||
var _command2 = _interopRequireDefault(_command); | ||
var _mixins = require('./mixins'); | ||
var _mixins2 = _interopRequireDefault(_mixins); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var api = function api(superclass) { | ||
return function (_superclass) { | ||
(0, _inherits3.default)(_class, _superclass); | ||
function _class() { | ||
(0, _classCallCheck3.default)(this, _class); | ||
return (0, _possibleConstructorReturn3.default)(this, (_class.__proto__ || (0, _getPrototypeOf2.default)(_class)).apply(this, arguments)); | ||
} | ||
if (!password) throw new Error('Not logged in') | ||
this.auth = {password} | ||
} | ||
} | ||
module.exports = command => { | ||
let BaseCommand = Command | ||
if (command.needsApp) BaseCommand = mixins.mix(BaseCommand).with(app()) | ||
if (command.needsAuth) BaseCommand = mixins.mix(BaseCommand).with(api) | ||
class NewCommand extends BaseCommand { | ||
async run () { | ||
this.debug = this.debugging | ||
await command.run(this) | ||
(0, _createClass3.default)(_class, [{ | ||
key: 'init', | ||
value: function () { | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
var password, netrc, host; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return (0, _get3.default)(_class.prototype.__proto__ || (0, _getPrototypeOf2.default)(_class.prototype), 'init', this).call(this); | ||
case 2: | ||
password = process.env.HEROKU_API_KEY; | ||
if (!password) { | ||
netrc = require('netrc')(); | ||
host = netrc['api.heroku.com']; | ||
if (host) password = host.password; | ||
} | ||
if (password) { | ||
_context.next = 6; | ||
break; | ||
} | ||
throw new Error('Not logged in'); | ||
case 6: | ||
this.auth = { password: password }; | ||
case 7: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function init() { | ||
return _ref.apply(this, arguments); | ||
} | ||
return init; | ||
}() | ||
}]); | ||
return _class; | ||
}(superclass); | ||
}; | ||
exports.default = function (command) { | ||
var BaseCommand = _command2.default; | ||
if (command.needsApp) BaseCommand = _mixins2.default.app(BaseCommand); | ||
if (command.needsAuth) BaseCommand = api(BaseCommand); | ||
var NewCommand = function (_BaseCommand) { | ||
(0, _inherits3.default)(NewCommand, _BaseCommand); | ||
function NewCommand() { | ||
(0, _classCallCheck3.default)(this, NewCommand); | ||
return (0, _possibleConstructorReturn3.default)(this, (NewCommand.__proto__ || (0, _getPrototypeOf2.default)(NewCommand)).apply(this, arguments)); | ||
} | ||
} | ||
NewCommand.topic = command.topic | ||
NewCommand.command = command.command | ||
NewCommand.description = command.description | ||
NewCommand.args = command.args | ||
NewCommand.variableArgs = command.variableArgs | ||
NewCommand.flags = command.flags | ||
return NewCommand | ||
} | ||
(0, _createClass3.default)(NewCommand, [{ | ||
key: 'run', | ||
value: function () { | ||
var _ref2 = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee2() { | ||
var ctx; | ||
return _regenerator2.default.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
ctx = new Proxy(this, { get: function get(ctx, name) { | ||
if (name === 'debug') return ctx.debugging; | ||
return ctx[name]; | ||
} }); | ||
_context2.next = 3; | ||
return command.run(ctx); | ||
case 3: | ||
case 'end': | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
function run() { | ||
return _ref2.apply(this, arguments); | ||
} | ||
return run; | ||
}() | ||
}]); | ||
return NewCommand; | ||
}(BaseCommand); | ||
NewCommand.topic = command.topic; | ||
NewCommand.command = command.command; | ||
NewCommand.description = command.description; | ||
NewCommand.args = command.args; | ||
NewCommand.flags = command.flags; | ||
// TODO: variableArgs | ||
// NewCommand.variableArgs = command.variableArgs | ||
return NewCommand; | ||
}; |
@@ -1,4 +0,100 @@ | ||
'use strict' | ||
'use strict'; | ||
const APP_FLAG = { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _get2 = require('babel-runtime/helpers/get'); | ||
var _get3 = _interopRequireDefault(_get2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
exports.default = function (Command) { | ||
var _class, _temp; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return _temp = _class = function (_Command) { | ||
(0, _inherits3.default)(AppMixin, _Command); | ||
function AppMixin() { | ||
(0, _classCallCheck3.default)(this, AppMixin); | ||
return (0, _possibleConstructorReturn3.default)(this, (AppMixin.__proto__ || (0, _getPrototypeOf2.default)(AppMixin)).apply(this, arguments)); | ||
} | ||
(0, _createClass3.default)(AppMixin, [{ | ||
key: 'init', | ||
value: function () { | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return (0, _get3.default)(AppMixin.prototype.__proto__ || (0, _getPrototypeOf2.default)(AppMixin.prototype), 'init', this).call(this); | ||
case 2: | ||
if (!(!this.app && options.required !== false)) { | ||
_context.next = 4; | ||
break; | ||
} | ||
throw new Error('No app specified'); | ||
case 4: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function init() { | ||
return _ref.apply(this, arguments); | ||
} | ||
return init; | ||
}() | ||
}, { | ||
key: 'app', | ||
get: function get() { | ||
if (this._app) return this._app; | ||
if (typeof this.flags.app === 'string') this._app = this.flags.app; | ||
return this._app; | ||
} | ||
}]); | ||
return AppMixin; | ||
}(Command), _class.flags = [APP_FLAG], _temp; | ||
}; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var APP_FLAG = { | ||
name: 'app', | ||
@@ -8,21 +104,5 @@ char: 'a', | ||
hasValue: true | ||
} | ||
module.exports = (options = {}) => { | ||
return superclass => { | ||
class klass extends superclass { | ||
async init () { | ||
await super.init() | ||
if (!this.app && options.required !== false) throw new Error('No app specified') | ||
} | ||
get app () { | ||
if (this._app) return this._app | ||
this._app = this.flags.app | ||
return this._app | ||
} | ||
} | ||
klass.flags = [APP_FLAG] | ||
return klass | ||
} | ||
} | ||
}; | ||
/* globals | ||
Class | ||
*/ |
@@ -1,32 +0,113 @@ | ||
'use strict' | ||
'use strict'; | ||
const http = require('../http') | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
module.exports = (options = {}) => { | ||
return superclass => class extends superclass { | ||
async init () { | ||
await super.init() | ||
let auth = process.env.HEROKU_API_KEY | ||
if (!auth) { | ||
const netrc = require('netrc')() | ||
const host = netrc['api.heroku.com'] | ||
if (host) auth = host.password | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _get2 = require('babel-runtime/helpers/get'); | ||
var _get3 = _interopRequireDefault(_get2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var http = require('../http'); | ||
module.exports = function () { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
return function (superclass) { | ||
return function (_superclass) { | ||
(0, _inherits3.default)(_class, _superclass); | ||
function _class() { | ||
(0, _classCallCheck3.default)(this, _class); | ||
return (0, _possibleConstructorReturn3.default)(this, (_class.__proto__ || (0, _getPrototypeOf2.default)(_class)).apply(this, arguments)); | ||
} | ||
if (!auth && options.required !== false) { | ||
throw new Error('Not logged in') | ||
} | ||
const HTTP = require('http-call') | ||
this.heroku = new HTTP({ | ||
host: 'api.heroku.com', | ||
protocol: 'https:', | ||
requestMiddleware: http.requestMiddleware.bind(this), | ||
responseMiddleware: http.responseMiddleware.bind(this), | ||
auth: `:${auth}`, | ||
headers: { | ||
'user-agent': `heroku-cli/${this.options.version}`, | ||
'accept': 'application/vnd.heroku+json; version=3' | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
(0, _createClass3.default)(_class, [{ | ||
key: 'init', | ||
value: function () { | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee() { | ||
var auth, netrc, host, HTTP; | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_context.next = 2; | ||
return (0, _get3.default)(_class.prototype.__proto__ || (0, _getPrototypeOf2.default)(_class.prototype), 'init', this).call(this); | ||
case 2: | ||
auth = process.env.HEROKU_API_KEY; | ||
if (!auth) { | ||
netrc = require('netrc')(); | ||
host = netrc['api.heroku.com']; | ||
if (host) auth = host.password; | ||
} | ||
if (!(!auth && options.required !== false)) { | ||
_context.next = 6; | ||
break; | ||
} | ||
throw new Error('Not logged in'); | ||
case 6: | ||
HTTP = require('http-call'); | ||
this.heroku = new HTTP({ | ||
host: 'api.heroku.com', | ||
protocol: 'https:', | ||
requestMiddleware: http.requestMiddleware.bind(this), | ||
responseMiddleware: http.responseMiddleware.bind(this), | ||
auth: ':' + auth, | ||
headers: { | ||
'user-agent': 'heroku-cli/' + this.options.version, | ||
'accept': 'application/vnd.heroku+json; version=3' | ||
} | ||
}); | ||
case 8: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function init() { | ||
return _ref.apply(this, arguments); | ||
} | ||
return init; | ||
}() | ||
}]); | ||
return _class; | ||
}(superclass); | ||
}; | ||
}; |
@@ -1,19 +0,20 @@ | ||
'use strict' | ||
'use strict'; | ||
let mix = superclass => new MixinBuilder(superclass) | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
class MixinBuilder { | ||
constructor (superclass) { | ||
this.superclass = superclass | ||
} | ||
var _app = require('./app'); | ||
with (...mixins) { | ||
return mixins.reduce((c, mixin) => mixin(c), this.superclass) | ||
} | ||
} | ||
var _app2 = _interopRequireDefault(_app); | ||
module.exports = { | ||
heroku: require('./heroku'), | ||
app: require('./app'), | ||
mix | ||
} | ||
var _heroku = require('./heroku'); | ||
var _heroku2 = _interopRequireDefault(_heroku); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
exports.default = { | ||
app: _app2.default, | ||
heroku: _heroku2.default | ||
}; |
@@ -1,18 +0,24 @@ | ||
'use strict' | ||
'use strict'; | ||
const got = require('got') | ||
var _stringify = require('babel-runtime/core-js/json/stringify'); | ||
function respond (body, payload) { | ||
var _stringify2 = _interopRequireDefault(_stringify); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var got = require('got'); | ||
function respond(body, payload) { | ||
return got.post(payload.response_url, { | ||
body: JSON.stringify(body), | ||
headers: {'Content-Type': 'application/json'} | ||
}).catch(err => { | ||
console.error('Error submitting response:') | ||
console.dir(body) | ||
console.dir(err) | ||
}) | ||
body: (0, _stringify2.default)(body), | ||
headers: { 'Content-Type': 'application/json' } | ||
}).catch(function (err) { | ||
console.error('Error submitting response:'); | ||
console.dir(body); | ||
console.dir(err); | ||
}); | ||
} | ||
module.exports = { | ||
respond | ||
} | ||
respond: respond | ||
}; |
238
lib/topic.js
@@ -1,82 +0,178 @@ | ||
const screen = require('./screen') | ||
const mixins = require('./mixins') | ||
const color = require('./color') | ||
const output = require('./output') | ||
'use strict'; | ||
class Topic extends mixins.mix(Object).with(color(), output()) { | ||
constructor (options) { | ||
super(options) | ||
this.commands = options.commands | ||
this.flags = options.flags | ||
} | ||
var _regenerator = require('babel-runtime/regenerator'); | ||
async help ({argv0, commands, args, matchedCommand}) { | ||
if (matchedCommand) this.commandHelp({command: matchedCommand, argv0}) | ||
if (this.constructor.topic === args[0]) this.listCommandsHelp({commands, argv0}) | ||
} | ||
var _regenerator2 = _interopRequireDefault(_regenerator); | ||
listCommandsHelp ({argv0}) { | ||
const max = require('lodash.maxby') | ||
const S = require('string') | ||
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator'); | ||
let commands = this.commands.filter(c => !c.hidden && c.command) | ||
if (commands.length === 0) return | ||
this.log(`${argv0} ${this.constructor.topic} commands: (${this.color.cmd(argv0 + ' help ' + this.constructor.topic + ':COMMAND')} for details) | ||
`) | ||
let maxLength = max(commands, 'command.length').command.length + this.constructor.topic.length + 1 | ||
for (let command of commands) { | ||
let cmd = command.command ? `${command.topic}:${command.command}` : command.topic | ||
this.log(` ${S(cmd).padRight(maxLength)}${command.description ? ' # ' + command.description : ''}`) | ||
} | ||
this.log() | ||
} | ||
var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2); | ||
commandHelp ({argv0, command}) { | ||
let cmd = command.command ? `${command.topic}:${command.command}` : command.topic | ||
// TODO: get usage if defined | ||
let usage = `${argv0} ${cmd}` + (command.args || []).map(this.renderArg).join('') | ||
this.log(`Usage: ${this.color.cmd(usage)}\n`) | ||
if (command.description) this.log(`${command.description.trim()}\n`) | ||
let flags = (command.flags || []).filter(f => !f.hidden) | ||
if (flags.length) this.log(`${this.renderFlags(flags)}\n`) | ||
if (command.help) this.log(`${command.help.trim()}\n`) | ||
} | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
renderArg (arg) { | ||
if (arg.required !== false && arg.optional !== true) return ` <${arg.name}>` | ||
else return ` [${arg.name}]` | ||
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); | ||
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); | ||
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); | ||
var _createClass2 = require('babel-runtime/helpers/createClass'); | ||
var _createClass3 = _interopRequireDefault(_createClass2); | ||
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); | ||
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); | ||
var _inherits2 = require('babel-runtime/helpers/inherits'); | ||
var _inherits3 = _interopRequireDefault(_inherits2); | ||
var _screen = require('./output/screen'); | ||
var _output = require('./output'); | ||
var _output2 = _interopRequireDefault(_output); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
/* globals | ||
Class | ||
*/ | ||
var Topic = function (_Output) { | ||
(0, _inherits3.default)(Topic, _Output); | ||
function Topic(commands, config) { | ||
(0, _classCallCheck3.default)(this, Topic); | ||
var _this = (0, _possibleConstructorReturn3.default)(this, (Topic.__proto__ || (0, _getPrototypeOf2.default)(Topic)).call(this, config)); | ||
_this.commands = commands; | ||
_this.argv0 = config.argv0; | ||
return _this; | ||
} | ||
renderFlags (flags) { | ||
const linewrap = require('../lib/linewrap') | ||
const max = require('lodash.maxby') | ||
const S = require('string') | ||
(0, _createClass3.default)(Topic, [{ | ||
key: 'help', | ||
value: function () { | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(args, matchedCommand) { | ||
return _regenerator2.default.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
if (matchedCommand) this.commandHelp(matchedCommand); | ||
if (this.constructor.topic === args[0]) this.listCommandsHelp(); | ||
let lines = [] | ||
for (let flag of flags) { | ||
let label = [] | ||
if (flag.char) label.push(`-${flag.char}`) | ||
if (flag.name) label.push(` --${flag.name}`) | ||
let usage = flag.hasValue ? ` ${flag.name.toUpperCase()}` : '' | ||
let description = flag.description || '' | ||
if (flag.required || flag.optional === false) description = `(required) ${description}` | ||
lines.push([label.join(',').trim() + usage, description]) | ||
} | ||
let maxLength = max(lines, '0')[0].length | ||
return lines.map(line => { | ||
let desc = line[1] || '' | ||
if (desc) { | ||
desc = linewrap(maxLength + 4, screen.errtermwidth(), { | ||
skipScheme: 'ansi-color' | ||
})(desc).trim() | ||
desc = ' # ' + desc.split('\n').map(l => { | ||
if (l[0] !== ' ') return l | ||
return l.substr(0, maxLength + 1) + ' # ' + l.substr(maxLength + 4) | ||
}).join('\n') | ||
case 2: | ||
case 'end': | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function help(_x, _x2) { | ||
return _ref.apply(this, arguments); | ||
} | ||
return ` ${S(line[0]).padRight(maxLength)}${desc}` | ||
}).join('\n') | ||
} | ||
} | ||
module.exports = Topic | ||
return help; | ||
}() | ||
}, { | ||
key: 'listCommandsHelp', | ||
value: function listCommandsHelp() { | ||
var _this2 = this; | ||
var commands = this.commands.filter(function (c) { | ||
return !c.hidden; | ||
}).map(function (c) { | ||
return [_this2.usage(c), c.description]; | ||
}); | ||
if (commands.length === 0) return; | ||
this.log(this.argv0 + ' ' + this.constructor.topic + ' commands: (' + this.color.cmd(this.argv0 + ' help ' + this.constructor.topic + ':COMMAND') + ' for details)\n'); | ||
this.log(this.renderList(commands)); | ||
this.log(); | ||
} | ||
}, { | ||
key: 'commandHelp', | ||
value: function commandHelp(command) { | ||
var usage = this.argv0 + ' ' + this.usage(command); | ||
this.log('Usage: ' + this.color.cmd(usage) + '\n'); | ||
if (command.description) this.log(command.description.trim() + '\n'); | ||
var flags = (command.flags || []).filter(function (f) { | ||
return !f.hidden; | ||
}); | ||
if (flags.length) this.log(this.renderFlags(flags) + '\n'); | ||
if (command.help) this.log(command.help.trim() + '\n'); | ||
} | ||
}, { | ||
key: 'renderArg', | ||
value: function renderArg(arg) { | ||
var name = arg.name.toUpperCase(); | ||
if (arg.required !== false && arg.optional !== true) return '' + name;else return '[' + name + ']'; | ||
} | ||
}, { | ||
key: 'renderFlags', | ||
value: function renderFlags(flags) { | ||
flags.sort(function (a, b) { | ||
if (a.char && !b.char) return -1; | ||
if (b.char && !a.char) return 1; | ||
if (a.name < b.name) return -1; | ||
if (b.name < a.name) return 1; | ||
return 0; | ||
}); | ||
return this.renderList(flags.map(function (f) { | ||
var label = []; | ||
if (f.char) label.push('-' + f.char); | ||
if (f.name) label.push(' --' + f.name); | ||
var usage = f.hasValue ? ' ' + f.name.toUpperCase() : ''; | ||
var description = f.description || ''; | ||
if (f.required || f.optional === false) description = '(required) ' + description; | ||
return [label.join(',').trim() + usage, description]; | ||
})); | ||
} | ||
}, { | ||
key: 'usage', | ||
value: function usage(command) { | ||
if (command.usage) return command.usage; | ||
var cmd = command.command ? command.topic + ':' + command.command : command.topic; | ||
if (!command.args) return cmd; | ||
var args = command.args.map(this.renderArg); | ||
return cmd + ' ' + args.join(' '); | ||
} | ||
}, { | ||
key: 'renderList', | ||
value: function renderList(items) { | ||
var _this3 = this; | ||
var S = require('string'); | ||
var max = require('lodash.maxby'); | ||
var maxLength = max(items, '[0].length')[0].length + 1; | ||
var lines = items.map(function (i) { | ||
return [ | ||
// left side | ||
' ' + S(i[0]).padRight(maxLength), | ||
// right side | ||
i[1] ? _this3.linewrap(maxLength + 4, i[1]) : '']; | ||
}) | ||
// join left + right side | ||
.map(function (i) { | ||
return i[1] ? i[0] + ' # ' + i[1] : i[0]; | ||
}); | ||
return lines.join('\n'); | ||
} | ||
}, { | ||
key: 'linewrap', | ||
value: function linewrap(length, s) { | ||
var linewrap = require('./output/linewrap'); | ||
return linewrap(length, _screen.stdtermwidth, { | ||
skipScheme: 'ansi-color' | ||
})(s).trim(); | ||
} | ||
}]); | ||
return Topic; | ||
}(_output2.default); | ||
module.exports = Topic; |
{ | ||
"name": "heroku-cli-command", | ||
"description": "base Heroku CLI command", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"author": "Jeff Dickey @dickeyxxx", | ||
@@ -9,2 +9,3 @@ "bugs": "https://github.com/heroku/heroku-cli-command/issues", | ||
"ansi-escapes": "1.4.0", | ||
"babel-runtime": "6.23.0", | ||
"cardinal": "1.0.0", | ||
@@ -14,3 +15,3 @@ "chalk": "1.1.3", | ||
"heroku-client": "3.0.1", | ||
"http-call": "1.0.7", | ||
"http-call": "1.0.11", | ||
"lodash.maxby": "4.6.0", | ||
@@ -22,9 +23,26 @@ "netrc": "0.1.4", | ||
"devDependencies": { | ||
"chai": "3.5.0", | ||
"mocha": "3.2.0", | ||
"babel-cli": "6.23.0", | ||
"babel-eslint": "7.1.1", | ||
"babel-jest": "18.0.0", | ||
"babel-plugin-transform-flow-strip-types": "6.22.0", | ||
"babel-plugin-transform-runtime": "6.23.0", | ||
"babel-preset-es2015": "6.22.0", | ||
"babel-preset-stage-2": "6.22.0", | ||
"codecov": "1.0.1", | ||
"flow-bin": "0.39.0", | ||
"flow-copy-source": "1.1.0", | ||
"flow-typed": "2.0.0", | ||
"jest": "18.1.0", | ||
"nock": "9.0.6", | ||
"np": "2.12.0", | ||
"nyc": "10.1.2", | ||
"rimraf": "2.6.0", | ||
"standard": "8.6.0" | ||
}, | ||
"homepage": "https://github.com/heroku/heroku-cli-command", | ||
"jest": { | ||
"testEnvironment": "node", | ||
"setupFiles": [ | ||
"./test/init.js" | ||
] | ||
}, | ||
"keywords": [ | ||
@@ -35,13 +53,20 @@ "heroku", | ||
"license": "ISC", | ||
"main": "index.js", | ||
"main": "lib/command.js", | ||
"repository": "https://github.com/heroku/heroku-command", | ||
"scripts": { | ||
"build": "babel src -d lib --ignore '*.test.js'", | ||
"clean": "rimraf lib", | ||
"copy-flow": "flow-copy-source -v -i '*.test.js' src lib", | ||
"prepare": "npm run clean && npm run build && npm run copy-flow", | ||
"release": "np", | ||
"test": "nyc mocha && standard" | ||
"test": "jest && flow && standard", | ||
"watch": "babel --watch src -d lib --ignore '*.test.js'" | ||
}, | ||
"standard": { | ||
"parser": "babel-eslint", | ||
"ignore": [ | ||
"lib/linewrap.js" | ||
"src/output/linewrap.js", | ||
"flow-typed" | ||
] | ||
} | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
39
2208
135649
11
16
5
+ Addedbabel-runtime@6.23.0
+ Addedbabel-runtime@6.23.0(transitive)
+ Addedcore-js@2.6.12(transitive)
+ Addedhttp-call@1.0.11(transitive)
+ Addedregenerator-runtime@0.10.5(transitive)
- Removedhttp-call@1.0.7(transitive)
Updatedhttp-call@1.0.11