Loading libs/environment/ng-package.json +4 −1 Original line number Diff line number Diff line Loading @@ -6,6 +6,9 @@ }, "allowedNonPeerDependencies": [ "@rxap/schematics-utilities", "@rxap/schematics-ts-morph", "@angular-devkit/schematics", "ts-morph", "tslib" ] } libs/environment/package.json +5 −2 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ }, "dependencies": { "@rxap/schematics-utilities": "^12.1.0", "tslib": "^2.2.0" "@angular-devkit/schematics": "^12.1.1", "tslib": "^2.2.0", "ts-morph": "^11.0.0", "@rxap/schematics-ts-morph": "^12.1.0" } } libs/environment/src/schematics/ng-add/index.ts +91 −4 Original line number Diff line number Diff line import { Rule } from '@angular-devkit/schematics'; import { InstallPeerDependencies } from '@rxap/schematics-utilities'; import { Rule, chain, Tree, SchematicsException } from '@angular-devkit/schematics'; import { InstallPeerDependencies, GetProjectSourceRoot } from '@rxap/schematics-utilities'; import { NgAddSchema } from './schema'; import { Project, QuoteKind, IndentationText } from 'ts-morph'; import { AddDir, ApplyTsMorphProject, AddNgModuleProvider, AddToArray } from '@rxap/schematics-ts-morph'; export default function(): Rule { return InstallPeerDependencies(); export default function(options: NgAddSchema): Rule { return (host: Tree) => { const rules: Rule[] = [ InstallPeerDependencies() ]; if (options.project) { const projectSourceRoot = GetProjectSourceRoot(host, options.project); const project = new Project({ useInMemoryFileSystem: true, manipulationSettings: { quoteKind: QuoteKind.Single, indentationText: IndentationText.TwoSpaces } }); AddDir(host.getDir(projectSourceRoot), project); const appModelSourceFile = project.getSourceFile('/app/app.module.ts'); if (!appModelSourceFile) { throw new SchematicsException(`Could not find the AppModule source file in '[projectSourceRoot]/app/app.module.ts'`); } AddNgModuleProvider( appModelSourceFile, { provide: 'RXAP_ENVIRONMENT', useValue: 'environment' }, [ { namedImports: [ 'RXAP_ENVIRONMENT' ], moduleSpecifier: '@rxap/environment' }, { namedImports: [ 'environment' ], moduleSpecifier: '../environments/environment' } ] ); const mainSourceFile = project.getSourceFile('/main.ts'); if (!mainSourceFile) { throw new SchematicsException(`Could not find the main.ts source file in '[projectSourceRoot]/main.ts'`); } AddToArray( mainSourceFile, 'setup', 'UpdateEnvironment(environment)', 'Promise<any>[]' ); mainSourceFile.addImportDeclarations([ { namedImports: [ 'UpdateEnvironment' ], moduleSpecifier: '@rxap/environment' }, { namedImports: [ 'environment' ], moduleSpecifier: './environments/environment' } ]); rules.push(ApplyTsMorphProject(project, projectSourceRoot)); } return chain(rules); }; } libs/environment/src/schematics/ng-add/schema.d.ts +1 −0 Original line number Diff line number Diff line export interface NgAddSchema { project?: string; } libs/environment/src/schematics/ng-add/schema.json +9 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,14 @@ "$schema": "http://json-schema.org/draft-07/schema", "$id": "environment-ng-add", "type": "object", "properties": {}, "properties": { "project": { "type": "string", "description": "The project where the environment feature should be added", "$default": { "$source": "projectName" } } }, "required": [] } Loading
libs/environment/ng-package.json +4 −1 Original line number Diff line number Diff line Loading @@ -6,6 +6,9 @@ }, "allowedNonPeerDependencies": [ "@rxap/schematics-utilities", "@rxap/schematics-ts-morph", "@angular-devkit/schematics", "ts-morph", "tslib" ] }
libs/environment/package.json +5 −2 Original line number Diff line number Diff line Loading @@ -35,6 +35,9 @@ }, "dependencies": { "@rxap/schematics-utilities": "^12.1.0", "tslib": "^2.2.0" "@angular-devkit/schematics": "^12.1.1", "tslib": "^2.2.0", "ts-morph": "^11.0.0", "@rxap/schematics-ts-morph": "^12.1.0" } }
libs/environment/src/schematics/ng-add/index.ts +91 −4 Original line number Diff line number Diff line import { Rule } from '@angular-devkit/schematics'; import { InstallPeerDependencies } from '@rxap/schematics-utilities'; import { Rule, chain, Tree, SchematicsException } from '@angular-devkit/schematics'; import { InstallPeerDependencies, GetProjectSourceRoot } from '@rxap/schematics-utilities'; import { NgAddSchema } from './schema'; import { Project, QuoteKind, IndentationText } from 'ts-morph'; import { AddDir, ApplyTsMorphProject, AddNgModuleProvider, AddToArray } from '@rxap/schematics-ts-morph'; export default function(): Rule { return InstallPeerDependencies(); export default function(options: NgAddSchema): Rule { return (host: Tree) => { const rules: Rule[] = [ InstallPeerDependencies() ]; if (options.project) { const projectSourceRoot = GetProjectSourceRoot(host, options.project); const project = new Project({ useInMemoryFileSystem: true, manipulationSettings: { quoteKind: QuoteKind.Single, indentationText: IndentationText.TwoSpaces } }); AddDir(host.getDir(projectSourceRoot), project); const appModelSourceFile = project.getSourceFile('/app/app.module.ts'); if (!appModelSourceFile) { throw new SchematicsException(`Could not find the AppModule source file in '[projectSourceRoot]/app/app.module.ts'`); } AddNgModuleProvider( appModelSourceFile, { provide: 'RXAP_ENVIRONMENT', useValue: 'environment' }, [ { namedImports: [ 'RXAP_ENVIRONMENT' ], moduleSpecifier: '@rxap/environment' }, { namedImports: [ 'environment' ], moduleSpecifier: '../environments/environment' } ] ); const mainSourceFile = project.getSourceFile('/main.ts'); if (!mainSourceFile) { throw new SchematicsException(`Could not find the main.ts source file in '[projectSourceRoot]/main.ts'`); } AddToArray( mainSourceFile, 'setup', 'UpdateEnvironment(environment)', 'Promise<any>[]' ); mainSourceFile.addImportDeclarations([ { namedImports: [ 'UpdateEnvironment' ], moduleSpecifier: '@rxap/environment' }, { namedImports: [ 'environment' ], moduleSpecifier: './environments/environment' } ]); rules.push(ApplyTsMorphProject(project, projectSourceRoot)); } return chain(rules); }; }
libs/environment/src/schematics/ng-add/schema.d.ts +1 −0 Original line number Diff line number Diff line export interface NgAddSchema { project?: string; }
libs/environment/src/schematics/ng-add/schema.json +9 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,14 @@ "$schema": "http://json-schema.org/draft-07/schema", "$id": "environment-ng-add", "type": "object", "properties": {}, "properties": { "project": { "type": "string", "description": "The project where the environment feature should be added", "$default": { "$source": "projectName" } } }, "required": [] }