UNPKG

@ts-bridge/cli

Version:

Bridge the gap between ES modules and CommonJS modules with an easy-to-use alternative to `tsc`.

39 lines (38 loc) 1.38 kB
import { dirname, relative } from 'path'; import { cleanOutputDirectory, getBuildFunction, getInitialProgram, } from './build-utils.js'; import { getBaseCompilerOptions, getTypeScriptConfig } from './config.js'; import { success } from './logging.js'; /** * Handle the `build` command. This is intended to be called by the CLI. * * @param options - The build command options. */ export async function buildHandler(options) { const { format, project, clean, system, verbose, references, shims = true, } = options; const tsConfig = getTypeScriptConfig(project, system); const baseOptions = getBaseCompilerOptions(dirname(project), tsConfig.options); const baseDirectory = dirname(project); cleanOutputDirectory(project, baseOptions, clean, verbose); const program = getInitialProgram({ project, system, tsConfig, format, }); const buildOptions = { name: relative(process.cwd(), project), projectReferences: tsConfig.projectReferences, compilerOptions: program.getCompilerOptions(), program, format, system, baseDirectory, tsConfig, verbose, shims, clean, }; const buildFunction = getBuildFunction(tsConfig, references); await buildFunction(buildOptions); verbose && success('Project built successfully.'); }