UNPKG

@pega/custom-dx-components

Version:

Utility for building custom UI components

114 lines (92 loc) 2.83 kB
import inquirer from 'inquirer'; import { Listr } from 'listr2'; import chalk from 'chalk'; import validate from '../validator/index.js'; import bundleComponent from '../bundle/index.js'; import lintComponent from '../linter/index.js'; import { getPublishComponentQuestions } from './helper.js'; import { getComponentDirectoryPath, showVersion, addDebugLog, cleanUp, getLibraryBased, checkLibraryAndArchives, getConfigDefaults, zipVersionAndArchive } from '../../util.js'; export default async options => { await showVersion(); await checkLibraryAndArchives(); addDebugLog("buildComponent", "", "+"); let componentKey; let sourceMap; let devBuild; let content; let showStats = true; if (options.params.length >= 6) { componentKey = options.params[3]; sourceMap = options.params[4]; const dBuild = options.params[5]; devBuild = (dBuild === 'Y' || dBuild === 'y' || dBuild === true || dBuild === 'true') ? true : false; content = { componentKey, sourceMap, devBuild}; } else { // VS Code pluggin would send in the component let paramComponentKey; if (options.params.length == 4) { paramComponentKey = options.params[3]; } const questions = await getPublishComponentQuestions(paramComponentKey); const answers = await inquirer.prompt(questions); ({ componentKey = paramComponentKey, sourceMap, devBuild } = answers); const isLibraryBased = getLibraryBased(); if (isLibraryBased) { devBuild = false; showStats = false; } content = { ...answers }; } const sDevBuild = devBuild ? '(dev build)' : ''; const tasks = new Listr( [ { title: 'Validate config schema', task: async () => { await validate(componentKey); } }, { title: 'Lint component', task: async () => { const targetDirectory = await getComponentDirectoryPath(componentKey); // console.log(`in buildComponent Lint component task: componentKey: ${componentKey} targetDirectory: ${targetDirectory}`); await lintComponent(targetDirectory); } }, { title: `Bundle Component ${sDevBuild}`, type: 'confirm', task: async () => await bundleComponent(componentKey, sourceMap, devBuild, showStats), skip: () => (options.skipBundle ? 'Skipped bundling component' : undefined) } ], { exitOnError: true } ); await tasks.run().catch(err => { console.log(chalk.bold.red(err.toString())); process.exit(1); }); const confDef = getConfigDefaults(); await zipVersionAndArchive(confDef.currentOrgLib, confDef.buildVersion); // remove dist/lib stuff await cleanUp(); addDebugLog("buildComponent", "END", "-"); return true; };