UNPKG

@commercetools-frontend/menu-cli

Version:

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

47 lines (38 loc) 1.24 kB
import path from 'path'; import menuUtils from '../utils/menu.js'; async function build(cliFlags, { cwd }) { if (!cliFlags.silent) { console.log(`==> Building application menu for ${path.basename(cwd)}`); } const menuConfigFile = path.join(cwd, cliFlags['menu-file']); const menuConfigImport = await import(menuConfigFile); const menuConfig = menuConfigImport.default; const data = menuUtils.serialize(cliFlags, menuConfig, cwd); const shouldWriteOutFile = cliFlags['out-file'] && cliFlags['out-file'].length > 0; // Either an output file will be written... if (shouldWriteOutFile) { menuUtils.write(cwd, cliFlags['out-file'], data); if (!cliFlags.silent) { console.log( `===> Finished building menu for ${path.basename(cwd)} into ${ cliFlags['out-file'] }.` ); } process.exit(0); } // ...or the data is logged and returned. if (!cliFlags.silent) { console.log( `===> Finished building menu for ${path.basename(cwd)} to stdout.` ); } // Log to stdout to be picked up by other scripts. if (!cliFlags.silent) { console.log(data); } // Return to be picked up by tests or other callers. return data; } export default build;