diff --git a/npm/ng-packs/packages/schematics/src/collection.json b/npm/ng-packs/packages/schematics/src/collection.json index 5c2df8ea366..0b1b738e087 100644 --- a/npm/ng-packs/packages/schematics/src/collection.json +++ b/npm/ng-packs/packages/schematics/src/collection.json @@ -5,6 +5,11 @@ "factory": "./commands/proxy-add", "schema": "./commands/proxy-add/schema.json" }, + "proxy-index": { + "description": "ABP Proxy Generator Index Schematics", + "factory": "./commands/proxy-index", + "schema": "./commands/proxy-index/schema.json" + }, "proxy-refresh": { "description": "ABP Proxy Generator Refresh Schematics", "factory": "./commands/proxy-refresh", diff --git a/npm/ng-packs/packages/schematics/src/commands/proxy-index/index.ts b/npm/ng-packs/packages/schematics/src/commands/proxy-index/index.ts new file mode 100644 index 00000000000..85c4707daa2 --- /dev/null +++ b/npm/ng-packs/packages/schematics/src/commands/proxy-index/index.ts @@ -0,0 +1,20 @@ +import { SchematicContext, Tree } from '@angular-devkit/schematics'; +import { + buildDefaultPath, + createProxyIndexGenerator, + removeDefaultPlaceholders, + resolveProject, +} from '../../utils'; + +export default function(schema: { target?: string }) { + const params = removeDefaultPlaceholders(schema); + + return async (host: Tree, _context: SchematicContext) => { + const target = await resolveProject(host, params.target!); + const targetPath = buildDefaultPath(target.definition); + + const generateIndex = createProxyIndexGenerator(targetPath); + + return generateIndex(host); + }; +} diff --git a/npm/ng-packs/packages/schematics/src/commands/proxy-index/schema.json b/npm/ng-packs/packages/schematics/src/commands/proxy-index/schema.json new file mode 100644 index 00000000000..632c6d7e51a --- /dev/null +++ b/npm/ng-packs/packages/schematics/src/commands/proxy-index/schema.json @@ -0,0 +1,18 @@ +{ + "$schema": "http://json-schema.org/schema", + "id": "SchematicsAbpIndexProxy", + "title": "ABP Index Proxy Schema", + "type": "object", + "properties": { + "target": { + "description": "Target Angular project to place the generated code", + "type": "string", + "$default": { + "$source": "argv", + "index": 0 + }, + "x-prompt": "Plese enter target Angular project to place the generated code. (default: workspace \"defaultProject\")" + } + }, + "required": [] +} diff --git a/npm/ng-packs/packages/schematics/src/utils/barrel.ts b/npm/ng-packs/packages/schematics/src/utils/barrel.ts index b21acc77fa6..adf6779ebe0 100644 --- a/npm/ng-packs/packages/schematics/src/utils/barrel.ts +++ b/npm/ng-packs/packages/schematics/src/utils/barrel.ts @@ -21,7 +21,7 @@ export function generateBarrelFromPath(tree: Tree, indexPath: string) { const _exports: string[] = []; dir.subfiles.forEach(fragment => { - if (!fragment.endsWith('.ts')) return; + if (!fragment.endsWith('.ts') || fragment === 'index.ts') return; _exports.push(`export * from './${fragment.replace(/\.ts$/, '')}';`); }); diff --git a/npm/ng-packs/scripts/build-schematics.ts b/npm/ng-packs/scripts/build-schematics.ts index 3a14d2f03cb..7efca32e725 100644 --- a/npm/ng-packs/scripts/build-schematics.ts +++ b/npm/ng-packs/scripts/build-schematics.ts @@ -21,6 +21,7 @@ class FileCopy { const PACKAGE_TO_BUILD = 'schematics'; const FILES_TO_COPY_AFTER_BUILD: (FileCopy | string)[] = [ { src: 'src/commands/proxy-add/schema.json', dest: 'commands/proxy-add/schema.json' }, + { src: 'src/commands/proxy-index/schema.json', dest: 'commands/proxy-index/schema.json' }, { src: 'src/commands/proxy-refresh/schema.json', dest: 'commands/proxy-refresh/schema.json' }, { src: 'src/commands/proxy-remove/schema.json', dest: 'commands/proxy-remove/schema.json' }, { src: 'src/commands/api/files-enum', dest: 'commands/api/files-enum' },