UNPKG

@semo/cli

Version:

A command line tools dispatcher

97 lines 4.57 kB
"use strict"; 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()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.handler = exports.builder = exports.desc = exports.command = exports.disabled = exports.plugin = exports.noblank = void 0; const core_1 = require("@semo/core"); const path_1 = __importDefault(require("path")); const shelljs_1 = __importDefault(require("shelljs")); const debug = core_1.Utils.debug('semo:'); exports.noblank = true; // run call another command so disable one blank line exports.plugin = 'semo'; exports.disabled = false; // Set to true to disable this command temporarily exports.command = 'run [plugin]'; exports.desc = 'Run any plugin command directly'; // export const aliases = '' // export const middleware = (argv) => {} const builder = function (yargs) { yargs.option('force', { describe: 'Force upgrade plugin cache', alias: 'F', boolean: true, default: false, }); yargs.option('scope', { default: '', describe: 'Set plugin npm scope' }); yargs.option('with', { describe: 'Set plugin dependent plugins' }); // yargs.commandDir('run') }; exports.builder = builder; const handler = function (argv) { return __awaiter(this, void 0, void 0, function* () { const scriptName = argv.scriptName || 'semo'; // Populate command string let pluginShort; if (argv.plugin) { if (argv.plugin.indexOf(`${scriptName}-plugin-`) === -1) { argv.plugin = `${scriptName}-plugin-${argv.plugin}`; } if (argv.scope) { argv.plugin = `@${argv.scope}/${argv.plugin}`; } try { core_1.Utils.installPackage(argv.plugin, 'run-plugin-cache', true, argv.force); } catch (e) { core_1.Utils.error(`Plugin ${argv.plugin} not found or entry not exist`); } pluginShort = argv.plugin.substring(argv.plugin.indexOf(`${scriptName}-plugin-`) + `${scriptName}-plugin-`.length); } argv.with = argv.with ? core_1.Utils._.castArray(argv.with) : []; if (argv.with && argv.with.length > 0) { argv.with.forEach(dep => { if (dep.indexOf(`${scriptName}-plugin-`) === -1) { dep = `${scriptName}-plugin-${dep}`; } if (argv.scope) { dep = `@${argv.scope}/${dep}`; } try { core_1.Utils.installPackage(dep, 'run-plugin-cache', true, argv.force); } catch (e) { core_1.Utils.error(`Plugin ${dep} not found or entry not exist`); } }); } // Pass SEMO_PLUGIN_DIR let extraPluginDirEnvName = core_1.Utils._.upperCase(scriptName) + '_PLUGIN_DIR'; let runPluginDir = path_1.default.resolve(String(process.env.HOME), `.${scriptName}`, 'run-plugin-cache', 'node_modules'); let command = argv._; command.shift(); if (command.length === 0 && pluginShort) { command = [pluginShort]; } command = command.concat(argv['--'] || []); if (shelljs_1.default.which('semo')) { debug(`Running: ${extraPluginDirEnvName}=${runPluginDir} semo ${command.join(' ')}`); core_1.Utils.exec(`${extraPluginDirEnvName}=${runPluginDir} semo ${command.join(' ')}`); } else { debug(`Running: ${extraPluginDirEnvName}=${runPluginDir} npx @semo/cli ${command.join(' ')}`); core_1.Utils.exec(`${extraPluginDirEnvName}=${runPluginDir} npx @semo/cli ${command.join(' ')}`); } }); }; exports.handler = handler; //# sourceMappingURL=run.js.map