@o3r/core
Version:
Core of the Otter Framework
65 lines • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ngGenerateSimpleSyncStore = void 0;
const path = require("node:path");
const core_1 = require("@angular-devkit/core");
const schematics_1 = require("@angular-devkit/schematics");
const schematics_2 = require("@o3r/schematics");
/**
* Create an Otter friendly simple sync store
* @param options
*/
function ngGenerateSimpleSyncStoreFn(options) {
const generateFiles = (tree, context) => {
const destination = (0, schematics_2.getDestinationPath)('@o3r/core:store', options.path, tree, options.projectName);
const commonTemplates = (0, schematics_1.url)('../common/templates');
const syncEntityTemplates = (0, schematics_1.url)('./templates');
options.storeName = options.storeName?.trim();
// Add extra formatted properties
const formattedProperties = {
isAsync: false,
isEntity: false,
storeName: core_1.strings.classify(options.storeName),
cStoreName: core_1.strings.camelize(options.storeName),
scuStoreName: core_1.strings.underscore(options.storeName).toUpperCase(),
fileName: core_1.strings.dasherize(options.storeName)
};
let currentStoreIndex = '';
const barrelPath = path.join(destination, options.storeName, 'index.ts');
if (tree.exists(barrelPath)) {
const currentStoreIndexBuffer = tree.read(barrelPath);
currentStoreIndex = currentStoreIndexBuffer ? currentStoreIndexBuffer.toString() : '';
tree.delete(barrelPath);
}
const rules = [];
rules.push((0, schematics_1.mergeWith)((0, schematics_1.apply)(commonTemplates, [
(0, schematics_1.template)({
...core_1.strings,
...options,
...formattedProperties,
currentStoreIndex
}),
(0, schematics_1.renameTemplateFiles)(),
(0, schematics_1.move)(`${destination}/${core_1.strings.dasherize(options.storeName)}`)
]), schematics_1.MergeStrategy.Overwrite), (0, schematics_1.mergeWith)((0, schematics_1.apply)(syncEntityTemplates, [
(0, schematics_1.template)({
...core_1.strings,
...options,
...formattedProperties,
currentStoreIndex
}),
(0, schematics_1.renameTemplateFiles)(),
(0, schematics_1.move)(`${destination}/${core_1.strings.dasherize(options.storeName)}`)
]), schematics_1.MergeStrategy.Overwrite));
if ((0, schematics_2.moduleHasSubEntryPoints)(tree, destination)) {
(0, schematics_2.writeSubEntryPointPackageJson)(tree, destination, core_1.strings.dasherize(options.storeName));
}
return (0, schematics_1.chain)(rules)(tree, context);
};
return (0, schematics_1.chain)([
generateFiles,
options.skipLinter ? (0, schematics_1.noop)() : (0, schematics_2.applyEsLintFix)()
]);
}
exports.ngGenerateSimpleSyncStore = (0, schematics_2.createOtterSchematic)(ngGenerateSimpleSyncStoreFn);
//# sourceMappingURL=index.js.map