@semo/cli
Version:
A command line tools dispatcher
50 lines • 2.05 kB
JavaScript
;
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.aliases = exports.desc = exports.command = exports.plugin = void 0;
const path_1 = __importDefault(require("path"));
const core_1 = require("@semo/core");
const shelljs_1 = __importDefault(require("shelljs"));
exports.plugin = 'semo';
exports.command = 'plugin <name>';
exports.desc = 'Generate a plugin structure';
exports.aliases = ['plug'];
const builder = function (yargs) {
yargs.option('force', {
describe: 'force creation, remove existed one',
alias: 'f',
});
};
exports.builder = builder;
const handler = function (argv) {
let pluginDir = argv.pluginMakeDir || argv.pluginDir;
if (!pluginDir || !core_1.Utils.fileExistsSyncCache(pluginDir)) {
core_1.Utils.error('"pluginDir" missing in config file or not exist in current directory!');
}
const namePattern = /[a-z0-9]+/;
if (!namePattern.test(argv.name)) {
core_1.Utils.error('Plugin name invalid!');
}
const scriptName = argv.scriptName || 'semo';
const pluginPath = path_1.default.resolve(pluginDir, `${scriptName}-plugin-${argv.name}`);
if (core_1.Utils.fileExistsSyncCache(pluginPath)) {
if (argv.force) {
core_1.Utils.warn(`Existed ${scriptName}-plugin-${argv.name} is deleted before creating a new one!`);
shelljs_1.default.rm('-rf', pluginPath);
}
else {
core_1.Utils.error(`Destination existed, command abort!`);
}
}
shelljs_1.default.mkdir('-p', pluginPath);
shelljs_1.default.cd(pluginPath);
if (!shelljs_1.default.which(scriptName)) {
core_1.Utils.error(`Script ${scriptName} not found!`);
}
core_1.Utils.exec('npm init --yes');
core_1.Utils.exec(`${scriptName} init --plugin`);
};
exports.handler = handler;
//# sourceMappingURL=plugin.js.map