UNPKG

create-snippet

Version:
33 lines (32 loc) 1.2 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const fs_1 = __importDefault(require("fs")); const path_1 = __importDefault(require("path")); const modules_1 = require("../modules"); const moduleArgv = new modules_1.ModuleArgv(); const arg = moduleArgv.getNotFormatted()[0]; const paths = fs_1.default.readdirSync(path_1.default.join(__dirname, '..', 'scripts')); function createTeamNamesFromFile(str) { const [filename] = str.split('.'); const firstLetters = filename .split('-') .map((word) => word[0]) .join(''); const hyphenated = `--${filename}`; const short = `-${firstLetters}`; return { [hyphenated]: str, [short]: str }; } const arrayCommands = paths.map((path) => ({ ...createTeamNamesFromFile(path), })); const commands = arrayCommands.reduce((flat, command) => { return { ...flat, ...command }; }, {}); const command = commands[arg]; if (typeof command === 'undefined') throw new Error('No script'); require(`../scripts/${commands[arg]}`);