@gapi/schematics 1.8.122
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc +4 -0
- package/README.md +35 -0
- package/collection.json +99 -0
- package/dist/lib/application/application.factory.d.ts +3 -0
- package/dist/lib/application/application.factory.js +35 -0
- package/dist/lib/application/application.factory.test.ts +88 -0
- package/dist/lib/application/application.factory.ts +54 -0
- package/dist/lib/application/application.schema.d.ts +34 -0
- package/dist/lib/application/files/js/.babelrc +4 -0
- package/dist/lib/application/files/js/.prettierrc +4 -0
- package/dist/lib/application/files/js/README.md +37 -0
- package/dist/lib/application/files/js/index.js +3 -0
- package/dist/lib/application/files/js/jsconfig.json +9 -0
- package/dist/lib/application/files/js/nest-cli.json +5 -0
- package/dist/lib/application/files/js/nodemon.json +6 -0
- package/dist/lib/application/files/js/package.json +46 -0
- package/dist/lib/application/files/js/src/app.controller.js +15 -0
- package/dist/lib/application/files/js/src/app.controller.spec.js +22 -0
- package/dist/lib/application/files/js/src/app.module.js +10 -0
- package/dist/lib/application/files/js/src/app.service.js +8 -0
- package/dist/lib/application/files/js/src/main.js +9 -0
- package/dist/lib/application/files/js/test/app.e2e-spec.js +23 -0
- package/dist/lib/application/files/js/test/jest-e2e.json +5 -0
- package/dist/lib/application/files/ts/.prettierrc +4 -0
- package/dist/lib/application/files/ts/README.md +75 -0
- package/dist/lib/application/files/ts/nest-cli.json +5 -0
- package/dist/lib/application/files/ts/nodemon-debug.json +6 -0
- package/dist/lib/application/files/ts/nodemon.json +6 -0
- package/dist/lib/application/files/ts/package.json +58 -0
- package/dist/lib/application/files/ts/src/app.controller.spec.ts +22 -0
- package/dist/lib/application/files/ts/src/app.controller.ts +12 -0
- package/dist/lib/application/files/ts/src/app.module.ts +10 -0
- package/dist/lib/application/files/ts/src/app.service.ts +8 -0
- package/dist/lib/application/files/ts/src/main.ts +8 -0
- package/dist/lib/application/files/ts/test/app.e2e-spec.ts +23 -0
- package/dist/lib/application/files/ts/test/jest-e2e.json +9 -0
- package/dist/lib/application/files/ts/tsconfig.build.json +4 -0
- package/dist/lib/application/files/ts/tsconfig.json +14 -0
- package/dist/lib/application/files/ts/tslint.json +18 -0
- package/dist/lib/application/schema.json +49 -0
- package/dist/lib/class/class.factory.d.ts +3 -0
- package/dist/lib/class/class.factory.js +35 -0
- package/dist/lib/class/class.factory.test.ts +100 -0
- package/dist/lib/class/class.factory.ts +54 -0
- package/dist/lib/class/class.schema.d.ts +28 -0
- package/dist/lib/class/files/js/__name__.js +1 -0
- package/dist/lib/class/files/js/__name__.spec.js +7 -0
- package/dist/lib/class/files/ts/__name__.spec.ts +7 -0
- package/dist/lib/class/files/ts/__name__.ts +1 -0
- package/dist/lib/class/schema.json +39 -0
- package/dist/lib/client-app/angular/angular.factory.d.ts +3 -0
- package/dist/lib/client-app/angular/angular.factory.js +97 -0
- package/dist/lib/client-app/angular/angular.factory.ts +139 -0
- package/dist/lib/client-app/angular/angular.schema.d.ts +32 -0
- package/dist/lib/client-app/angular/files/angular.constants.ts +4 -0
- package/dist/lib/client-app/angular/files/angular.module.ts +41 -0
- package/dist/lib/client-app/angular/files/angular.providers.ts +27 -0
- package/dist/lib/client-app/angular/files/angular.utils.ts +19 -0
- package/dist/lib/client-app/angular/files/interfaces/angular-options.interface.ts +87 -0
- package/dist/lib/client-app/angular/files/loaders/abstract.loader.ts +16 -0
- package/dist/lib/client-app/angular/files/loaders/express.loader.ts +25 -0
- package/dist/lib/client-app/angular/files/loaders/fastify.loader.ts +34 -0
- package/dist/lib/client-app/angular/files/loaders/noop.loader.ts +12 -0
- package/dist/lib/client-app/angular/schema.json +24 -0
- package/dist/lib/component/component.factory.d.ts +3 -0
- package/dist/lib/component/component.factory.js +62 -0
- package/dist/lib/component/component.factory.test.ts +191 -0
- package/dist/lib/component/component.factory.ts +91 -0
- package/dist/lib/component/component.schema.d.ts +44 -0
- package/dist/lib/component/files/js/__name__.component.js +56 -0
- package/dist/lib/component/files/js/__name__.component.spec.js +31 -0
- package/dist/lib/component/files/ts/__name__.component.spec.ts +31 -0
- package/dist/lib/component/files/ts/__name__.component.ts +56 -0
- package/dist/lib/component/schema.json +47 -0
- package/dist/lib/configuration/configuration.factory.d.ts +3 -0
- package/dist/lib/configuration/configuration.factory.js +24 -0
- package/dist/lib/configuration/configuration.factory.test.ts +60 -0
- package/dist/lib/configuration/configuration.factory.ts +35 -0
- package/dist/lib/configuration/configuration.schema.d.ts +18 -0
- package/dist/lib/configuration/files/js/nest-cli.json +5 -0
- package/dist/lib/configuration/files/ts/nest-cli.json +5 -0
- package/dist/lib/controller/controller.factory.d.ts +3 -0
- package/dist/lib/controller/controller.factory.js +62 -0
- package/dist/lib/controller/controller.factory.test.ts +191 -0
- package/dist/lib/controller/controller.factory.ts +91 -0
- package/dist/lib/controller/controller.schema.d.ts +44 -0
- package/dist/lib/controller/files/js/__name__.controller.js +24 -0
- package/dist/lib/controller/files/js/__name__.controller.spec.js +61 -0
- package/dist/lib/controller/files/ts/__name__.controller.spec.ts +61 -0
- package/dist/lib/controller/files/ts/__name__.controller.ts +24 -0
- package/dist/lib/controller/schema.json +47 -0
- package/dist/lib/decorator/decorator.factory.d.ts +3 -0
- package/dist/lib/decorator/decorator.factory.js +32 -0
- package/dist/lib/decorator/decorator.factory.test.ts +111 -0
- package/dist/lib/decorator/decorator.factory.ts +48 -0
- package/dist/lib/decorator/decorator.schema.d.ts +24 -0
- package/dist/lib/decorator/files/js/__name__.decorator.js +3 -0
- package/dist/lib/decorator/files/ts/__name__.decorator.ts +3 -0
- package/dist/lib/decorator/schema.json +35 -0
- package/dist/lib/defaults.d.ts +6 -0
- package/dist/lib/defaults.js +9 -0
- package/dist/lib/defaults.ts +6 -0
- package/dist/lib/effect/effect.factory.d.ts +3 -0
- package/dist/lib/effect/effect.factory.js +62 -0
- package/dist/lib/effect/effect.factory.test.ts +190 -0
- package/dist/lib/effect/effect.factory.ts +91 -0
- package/dist/lib/effect/effect.schema.d.ts +44 -0
- package/dist/lib/effect/files/js/__name__.effect.js +11 -0
- package/dist/lib/effect/files/js/__name__.effect.spec.js +17 -0
- package/dist/lib/effect/files/ts/__name__.effect.spec.ts +17 -0
- package/dist/lib/effect/files/ts/__name__.effect.ts +11 -0
- package/dist/lib/effect/schema.json +39 -0
- package/dist/lib/filter/files/js/__name__.filter.js +6 -0
- package/dist/lib/filter/files/js/__name__.filter.spec.js +7 -0
- package/dist/lib/filter/files/ts/__name__.filter.spec.ts +7 -0
- package/dist/lib/filter/files/ts/__name__.filter.ts +6 -0
- package/dist/lib/filter/filter.factory.d.ts +3 -0
- package/dist/lib/filter/filter.factory.js +33 -0
- package/dist/lib/filter/filter.factory.test.ts +147 -0
- package/dist/lib/filter/filter.factory.ts +51 -0
- package/dist/lib/filter/filter.schema.d.ts +28 -0
- package/dist/lib/filter/schema.json +39 -0
- package/dist/lib/gateway/files/js/__name__.gateway.js +9 -0
- package/dist/lib/gateway/files/js/__name__.gateway.spec.js +18 -0
- package/dist/lib/gateway/files/ts/__name__.gateway.spec.ts +18 -0
- package/dist/lib/gateway/files/ts/__name__.gateway.ts +9 -0
- package/dist/lib/gateway/gateway.factory.d.ts +3 -0
- package/dist/lib/gateway/gateway.factory.js +61 -0
- package/dist/lib/gateway/gateway.factory.test.ts +147 -0
- package/dist/lib/gateway/gateway.factory.ts +92 -0
- package/dist/lib/gateway/gateway.schema.d.ts +36 -0
- package/dist/lib/gateway/schema.json +39 -0
- package/dist/lib/guard/files/js/__name__.guard.js +17 -0
- package/dist/lib/guard/files/js/__name__.guard.spec.js +7 -0
- package/dist/lib/guard/files/ts/__name__.guard.spec.ts +7 -0
- package/dist/lib/guard/files/ts/__name__.guard.ts +17 -0
- package/dist/lib/guard/guard.factory.d.ts +3 -0
- package/dist/lib/guard/guard.factory.js +33 -0
- package/dist/lib/guard/guard.factory.test.ts +156 -0
- package/dist/lib/guard/guard.factory.ts +51 -0
- package/dist/lib/guard/guard.schema.d.ts +28 -0
- package/dist/lib/guard/schema.json +39 -0
- package/dist/lib/interceptor/files/js/__name__.interceptor.js +18 -0
- package/dist/lib/interceptor/files/js/__name__.interceptor.spec.js +7 -0
- package/dist/lib/interceptor/files/ts/__name__.interceptor.spec.ts +7 -0
- package/dist/lib/interceptor/files/ts/__name__.interceptor.ts +19 -0
- package/dist/lib/interceptor/interceptor.factory.d.ts +3 -0
- package/dist/lib/interceptor/interceptor.factory.js +33 -0
- package/dist/lib/interceptor/interceptor.factory.test.ts +146 -0
- package/dist/lib/interceptor/interceptor.factory.ts +51 -0
- package/dist/lib/interceptor/interceptor.schema.d.ts +28 -0
- package/dist/lib/interceptor/schema.json +39 -0
- package/dist/lib/interface/files/__name__.interface.ts +1 -0
- package/dist/lib/interface/interface.factory.d.ts +3 -0
- package/dist/lib/interface/interface.factory.js +31 -0
- package/dist/lib/interface/interface.factory.test.ts +84 -0
- package/dist/lib/interface/interface.factory.ts +47 -0
- package/dist/lib/interface/interface.schema.d.ts +20 -0
- package/dist/lib/interface/schema.json +31 -0
- package/dist/lib/library/files/js/.babelrc +4 -0
- package/dist/lib/library/files/js/jsconfig.json +9 -0
- package/dist/lib/library/files/js/package.json +8 -0
- package/dist/lib/library/files/js/src/__name__.module.js +8 -0
- package/dist/lib/library/files/js/src/__name__.service.js +4 -0
- package/dist/lib/library/files/js/src/__name__.service.spec.js +18 -0
- package/dist/lib/library/files/js/src/index.js +2 -0
- package/dist/lib/library/files/ts/package.json +8 -0
- package/dist/lib/library/files/ts/src/__name__.module.ts +8 -0
- package/dist/lib/library/files/ts/src/__name__.service.spec.ts +18 -0
- package/dist/lib/library/files/ts/src/__name__.service.ts +4 -0
- package/dist/lib/library/files/ts/src/index.ts +2 -0
- package/dist/lib/library/files/ts/tsconfig.lib.json +5 -0
- package/dist/lib/library/files/ts/tslint.json +3 -0
- package/dist/lib/library/library.factory.d.ts +3 -0
- package/dist/lib/library/library.factory.js +97 -0
- package/dist/lib/library/library.factory.test.ts +68 -0
- package/dist/lib/library/library.factory.ts +158 -0
- package/dist/lib/library/library.schema.d.ts +24 -0
- package/dist/lib/library/schema.json +37 -0
- package/dist/lib/module/files/js/__name__.module.js +4 -0
- package/dist/lib/module/files/ts/__name__.module.ts +4 -0
- package/dist/lib/module/module.factory.d.ts +3 -0
- package/dist/lib/module/module.factory.js +54 -0
- package/dist/lib/module/module.factory.test.ts +165 -0
- package/dist/lib/module/module.factory.ts +79 -0
- package/dist/lib/module/module.schema.d.ts +36 -0
- package/dist/lib/module/schema.json +40 -0
- package/dist/lib/pipe/files/js/__name__.pipe.js +8 -0
- package/dist/lib/pipe/files/js/__name__.pipe.spec.js +7 -0
- package/dist/lib/pipe/files/ts/__name__.pipe.spec.ts +7 -0
- package/dist/lib/pipe/files/ts/__name__.pipe.ts +8 -0
- package/dist/lib/pipe/pipe.factory.d.ts +3 -0
- package/dist/lib/pipe/pipe.factory.js +33 -0
- package/dist/lib/pipe/pipe.factory.test.ts +141 -0
- package/dist/lib/pipe/pipe.factory.ts +51 -0
- package/dist/lib/pipe/pipe.schema.d.ts +28 -0
- package/dist/lib/pipe/schema.json +39 -0
- package/dist/lib/plugin/files/js/__name__.plugin.js +28 -0
- package/dist/lib/plugin/files/js/__name__.plugin.spec.js +7 -0
- package/dist/lib/plugin/files/ts/__name__.plugin.spec.ts +7 -0
- package/dist/lib/plugin/files/ts/__name__.plugin.ts +28 -0
- package/dist/lib/plugin/plugin.factory.d.ts +3 -0
- package/dist/lib/plugin/plugin.factory.js +61 -0
- package/dist/lib/plugin/plugin.factory.test.ts +191 -0
- package/dist/lib/plugin/plugin.factory.ts +91 -0
- package/dist/lib/plugin/plugin.schema.d.ts +44 -0
- package/dist/lib/plugin/schema.json +52 -0
- package/dist/lib/provider/files/js/__name__.js +4 -0
- package/dist/lib/provider/files/js/__name__.spec.js +17 -0
- package/dist/lib/provider/files/ts/__name__.spec.ts +17 -0
- package/dist/lib/provider/files/ts/__name__.ts +4 -0
- package/dist/lib/provider/provider.factory.d.ts +3 -0
- package/dist/lib/provider/provider.factory.js +59 -0
- package/dist/lib/provider/provider.factory.test.ts +151 -0
- package/dist/lib/provider/provider.factory.ts +89 -0
- package/dist/lib/provider/provider.schema.d.ts +44 -0
- package/dist/lib/provider/schema.json +39 -0
- package/dist/lib/resolver/files/js/__name__.resolver.js +4 -0
- package/dist/lib/resolver/files/js/__name__.resolver.spec.js +18 -0
- package/dist/lib/resolver/files/ts/__name__.resolver.spec.ts +18 -0
- package/dist/lib/resolver/files/ts/__name__.resolver.ts +4 -0
- package/dist/lib/resolver/resolver.factory.d.ts +3 -0
- package/dist/lib/resolver/resolver.factory.js +61 -0
- package/dist/lib/resolver/resolver.factory.test.ts +117 -0
- package/dist/lib/resolver/resolver.factory.ts +92 -0
- package/dist/lib/resolver/resolver.schema.d.ts +36 -0
- package/dist/lib/resolver/schema.json +39 -0
- package/dist/lib/service/files/js/__name__.service.js +4 -0
- package/dist/lib/service/files/js/__name__.service.spec.js +17 -0
- package/dist/lib/service/files/ts/__name__.service.spec.ts +17 -0
- package/dist/lib/service/files/ts/__name__.service.ts +4 -0
- package/dist/lib/service/schema.json +39 -0
- package/dist/lib/service/service.factory.d.ts +3 -0
- package/dist/lib/service/service.factory.js +62 -0
- package/dist/lib/service/service.factory.test.ts +190 -0
- package/dist/lib/service/service.factory.ts +91 -0
- package/dist/lib/service/service.schema.d.ts +44 -0
- package/dist/lib/type/files/js/__name__.type.js +10 -0
- package/dist/lib/type/files/ts/__name__.type.ts +10 -0
- package/dist/lib/type/schema.json +43 -0
- package/dist/lib/type/type.factory.d.ts +3 -0
- package/dist/lib/type/type.factory.js +61 -0
- package/dist/lib/type/type.factory.test.ts +191 -0
- package/dist/lib/type/type.factory.ts +91 -0
- package/dist/lib/type/type.schema.d.ts +44 -0
- package/dist/utils/metadata.manager.d.ts +13 -0
- package/dist/utils/metadata.manager.js +159 -0
- package/dist/utils/metadata.manager.ts +219 -0
- package/dist/utils/module-import.declarator.d.ts +11 -0
- package/dist/utils/module-import.declarator.js +37 -0
- package/dist/utils/module-import.declarator.ts +41 -0
- package/dist/utils/module-metadata.declarator.d.ts +4 -0
- package/dist/utils/module-metadata.declarator.js +12 -0
- package/dist/utils/module-metadata.declarator.ts +14 -0
- package/dist/utils/module.declarator.d.ts +22 -0
- package/dist/utils/module.declarator.js +29 -0
- package/dist/utils/module.declarator.ts +41 -0
- package/dist/utils/module.finder.d.ts +13 -0
- package/dist/utils/module.finder.js +24 -0
- package/dist/utils/module.finder.ts +32 -0
- package/dist/utils/name.parser.d.ts +13 -0
- package/dist/utils/name.parser.js +20 -0
- package/dist/utils/name.parser.ts +29 -0
- package/dist/utils/path.solver.d.ts +5 -0
- package/dist/utils/path.solver.js +15 -0
- package/dist/utils/path.solver.ts +17 -0
- package/dist/utils/source-root.helpers.d.ts +6 -0
- package/dist/utils/source-root.helpers.js +25 -0
- package/dist/utils/source-root.helpers.ts +30 -0
- package/package.json +44 -0
- package/src/lib/application/application.factory.test.ts +88 -0
- package/src/lib/application/application.factory.ts +54 -0
- package/src/lib/application/application.schema.d.ts +34 -0
- package/src/lib/application/files/js/.babelrc +4 -0
- package/src/lib/application/files/js/.prettierrc +4 -0
- package/src/lib/application/files/js/README.md +37 -0
- package/src/lib/application/files/js/index.js +3 -0
- package/src/lib/application/files/js/jsconfig.json +9 -0
- package/src/lib/application/files/js/nest-cli.json +5 -0
- package/src/lib/application/files/js/nodemon.json +6 -0
- package/src/lib/application/files/js/package.json +46 -0
- package/src/lib/application/files/js/src/app.controller.js +15 -0
- package/src/lib/application/files/js/src/app.controller.spec.js +22 -0
- package/src/lib/application/files/js/src/app.module.js +10 -0
- package/src/lib/application/files/js/src/app.service.js +8 -0
- package/src/lib/application/files/js/src/main.js +9 -0
- package/src/lib/application/files/js/test/app.e2e-spec.js +23 -0
- package/src/lib/application/files/js/test/jest-e2e.json +5 -0
- package/src/lib/application/files/ts/.prettierrc +4 -0
- package/src/lib/application/files/ts/README.md +75 -0
- package/src/lib/application/files/ts/nest-cli.json +5 -0
- package/src/lib/application/files/ts/nodemon-debug.json +6 -0
- package/src/lib/application/files/ts/nodemon.json +6 -0
- package/src/lib/application/files/ts/package.json +58 -0
- package/src/lib/application/files/ts/src/app.controller.spec.ts +22 -0
- package/src/lib/application/files/ts/src/app.controller.ts +12 -0
- package/src/lib/application/files/ts/src/app.module.ts +10 -0
- package/src/lib/application/files/ts/src/app.service.ts +8 -0
- package/src/lib/application/files/ts/src/main.ts +8 -0
- package/src/lib/application/files/ts/test/app.e2e-spec.ts +23 -0
- package/src/lib/application/files/ts/test/jest-e2e.json +9 -0
- package/src/lib/application/files/ts/tsconfig.build.json +4 -0
- package/src/lib/application/files/ts/tsconfig.json +14 -0
- package/src/lib/application/files/ts/tslint.json +18 -0
- package/src/lib/application/schema.json +49 -0
- package/src/lib/class/class.factory.test.ts +100 -0
- package/src/lib/class/class.factory.ts +54 -0
- package/src/lib/class/class.schema.d.ts +28 -0
- package/src/lib/class/files/js/__name__.js +1 -0
- package/src/lib/class/files/js/__name__.spec.js +7 -0
- package/src/lib/class/files/ts/__name__.spec.ts +7 -0
- package/src/lib/class/files/ts/__name__.ts +1 -0
- package/src/lib/class/schema.json +39 -0
- package/src/lib/client-app/angular/angular.factory.ts +139 -0
- package/src/lib/client-app/angular/angular.schema.d.ts +32 -0
- package/src/lib/client-app/angular/files/angular.constants.ts +4 -0
- package/src/lib/client-app/angular/files/angular.module.ts +41 -0
- package/src/lib/client-app/angular/files/angular.providers.ts +27 -0
- package/src/lib/client-app/angular/files/angular.utils.ts +19 -0
- package/src/lib/client-app/angular/files/interfaces/angular-options.interface.ts +87 -0
- package/src/lib/client-app/angular/files/loaders/abstract.loader.ts +16 -0
- package/src/lib/client-app/angular/files/loaders/express.loader.ts +25 -0
- package/src/lib/client-app/angular/files/loaders/fastify.loader.ts +34 -0
- package/src/lib/client-app/angular/files/loaders/noop.loader.ts +12 -0
- package/src/lib/client-app/angular/schema.json +24 -0
- package/src/lib/component/component.factory.test.ts +191 -0
- package/src/lib/component/component.factory.ts +91 -0
- package/src/lib/component/component.schema.d.ts +44 -0
- package/src/lib/component/files/js/__name__.component.js +56 -0
- package/src/lib/component/files/js/__name__.component.spec.js +31 -0
- package/src/lib/component/files/ts/__name__.component.spec.ts +31 -0
- package/src/lib/component/files/ts/__name__.component.ts +56 -0
- package/src/lib/component/schema.json +47 -0
- package/src/lib/configuration/configuration.factory.test.ts +60 -0
- package/src/lib/configuration/configuration.factory.ts +35 -0
- package/src/lib/configuration/configuration.schema.d.ts +18 -0
- package/src/lib/configuration/files/js/nest-cli.json +5 -0
- package/src/lib/configuration/files/ts/nest-cli.json +5 -0
- package/src/lib/controller/controller.factory.test.ts +191 -0
- package/src/lib/controller/controller.factory.ts +91 -0
- package/src/lib/controller/controller.schema.d.ts +44 -0
- package/src/lib/controller/files/js/__name__.controller.js +24 -0
- package/src/lib/controller/files/js/__name__.controller.spec.js +61 -0
- package/src/lib/controller/files/ts/__name__.controller.spec.ts +61 -0
- package/src/lib/controller/files/ts/__name__.controller.ts +24 -0
- package/src/lib/controller/schema.json +47 -0
- package/src/lib/decorator/decorator.factory.test.ts +111 -0
- package/src/lib/decorator/decorator.factory.ts +48 -0
- package/src/lib/decorator/decorator.schema.d.ts +24 -0
- package/src/lib/decorator/files/js/__name__.decorator.js +3 -0
- package/src/lib/decorator/files/ts/__name__.decorator.ts +3 -0
- package/src/lib/decorator/schema.json +35 -0
- package/src/lib/defaults.ts +6 -0
- package/src/lib/effect/effect.factory.test.ts +190 -0
- package/src/lib/effect/effect.factory.ts +91 -0
- package/src/lib/effect/effect.schema.d.ts +44 -0
- package/src/lib/effect/files/js/__name__.effect.js +11 -0
- package/src/lib/effect/files/js/__name__.effect.spec.js +17 -0
- package/src/lib/effect/files/ts/__name__.effect.spec.ts +17 -0
- package/src/lib/effect/files/ts/__name__.effect.ts +11 -0
- package/src/lib/effect/schema.json +39 -0
- package/src/lib/filter/files/js/__name__.filter.js +6 -0
- package/src/lib/filter/files/js/__name__.filter.spec.js +7 -0
- package/src/lib/filter/files/ts/__name__.filter.spec.ts +7 -0
- package/src/lib/filter/files/ts/__name__.filter.ts +6 -0
- package/src/lib/filter/filter.factory.test.ts +147 -0
- package/src/lib/filter/filter.factory.ts +51 -0
- package/src/lib/filter/filter.schema.d.ts +28 -0
- package/src/lib/filter/schema.json +39 -0
- package/src/lib/gateway/files/js/__name__.gateway.js +9 -0
- package/src/lib/gateway/files/js/__name__.gateway.spec.js +18 -0
- package/src/lib/gateway/files/ts/__name__.gateway.spec.ts +18 -0
- package/src/lib/gateway/files/ts/__name__.gateway.ts +9 -0
- package/src/lib/gateway/gateway.factory.test.ts +147 -0
- package/src/lib/gateway/gateway.factory.ts +92 -0
- package/src/lib/gateway/gateway.schema.d.ts +36 -0
- package/src/lib/gateway/schema.json +39 -0
- package/src/lib/guard/files/js/__name__.guard.js +17 -0
- package/src/lib/guard/files/js/__name__.guard.spec.js +7 -0
- package/src/lib/guard/files/ts/__name__.guard.spec.ts +7 -0
- package/src/lib/guard/files/ts/__name__.guard.ts +17 -0
- package/src/lib/guard/guard.factory.test.ts +156 -0
- package/src/lib/guard/guard.factory.ts +51 -0
- package/src/lib/guard/guard.schema.d.ts +28 -0
- package/src/lib/guard/schema.json +39 -0
- package/src/lib/interceptor/files/js/__name__.interceptor.js +18 -0
- package/src/lib/interceptor/files/js/__name__.interceptor.spec.js +7 -0
- package/src/lib/interceptor/files/ts/__name__.interceptor.spec.ts +7 -0
- package/src/lib/interceptor/files/ts/__name__.interceptor.ts +19 -0
- package/src/lib/interceptor/interceptor.factory.test.ts +146 -0
- package/src/lib/interceptor/interceptor.factory.ts +51 -0
- package/src/lib/interceptor/interceptor.schema.d.ts +28 -0
- package/src/lib/interceptor/schema.json +39 -0
- package/src/lib/interface/files/__name__.interface.ts +1 -0
- package/src/lib/interface/interface.factory.test.ts +84 -0
- package/src/lib/interface/interface.factory.ts +47 -0
- package/src/lib/interface/interface.schema.d.ts +20 -0
- package/src/lib/interface/schema.json +31 -0
- package/src/lib/library/files/js/.babelrc +4 -0
- package/src/lib/library/files/js/jsconfig.json +9 -0
- package/src/lib/library/files/js/package.json +8 -0
- package/src/lib/library/files/js/src/__name__.module.js +8 -0
- package/src/lib/library/files/js/src/__name__.service.js +4 -0
- package/src/lib/library/files/js/src/__name__.service.spec.js +18 -0
- package/src/lib/library/files/js/src/index.js +2 -0
- package/src/lib/library/files/ts/package.json +8 -0
- package/src/lib/library/files/ts/src/__name__.module.ts +8 -0
- package/src/lib/library/files/ts/src/__name__.service.spec.ts +18 -0
- package/src/lib/library/files/ts/src/__name__.service.ts +4 -0
- package/src/lib/library/files/ts/src/index.ts +2 -0
- package/src/lib/library/files/ts/tsconfig.lib.json +5 -0
- package/src/lib/library/files/ts/tslint.json +3 -0
- package/src/lib/library/library.factory.test.ts +68 -0
- package/src/lib/library/library.factory.ts +158 -0
- package/src/lib/library/library.schema.d.ts +24 -0
- package/src/lib/library/schema.json +37 -0
- package/src/lib/module/files/js/__name__.module.js +4 -0
- package/src/lib/module/files/ts/__name__.module.ts +4 -0
- package/src/lib/module/module.factory.test.ts +165 -0
- package/src/lib/module/module.factory.ts +79 -0
- package/src/lib/module/module.schema.d.ts +36 -0
- package/src/lib/module/schema.json +40 -0
- package/src/lib/pipe/files/js/__name__.pipe.js +8 -0
- package/src/lib/pipe/files/js/__name__.pipe.spec.js +7 -0
- package/src/lib/pipe/files/ts/__name__.pipe.spec.ts +7 -0
- package/src/lib/pipe/files/ts/__name__.pipe.ts +8 -0
- package/src/lib/pipe/pipe.factory.test.ts +141 -0
- package/src/lib/pipe/pipe.factory.ts +51 -0
- package/src/lib/pipe/pipe.schema.d.ts +28 -0
- package/src/lib/pipe/schema.json +39 -0
- package/src/lib/plugin/files/js/__name__.plugin.js +28 -0
- package/src/lib/plugin/files/js/__name__.plugin.spec.js +7 -0
- package/src/lib/plugin/files/ts/__name__.plugin.spec.ts +7 -0
- package/src/lib/plugin/files/ts/__name__.plugin.ts +28 -0
- package/src/lib/plugin/plugin.factory.d.ts +3 -0
- package/src/lib/plugin/plugin.factory.js +61 -0
- package/src/lib/plugin/plugin.factory.test.ts +191 -0
- package/src/lib/plugin/plugin.factory.ts +91 -0
- package/src/lib/plugin/plugin.schema.d.ts +44 -0
- package/src/lib/plugin/schema.json +52 -0
- package/src/lib/provider/files/js/__name__.js +4 -0
- package/src/lib/provider/files/js/__name__.spec.js +17 -0
- package/src/lib/provider/files/ts/__name__.spec.ts +17 -0
- package/src/lib/provider/files/ts/__name__.ts +4 -0
- package/src/lib/provider/provider.factory.d.ts +3 -0
- package/src/lib/provider/provider.factory.js +59 -0
- package/src/lib/provider/provider.factory.test.ts +151 -0
- package/src/lib/provider/provider.factory.ts +89 -0
- package/src/lib/provider/provider.schema.d.ts +44 -0
- package/src/lib/provider/schema.json +39 -0
- package/src/lib/resolver/files/js/__name__.resolver.js +4 -0
- package/src/lib/resolver/files/js/__name__.resolver.spec.js +18 -0
- package/src/lib/resolver/files/ts/__name__.resolver.spec.ts +18 -0
- package/src/lib/resolver/files/ts/__name__.resolver.ts +4 -0
- package/src/lib/resolver/resolver.factory.test.ts +117 -0
- package/src/lib/resolver/resolver.factory.ts +92 -0
- package/src/lib/resolver/resolver.schema.d.ts +36 -0
- package/src/lib/resolver/schema.json +39 -0
- package/src/lib/service/files/js/__name__.service.js +4 -0
- package/src/lib/service/files/js/__name__.service.spec.js +17 -0
- package/src/lib/service/files/ts/__name__.service.spec.ts +17 -0
- package/src/lib/service/files/ts/__name__.service.ts +4 -0
- package/src/lib/service/schema.json +39 -0
- package/src/lib/service/service.factory.test.ts +190 -0
- package/src/lib/service/service.factory.ts +91 -0
- package/src/lib/service/service.schema.d.ts +44 -0
- package/src/lib/type/files/js/__name__.type.js +10 -0
- package/src/lib/type/files/ts/__name__.type.ts +10 -0
- package/src/lib/type/schema.json +43 -0
- package/src/lib/type/type.factory.d.ts +3 -0
- package/src/lib/type/type.factory.js +61 -0
- package/src/lib/type/type.factory.test.ts +191 -0
- package/src/lib/type/type.factory.ts +91 -0
- package/src/lib/type/type.schema.d.ts +44 -0
- package/src/utils/metadata.manager.ts +219 -0
- package/src/utils/module-import.declarator.ts +41 -0
- package/src/utils/module-metadata.declarator.ts +14 -0
- package/src/utils/module.declarator.ts +41 -0
- package/src/utils/module.finder.ts +32 -0
- package/src/utils/name.parser.ts +29 -0
- package/src/utils/path.solver.ts +17 -0
- package/src/utils/source-root.helpers.ts +30 -0
- package/tsconfig.json +26 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { normalize } from '@angular-devkit/core';
|
|
2
|
+
import {
|
|
3
|
+
SchematicTestRunner,
|
|
4
|
+
UnitTestTree,
|
|
5
|
+
} from '@angular-devkit/schematics/testing';
|
|
6
|
+
import * as path from 'path';
|
|
7
|
+
import { ApplicationOptions } from '../application/application.schema';
|
|
8
|
+
import { ModuleOptions } from '../module/module.schema';
|
|
9
|
+
import { ControllerOptions } from './controller.schema';
|
|
10
|
+
|
|
11
|
+
describe('Controller Factory', () => {
|
|
12
|
+
const runner: SchematicTestRunner = new SchematicTestRunner(
|
|
13
|
+
'.',
|
|
14
|
+
path.join(process.cwd(), 'src/collection.json'),
|
|
15
|
+
);
|
|
16
|
+
it('should manage name only', () => {
|
|
17
|
+
const options: ControllerOptions = {
|
|
18
|
+
name: 'foo',
|
|
19
|
+
skipImport: true,
|
|
20
|
+
spec: false,
|
|
21
|
+
flat: false,
|
|
22
|
+
};
|
|
23
|
+
const tree: UnitTestTree = runner.runSchematic('controller', options);
|
|
24
|
+
const files: string[] = tree.files;
|
|
25
|
+
|
|
26
|
+
expect(
|
|
27
|
+
files.find(filename => filename === '/foo/foo.controller.ts'),
|
|
28
|
+
).toBeDefined();
|
|
29
|
+
expect(
|
|
30
|
+
files.find(filename => filename === '/foo/foo.controller.spec.ts'),
|
|
31
|
+
).not.toBeDefined();
|
|
32
|
+
expect(tree.readContent('/foo/foo.controller.ts')).toEqual(
|
|
33
|
+
"import { Controller } from '@nestjs/common';\n" +
|
|
34
|
+
'\n' +
|
|
35
|
+
"@Controller('foo')\n" +
|
|
36
|
+
'export class FooController {}\n',
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
it('should manage name has a path', () => {
|
|
40
|
+
const options: ControllerOptions = {
|
|
41
|
+
name: 'bar/foo',
|
|
42
|
+
skipImport: true,
|
|
43
|
+
};
|
|
44
|
+
const tree: UnitTestTree = runner.runSchematic('controller', options);
|
|
45
|
+
const files: string[] = tree.files;
|
|
46
|
+
expect(
|
|
47
|
+
files.find(filename => filename === '/bar/foo/foo.controller.ts'),
|
|
48
|
+
).toBeDefined();
|
|
49
|
+
expect(
|
|
50
|
+
files.find(filename => filename === '/bar/foo/foo.controller.spec.ts'),
|
|
51
|
+
).toBeDefined();
|
|
52
|
+
expect(tree.readContent('/bar/foo/foo.controller.ts')).toEqual(
|
|
53
|
+
"import { Controller } from '@nestjs/common';\n" +
|
|
54
|
+
'\n' +
|
|
55
|
+
"@Controller('foo')\n" +
|
|
56
|
+
'export class FooController {}\n',
|
|
57
|
+
);
|
|
58
|
+
});
|
|
59
|
+
it('should manage name and path', () => {
|
|
60
|
+
const options: ControllerOptions = {
|
|
61
|
+
name: 'foo',
|
|
62
|
+
path: 'bar',
|
|
63
|
+
skipImport: true,
|
|
64
|
+
};
|
|
65
|
+
const tree: UnitTestTree = runner.runSchematic('controller', options);
|
|
66
|
+
const files: string[] = tree.files;
|
|
67
|
+
expect(
|
|
68
|
+
files.find(filename => filename === '/bar/foo/foo.controller.ts'),
|
|
69
|
+
).toBeDefined();
|
|
70
|
+
expect(
|
|
71
|
+
files.find(filename => filename === '/bar/foo/foo.controller.spec.ts'),
|
|
72
|
+
).toBeDefined();
|
|
73
|
+
expect(tree.readContent('/bar/foo/foo.controller.ts')).toEqual(
|
|
74
|
+
"import { Controller } from '@nestjs/common';\n" +
|
|
75
|
+
'\n' +
|
|
76
|
+
"@Controller('foo')\n" +
|
|
77
|
+
'export class FooController {}\n',
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
|
+
it('should manage name to dasherize', () => {
|
|
81
|
+
const options: ControllerOptions = {
|
|
82
|
+
name: 'fooBar',
|
|
83
|
+
skipImport: true,
|
|
84
|
+
};
|
|
85
|
+
const tree: UnitTestTree = runner.runSchematic('controller', options);
|
|
86
|
+
const files: string[] = tree.files;
|
|
87
|
+
expect(
|
|
88
|
+
files.find(filename => filename === '/foo-bar/foo-bar.controller.ts'),
|
|
89
|
+
).toBeDefined();
|
|
90
|
+
expect(
|
|
91
|
+
files.find(
|
|
92
|
+
filename => filename === '/foo-bar/foo-bar.controller.spec.ts',
|
|
93
|
+
),
|
|
94
|
+
).toBeDefined();
|
|
95
|
+
expect(tree.readContent('/foo-bar/foo-bar.controller.ts')).toEqual(
|
|
96
|
+
"import { Controller } from '@nestjs/common';\n" +
|
|
97
|
+
'\n' +
|
|
98
|
+
"@Controller('foo-bar')\n" +
|
|
99
|
+
'export class FooBarController {}\n',
|
|
100
|
+
);
|
|
101
|
+
});
|
|
102
|
+
it('should manage path to dasherize', () => {
|
|
103
|
+
const options: ControllerOptions = {
|
|
104
|
+
name: 'barBaz/foo',
|
|
105
|
+
skipImport: true,
|
|
106
|
+
};
|
|
107
|
+
const tree: UnitTestTree = runner.runSchematic('controller', options);
|
|
108
|
+
const files: string[] = tree.files;
|
|
109
|
+
expect(
|
|
110
|
+
files.find(filename => filename === '/bar-baz/foo/foo.controller.ts'),
|
|
111
|
+
).toBeDefined();
|
|
112
|
+
expect(
|
|
113
|
+
files.find(
|
|
114
|
+
filename => filename === '/bar-baz/foo/foo.controller.spec.ts',
|
|
115
|
+
),
|
|
116
|
+
).toBeDefined();
|
|
117
|
+
expect(tree.readContent('/bar-baz/foo/foo.controller.ts')).toEqual(
|
|
118
|
+
"import { Controller } from '@nestjs/common';\n" +
|
|
119
|
+
'\n' +
|
|
120
|
+
"@Controller('foo')\n" +
|
|
121
|
+
'export class FooController {}\n',
|
|
122
|
+
);
|
|
123
|
+
});
|
|
124
|
+
it('should manage javascript file', () => {
|
|
125
|
+
const options: ControllerOptions = {
|
|
126
|
+
name: 'foo',
|
|
127
|
+
language: 'js',
|
|
128
|
+
skipImport: true,
|
|
129
|
+
};
|
|
130
|
+
const tree: UnitTestTree = runner.runSchematic('controller', options);
|
|
131
|
+
const files: string[] = tree.files;
|
|
132
|
+
expect(
|
|
133
|
+
files.find(filename => filename === '/foo/foo.controller.js'),
|
|
134
|
+
).toBeDefined();
|
|
135
|
+
expect(
|
|
136
|
+
files.find(filename => filename === '/foo/foo.controller.spec.js'),
|
|
137
|
+
).toBeDefined();
|
|
138
|
+
expect(tree.readContent('/foo/foo.controller.js')).toEqual(
|
|
139
|
+
"import { Controller } from '@nestjs/common';\n" +
|
|
140
|
+
'\n' +
|
|
141
|
+
"@Controller('foo')\n" +
|
|
142
|
+
'export class FooController {}\n',
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
it('should manage declaration in app module', () => {
|
|
146
|
+
const app: ApplicationOptions = {
|
|
147
|
+
name: '',
|
|
148
|
+
};
|
|
149
|
+
let tree: UnitTestTree = runner.runSchematic('application', app);
|
|
150
|
+
const options: ControllerOptions = {
|
|
151
|
+
name: 'foo',
|
|
152
|
+
};
|
|
153
|
+
tree = runner.runSchematic('controller', options, tree);
|
|
154
|
+
expect(tree.readContent(normalize('/src/app.module.ts'))).toEqual(
|
|
155
|
+
"import { Module } from '@nestjs/common';\n" +
|
|
156
|
+
"import { AppController } from './app.controller';\n" +
|
|
157
|
+
"import { AppService } from './app.service';\n" +
|
|
158
|
+
"import { FooController } from './foo/foo.controller';\n" +
|
|
159
|
+
'\n' +
|
|
160
|
+
'@Module({\n' +
|
|
161
|
+
' imports: [],\n' +
|
|
162
|
+
' controllers: [AppController, FooController],\n' +
|
|
163
|
+
' providers: [AppService],\n' +
|
|
164
|
+
'})\n' +
|
|
165
|
+
'export class AppModule {}\n',
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
it('should manage declaration in foo module', () => {
|
|
169
|
+
const app: ApplicationOptions = {
|
|
170
|
+
name: '',
|
|
171
|
+
};
|
|
172
|
+
let tree: UnitTestTree = runner.runSchematic('application', app);
|
|
173
|
+
const module: ModuleOptions = {
|
|
174
|
+
name: 'foo',
|
|
175
|
+
};
|
|
176
|
+
tree = runner.runSchematic('module', module, tree);
|
|
177
|
+
const options: ControllerOptions = {
|
|
178
|
+
name: 'foo',
|
|
179
|
+
};
|
|
180
|
+
tree = runner.runSchematic('controller', options, tree);
|
|
181
|
+
expect(tree.readContent(normalize('/src/foo/foo.module.ts'))).toEqual(
|
|
182
|
+
"import { Module } from '@nestjs/common';\n" +
|
|
183
|
+
"import { FooController } from './foo.controller';\n" +
|
|
184
|
+
'\n' +
|
|
185
|
+
'@Module({\n' +
|
|
186
|
+
' controllers: [FooController]\n' +
|
|
187
|
+
'})\n' +
|
|
188
|
+
'export class FooModule {}\n',
|
|
189
|
+
);
|
|
190
|
+
});
|
|
191
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { join, Path, strings } from '@angular-devkit/core';
|
|
2
|
+
import {
|
|
3
|
+
apply,
|
|
4
|
+
branchAndMerge,
|
|
5
|
+
chain,
|
|
6
|
+
filter,
|
|
7
|
+
mergeWith,
|
|
8
|
+
move,
|
|
9
|
+
noop,
|
|
10
|
+
Rule,
|
|
11
|
+
SchematicContext,
|
|
12
|
+
template,
|
|
13
|
+
Tree,
|
|
14
|
+
url,
|
|
15
|
+
} from '@angular-devkit/schematics';
|
|
16
|
+
import {
|
|
17
|
+
DeclarationOptions,
|
|
18
|
+
ModuleDeclarator,
|
|
19
|
+
} from '../../utils/module.declarator';
|
|
20
|
+
import { ModuleFinder } from '../../utils/module.finder';
|
|
21
|
+
import { Location, NameParser } from '../../utils/name.parser';
|
|
22
|
+
import { mergeSourceRoot } from '../../utils/source-root.helpers';
|
|
23
|
+
import { DEFAULT_LANGUAGE } from '../defaults';
|
|
24
|
+
import { ControllerOptions } from './type.schema';
|
|
25
|
+
|
|
26
|
+
const ELEMENT_METADATA = 'controllers';
|
|
27
|
+
const ELEMENT_TYPE = 'controller';
|
|
28
|
+
|
|
29
|
+
export function main(options: ControllerOptions): Rule {
|
|
30
|
+
options = transform(options);
|
|
31
|
+
return (tree: Tree, context: SchematicContext) => {
|
|
32
|
+
return branchAndMerge(
|
|
33
|
+
chain([
|
|
34
|
+
mergeSourceRoot(options),
|
|
35
|
+
mergeWith(generate(options)),
|
|
36
|
+
addDeclarationToModule(options),
|
|
37
|
+
]),
|
|
38
|
+
)(tree, context);
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function transform(source: ControllerOptions): ControllerOptions {
|
|
43
|
+
const target: ControllerOptions = Object.assign({}, source);
|
|
44
|
+
target.metadata = ELEMENT_METADATA;
|
|
45
|
+
target.type = ELEMENT_TYPE;
|
|
46
|
+
|
|
47
|
+
const location: Location = new NameParser().parse(target);
|
|
48
|
+
target.name = strings.dasherize(location.name);
|
|
49
|
+
target.path = strings.dasherize(location.path);
|
|
50
|
+
target.language =
|
|
51
|
+
target.language !== undefined ? target.language : DEFAULT_LANGUAGE;
|
|
52
|
+
|
|
53
|
+
target.path = target.flat
|
|
54
|
+
? target.path
|
|
55
|
+
: join(target.path as Path, target.name);
|
|
56
|
+
return target;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function generate(options: ControllerOptions) {
|
|
60
|
+
return (context: SchematicContext) =>
|
|
61
|
+
apply(url(join('./files' as Path, options.language)), [
|
|
62
|
+
options.spec ? noop() : filter(path => !path.endsWith('.spec.ts')),
|
|
63
|
+
template({
|
|
64
|
+
...strings,
|
|
65
|
+
...options,
|
|
66
|
+
}),
|
|
67
|
+
move(options.path),
|
|
68
|
+
])(context);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function addDeclarationToModule(options: ControllerOptions): Rule {
|
|
72
|
+
return (tree: Tree) => {
|
|
73
|
+
if (options.skipImport !== undefined && options.skipImport) {
|
|
74
|
+
return tree;
|
|
75
|
+
}
|
|
76
|
+
options.module = new ModuleFinder(tree).find({
|
|
77
|
+
name: options.name,
|
|
78
|
+
path: options.path as Path,
|
|
79
|
+
});
|
|
80
|
+
if (!options.module) {
|
|
81
|
+
return tree;
|
|
82
|
+
}
|
|
83
|
+
const content = tree.read(options.module).toString();
|
|
84
|
+
const declarator: ModuleDeclarator = new ModuleDeclarator();
|
|
85
|
+
tree.overwrite(
|
|
86
|
+
options.module,
|
|
87
|
+
declarator.declare(content, options as DeclarationOptions),
|
|
88
|
+
);
|
|
89
|
+
return tree;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Path } from '@angular-devkit/core';
|
|
2
|
+
|
|
3
|
+
export interface ControllerOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The name of the controller.
|
|
6
|
+
*/
|
|
7
|
+
name: string;
|
|
8
|
+
/**
|
|
9
|
+
* The path to create the controller.
|
|
10
|
+
*/
|
|
11
|
+
path?: string | Path;
|
|
12
|
+
/**
|
|
13
|
+
* The path to insert the controller declaration.
|
|
14
|
+
*/
|
|
15
|
+
module?: Path;
|
|
16
|
+
/**
|
|
17
|
+
* Directive to insert declaration in module.
|
|
18
|
+
*/
|
|
19
|
+
skipImport?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Metadata name affected by declaration insertion.
|
|
22
|
+
*/
|
|
23
|
+
metadata?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Nest element type name
|
|
26
|
+
*/
|
|
27
|
+
type?: string;
|
|
28
|
+
/**
|
|
29
|
+
* Application language.
|
|
30
|
+
*/
|
|
31
|
+
language?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The source root path
|
|
34
|
+
*/
|
|
35
|
+
sourceRoot?: string;
|
|
36
|
+
/**
|
|
37
|
+
* Specifies if a spec file is generated.
|
|
38
|
+
*/
|
|
39
|
+
spec?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Flag to indicate if a directory is created.
|
|
42
|
+
*/
|
|
43
|
+
flat?: boolean;
|
|
44
|
+
}
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ArrayLiteralExpression,
|
|
3
|
+
CallExpression,
|
|
4
|
+
createSourceFile,
|
|
5
|
+
Decorator,
|
|
6
|
+
Expression,
|
|
7
|
+
Identifier,
|
|
8
|
+
Node,
|
|
9
|
+
NodeArray,
|
|
10
|
+
ObjectLiteralElement,
|
|
11
|
+
ObjectLiteralExpression,
|
|
12
|
+
PropertyAssignment,
|
|
13
|
+
ScriptTarget,
|
|
14
|
+
SourceFile,
|
|
15
|
+
StringLiteral,
|
|
16
|
+
SyntaxKind,
|
|
17
|
+
} from 'typescript';
|
|
18
|
+
import { DeclarationOptions } from './module.declarator';
|
|
19
|
+
|
|
20
|
+
export class MetadataManager {
|
|
21
|
+
constructor(private content: string) {}
|
|
22
|
+
|
|
23
|
+
public insert(
|
|
24
|
+
metadata: string,
|
|
25
|
+
symbol: string,
|
|
26
|
+
staticOptions?: DeclarationOptions['staticOptions'],
|
|
27
|
+
): string {
|
|
28
|
+
const source: SourceFile = createSourceFile(
|
|
29
|
+
'filename.ts',
|
|
30
|
+
this.content,
|
|
31
|
+
ScriptTarget.ES2017,
|
|
32
|
+
);
|
|
33
|
+
const decoratorNodes: Node[] = this.getDecoratorMetadata(source, '@Module');
|
|
34
|
+
const node: Node = decoratorNodes[0];
|
|
35
|
+
const matchingProperties: ObjectLiteralElement[] = (node as ObjectLiteralExpression).properties
|
|
36
|
+
.filter(prop => prop.kind === SyntaxKind.PropertyAssignment)
|
|
37
|
+
.filter((prop: PropertyAssignment) => {
|
|
38
|
+
const name = prop.name;
|
|
39
|
+
switch (name.kind) {
|
|
40
|
+
case SyntaxKind.Identifier:
|
|
41
|
+
return (name as Identifier).getText(source) === metadata;
|
|
42
|
+
case SyntaxKind.StringLiteral:
|
|
43
|
+
return (name as StringLiteral).text === metadata;
|
|
44
|
+
default:
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
symbol = this.mergeSymbolAndExpr(symbol, staticOptions);
|
|
50
|
+
const addBlankLinesIfDynamic = () => {
|
|
51
|
+
symbol = staticOptions ? this.addBlankLines(symbol) : symbol;
|
|
52
|
+
};
|
|
53
|
+
if (matchingProperties.length === 0) {
|
|
54
|
+
const expr = node as ObjectLiteralExpression;
|
|
55
|
+
if (expr.properties.length === 0) {
|
|
56
|
+
addBlankLinesIfDynamic();
|
|
57
|
+
return this.insertMetadataToEmptyModuleDecorator(
|
|
58
|
+
expr,
|
|
59
|
+
metadata,
|
|
60
|
+
symbol,
|
|
61
|
+
);
|
|
62
|
+
} else {
|
|
63
|
+
addBlankLinesIfDynamic();
|
|
64
|
+
return this.insertNewMetadataToDecorator(
|
|
65
|
+
expr,
|
|
66
|
+
source,
|
|
67
|
+
metadata,
|
|
68
|
+
symbol,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
return this.insertSymbolToMetadata(
|
|
73
|
+
source,
|
|
74
|
+
matchingProperties,
|
|
75
|
+
symbol,
|
|
76
|
+
staticOptions,
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private getDecoratorMetadata(source: SourceFile, identifier: string): Node[] {
|
|
82
|
+
return this.getSourceNodes(source)
|
|
83
|
+
.filter(
|
|
84
|
+
node =>
|
|
85
|
+
node.kind === SyntaxKind.Decorator &&
|
|
86
|
+
(node as Decorator).expression.kind === SyntaxKind.CallExpression,
|
|
87
|
+
)
|
|
88
|
+
.map(node => (node as Decorator).expression as CallExpression)
|
|
89
|
+
.filter(
|
|
90
|
+
expr =>
|
|
91
|
+
expr.arguments[0] &&
|
|
92
|
+
expr.arguments[0].kind === SyntaxKind.ObjectLiteralExpression,
|
|
93
|
+
)
|
|
94
|
+
.map(expr => expr.arguments[0] as ObjectLiteralExpression);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private getSourceNodes(sourceFile: SourceFile): Node[] {
|
|
98
|
+
const nodes: Node[] = [sourceFile];
|
|
99
|
+
const result = [];
|
|
100
|
+
while (nodes.length > 0) {
|
|
101
|
+
const node = nodes.shift();
|
|
102
|
+
if (node) {
|
|
103
|
+
result.push(node);
|
|
104
|
+
if (node.getChildCount(sourceFile) >= 0) {
|
|
105
|
+
nodes.unshift(...node.getChildren());
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return result;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private insertMetadataToEmptyModuleDecorator(
|
|
113
|
+
expr: ObjectLiteralExpression,
|
|
114
|
+
metadata: string,
|
|
115
|
+
symbol: string,
|
|
116
|
+
): string {
|
|
117
|
+
const position = expr.getEnd() - 1;
|
|
118
|
+
const toInsert = ` ${metadata}: [${symbol}]`;
|
|
119
|
+
return this.content.split('').reduce((content, char, index) => {
|
|
120
|
+
if (index === position) {
|
|
121
|
+
return `${content}\n${toInsert}\n${char}`;
|
|
122
|
+
} else {
|
|
123
|
+
return `${content}${char}`;
|
|
124
|
+
}
|
|
125
|
+
}, '');
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private insertNewMetadataToDecorator(
|
|
129
|
+
expr: ObjectLiteralExpression,
|
|
130
|
+
source: SourceFile,
|
|
131
|
+
metadata: string,
|
|
132
|
+
symbol: string,
|
|
133
|
+
): string {
|
|
134
|
+
const node = expr.properties[expr.properties.length - 1];
|
|
135
|
+
const position = node.getEnd();
|
|
136
|
+
const text = node.getFullText(source);
|
|
137
|
+
const matches = text.match(/^\r?\n\s*/);
|
|
138
|
+
let toInsert: string;
|
|
139
|
+
if (matches.length > 0) {
|
|
140
|
+
toInsert = `,${matches[0]}${metadata}: [${symbol}]`;
|
|
141
|
+
} else {
|
|
142
|
+
toInsert = `, ${metadata}: [${symbol}]`;
|
|
143
|
+
}
|
|
144
|
+
return this.content.split('').reduce((content, char, index) => {
|
|
145
|
+
if (index === position) {
|
|
146
|
+
return `${content}${toInsert}${char}`;
|
|
147
|
+
} else {
|
|
148
|
+
return `${content}${char}`;
|
|
149
|
+
}
|
|
150
|
+
}, '');
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private insertSymbolToMetadata(
|
|
154
|
+
source: SourceFile,
|
|
155
|
+
matchingProperties: ObjectLiteralElement[],
|
|
156
|
+
symbol: string,
|
|
157
|
+
staticOptions?: DeclarationOptions['staticOptions'],
|
|
158
|
+
): string {
|
|
159
|
+
const assignment = matchingProperties[0] as PropertyAssignment;
|
|
160
|
+
let node: Node | NodeArray<Expression>;
|
|
161
|
+
const arrLiteral = assignment.initializer as ArrayLiteralExpression;
|
|
162
|
+
if (arrLiteral.elements.length === 0) {
|
|
163
|
+
node = arrLiteral;
|
|
164
|
+
} else {
|
|
165
|
+
node = arrLiteral.elements;
|
|
166
|
+
}
|
|
167
|
+
if (Array.isArray(node)) {
|
|
168
|
+
const nodeArray = (node as {}) as Node[];
|
|
169
|
+
const symbolsArray = nodeArray.map(childNode =>
|
|
170
|
+
childNode.getText(source),
|
|
171
|
+
);
|
|
172
|
+
if (symbolsArray.includes(symbol)) {
|
|
173
|
+
return this.content;
|
|
174
|
+
}
|
|
175
|
+
node = node[node.length - 1];
|
|
176
|
+
}
|
|
177
|
+
let toInsert: string;
|
|
178
|
+
let position = (node as Node).getEnd();
|
|
179
|
+
|
|
180
|
+
if ((node as Node).kind === SyntaxKind.ArrayLiteralExpression) {
|
|
181
|
+
position--;
|
|
182
|
+
toInsert = staticOptions ? this.addBlankLines(symbol) : `${symbol}`;
|
|
183
|
+
} else {
|
|
184
|
+
const text = (node as Node).getFullText(source);
|
|
185
|
+
if (text.match(/^\r?\n/)) {
|
|
186
|
+
toInsert = `,${text.match(/^\r?\n(\r?)\s+/)[0]}${symbol}`;
|
|
187
|
+
} else {
|
|
188
|
+
toInsert = `, ${symbol}`;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return this.content.split('').reduce((content, char, index) => {
|
|
192
|
+
if (index === position) {
|
|
193
|
+
return `${content}${toInsert}${char}`;
|
|
194
|
+
} else {
|
|
195
|
+
return `${content}${char}`;
|
|
196
|
+
}
|
|
197
|
+
}, '');
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private mergeSymbolAndExpr(
|
|
201
|
+
symbol: string,
|
|
202
|
+
staticOptions?: DeclarationOptions['staticOptions'],
|
|
203
|
+
): string {
|
|
204
|
+
if (!staticOptions) {
|
|
205
|
+
return symbol;
|
|
206
|
+
}
|
|
207
|
+
const spacing = 6;
|
|
208
|
+
let options = JSON.stringify(staticOptions.value, null, spacing);
|
|
209
|
+
options = options.replace(/\"([^(\")"]+)\":/g, '$1:');
|
|
210
|
+
options = options.replace(/\"/g, `'`);
|
|
211
|
+
options = options.slice(0, options.length - 1) + ' }';
|
|
212
|
+
symbol += `.${staticOptions.name}(${options})`;
|
|
213
|
+
return symbol;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private addBlankLines(expr: string): string {
|
|
217
|
+
return `\n ${expr}\n `;
|
|
218
|
+
}
|
|
219
|
+
}
|