@lenne.tech/cli
Version:
lenne.Tech CLI: lt
67 lines (66 loc) • 3.1 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");
const command_help_1 = require("./lib/command-help");
/**
* 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 top-level help, h, --help, -h
.version() // provides default for version, v, --version, -v
.create();
// Generic per-command `--help` / `-h`: gluegun's `.help()` only covers the
// top level, so without this a subcommand like `lt fullstack convert-mode
// --help` would actually RUN. The interceptor makes every command print
// help and return without executing when help is requested.
(0, command_help_1.installHelpInterceptor)(cli.commands, cli.defaultCommand);
// 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 };