UNPKG

@storm-software/workspace-tools

Version:

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

151 lines (130 loc) • 6.44 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 _chunkHXQRGLIIjs = require('./chunk-HXQRGLII.js'); var _chunkBSW6NZVBjs = require('./chunk-BSW6NZVB.js'); var _chunkIHMF6RANjs = require('./chunk-IHMF6RAN.js'); var _chunkLMYTVXGXjs = require('./chunk-LMYTVXGX.js'); // src/base/base-executor.ts var _defu = require('defu'); var withRunExecutor = (name, executorFn, executorOptions = {}) => async (_options, context) => { const stopwatch = _chunkIHMF6RANjs.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 = _chunkLMYTVXGXjs.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; _chunkIHMF6RANjs.writeInfo.call(void 0, `${_chunkIHMF6RANjs.brandIcon.call(void 0, config)} Running the ${name} executor for ${projectName} `, config ); if (!executorOptions.skipReadingConfig) { _chunkIHMF6RANjs.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 _chunkBSW6NZVBjs.getConfig.call(void 0, workspaceRoot); } if (_optionalChain([executorOptions, 'optionalAccess', _3 => _3.hooks, 'optionalAccess', _4 => _4.applyDefaultOptions])) { _chunkIHMF6RANjs.writeDebug.call(void 0, "Running the applyDefaultOptions hook...", config); options = await Promise.resolve( executorOptions.hooks.applyDefaultOptions(options, config) ); _chunkIHMF6RANjs.writeDebug.call(void 0, "Completed the applyDefaultOptions hook", config); } _chunkIHMF6RANjs.writeTrace.call(void 0, `Executor schema options \u2699\uFE0F ${_chunkIHMF6RANjs.formatLogMessage.call(void 0, options)} `, config ); const tokenized = await _chunkHXQRGLIIjs.applyWorkspaceTokens.call(void 0, options, _defu.defu.call(void 0, { workspaceRoot, projectRoot, sourceRoot, projectName, config }, config, context.projectsConfigurations.projects[context.projectName] ), _chunkHXQRGLIIjs.applyWorkspaceProjectTokens ); _chunkIHMF6RANjs.writeTrace.call(void 0, `Executor schema tokenized options \u2699\uFE0F ${_chunkIHMF6RANjs.formatLogMessage.call(void 0, tokenized)} `, config ); if (_optionalChain([executorOptions, 'optionalAccess', _5 => _5.hooks, 'optionalAccess', _6 => _6.preProcess])) { _chunkIHMF6RANjs.writeDebug.call(void 0, "Running the preProcess hook...", config); await Promise.resolve( executorOptions.hooks.preProcess(tokenized, config) ); _chunkIHMF6RANjs.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) { void iter; } } 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")) { throw new Error( `Failure determined while running the ${name} executor ${_chunkIHMF6RANjs.formatLogMessage.call(void 0, result )}`, { cause: _optionalChain([result, 'optionalAccess', _16 => _16.error]) } ); } if (_optionalChain([executorOptions, 'optionalAccess', _17 => _17.hooks, 'optionalAccess', _18 => _18.postProcess])) { _chunkIHMF6RANjs.writeDebug.call(void 0, "Running the postProcess hook...", config); await Promise.resolve(executorOptions.hooks.postProcess(config)); _chunkIHMF6RANjs.writeDebug.call(void 0, "Completed the postProcess hook", config); } _chunkIHMF6RANjs.writeSuccess.call(void 0, `Completed running the ${name} task executor! `, config); return { success: true }; } catch (error) { _chunkIHMF6RANjs.writeFatal.call(void 0, "A fatal error occurred while running the executor - the process was forced to terminate", config ); _chunkIHMF6RANjs.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(); } }; var _isFunction = (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; } }; exports.withRunExecutor = withRunExecutor;