@storm-software/esbuild
Version:
A package containing `esbuild` utilities for building Storm Software libraries and applications
92 lines (89 loc) • 2.73 kB
JavaScript
import {
copyBuildAssets
} from "./chunk-MTZGYTJP.js";
import {
cleanDirectories
} from "./chunk-XKSMSRQZ.js";
import {
resolveContext
} from "./chunk-N6LM74ZB.js";
import {
generatePackageJson
} from "./chunk-CZC4I6SL.js";
import {
executeTsup
} from "./chunk-ZH5YCT67.js";
// src/build.ts
import {
brandIcon,
getStopwatch,
writeDebug,
writeError,
writeFatal,
writeSuccess,
writeWarning
} from "@storm-software/config-tools/logger/console";
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(` ${brandIcon()} 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
};