UNPKG

@storm-software/esbuild

Version:

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

92 lines (70 loc) 3.85 kB
"use strict";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 _chunkDJNFLJSOcjs = require('./chunk-DJNFLJSO.cjs'); var _chunkBXCOVK3Icjs = require('./chunk-BXCOVK3I.cjs'); var _chunkCXIJUB3Ocjs = require('./chunk-CXIJUB3O.cjs'); var _chunkCRFWMPZNcjs = require('./chunk-CRFWMPZN.cjs'); var _chunkV7AFF6GWcjs = require('./chunk-V7AFF6GW.cjs'); // src/build.ts var _console = require('@storm-software/config-tools/logger/console'); async function reportResults(context) { if (_optionalChain([context, 'access', _ => _.result, 'optionalAccess', _2 => _2.errors, 'access', _3 => _3.length]) === 0) { if (context.result.warnings.length > 0) { _console.writeWarning.call(void 0, ` \u{1F6A7} The following warnings occurred during the build: ${context.result.warnings.map((warning) => warning.text).join("\n")}`, context.workspaceConfig ); } _console.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) { _console.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) { _console.writeDebug.call(void 0, ` \u{1F9F9} Cleaning ${context.options.name} output path: ${context.outputPath}`, context.workspaceConfig ); const stopwatch = _console.getStopwatch.call(void 0, `${context.options.name} output clean`); await _chunkBXCOVK3Icjs.cleanDirectories.call(void 0, context.outputPath); stopwatch(); } return context; } async function build(options) { _console.writeDebug.call(void 0, ` ${_console.brandIcon.call(void 0, )} Executing Storm ESBuild pipeline`); const stopwatch = _console.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 _chunkCXIJUB3Ocjs.resolveContext.call(void 0, options); await cleanOutputPath(context); await Promise.all([ // dependencyCheck(context.options), _chunkCRFWMPZNcjs.generatePackageJson.call(void 0, context), _chunkDJNFLJSOcjs.copyBuildAssets.call(void 0, context), _chunkV7AFF6GWcjs.executeTsup.call(void 0, context) ]); await reportResults(context); _console.writeSuccess.call(void 0, " \u{1F3C1} ESBuild pipeline build completed successfully"); } catch (error) { _console.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;