UNPKG

@storm-software/workspace-tools

Version:

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

89 lines (68 loc) 4.76 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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-generator.ts var withRunGenerator = /* @__PURE__ */ _chunk3GQAWCBQjs.__name.call(void 0, (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, _options) => { const stopwatch = _chunkSKMT7WD5js.getStopwatch.call(void 0, name); let options = _options; let config; try { _chunkSKMT7WD5js.writeInfo.call(void 0, `\u26A1 Running the ${name} generator... `, config); const workspaceRoot = _chunk4JOIS7WWjs.findWorkspaceRoot.call(void 0, ); if (!generatorOptions.skipReadingConfig) { _chunkSKMT7WD5js.writeDebug.call(void 0, `Loading the Storm Config from environment variables and storm.config.js file... - workspaceRoot: ${workspaceRoot}`, config); config = await _chunkSKMT7WD5js.getConfig.call(void 0, workspaceRoot); } if (_optionalChain([generatorOptions, 'optionalAccess', _ => _.hooks, 'optionalAccess', _2 => _2.applyDefaultOptions])) { _chunkSKMT7WD5js.writeDebug.call(void 0, "Running the applyDefaultOptions hook...", config); options = await Promise.resolve(generatorOptions.hooks.applyDefaultOptions(options, config)); _chunkSKMT7WD5js.writeDebug.call(void 0, "Completed the applyDefaultOptions hook", config); } _chunkSKMT7WD5js.writeTrace.call(void 0, `Generator schema options \u2699\uFE0F ${Object.keys(_nullishCoalesce(options, () => ( {}))).map((key) => ` - ${key}=${JSON.stringify(options[key])}`).join("\n")}`, config); const tokenized = await _chunkUALZJZUKjs.applyWorkspaceTokens.call(void 0, options, { workspaceRoot: tree.root, config }, _chunkUALZJZUKjs.applyWorkspaceBaseTokens); if (_optionalChain([generatorOptions, 'optionalAccess', _3 => _3.hooks, 'optionalAccess', _4 => _4.preProcess])) { _chunkSKMT7WD5js.writeDebug.call(void 0, "Running the preProcess hook...", config); await Promise.resolve(generatorOptions.hooks.preProcess(tokenized, config)); _chunkSKMT7WD5js.writeDebug.call(void 0, "Completed the preProcess hook", config); } const result = await Promise.resolve(generatorFn(tree, tokenized, config)); if (result) { if (result.success === false || result.error && _optionalChain([result, 'optionalAccess', _5 => _5.error, 'optionalAccess', _6 => _6.message]) && typeof _optionalChain([result, 'optionalAccess', _7 => _7.error, 'optionalAccess', _8 => _8.message]) === "string" && _optionalChain([result, 'optionalAccess', _9 => _9.error, 'optionalAccess', _10 => _10.name]) && typeof _optionalChain([result, 'optionalAccess', _11 => _11.error, 'optionalAccess', _12 => _12.name]) === "string") { throw new Error(`The ${name} generator failed to run`, { cause: _optionalChain([result, 'optionalAccess', _13 => _13.error]) }); } else if (result.success && result.data) { return result; } } if (_optionalChain([generatorOptions, 'optionalAccess', _14 => _14.hooks, 'optionalAccess', _15 => _15.postProcess])) { _chunkSKMT7WD5js.writeDebug.call(void 0, "Running the postProcess hook...", config); await Promise.resolve(generatorOptions.hooks.postProcess(config)); _chunkSKMT7WD5js.writeDebug.call(void 0, "Completed the postProcess hook", config); } return () => { _chunkSKMT7WD5js.writeSuccess.call(void 0, `Completed running the ${name} generator! `, config); }; } catch (error) { return () => { _chunkSKMT7WD5js.writeFatal.call(void 0, "A fatal error occurred while running the generator - the process was forced to terminate", config); _chunkSKMT7WD5js.writeError.call(void 0, `An exception was thrown in the generator's process - Details: ${error.message} - Stacktrace: ${error.stack}`, config); }; } finally { stopwatch(); } }, "withRunGenerator"); exports.withRunGenerator = withRunGenerator;