UNPKG

@o3r/core

Version:
103 lines 5.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ngGenerateComponentPresenter = exports.PRESENTER_FOLDER = void 0; const path = require("node:path"); const schematics_1 = require("@angular-devkit/schematics"); const schematics_2 = require("@o3r/schematics"); const analytics_1 = require("../../rule-factories/component/analytics"); const configuration_1 = require("../../rule-factories/component/configuration"); const context_1 = require("../../rule-factories/component/context"); const design_token_1 = require("../../rule-factories/component/design-token"); const fixture_1 = require("../../rule-factories/component/fixture"); const localization_1 = require("../../rule-factories/component/localization"); const theming_1 = require("../../rule-factories/component/theming"); const structures_types_1 = require("../structures.types"); exports.PRESENTER_FOLDER = 'presenter'; /** * Generates the template properties * @param options * @param componentStructureDef * @param prefix */ const getTemplateProperties = (options, componentStructureDef, prefix) => { const inputComponentName = (0, schematics_2.getInputComponentName)(options.componentName); const folderName = (0, schematics_2.getComponentFolderName)(inputComponentName); const structure = componentStructureDef === structures_types_1.ComponentStructureDef.Simple ? '' : componentStructureDef; return { ...options, componentName: (0, schematics_2.getComponentBaseName)(inputComponentName, structure), componentSelector: (0, schematics_2.getComponentSelectorWithoutSuffix)(options.componentName, prefix || null), projectName: options.projectName || (0, schematics_2.getLibraryNameFromPath)(options.path), folderName, name: (0, schematics_2.getComponentFileName)(options.componentName, structure, options.type), suffix: structure.toLowerCase(), description: options.description || '' }; }; /** * Add Otter component to an Angular Project * @param options */ function ngGenerateComponentPresenterFn(options) { const fullStructureRequested = options.componentStructure === 'full'; const generateFiles = (tree, _context) => { const workspaceProject = options.projectName ? (0, schematics_2.getWorkspaceConfig)(tree)?.projects[options.projectName] : undefined; const properties = getTemplateProperties(options, options.componentStructure === 'simple' ? structures_types_1.ComponentStructureDef.Simple : structures_types_1.ComponentStructureDef.Pres, options.prefix || workspaceProject?.prefix); const destination = (0, schematics_2.getDestinationPath)('@o3r/core:component', options.path, tree, options.projectName); const componentDestination = path.posix.join(destination, fullStructureRequested ? path.posix.join(properties.folderName, exports.PRESENTER_FOLDER) : `${properties.folderName}${properties.suffix ? ('-' + properties.suffix) : ''}`); const componentPath = path.posix.join(componentDestination, `${properties.name}.ts`); const stylePath = path.posix.join(componentDestination, `${properties.name}.scss`); const o3rDesignTokenPath = path.posix.join(componentDestination, `${properties.name}.theme.json`); const componentSelector = `${properties.componentSelector}${properties.suffix ? ('-' + properties.suffix) : ''}`; const rules = []; if (!options.standalone) { rules.push((0, schematics_1.externalSchematic)('@schematics/angular', 'module', { project: properties.projectName, path: componentDestination, flat: true, name: properties.componentName })); } rules.push((0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./templates'), [ (0, schematics_1.template)(properties), (0, schematics_1.renameTemplateFiles)(), (0, schematics_1.move)(componentDestination) ]), schematics_1.MergeStrategy.Overwrite), (0, schematics_1.externalSchematic)('@schematics/angular', 'component', { project: properties.projectName, selector: componentSelector, path: componentDestination, name: properties.componentName, inlineStyle: false, inlineTemplate: false, viewEncapsulation: 'None', changeDetection: 'OnPush', style: 'scss', type: options.type, skipSelector: false, standalone: options.standalone, ...(options.standalone ? { skipImport: true } : { module: `${properties.name}-module.ts`, export: true }), flat: true }), (0, schematics_1.schematic)('convert-component', { path: componentPath, skipLinter: options.skipLinter }), (0, configuration_1.getAddConfigurationRules)(componentPath, options), (0, theming_1.getAddThemingRules)(stylePath, options), (0, design_token_1.getAddDesignTokenRules)(stylePath, o3rDesignTokenPath, options), (0, localization_1.getAddLocalizationRules)(componentPath, options), (0, fixture_1.getAddFixtureRules)(componentPath, options), (0, analytics_1.getAddAnalyticsRules)(componentPath, options), (0, context_1.getAddContextRules)(componentPath, options)); return (0, schematics_1.chain)(rules); }; return (0, schematics_1.chain)([ generateFiles, fullStructureRequested ? (0, schematics_1.noop)() : (options.skipLinter ? (0, schematics_1.noop)() : (0, schematics_2.applyEsLintFix)()) ]); } /** * Add Otter component to an Angular Project * @param options */ exports.ngGenerateComponentPresenter = (0, schematics_2.createOtterSchematic)(ngGenerateComponentPresenterFn); //# sourceMappingURL=index.js.map