import path from 'path' import { Command } from '@oclif/command' import chalk from 'chalk' import { existsSync } from 'fs-extra' import { getSalesAppMonorepoDir, getTempDir } from '../utils/directory' import { logger } from '../utils/logger' import { getWebpackCompiler } from '../utils/webpack' import { createTempDir } from '../utils/createTempDir' export default class Build extends Command { public static description = 'Build your Sales App Extension Points' public static examples: string[] | undefined = ['$ sales-app build {account}'] public static args = [ { name: 'account', description: 'your VTEX account', required: true, }, ] public async run() { const { args } = this.parse(Build) const monorepoDir = getSalesAppMonorepoDir(args.account) const salesAppMonorepoSrcDir = path.join(monorepoDir, 'src') if (!existsSync(salesAppMonorepoSrcDir)) { logger.log( `${chalk.red( 'Error' )} - Sales App project not created. Please run "sales-app create" first` ) return } const tempDir = getTempDir(monorepoDir) if (!existsSync(tempDir)) { await createTempDir(monorepoDir) } const { compiler } = getWebpackCompiler(monorepoDir, 'production') compiler.run((err: Error | null) => { if (err) { logger.log( `${chalk.red('Error')} - Failed to execute build command: ${ err?.message }` ) } else { this.log(`${chalk.green('Success')} - Build completed and saved at:`) this.log(path.join(tempDir, 'build')) } compiler.close((closeErr: Error | null) => { logger.log(closeErr?.message) }) }) } }