import { Command } from '@oclif/command' ; import { join } from 'path' ; import spawn from 'cross-spawn' ; import { existsSync } from 'fs' ; import { cleanJsFile } from '../utils/cleanJsFile' ; import { genServer } from '../generators/server' ; import { genConfig } from '../generators/config' ; import { genControllers } from '../generators/controllers' ; import { genResolvers } from '../generators/resolvers' ; import { genSchedules } from '../generators/schedules' ; import { genEvents } from '../generators/events' ; import { genConfigs } from '../generators/configs' ; function getCommand ( ) { const cwd = process . cwd ( ) ; const baseDir = join ( __dirname , '..' , '..' ) ; const command = join ( cwd , 'node_modules' , '.bin' , 'tsc' ) ; if ( existsSync ( command ) ) { return command ; } else { return join ( baseDir , 'node_modules' , '.bin' , 'tsc' ) ; } } export default class Build extends Command { static description = 'Build the project' ; static examples = [ `$ tie build` ] ; private getTsconfigPath ( ) { const cwd = process . cwd ( ) ; const serverTsconfigPath = join ( cwd , 'tsconfig.server.json' ) ; const tsconfigPath = join ( cwd , 'tsconfig.json' ) ; if ( existsSync ( serverTsconfigPath ) ) return serverTsconfigPath ; return tsconfigPath ; } async run ( ) { const cwd = process . cwd ( ) ; const command = getCommand ( ) ; const tsconfigPath = this . getTsconfigPath ( ) ; const startArgs = [ '--project' , tsconfigPath ] ; cleanJsFile ( cwd ) ; await Promise . all ( [ genControllers ( ) , genResolvers ( ) , genSchedules ( ) , genEvents ( ) , genServer ( ) , genConfigs ( ) , ] ) ; await genConfig ( ) ; spawn . sync ( command , startArgs , { stdio : 'inherit' } ) ; } }