UNPKG

@storm-software/k8s-tools

Version:

Tools for managing Kubernetes (k8s) infrastructure within a Nx workspace.

107 lines (88 loc) 4.8 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 _chunk5KOGMQTWjs = require('./chunk-5KOGMQTW.js'); var _chunkPJSA4K3Hjs = require('./chunk-PJSA4K3H.js'); // ../workspace-tools/src/base/base-generator.ts var withRunGenerator = (name, generatorFn, generatorOptions = { skipReadingConfig: false }) => async (tree, _options) => { const stopwatch = _chunkPJSA4K3Hjs.getStopwatch.call(void 0, name); let options = _options; let config; try { _chunkPJSA4K3Hjs.writeInfo.call(void 0, `${_chunkPJSA4K3Hjs.brandIcon.call(void 0, config)} Running the ${name} generator... `, config ); const workspaceRoot = _chunkPJSA4K3Hjs.findWorkspaceRoot.call(void 0, ); if (!generatorOptions.skipReadingConfig) { _chunkPJSA4K3Hjs.writeDebug.call(void 0, `Loading the Storm Config from environment variables and storm.config.js file... - workspaceRoot: ${workspaceRoot}`, config ); config = await _chunkPJSA4K3Hjs.getConfig.call(void 0, workspaceRoot); } if (_optionalChain([generatorOptions, 'optionalAccess', _ => _.hooks, 'optionalAccess', _2 => _2.applyDefaultOptions])) { _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Running the applyDefaultOptions hook...", config); options = await Promise.resolve( generatorOptions.hooks.applyDefaultOptions(options, config) ); _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Completed the applyDefaultOptions hook", config); } _chunkPJSA4K3Hjs.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 _chunk5KOGMQTWjs.applyWorkspaceTokens.call(void 0, options, { workspaceRoot: tree.root, config }, _chunk5KOGMQTWjs.applyWorkspaceBaseTokens ); if (_optionalChain([generatorOptions, 'optionalAccess', _3 => _3.hooks, 'optionalAccess', _4 => _4.preProcess])) { _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Running the preProcess hook...", config); await Promise.resolve( generatorOptions.hooks.preProcess(tokenized, config) ); _chunkPJSA4K3Hjs.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])) { _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Running the postProcess hook...", config); await Promise.resolve(generatorOptions.hooks.postProcess(config)); _chunkPJSA4K3Hjs.writeDebug.call(void 0, "Completed the postProcess hook", config); } return () => { _chunkPJSA4K3Hjs.writeSuccess.call(void 0, `Completed running the ${name} generator! `, config); }; } catch (error) { return () => { _chunkPJSA4K3Hjs.writeFatal.call(void 0, "A fatal error occurred while running the generator - the process was forced to terminate", config ); _chunkPJSA4K3Hjs.writeError.call(void 0, `An exception was thrown in the generator's process - Details: ${error.message} - Stacktrace: ${error.stack}`, config ); }; } finally { stopwatch(); } }; exports.withRunGenerator = withRunGenerator;