@rxap/plugin-library
Version:
This package provides generators and executors for managing and maintaining Nx plugin libraries. It includes functionality for generating index exports, fixing dependencies, generating JSON schemas, and more. It helps streamline the development process fo
122 lines • 4.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.runExecutor = runExecutor;
const tslib_1 = require("tslib");
const plugin_utilities_1 = require("@rxap/plugin-utilities");
const workspace_utilities_1 = require("@rxap/workspace-utilities");
const run_commands_impl_1 = tslib_1.__importDefault(require("nx/src/executors/run-commands/run-commands.impl"));
function buildParameters(options = {}) {
const params = [];
for (const [key, value] of Object.entries(options)) {
if (Array.isArray(value)) {
for (const item of value) {
if (typeof item === 'object') {
params.push(`--${key}='${JSON.stringify(item)}'`);
}
else {
params.push(`--${key}='${item}'`);
}
}
}
else if (typeof value === 'object') {
params.push(`--${key}='${JSON.stringify(value)}'`);
}
else {
params.push(`--${key}='${value}'`);
}
}
return params.join(' ');
}
function stringInterpolation(options, params) {
if (!options) {
return;
}
for (const [key, value] of Object.entries(options)) {
if (typeof value === 'string') {
options[key] = value.replace(/\{([^}]+)}/g, (match, property) => {
if (!params[property]) {
throw new Error(`Could not find property ${property} in possible string interpolation parameters: ${JSON.stringify(params)}`);
}
return params[property];
});
}
}
}
function extractFlattenOptions(options) {
const extracted = {};
for (const [option, value] of Object.entries(options)) {
let key = undefined;
if (option.startsWith('options-')) {
key = option.replace('options-', '');
}
if (option.startsWith('option-')) {
key = option.replace('option-', '');
}
if (option.match(/option[A-Z]/)) {
key = option.replace(/option([A-Z])/g, (match, letter) => letter.toLowerCase());
}
if (option.match(/options[A-Z]/)) {
key = option.replace(/options([A-Z])/g, (match, letter) => letter.toLowerCase());
}
if (key) {
extracted[key] = value;
}
}
return extracted;
}
function runExecutor(options, context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
var _a, _b, _c, _d;
var _e;
console.log('Executor ran for RunGenerator', options);
let command = `nx g ${options.generator}`;
if ((0, workspace_utilities_1.IsRxapRepository)(context.root)) {
if ((_a = options.generator) === null || _a === void 0 ? void 0 : _a.match(/@rxap\/schematic/)) {
command = `yarn schematic ${options.generator}`;
}
}
(_b = options.options) !== null && _b !== void 0 ? _b : (options.options = {});
if (!options.withoutProjectArgument) {
(_c = (_e = options.options)['project']) !== null && _c !== void 0 ? _c : (_e['project'] = context.projectName);
}
if (!context.projectName) {
console.error(`No project name found in the context`);
return {
success: false,
};
}
if (!context.targetName) {
console.error(`No target name found in the context`);
return {
success: false,
};
}
if (!context.configurationName) {
console.warn(`No configuration name found in the context`);
}
stringInterpolation(options.options, {
workspaceRoot: context.root,
projectRoot: (0, plugin_utilities_1.GetProjectRoot)(context),
projectSourceRoot: (0, plugin_utilities_1.GetProjectSourceRoot)(context),
projectName: context.projectName,
configurationName: (_d = context.configurationName) !== null && _d !== void 0 ? _d : '',
cwd: context.cwd,
targetName: context.targetName,
});
command += ` ${buildParameters(Object.assign(Object.assign({}, options.options), extractFlattenOptions(options)))}`;
if (options.dryRun) {
command += ' --dry-run';
}
if (options.verbose) {
command += ' --verbose';
}
console.log('command: ', command);
return (0, run_commands_impl_1.default)({
cwd: context.root,
command,
__unparsed__: [],
}, context);
});
}
exports.default = runExecutor;
//# sourceMappingURL=executor.js.map