@o3r/schematics
Version:
Schematics module of the Otter framework
28 lines • 1.38 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.createSchematicWithOptionsFromWorkspace = createSchematicWithOptionsFromWorkspace;
const collection_1 = require("../../utility/collection");
const loaders_1 = require("../../utility/loaders");
/**
* Wrapper method of a schematic to retrieve options from workspace and merge it with the one from the run of the schematic
* NOTE: please do not use it directly, instead use {@link createOtterSchematic} to wrap your schematic
* @param schematicFn
*/
function createSchematicWithOptionsFromWorkspace(schematicFn) {
return (options) => (tree, context) => {
const workspace = (0, loaders_1.getWorkspaceConfig)(tree);
const workspaceOptions = (0, collection_1.getDefaultOptionsForSchematic)(workspace, context.schematic.description.collection.name, context.schematic.description.name, { projectName: undefined, ...options });
const schematicOptionsWithoutUndefined = Object.entries(options).reduce((acc, [key, value]) => {
if (typeof value !== 'undefined') {
acc[key] = value;
}
return acc;
}, {});
const schematicOptions = {
...workspaceOptions,
...schematicOptionsWithoutUndefined
};
return schematicFn(schematicOptions);
};
}
//# sourceMappingURL=index.js.map