UNPKG

@storm-software/esbuild

Version:

A package containing `esbuild` utilities for building Storm Software libraries and applications

95 lines (92 loc) 2.75 kB
import { copyBuildAssets } from "./chunk-R3SVN3BO.js"; import { cleanDirectories } from "./chunk-4YDNSQCF.js"; import { resolveContext } from "./chunk-ZXS7BLGE.js"; import { generatePackageJson } from "./chunk-SPIG74KS.js"; import { executeTsup } from "./chunk-5EIXD3FY.js"; import { getStopwatch, writeDebug, writeError, writeFatal, writeSuccess, writeWarning } from "./chunk-CKFE6AY5.js"; import { init_esm_shims } from "./chunk-5OCVL4NC.js"; // src/build.ts init_esm_shims(); async function reportResults(context) { if (context.result?.errors.length === 0) { if (context.result.warnings.length > 0) { writeWarning( ` \u{1F6A7} The following warnings occurred during the build: ${context.result.warnings.map((warning) => warning.text).join("\n")}`, context.workspaceConfig ); } writeSuccess( ` \u{1F4E6} The ${context.options.name} build completed successfully`, context.workspaceConfig ); } else if (context.result?.errors && context.result?.errors.length > 0) { writeError( ` \u274C The ${context.options.name} build failed with the following errors: ${context.result.errors.map((error) => error.text).join("\n")}`, context.workspaceConfig ); throw new Error( `The ${context.options.name} build failed with the following errors: ${context.result.errors.map((error) => error.text).join("\n")}` ); } } async function cleanOutputPath(context) { if (context.clean !== false && context.outputPath) { writeDebug( ` \u{1F9F9} Cleaning ${context.options.name} output path: ${context.outputPath}`, context.workspaceConfig ); const stopwatch = getStopwatch(`${context.options.name} output clean`); await cleanDirectories(context.outputPath); stopwatch(); } return context; } async function build(options) { writeDebug(` \u26A1 Executing Storm ESBuild pipeline`); const stopwatch = getStopwatch("ESBuild pipeline"); try { const opts = Array.isArray(options) ? options : [options]; if (opts.length === 0) { throw new Error("No build options were provided"); } const context = await resolveContext(options); await cleanOutputPath(context); await Promise.all([ // dependencyCheck(context.options), generatePackageJson(context), copyBuildAssets(context), executeTsup(context) ]); await reportResults(context); writeSuccess(" \u{1F3C1} ESBuild pipeline build completed successfully"); } catch (error) { writeFatal( "Fatal errors that the build process could not recover from have occured. The build process has been terminated." ); throw error; } finally { stopwatch(); } } export { build };