UNPKG

@commercetools-frontend/menu-cli

Version:

CLI to manage a Custom Application menu.json with translations support.

63 lines (52 loc) 1.8 kB
#!/usr/bin/env node import mri from 'mri'; import build from '../commands/build.js'; process.env.NODE_ENV = 'production'; // Resolve the absolute path of the caller location. This is necessary // to point to files within that folder. const cwd = process.cwd(); (async () => { try { const cliFlags = mri(process.argv.slice(2), { alias: { help: ['h'] }, default: { 'menu-file': 'menu.mjs', 'out-file': 'menu.json', 'i18n-folder': 'i18n/data', locales: 'en, de, es, fr-FR, zh-CN, ja', silent: false, }, }); const cliCommands = cliFlags._; if ( cliCommands.length === 0 || (cliCommands.help && cliCommands.length === 0) ) { console.log(` Usage: menu-cli [command] [flags] Displays help information. Command: build Build menu of the application. Options: --menu-file (optional) The file containing an ES module of the menu configuration with react-intl messages. Defaults to 'menu.mjs' file. --out-file (optional) The generated JSON file with the menu configuration. Defaults to 'menu.json' file. --i18n-folder (optional) The folder containing the generated translations. Defaults to 'i18n/data'. --locales (optional) The comma seperated locales to generate translations for. Defaults to 'en', 'de', 'es', 'fr-FR', 'zh-CN', 'ja'. --silent (optional) Disable logging. Defaults to false. `); process.exit(0); } const cliCommand = cliCommands[0]; switch (cliCommand) { case 'build': await build(cliFlags, { cwd }); process.exit(0); break; default: throw new Error(`💀 Unknown command "${cliCommand}".`); } } catch (error) { console.error(error); process.exit(1); } })();