UNPKG

@storm-software/workspace-tools

Version:

Tools for managing a Storm workspace, including various Nx generators and executors for common development tasks.

119 lines (98 loc) • 6.39 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 _chunkUALZJZUKjs = require('./chunk-UALZJZUK.js'); var _chunkSKMT7WD5js = require('./chunk-SKMT7WD5.js'); var _chunk4JOIS7WWjs = require('./chunk-4JOIS7WW.js'); var _chunk3GQAWCBQjs = require('./chunk-3GQAWCBQ.js'); // src/base/base-executor.ts var _defu = require('defu'); var withRunExecutor = /* @__PURE__ */ _chunk3GQAWCBQjs.__name.call(void 0, (name, executorFn, executorOptions = {}) => async (_options, context) => { const stopwatch = _chunkSKMT7WD5js.getStopwatch.call(void 0, name); let options = _options; let config = {}; try { if (!_optionalChain([context, 'access', _ => _.projectsConfigurations, 'optionalAccess', _2 => _2.projects]) || !context.projectName || !context.projectsConfigurations.projects[context.projectName]) { throw new Error("The Build process failed because the context is not valid. Please run this command from a workspace."); } const workspaceRoot = _chunk4JOIS7WWjs.findWorkspaceRoot.call(void 0, ); const projectRoot = context.projectsConfigurations.projects[context.projectName].root || workspaceRoot; const sourceRoot = context.projectsConfigurations.projects[context.projectName].sourceRoot || projectRoot || workspaceRoot; const projectName = context.projectName; config.workspaceRoot = workspaceRoot; _chunkSKMT7WD5js.writeInfo.call(void 0, `\u26A1 Running the ${name} executor for ${projectName} `, config); if (!executorOptions.skipReadingConfig) { _chunkSKMT7WD5js.writeTrace.call(void 0, `Loading the Storm Config from environment variables and storm.config.js file... - workspaceRoot: ${workspaceRoot} - projectRoot: ${projectRoot} - sourceRoot: ${sourceRoot} - projectName: ${projectName} `, config); config = await _chunkSKMT7WD5js.getConfig.call(void 0, workspaceRoot); } if (_optionalChain([executorOptions, 'optionalAccess', _3 => _3.hooks, 'optionalAccess', _4 => _4.applyDefaultOptions])) { _chunkSKMT7WD5js.writeDebug.call(void 0, "Running the applyDefaultOptions hook...", config); options = await Promise.resolve(executorOptions.hooks.applyDefaultOptions(options, config)); _chunkSKMT7WD5js.writeDebug.call(void 0, "Completed the applyDefaultOptions hook", config); } _chunkSKMT7WD5js.writeTrace.call(void 0, `Executor schema options \u2699\uFE0F ${_chunkSKMT7WD5js.formatLogMessage.call(void 0, options)} `, config); const tokenized = await _chunkUALZJZUKjs.applyWorkspaceTokens.call(void 0, options, _defu.defu.call(void 0, { workspaceRoot, projectRoot, sourceRoot, projectName, config }, config, context.projectsConfigurations.projects[context.projectName]), _chunkUALZJZUKjs.applyWorkspaceProjectTokens); _chunkSKMT7WD5js.writeTrace.call(void 0, `Executor schema tokenized options \u2699\uFE0F ${_chunkSKMT7WD5js.formatLogMessage.call(void 0, tokenized)} `, config); if (_optionalChain([executorOptions, 'optionalAccess', _5 => _5.hooks, 'optionalAccess', _6 => _6.preProcess])) { _chunkSKMT7WD5js.writeDebug.call(void 0, "Running the preProcess hook...", config); await Promise.resolve(executorOptions.hooks.preProcess(tokenized, config)); _chunkSKMT7WD5js.writeDebug.call(void 0, "Completed the preProcess hook", config); } const ret = executorFn(tokenized, context, config); if (_isFunction(_optionalChain([ret, 'optionalAccess', _7 => _7.next]))) { const asyncGen = ret; for await (const iter of asyncGen) { } } const result = await Promise.resolve(ret); if (result && (!result.success || result.error && _optionalChain([result, 'optionalAccess', _8 => _8.error, 'optionalAccess', _9 => _9.message]) && typeof _optionalChain([result, 'optionalAccess', _10 => _10.error, 'optionalAccess', _11 => _11.message]) === "string" && _optionalChain([result, 'optionalAccess', _12 => _12.error, 'optionalAccess', _13 => _13.name]) && typeof _optionalChain([result, 'optionalAccess', _14 => _14.error, 'optionalAccess', _15 => _15.name]) === "string")) { _chunkSKMT7WD5js.writeTrace.call(void 0, `Failure determined by the ${name} executor ${_chunkSKMT7WD5js.formatLogMessage.call(void 0, result)}`, config); console.error(result); throw new Error(`The ${name} executor failed to run`, { cause: _optionalChain([result, 'optionalAccess', _16 => _16.error]) }); } if (_optionalChain([executorOptions, 'optionalAccess', _17 => _17.hooks, 'optionalAccess', _18 => _18.postProcess])) { _chunkSKMT7WD5js.writeDebug.call(void 0, "Running the postProcess hook...", config); await Promise.resolve(executorOptions.hooks.postProcess(config)); _chunkSKMT7WD5js.writeDebug.call(void 0, "Completed the postProcess hook", config); } _chunkSKMT7WD5js.writeSuccess.call(void 0, `Completed running the ${name} task executor! `, config); return { success: true }; } catch (error) { _chunkSKMT7WD5js.writeFatal.call(void 0, "A fatal error occurred while running the executor - the process was forced to terminate", config); _chunkSKMT7WD5js.writeError.call(void 0, `An exception was thrown in the executor's process - Details: ${error.message} - Stacktrace: ${error.stack}`, config); return { success: false }; } finally { stopwatch(); } }, "withRunExecutor"); var _isFunction = /* @__PURE__ */ _chunk3GQAWCBQjs.__name.call(void 0, (value) => { try { return value instanceof Function || typeof value === "function" || !!(_optionalChain([value, 'optionalAccess', _19 => _19.constructor]) && _optionalChain([value, 'optionalAccess', _20 => _20.call]) && _optionalChain([value, 'optionalAccess', _21 => _21.apply])); } catch (e) { return false; } }, "_isFunction"); exports.withRunExecutor = withRunExecutor;