classy-commander
Advanced tools
Comparing version 4.0.0 to 4.1.0
172
classy.js
@@ -11,128 +11,84 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Commander = void 0; | ||
// tslint:disable:no-console | ||
var chalk = require("chalk"); | ||
var cli = require("commander"); | ||
var fs = require("fs-extra"); | ||
var glob = require("glob"); | ||
var path = require("path"); | ||
var commander_1 = require("./commander"); | ||
var modules_1 = require("./modules"); | ||
var Commander = /** @class */ (function () { | ||
function Commander() { | ||
} | ||
Commander.prototype.ioc = function (iocContainer) { | ||
const chalk = require("chalk"); | ||
const cli = require("commander"); | ||
const fs = require("fs-extra"); | ||
const glob = require("glob"); | ||
const path = require("path"); | ||
const commander_1 = require("./commander"); | ||
const modules_1 = require("./modules"); | ||
class Commander { | ||
ioc(iocContainer) { | ||
(0, commander_1.setIocContainer)(iocContainer); | ||
return this; | ||
}; | ||
Commander.prototype.commandsFromDirectory = function (directoryPath) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, new Promise(function (resolve, reject) { | ||
var pattern = path.join(directoryPath, '**/*.@(js|ts)'); | ||
glob(pattern, function (err, matches) { | ||
if (err) { | ||
return reject(err); | ||
} | ||
var moduleFileNames = (0, modules_1.getUniqueModuleNames)(matches); | ||
for (var _i = 0, moduleFileNames_1 = moduleFileNames; _i < moduleFileNames_1.length; _i++) { | ||
var moduleFileName = moduleFileNames_1[_i]; | ||
require(moduleFileName); | ||
} | ||
resolve(_this); | ||
}); | ||
})]; | ||
} | ||
commandsFromDirectory(directoryPath) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return new Promise((resolve, reject) => { | ||
const pattern = path.join(directoryPath, '**/*.@(js|ts)'); | ||
glob(pattern, (err, matches) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
const moduleFileNames = (0, modules_1.getUniqueModuleNames)(matches); | ||
for (const moduleFileName of moduleFileNames) { | ||
require(moduleFileName); | ||
} | ||
resolve(this); | ||
}); | ||
}); | ||
}); | ||
}; | ||
Commander.prototype.version = function (version) { | ||
} | ||
version(version) { | ||
this._version = version; | ||
return this; | ||
}; | ||
Commander.prototype.versionFromPackage = function (directoryPath) { | ||
} | ||
versionFromPackage(directoryPath) { | ||
this._version = this.getPackageVersion(path.resolve(directoryPath, './package.json')); | ||
return this; | ||
}; | ||
Commander.prototype.execute = function (argv) { | ||
} | ||
execute(argv) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var args, err_1, errorMessage; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
if (this._version) { | ||
cli.program.version(this._version); | ||
} | ||
args = argv || process.argv; | ||
cli.program.addHelpText('after', '\n'); | ||
if (args.length <= 2) { | ||
cli.program.outputHelp(); | ||
return [2 /*return*/]; | ||
} | ||
cli.program.on('command:*', function () { | ||
console.error(); | ||
console.error('Invalid command: %s\nSee --help for a list of available commands.', cli.program.args.join(' ')); | ||
console.error(); | ||
process.exitCode = 1; | ||
}); | ||
_b.label = 1; | ||
case 1: | ||
_b.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, cli.program.parseAsync(args)]; | ||
case 2: | ||
_b.sent(); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
err_1 = _b.sent(); | ||
process.exitCode = 1; | ||
console.error(); | ||
errorMessage = (_a = err_1.message) !== null && _a !== void 0 ? _a : err_1; | ||
console.error(chalk.red(errorMessage)); | ||
console.error(); | ||
throw err_1; | ||
case 4: return [2 /*return*/]; | ||
} | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this._version) { | ||
cli.program.version(this._version); | ||
} | ||
const args = argv || process.argv; | ||
cli.program.addHelpText('after', '\n'); | ||
if (args.length <= 2) { | ||
cli.program.outputHelp(); | ||
return; | ||
} | ||
cli.program.on('command:*', () => { | ||
console.error(); | ||
console.error('Invalid command: %s\nSee --help for a list of available commands.', cli.program.args.join(' ')); | ||
console.error(); | ||
process.exitCode = 1; | ||
}); | ||
try { | ||
yield cli.program.parseAsync(args); | ||
} | ||
catch (err) { | ||
process.exitCode = 1; | ||
console.error(); | ||
// istanbul ignore next | ||
const errorMessage = (_a = err.message) !== null && _a !== void 0 ? _a : err; | ||
console.error(chalk.red(errorMessage)); | ||
console.error(); | ||
throw err; | ||
} | ||
}); | ||
}; | ||
Commander.prototype.getPackageVersion = function (packageFileName) { | ||
var exists = fs.pathExistsSync(packageFileName); | ||
} | ||
getPackageVersion(packageFileName) { | ||
const exists = fs.pathExistsSync(packageFileName); | ||
if (!exists) { | ||
throw new Error('Could not find package.json to load version from'); | ||
} | ||
var packageObject = fs.readJSONSync(packageFileName); | ||
var version = packageObject && packageObject.version; | ||
const packageObject = fs.readJSONSync(packageFileName); | ||
const version = packageObject && packageObject.version; | ||
return version; | ||
}; | ||
return Commander; | ||
}()); | ||
} | ||
} | ||
exports.Commander = Commander; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.coerceValue = void 0; | ||
var boolean_1 = require("boolean"); | ||
const boolean_1 = require("boolean"); | ||
function coerceValue(value, toType, defaultValue) { | ||
@@ -10,3 +10,3 @@ if (value === undefined) { | ||
if (value instanceof Array) { | ||
return value.map(function (v) { return coerceValue(v, toType, undefined); }); | ||
return value.map((v) => coerceValue(v, toType, undefined)); | ||
} | ||
@@ -13,0 +13,0 @@ if (toType === Number) { |
149
commander.js
@@ -11,37 +11,9 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCommandUsage = exports.getCommandDefinitionUsage = exports.registerCommand = exports.getIocContainer = exports.setIocContainer = void 0; | ||
var cli = require("commander"); | ||
var _ = require("lodash"); | ||
var coercion_1 = require("./coercion"); | ||
var metadata_1 = require("./metadata"); | ||
var iocContainer; | ||
var commandDefinitions = []; | ||
const cli = require("commander"); | ||
const coercion_1 = require("./coercion"); | ||
const metadata_1 = require("./metadata"); | ||
let iocContainer; | ||
const commandDefinitions = []; | ||
function setIocContainer(container) { | ||
@@ -56,9 +28,9 @@ iocContainer = container; | ||
function getOptionUsage(option) { | ||
var result = ''; | ||
let result = ''; | ||
if (option.shortName) { | ||
result = "-".concat(option.shortName, ", "); | ||
result = `-${option.shortName}, `; | ||
} | ||
result += "--".concat(option.name.toString(), " "); | ||
result += `--${option.name.toString()} `; | ||
if (option.valueName) { | ||
result += "<".concat(option.valueName, ">"); | ||
result += `<${option.valueName}>`; | ||
} | ||
@@ -68,17 +40,15 @@ return result.trim(); | ||
function getParams(command, args) { | ||
var values = (0, metadata_1.getCommandValues)(command.paramsClass.prototype); | ||
var options = (0, metadata_1.getCommandOptions)(command.paramsClass.prototype); | ||
var params = new command.paramsClass(); | ||
var paramIndex = 0; | ||
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) { | ||
var value = values_1[_i]; | ||
var argValue = args[paramIndex++]; | ||
var defaultValue = params[value.name]; | ||
var paramValue = (0, coercion_1.coerceValue)(argValue, value.type, defaultValue); | ||
const values = (0, metadata_1.getCommandValues)(command.paramsClass.prototype); | ||
const options = (0, metadata_1.getCommandOptions)(command.paramsClass.prototype); | ||
const params = new command.paramsClass(); | ||
let paramIndex = 0; | ||
for (const value of values) { | ||
const argValue = args[paramIndex++]; | ||
const defaultValue = params[value.name]; | ||
const paramValue = (0, coercion_1.coerceValue)(argValue, value.type, defaultValue); | ||
params[value.name] = paramValue; | ||
} | ||
var optionValues = args[paramIndex]; | ||
for (var _a = 0, options_1 = options; _a < options_1.length; _a++) { | ||
var option = options_1[_a]; | ||
var value = optionValues[option.name]; | ||
const optionValues = args[paramIndex]; | ||
for (const option of options) { | ||
const value = optionValues[option.name]; | ||
if (value !== undefined) { | ||
@@ -91,4 +61,4 @@ params[option.name.toString()] = value; | ||
function instantiateCommand(command) { | ||
var constructor = command.type; | ||
var instance = iocContainer ? iocContainer.get(constructor) : new constructor(); | ||
const constructor = command.type; | ||
const instance = iocContainer ? iocContainer.get(constructor) : new constructor(); | ||
return instance; | ||
@@ -98,4 +68,4 @@ } | ||
var _a; | ||
var optionUsage = getOptionUsage(option); | ||
var coercedValue = (function (value) { | ||
const optionUsage = getOptionUsage(option); | ||
const coercedValue = ((value) => { | ||
if (option.valueName && option.type === Number) { | ||
@@ -108,59 +78,40 @@ return +value; | ||
}); | ||
var params = new paramsClass(); | ||
var defaultValue = params[option.name]; | ||
const params = new paramsClass(); | ||
const defaultValue = params[option.name]; | ||
cliCommand.option(optionUsage, (_a = option.description) !== null && _a !== void 0 ? _a : '', coercedValue, defaultValue); | ||
} | ||
function registerCommand(commandDefinition) { | ||
var _this = this; | ||
commandDefinitions.push(commandDefinition); | ||
var usage = getCommandDefinitionUsage(commandDefinition); | ||
var cliCommand = cli.program.command(usage); | ||
const usage = getCommandDefinitionUsage(commandDefinition); | ||
const cliCommand = cli.program.command(usage); | ||
if (commandDefinition.description) { | ||
cliCommand.description(commandDefinition.description); | ||
} | ||
var options = (0, metadata_1.getCommandOptions)(commandDefinition.paramsClass.prototype); | ||
for (var _i = 0, options_2 = options; _i < options_2.length; _i++) { | ||
var option = options_2[_i]; | ||
const options = (0, metadata_1.getCommandOptions)(commandDefinition.paramsClass.prototype); | ||
for (const option of options) { | ||
registerCommandOption(cliCommand, commandDefinition.paramsClass, option); | ||
} | ||
cliCommand.action(function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
return __awaiter(_this, void 0, void 0, function () { | ||
var commandInstance, params; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
commandInstance = instantiateCommand(commandDefinition); | ||
params = getParams(commandDefinition, args); | ||
return [4 /*yield*/, commandInstance.execute(params)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}); | ||
cliCommand.action((...args) => __awaiter(this, void 0, void 0, function* () { | ||
const commandInstance = instantiateCommand(commandDefinition); | ||
const params = getParams(commandDefinition, args); | ||
yield commandInstance.execute(params); | ||
})); | ||
} | ||
exports.registerCommand = registerCommand; | ||
function valueDefinitionToUsageString(value) { | ||
var name = "".concat(value.name).concat(value.variadic ? '...' : ''); | ||
var usage = value.optional ? "[".concat(name, "]") : "<".concat(name, ">"); | ||
const name = `${value.name}${value.variadic ? '...' : ''}`; | ||
const usage = value.optional ? `[${name}]` : `<${name}>`; | ||
return usage; | ||
} | ||
function getCommandDefinitionUsage(commandDefinition) { | ||
var values = (0, metadata_1.getCommandValues)(commandDefinition.paramsClass.prototype); | ||
var valuesUsage = _ | ||
.chain(values) | ||
.map(function (value, index) { return ({ | ||
value: value, | ||
index: index | ||
}); }) | ||
.sort(function (a, b) { return a.value.variadic ? 1 : b.value.variadic ? -1 : a.index - b.index; }) | ||
.map(function (valueAndIndex) { return valueDefinitionToUsageString(valueAndIndex.value); }) | ||
.join(' ') | ||
.value(); | ||
var usage = "".concat(commandDefinition.name, " ").concat(valuesUsage).trim(); | ||
const values = (0, metadata_1.getCommandValues)(commandDefinition.paramsClass.prototype); | ||
const valuesUsage = values | ||
.map((value, index) => ({ | ||
value, | ||
index | ||
})) | ||
.sort((a, b) => a.value.variadic ? 1 : b.value.variadic ? -1 : a.index - b.index) | ||
.map((valueAndIndex) => valueDefinitionToUsageString(valueAndIndex.value)) | ||
.join(' '); | ||
const usage = `${commandDefinition.name} ${valuesUsage}`.trim(); | ||
return usage; | ||
@@ -170,10 +121,10 @@ } | ||
function getCommandUsage(commandClass) { | ||
var commandDefinition = commandDefinitions | ||
.find(function (item) { return item.type === commandClass; }); | ||
const commandDefinition = commandDefinitions | ||
.find((item) => item.type === commandClass); | ||
if (!commandDefinition) { | ||
throw new Error('Class is not a command'); | ||
} | ||
var usage = getCommandDefinitionUsage(commandDefinition); | ||
const usage = getCommandDefinitionUsage(commandDefinition); | ||
return usage; | ||
} | ||
exports.getCommandUsage = getCommandUsage; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.value = exports.option = exports.command = void 0; | ||
var commander_1 = require("./commander"); | ||
var meta = require("./metadata"); | ||
var command = function (name, paramsClass, description) { | ||
return function (target) { | ||
const commander_1 = require("./commander"); | ||
const meta = require("./metadata"); | ||
const command = (name, paramsClass, description) => { | ||
return (target) => { | ||
(0, commander_1.registerCommand)({ | ||
name: name, | ||
description: description, | ||
name, | ||
description, | ||
type: target, | ||
paramsClass: paramsClass, | ||
paramsClass, | ||
}); | ||
@@ -17,9 +17,9 @@ }; | ||
exports.command = command; | ||
var option = function (options) { return function (target, name) { | ||
const option = (options) => (target, name) => { | ||
meta.addCommandOption(target, name, options); | ||
}; }; | ||
}; | ||
exports.option = option; | ||
var value = function (options) { return function (target, name) { | ||
const value = (options) => (target, name) => { | ||
meta.addCommandValue({ | ||
name: name, | ||
name, | ||
paramsClassPrototype: target, | ||
@@ -29,3 +29,3 @@ optional: !!(options && options.optional), | ||
}); | ||
}; }; | ||
}; | ||
exports.value = value; |
45
index.js
@@ -11,33 +11,6 @@ "use strict"; | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (g && (g = 0, op[0] && (_ = 0)), _) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getCommandUsageString = exports.execute = exports.commandsFromDirectory = exports.ioc = exports.versionFromPackage = exports.version = exports.value = exports.option = exports.command = void 0; | ||
var classy_1 = require("./classy"); | ||
var commander_1 = require("./commander"); | ||
const classy_1 = require("./classy"); | ||
const commander_1 = require("./commander"); | ||
var decorators_1 = require("./decorators"); | ||
@@ -47,3 +20,3 @@ Object.defineProperty(exports, "command", { enumerable: true, get: function () { return decorators_1.command; } }); | ||
Object.defineProperty(exports, "value", { enumerable: true, get: function () { return decorators_1.value; } }); | ||
var commander = new classy_1.Commander(); | ||
const commander = new classy_1.Commander(); | ||
// tslint:disable-next-line:no-shadowed-variable | ||
@@ -67,6 +40,4 @@ function version(version) { | ||
function commandsFromDirectory(directoryPath) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, commander.commandsFromDirectory(directoryPath)]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return commander.commandsFromDirectory(directoryPath); | ||
}); | ||
@@ -76,6 +47,4 @@ } | ||
function execute(argv) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, commander.execute(argv)]; | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return commander.execute(argv); | ||
}); | ||
@@ -82,0 +51,0 @@ } |
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -31,18 +11,18 @@ exports.addCommandOption = exports.getCommandOptions = exports.addCommandValue = exports.getCommandValues = exports.metadataKeys = void 0; | ||
function getCommandValues(paramsClassPrototype) { | ||
return __spreadArray([], (Reflect.getOwnMetadata(exports.metadataKeys.values, paramsClassPrototype) || []), true); | ||
return [...(Reflect.getOwnMetadata(exports.metadataKeys.values, paramsClassPrototype) || [])]; | ||
} | ||
exports.getCommandValues = getCommandValues; | ||
function addCommandValue(options) { | ||
var name = options.name, optional = options.optional, paramsClassPrototype = options.paramsClassPrototype, variadicType = options.variadicType; | ||
var type = variadicType || Reflect.getMetadata('design:type', paramsClassPrototype, name); | ||
var variadic = !!variadicType; | ||
var values = getCommandValues(paramsClassPrototype); | ||
if (variadic && values.some(function (value) { return value.variadic; })) { | ||
const { name, optional, paramsClassPrototype, variadicType } = options; | ||
const type = variadicType || Reflect.getMetadata('design:type', paramsClassPrototype, name); | ||
const variadic = !!variadicType; | ||
const values = getCommandValues(paramsClassPrototype); | ||
if (variadic && values.some((value) => value.variadic)) { | ||
throw new Error('Command can have only one variadic value'); | ||
} | ||
values.push({ | ||
name: name, | ||
type: type, | ||
optional: optional, | ||
variadic: variadic | ||
name, | ||
type, | ||
optional, | ||
variadic | ||
}); | ||
@@ -53,11 +33,12 @@ Reflect.defineMetadata(exports.metadataKeys.values, values, options.paramsClassPrototype); | ||
function getCommandOptions(paramsClassPrototype) { | ||
return __spreadArray([], (Reflect.getOwnMetadata(exports.metadataKeys.options, paramsClassPrototype) || []), true); | ||
return [...(Reflect.getOwnMetadata(exports.metadataKeys.options, paramsClassPrototype) || [])]; | ||
} | ||
exports.getCommandOptions = getCommandOptions; | ||
function addCommandOption(paramsClassPrototype, name, options) { | ||
var type = Reflect.getMetadata('design:type', paramsClassPrototype, name); | ||
var allOptions = getCommandOptions(paramsClassPrototype); | ||
allOptions.push(__assign({ name: name, type: type }, options)); | ||
const type = Reflect.getMetadata('design:type', paramsClassPrototype, name); | ||
const allOptions = getCommandOptions(paramsClassPrototype); | ||
allOptions.push(Object.assign({ name, | ||
type }, options)); | ||
Reflect.defineMetadata(exports.metadataKeys.options, allOptions, paramsClassPrototype); | ||
} | ||
exports.addCommandOption = addCommandOption; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getUniqueModuleNames = void 0; | ||
var _ = require("lodash"); | ||
function isFileNameTypeScriptOrJavaScript(fileName) { | ||
@@ -15,11 +14,10 @@ return /.\.(ts|js)$/i.test(fileName); | ||
function getUniqueModuleNames(fileNames) { | ||
var moduleNames = _ | ||
.chain(fileNames) | ||
.filter(function (fileName) { return !isFileNameDeclarationFile(fileName); }) | ||
.filter(isFileNameTypeScriptOrJavaScript) | ||
.map(removeFileExtension) | ||
.uniq() | ||
.value(); | ||
const moduleNames = [ | ||
...new Set(fileNames | ||
.filter((filename) => !isFileNameDeclarationFile(filename)) | ||
.filter(isFileNameTypeScriptOrJavaScript) | ||
.map(removeFileExtension)), | ||
]; | ||
return moduleNames; | ||
} | ||
exports.getUniqueModuleNames = getUniqueModuleNames; |
{ | ||
"name": "classy-commander", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"description": "A TypeScript wrapper for Commander that lets you easily declare commands using classes & decorators and provides strongly typed arguments.", | ||
@@ -21,3 +21,3 @@ "main": "index.js", | ||
"type": "git", | ||
"url": "https://github.com/codeandcats/classy-commander.git" | ||
"url": "git+https://github.com/codeandcats/classy-commander.git" | ||
}, | ||
@@ -30,5 +30,4 @@ "dependencies": { | ||
"glob": "7.1.6", | ||
"lodash": "^4.17.21", | ||
"reflect-metadata": "0.1.13" | ||
} | ||
} |
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
6
30864
18
477
- Removedlodash@^4.17.21
- Removedlodash@4.17.21(transitive)