/* eslint-disable no-console */ import { spawnSync } from 'child_process' import { Command } from '@oclif/command' import chalk from 'chalk' import { existsSync } from 'fs-extra' import { dotSalesAppDir, salesAppMonorepoSrcDir, webpackBinPath, } from '../utils/directory' export default class Build extends Command { public async run() { if (!existsSync(salesAppMonorepoSrcDir)) { console.error( `${chalk.red( 'Error' )} - Sales App project not initialized. Please run sales-app-cli init first` ) return } const buildCommand = `"${webpackBinPath}" --mode production` const buildResult = spawnSync(buildCommand, { shell: true, cwd: dotSalesAppDir, stdio: 'inherit', }) if (buildResult.error) { console.error( `${chalk.red('Error')} - Failed to execute build command: ${ buildResult.error.message }` ) process.exit(1) } console.log(`${chalk.green('Success')} - Build completed`) } }