@storm-software/esbuild
Version:
A package containing `esbuild` utilities for building Storm Software libraries and applications
95 lines (72 loc) • 4 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
var _chunkE7QRYIXPcjs = require('./chunk-E7QRYIXP.cjs');
var _chunkBG2GOKPNcjs = require('./chunk-BG2GOKPN.cjs');
var _chunkDNQXOUY4cjs = require('./chunk-DNQXOUY4.cjs');
var _chunk4F23ZOVVcjs = require('./chunk-4F23ZOVV.cjs');
var _chunkVIQ4UDWAcjs = require('./chunk-VIQ4UDWA.cjs');
var _chunk7DZ3NOLBcjs = require('./chunk-7DZ3NOLB.cjs');
var _chunkJG7MZJV2cjs = require('./chunk-JG7MZJV2.cjs');
// src/build.ts
_chunkJG7MZJV2cjs.init_cjs_shims.call(void 0, );
async function reportResults(context) {
if (_optionalChain([context, 'access', _ => _.result, 'optionalAccess', _2 => _2.errors, 'access', _3 => _3.length]) === 0) {
if (context.result.warnings.length > 0) {
_chunk7DZ3NOLBcjs.writeWarning.call(void 0,
` \u{1F6A7} The following warnings occurred during the build: ${context.result.warnings.map((warning) => warning.text).join("\n")}`,
context.workspaceConfig
);
}
_chunk7DZ3NOLBcjs.writeSuccess.call(void 0,
` \u{1F4E6} The ${context.options.name} build completed successfully`,
context.workspaceConfig
);
} else if (_optionalChain([context, 'access', _4 => _4.result, 'optionalAccess', _5 => _5.errors]) && _optionalChain([context, 'access', _6 => _6.result, 'optionalAccess', _7 => _7.errors, 'access', _8 => _8.length]) > 0) {
_chunk7DZ3NOLBcjs.writeError.call(void 0,
` \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) {
_chunk7DZ3NOLBcjs.writeDebug.call(void 0,
` \u{1F9F9} Cleaning ${context.options.name} output path: ${context.outputPath}`,
context.workspaceConfig
);
const stopwatch = _chunk7DZ3NOLBcjs.getStopwatch.call(void 0, `${context.options.name} output clean`);
await _chunkBG2GOKPNcjs.cleanDirectories.call(void 0, context.outputPath);
stopwatch();
}
return context;
}
async function build(options) {
_chunk7DZ3NOLBcjs.writeDebug.call(void 0, ` \u26A1 Executing Storm ESBuild pipeline`);
const stopwatch = _chunk7DZ3NOLBcjs.getStopwatch.call(void 0, "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 _chunkDNQXOUY4cjs.resolveContext.call(void 0, options);
await cleanOutputPath(context);
await Promise.all([
// dependencyCheck(context.options),
_chunk4F23ZOVVcjs.generatePackageJson.call(void 0, context),
_chunkE7QRYIXPcjs.copyBuildAssets.call(void 0, context),
_chunkVIQ4UDWAcjs.executeTsup.call(void 0, context)
]);
await reportResults(context);
_chunk7DZ3NOLBcjs.writeSuccess.call(void 0, " \u{1F3C1} ESBuild pipeline build completed successfully");
} catch (error) {
_chunk7DZ3NOLBcjs.writeFatal.call(void 0,
"Fatal errors that the build process could not recover from have occured. The build process has been terminated."
);
throw error;
} finally {
stopwatch();
}
}
exports.build = build;