UNPKG

@pega/custom-dx-components

Version:

Utility for building custom UI components

297 lines (292 loc) 6.09 kB
import arg from 'arg'; import chalk from 'chalk'; import { authenticate, buildComponent, buildAllComponents, buildLibrary, createComponent, createAllComponents, createLibrary, switchLibrary, createVersion, switchVersion, deleteComponent, deleteAllComponents, deleteLibrary, deletePublished, deleteVersion, importArchive, exportArchive, exportRC, importComponent, initProject, listComponents, listLibrary, listPublished, publishComponent, publishAllComponents, publishLibrary, quarantine, renameComponent, moveComponent, renameLibrary, restoreConfig, restore, revertWebPack, promoteWebPack, showStatus, showHelp, setPermanent, storeComponents, updateComponent, validate, upgrade, buildJestAssets, startDevServer } from './tasks/index.js'; const TASKS = { INIT: 'init', CREATE: 'create', CREATE_ALL: 'createAll', CREATE_LIB: 'createLibrary', SWITCH_LIB: 'switchLibrary', CREATE_VERSION: 'createVersion', SWITCH_VERSION: 'switchVersion', BUILD: 'buildComponent', BUILD_ALL: 'buildAllComponents', BUILD_LIB: 'buildLibrary', PROMOTE_WEBPACK: 'promoteWebPack', REVERT_WEBPACK: 'revertWebPack', PUBLISH: 'publish', PUBLISH_ALL: 'publishAll', PUBLISH_LIB: 'publishLibrary', RENAME: 'rename', RENAME_LIB: 'renameLibrary', RESTORE_CONFIG: 'restoreConfig', RESTORE_LIB: 'restore', QUARANTINE: 'quarantine', MOVE: 'moveComponent', LIST: 'list', LIST_LIB: 'listLibrary', LIST_PUB: 'listPublished', SHOW_STATUS: 'showStatus', SHOW_HELP: 'showHelp', SET_PERM: 'setPermanent', STORE: 'storeComponents', VALIDATE_SCHEMA: 'validateSchema', UPDATE: 'update', DELETE: 'delete', DELETE_ALL: 'deleteAll', DELETE_LIBRARY: 'deleteLibrary', DELETE_PUB: 'deletePublished', DELETE_VERSION: 'deleteVersion', IMPORT_ARCHIVE: 'importArchive', EXPORT_ARCHIVE: 'exportArchive', EXPORT_RC: 'exportRC', IMPORT_COMP: 'importComponent', AUTHENTICATE: 'authenticate', UPGRADE: 'upgrade', BUILD_JEST_ASSETS: 'buildJestAssets', START_DEV_SERVER: 'startDevServer' }; const parseArgumentsIntoOptions = rawArgs => { const args = arg( { '--install': Boolean, '--skipBundle': Boolean }, { argv: rawArgs.slice(2) } ); return { task: args._[0], git: true, // args['--git'] || false runInstall: true, // args['--install'] || false skipBundle: args['--skipBundle'] || false, params: rawArgs }; }; export default async (args = []) => { const options = parseArgumentsIntoOptions(args); const { task } = options; switch (task) { case TASKS.INIT: { initProject(options); break; } case TASKS.CREATE: { createComponent(options); break; } case TASKS.CREATE_ALL: { createAllComponents(options); break; } case TASKS.CREATE_LIB: { createLibrary(options); break; } case TASKS.SWITCH_LIB: { switchLibrary(options); break; } case TASKS.CREATE_VERSION: { createVersion(options); break; } case TASKS.SWITCH_VERSION: { switchVersion(options); break; } case TASKS.PROMOTE_WEBPACK: { promoteWebPack(options); break; } case TASKS.REVERT_WEBPACK: { revertWebPack(options); break; } case TASKS.PUBLISH: { publishComponent(options); break; } case TASKS.PUBLISH_ALL: { publishAllComponents(options); break; } case TASKS.PUBLISH_LIB: { publishLibrary(options); break; } case TASKS.RENAME: { renameComponent(options); break; } case TASKS.RENAME_LIB: { renameLibrary(options); break; } case TASKS.RESTORE_CONFIG: { restoreConfig(options); break; } case TASKS.RESTORE_LIB: { restore(options); break; } case TASKS.QUARANTINE: { quarantine(options); break; } case TASKS.MOVE: { moveComponent(options); break; } case TASKS.BUILD: { buildComponent(options); break; } case TASKS.BUILD_ALL: { buildAllComponents(options); break; } case TASKS.BUILD_LIB: { buildLibrary(options); break; } case TASKS.LIST: { listComponents(options); break; } case TASKS.LIST_LIB: { listLibrary(options); break; } case TASKS.LIST_PUB: { listPublished(options); break; } case TASKS.SHOW_STATUS: { showStatus(options); break; } case TASKS.SHOW_HELP: { showHelp(options); break; } case TASKS.SET_PERM: { setPermanent(options); break; } case TASKS.STORE: { storeComponents(options); break; } case TASKS.IMPORT_ARCHIVE: { importArchive(options); break; } case TASKS.EXPORT_ARCHIVE: { exportArchive(options); break; } case TASKS.EXPORT_RC: { exportRC(options); break; } case TASKS.IMPORT_COMP: { importComponent(options); break; } case TASKS.VALIDATE_SCHEMA: { validate(options); break; } case TASKS.UPDATE: { updateComponent(options); break; } case TASKS.DELETE: { deleteComponent(options); break; } case TASKS.DELETE_ALL: { deleteAllComponents(options); break; } case TASKS.DELETE_LIBRARY: { deleteLibrary(options); break; } case TASKS.DELETE_PUB: { deletePublished(options); break; } case TASKS.DELETE_VERSION: { deleteVersion(options); break; } case TASKS.AUTHENTICATE: { authenticate(options); break; } case TASKS.UPGRADE: { upgrade(options); break; } case TASKS.BUILD_JEST_ASSETS: { buildJestAssets(options); break; } case TASKS.START_DEV_SERVER: { startDevServer(options); break; } default: { console.log(chalk.red(`No task matched with ${task}`)); break; } } }