@lenne.tech/cli
Version:
lenne.Tech CLI: lt
61 lines (60 loc) • 2.62 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const gluegun_1 = require("gluegun");
const path_1 = require("path");
/**
* Create the cli and kick it off
*/
function run(argv) {
return __awaiter(this, void 0, void 0, function* () {
try {
// Create a CLI runtime
const cli = (0, gluegun_1.build)()
.brand('lt')
.src(__dirname)
// .plugins('./node_modules', { matching: 'lt-*', hidden: true })
.plugin((0, path_1.join)(__dirname, '..', 'node_modules', '@lenne.tech', 'cli-plugin-helper', 'dist'), {
commandFilePattern: ['*.js'],
extensionFilePattern: ['*.js'],
})
.help() // provides default for help, h, --help, -h
.version() // provides default for version, v, --version, -v
.create();
// Run cli
const toolbox = yield cli.run(argv);
// Record command in history (if history extension is available)
if ((toolbox === null || toolbox === void 0 ? void 0 : toolbox.history) && toolbox.commandName && !['completion', 'history'].includes(toolbox.commandName)) {
try {
const args = argv.slice(1); // Remove the command name
toolbox.history.addEntry(toolbox.commandName, args);
}
catch (_a) {
// Ignore history errors
}
}
// Send it back (for testing, mostly)
return toolbox;
}
catch (e) {
// Abort via CTRL-C
if (!e) {
// eslint-disable-next-line no-console
console.log('Goodbye ✌️');
}
else {
// Throw error
throw e;
}
}
});
}
module.exports = { run };