Browse Source

create-lib schema updated

pull/22645/head
erdemcaygor 1 year ago
parent
commit
c7718ec923
  1. 32
      npm/ng-packs/packages/schematics/src/commands/create-lib/index.ts
  2. 4
      npm/ng-packs/packages/schematics/src/commands/create-lib/models/generate-lib-schema.ts
  3. 29
      npm/ng-packs/packages/schematics/src/commands/create-lib/schema.json

32
npm/ng-packs/packages/schematics/src/commands/create-lib/index.ts

@ -67,20 +67,18 @@ function createLibrary(options: GenerateLibSchema): Rule {
return async (tree: Tree) => { return async (tree: Tree) => {
const target = await resolveProject(tree, options.packageName, null); const target = await resolveProject(tree, options.packageName, null);
if (!target || options.override) { if (!target || options.override) {
if (options.isModuleTemplate) {
if (options.isStandaloneTemplate) {
return createLibFromModuleStandaloneTemplate(tree, options);
} else {
return createLibFromModuleTemplate(tree, options);
}
}
if (options.isSecondaryEntrypoint) { if (options.isSecondaryEntrypoint) {
if (options.isStandaloneTemplate) { if (options.templateType === 'standalone') {
return createLibSecondaryEntryWithStandaloneTemplate(tree, options); return createLibSecondaryEntryWithStandaloneTemplate(tree, options);
} else { } else {
return createLibSecondaryEntry(tree, options); return createLibSecondaryEntry(tree, options);
} }
} }
if (options.templateType === 'module') {
return createLibFromModuleTemplate(tree, options);
} else {
return createLibFromModuleStandaloneTemplate(tree, options);
}
} else { } else {
throw new SchematicsException( throw new SchematicsException(
interpolate(Exception.LibraryAlreadyExists, options.packageName), interpolate(Exception.LibraryAlreadyExists, options.packageName),
@ -230,7 +228,7 @@ export function importConfigModuleToDefaultProjectAppModule(
console.log('isStandalone --->>>>', isSourceStandalone); console.log('isStandalone --->>>>', isSourceStandalone);
const rules: Rule[] = []; const rules: Rule[] = [];
if (options.isStandaloneTemplate) { if (options.templateType === 'standalone') {
rules.push( rules.push(
addRootProvider(projectName, code => { addRootProvider(projectName, code => {
const configFn = code.external( const configFn = code.external(
@ -247,7 +245,7 @@ export function importConfigModuleToDefaultProjectAppModule(
`${pascal(packageName)}ConfigModule`, `${pascal(packageName)}ConfigModule`,
`${kebab(packageName)}/config`, `${kebab(packageName)}/config`,
); );
return code.code`${configFn}()`; return code.code`${configFn}.forRoot()`;
}), }),
); );
} }
@ -317,9 +315,10 @@ export function addRoutingToAppRoutingModule(
if (isSourceStandalone) { if (isSourceStandalone) {
return addRootProvider(projectName, code => { return addRootProvider(projectName, code => {
const routeExpr = options.isStandaloneTemplate const routeExpr =
? `() => import('${routePath}/routes').then(m => m.${pascalName}Routes)` options.templateType === 'standalone'
: `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`; ? `() => import('${routePath}').then(m => m.${pascalName}Routes)`
: `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`;
return code.code`provideRouter([ return code.code`provideRouter([
{ path: '${routePath}', loadChildren: ${routeExpr} } { path: '${routePath}', loadChildren: ${routeExpr} }
@ -344,9 +343,10 @@ export function addRoutingToAppRoutingModule(
ts.ScriptTarget.Latest, ts.ScriptTarget.Latest,
true, true,
); );
const importStatement = options.isStandaloneTemplate const importStatement =
? `() => import('${routePath}').then(m => m.${pascalName}Routes)` options.templateType === 'standalone'
: `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`; ? `() => import('${routePath}').then(m => m.${pascalName}Routes)`
: `() => import('${routePath}').then(m => m.${moduleName}.forLazy())`;
const routeDefinition = `{ path: '${routePath}', loadChildren: ${importStatement} }`; const routeDefinition = `{ path: '${routePath}', loadChildren: ${importStatement} }`;
const change = addRouteDeclarationToModule(source, routePath, routeDefinition); const change = addRouteDeclarationToModule(source, routePath, routeDefinition);

4
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 * İs the package has standalone template
*/ */
isStandaloneTemplate: boolean; templateType: 'standalone' | 'module';
isModuleTemplate: boolean;
override: boolean; override: boolean;

29
npm/ng-packs/packages/schematics/src/commands/create-lib/schema.json

@ -22,23 +22,18 @@
}, },
"x-prompt": "Is secondary entrypoint?" "x-prompt": "Is secondary entrypoint?"
}, },
"isModuleTemplate": { "templateType": {
"description": "Is module template", "type": "string",
"type": "boolean", "description": "Type of the template",
"$default": { "enum": ["module", "standalone"],
"$source": "argv", "x-prompt": {
"index": 2 "message": "Select the type of template to generate:",
}, "type": "list",
"x-prompt": "Is module template?" "items": [
}, { "value": "module", "label": "Module Template" },
"isStandaloneTemplate": { { "value": "standalone", "label": "Standalone Template" }
"description": "Is standalone template", ]
"type": "boolean", }
"$default": {
"$source": "argv",
"index": 3
},
"x-prompt": "Is standalone template?"
}, },
"override": { "override": {
"description": "Override existing files", "description": "Override existing files",

Loading…
Cancel
Save