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) => {
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);

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
*/
isStandaloneTemplate: boolean;
isModuleTemplate: boolean;
templateType: 'standalone' | 'module';
override: boolean;

29
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",

Loading…
Cancel
Save