From c7718ec923da829510c68ca4818204a9a9c74316 Mon Sep 17 00:00:00 2001 From: erdemcaygor Date: Thu, 17 Apr 2025 11:31:58 +0300 Subject: [PATCH] create-lib schema updated --- .../src/commands/create-lib/index.ts | 32 +++++++++---------- .../create-lib/models/generate-lib-schema.ts | 4 +-- .../src/commands/create-lib/schema.json | 29 +++++++---------- 3 files changed, 29 insertions(+), 36 deletions(-) diff --git a/npm/ng-packs/packages/schematics/src/commands/create-lib/index.ts b/npm/ng-packs/packages/schematics/src/commands/create-lib/index.ts index 44d181a175..f2a9f6347f 100644 --- a/npm/ng-packs/packages/schematics/src/commands/create-lib/index.ts +++ b/npm/ng-packs/packages/schematics/src/commands/create-lib/index.ts @@ -67,20 +67,18 @@ function createLibrary(options: GenerateLibSchema): Rule { return async (tree: Tree) => { const target = await resolveProject(tree, options.packageName, null); if (!target || options.override) { - if (options.isModuleTemplate) { - if (options.isStandaloneTemplate) { - return createLibFromModuleStandaloneTemplate(tree, options); - } else { - return createLibFromModuleTemplate(tree, options); - } - } if (options.isSecondaryEntrypoint) { - if (options.isStandaloneTemplate) { + if (options.templateType === 'standalone') { return createLibSecondaryEntryWithStandaloneTemplate(tree, options); } else { return createLibSecondaryEntry(tree, options); } } + if (options.templateType === 'module') { + return createLibFromModuleTemplate(tree, options); + } else { + return createLibFromModuleStandaloneTemplate(tree, options); + } } else { throw new SchematicsException( interpolate(Exception.LibraryAlreadyExists, options.packageName), @@ -230,7 +228,7 @@ export function importConfigModuleToDefaultProjectAppModule( console.log('isStandalone --->>>>', isSourceStandalone); const rules: Rule[] = []; - if (options.isStandaloneTemplate) { + if (options.templateType === 'standalone') { rules.push( addRootProvider(projectName, code => { const configFn = code.external( @@ -247,7 +245,7 @@ export function importConfigModuleToDefaultProjectAppModule( `${pascal(packageName)}ConfigModule`, `${kebab(packageName)}/config`, ); - return code.code`${configFn}()`; + return code.code`${configFn}.forRoot()`; }), ); } @@ -317,9 +315,10 @@ export function addRoutingToAppRoutingModule( if (isSourceStandalone) { return addRootProvider(projectName, code => { - const routeExpr = options.isStandaloneTemplate - ? `() => import('${routePath}/routes').then(m => m.${pascalName}Routes)` - : `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`; + const routeExpr = + options.templateType === 'standalone' + ? `() => import('${routePath}').then(m => m.${pascalName}Routes)` + : `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`; return code.code`provideRouter([ { path: '${routePath}', loadChildren: ${routeExpr} } @@ -344,9 +343,10 @@ export function addRoutingToAppRoutingModule( ts.ScriptTarget.Latest, true, ); - const importStatement = options.isStandaloneTemplate - ? `() => import('${routePath}').then(m => m.${pascalName}Routes)` - : `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`; + const importStatement = + options.templateType === 'standalone' + ? `() => import('${routePath}').then(m => m.${pascalName}Routes)` + : `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`; const routeDefinition = `{ path: '${routePath}', loadChildren: ${importStatement} }`; const change = addRouteDeclarationToModule(source, routePath, routeDefinition); diff --git a/npm/ng-packs/packages/schematics/src/commands/create-lib/models/generate-lib-schema.ts b/npm/ng-packs/packages/schematics/src/commands/create-lib/models/generate-lib-schema.ts index a6d32e1da0..a3a9314abe 100644 --- a/npm/ng-packs/packages/schematics/src/commands/create-lib/models/generate-lib-schema.ts +++ b/npm/ng-packs/packages/schematics/src/commands/create-lib/models/generate-lib-schema.ts @@ -11,9 +11,7 @@ export interface GenerateLibSchema { /** * İs the package has standalone template */ - isStandaloneTemplate: boolean; - - isModuleTemplate: boolean; + templateType: 'standalone' | 'module'; override: boolean; diff --git a/npm/ng-packs/packages/schematics/src/commands/create-lib/schema.json b/npm/ng-packs/packages/schematics/src/commands/create-lib/schema.json index 19de7420ae..df9f64a470 100644 --- a/npm/ng-packs/packages/schematics/src/commands/create-lib/schema.json +++ b/npm/ng-packs/packages/schematics/src/commands/create-lib/schema.json @@ -22,23 +22,18 @@ }, "x-prompt": "Is secondary entrypoint?" }, - "isModuleTemplate": { - "description": "Is module template", - "type": "boolean", - "$default": { - "$source": "argv", - "index": 2 - }, - "x-prompt": "Is module template?" - }, - "isStandaloneTemplate": { - "description": "Is standalone template", - "type": "boolean", - "$default": { - "$source": "argv", - "index": 3 - }, - "x-prompt": "Is standalone template?" + "templateType": { + "type": "string", + "description": "Type of the template", + "enum": ["module", "standalone"], + "x-prompt": { + "message": "Select the type of template to generate:", + "type": "list", + "items": [ + { "value": "module", "label": "Module Template" }, + { "value": "standalone", "label": "Standalone Template" } + ] + } }, "override": { "description": "Override existing files",