@storm-software/k8s-tools
Version:
Tools for managing Kubernetes (k8s) infrastructure within a Nx workspace.
103 lines (85 loc) • 4.74 kB
JavaScript
;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 _chunkHFE7ETH4js = require('./chunk-HFE7ETH4.js');
var _chunkHEVP2Q77js = require('./chunk-HEVP2Q77.js');
// ../workspace-tools/src/base/base-generator.ts
var withRunGenerator = (name, generatorFn, generatorOptions = {
skipReadingConfig: false
}) => async (tree, _options) => {
const stopwatch = _chunkHEVP2Q77js.getStopwatch.call(void 0, name);
let options = _options;
let config;
try {
_chunkHEVP2Q77js.writeInfo.call(void 0, `\u26A1 Running the ${name} generator...
`, config);
const workspaceRoot = _chunkHEVP2Q77js.findWorkspaceRoot.call(void 0, );
if (!generatorOptions.skipReadingConfig) {
_chunkHEVP2Q77js.writeDebug.call(void 0,
`Loading the Storm Config from environment variables and storm.config.js file...
- workspaceRoot: ${workspaceRoot}`,
config
);
config = await _chunkHEVP2Q77js.getConfig.call(void 0, workspaceRoot);
}
if (_optionalChain([generatorOptions, 'optionalAccess', _ => _.hooks, 'optionalAccess', _2 => _2.applyDefaultOptions])) {
_chunkHEVP2Q77js.writeDebug.call(void 0, "Running the applyDefaultOptions hook...", config);
options = await Promise.resolve(
generatorOptions.hooks.applyDefaultOptions(options, config)
);
_chunkHEVP2Q77js.writeDebug.call(void 0, "Completed the applyDefaultOptions hook", config);
}
_chunkHEVP2Q77js.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 _chunkHFE7ETH4js.applyWorkspaceTokens.call(void 0,
options,
{ workspaceRoot: tree.root, config },
_chunkHFE7ETH4js.applyWorkspaceBaseTokens
);
if (_optionalChain([generatorOptions, 'optionalAccess', _3 => _3.hooks, 'optionalAccess', _4 => _4.preProcess])) {
_chunkHEVP2Q77js.writeDebug.call(void 0, "Running the preProcess hook...", config);
await Promise.resolve(
generatorOptions.hooks.preProcess(tokenized, config)
);
_chunkHEVP2Q77js.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])) {
_chunkHEVP2Q77js.writeDebug.call(void 0, "Running the postProcess hook...", config);
await Promise.resolve(generatorOptions.hooks.postProcess(config));
_chunkHEVP2Q77js.writeDebug.call(void 0, "Completed the postProcess hook", config);
}
return () => {
_chunkHEVP2Q77js.writeSuccess.call(void 0, `Completed running the ${name} generator!
`, config);
};
} catch (error) {
return () => {
_chunkHEVP2Q77js.writeFatal.call(void 0,
"A fatal error occurred while running the generator - the process was forced to terminate",
config
);
_chunkHEVP2Q77js.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;