@o3r/schematics
Version:
Schematics module of the Otter framework
34 lines • 1.44 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMigrationRuleRunner = getMigrationRuleRunner;
const schematics_1 = require("@angular-devkit/schematics");
const semver_1 = require("semver");
/**
* Generate the Migration Rule Schematic runner to execute rules according to the range
* @param rulesMapping Mapping of rules to execute based on its semver range
* @param options Additional options
*/
function getMigrationRuleRunner(rulesMapping, options) {
const rangeMapping = Object.entries(rulesMapping)
.reduce((acc, [range, rule]) => {
const checkedRange = (0, semver_1.validRange)(range);
if (checkedRange) {
acc.push([checkedRange, Array.isArray(rule) ? rule : [rule]]);
}
else {
options?.logger?.warn(`The range "${range}" is invalid and will be ignored in the Migration rule`);
}
return acc;
}, []);
/**
* Migration rule runner
* @param config Provide information regarding the range to match
*/
return (config) => {
const fromToRange = new semver_1.Range(config.to ? `>${config.from} <=${config.to}` : `>${config.from}`);
return (0, schematics_1.chain)(rangeMapping
.filter(([range]) => (0, semver_1.intersects)(range, fromToRange))
.map(([_, rules]) => (0, schematics_1.chain)(rules)));
};
}
//# sourceMappingURL=migration.js.map