-
Notifications
You must be signed in to change notification settings - Fork 3
feat(schematics): ng add ui-platform #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
richavyas
wants to merge
16
commits into
develop
Choose a base branch
from
feature/schematics-ng-add
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ffaad19
feat(schematics): ng add scaffolding
richavyas 221a9c7
feat(schematics): add sso optionally and create proxy file
richavyas be312ea
feat(schematics): add sso imports
richavyas 2f86701
feat(schematics): insert imports
richavyas 5e5c174
feat(schematics): add interceptors
richavyas 6016c64
feat(schematics): add app routes
richavyas 53ed920
feat(schematics): remove unused imports
richavyas 68947ce
feat(schematics): add routes file as part of sso
richavyas 84470d6
feat(schematics): exclude schematics from overall tests
richavyas a93da14
Merge branch 'develop' into feature/schematics-ng-add
jeremysmartt b30fd11
feat(schematics): ng add proxy file
richavyas ea7d340
Merge branch 'feature/schematics-ng-add' of https://github.com/Terada…
richavyas 6d8d886
feat(schematics): rename schematics test script
richavyas 771f877
feat(schematics): rename schematics test script
richavyas dfb367e
Merge branch 'develop' into feature/schematics-ng-add
jeremysmartt 62a637f
Merge branch 'develop' into feature/schematics-ng-add
jeremysmartt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Run test and linter | ||
| npm run test:schematics | ||
| npm run tslint | ||
|
|
||
| # Link project | ||
| cd ../src/lib | ||
| npm link | ||
|
|
||
| # Create Angular base project | ||
| cd /tmp | ||
| rm -rf testxyz | ||
| ng new testxyz | ||
|
|
||
| # Run covalent schematics | ||
| cd testxyz | ||
| npm link @td-vantage/ui-platform | ||
| ng g @td-vantage/ui-platform:ng-add | ||
|
|
||
| # Check generated files | ||
| git status | ||
| npm i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Outputs | ||
| **/*.js | ||
| **/*.js.map | ||
| **/*.d.ts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "$schema": "../../../node_modules/@angular-devkit/schematics/collection-schema.json", | ||
| "schematics": { | ||
| "ng-add": { | ||
| "description": "Adds vantage ui platform to the application without affecting any templates", | ||
| "factory": "./ng-add/index#addDependenciesAndFiles", | ||
| "schema": "./ng-add/schema.json", | ||
| "aliases": ["vantage-shell", "install"] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| const vantageLoginProxyConfig = require('./src/lib/auth/config/vantageLoginProxyConfig'); | ||
|
|
||
| /* * * * * * * * * * * */ | ||
| /* Edit these variables to point to your */ | ||
| /* Vantage and local development environments */ | ||
| /* * * * * * * * * * * */ | ||
|
|
||
| const serverUrl = 'https://vantage.url.io'; // REPLACE WITH VANTAGE BASE URL | ||
| const localUrl = "localhost:4200"; | ||
| const localProto = "http"; // http or https | ||
|
|
||
| /* * * * * * * * * * * */ | ||
| /* This section contains the routes proxied through */ | ||
| /* your local development environment and the Vantage deployment */ | ||
| /* * * * * * * * * * * */ | ||
|
|
||
| const PROXY_CONFIG = { | ||
| ...vantageLoginProxyConfig({ serverUrl, localUrl, localProto }), | ||
| '/api': { | ||
| target: serverUrl, | ||
| secure: false, | ||
| changeOrigin: true, | ||
| }, | ||
| }; | ||
|
|
||
| module.exports = PROXY_CONFIG; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Routes, RouterModule } from '@angular/router'; | ||
|
|
||
| import { VantageAuthenticationGuard } from '@td-vantage/ui-platform/auth'; | ||
|
|
||
| const routes: Routes = [ | ||
| { | ||
| path: '', | ||
| canActivate: [VantageAuthenticationGuard], | ||
| children: [], | ||
| }, | ||
| { path: '**', redirectTo: '/' }, | ||
| ]; | ||
|
|
||
| export const appRoutingProviders: any[] = [ | ||
| VantageAuthenticationGuard, | ||
| ]; | ||
|
|
||
| export const appRoutes: any = RouterModule.forRoot(routes); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| import { getFileContent } from '@schematics/angular/utility/test'; | ||
| import { Tree } from '@angular-devkit/schematics'; | ||
| import { uiPlatformVersion } from '../version-names'; | ||
| import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; | ||
| import { Schema as WorkspaceOptions } from '@schematics/angular/workspace/schema'; | ||
| import { Schema as ApplicationOptions } from '@schematics/angular/application/schema'; | ||
|
|
||
| const collectionPath: string = require.resolve('../collection.json'); | ||
|
|
||
| describe('ng-add schematic', () => { | ||
| const testRunner: SchematicTestRunner = new SchematicTestRunner('rocket', collectionPath); | ||
|
|
||
| const workspaceOptions: WorkspaceOptions = { | ||
| name: 'workspace', | ||
| newProjectRoot: 'projects', | ||
| version: '1.0.0', | ||
| }; | ||
|
|
||
| const appOptions: ApplicationOptions = { | ||
| name: 'ui-platform-workspace', | ||
| }; | ||
|
|
||
| let appTree: UnitTestTree; | ||
|
|
||
| beforeEach(async () => { | ||
| const workspaceTree: UnitTestTree = await testRunner | ||
| .runExternalSchematicAsync('@schematics/angular', 'workspace', workspaceOptions) | ||
| .toPromise(); | ||
| appTree = await testRunner | ||
| .runExternalSchematicAsync('@schematics/angular', 'application', appOptions, workspaceTree) | ||
| .toPromise(); | ||
| }); | ||
|
|
||
| it('should update package.json', async () => { | ||
| const tree: Tree = await testRunner.runSchematicAsync('ng-add', undefined, appTree).toPromise(); | ||
| const packageJson: any = JSON.parse(getFileContent(tree, '/package.json')); | ||
| const dependencies: any = packageJson.dependencies; | ||
|
|
||
| const expectedUIPlatformVersion: string = `${uiPlatformVersion}`; | ||
|
|
||
| expectVersionToBe(dependencies, '@td-vantage/ui-platform', expectedUIPlatformVersion); | ||
| }); | ||
|
|
||
| it('should create proxy.conf.js when sso option is selected by user', async () => { | ||
| const dependencyOptions: any = { ssoServerURL: 'https://vantage.url.io' }; | ||
| const tree: Tree = await testRunner.runSchematicAsync('ng-add', dependencyOptions, appTree).toPromise(); | ||
| expect(tree.exists('proxy.conf.js')).toBe(true); | ||
| const fileContent: string = getFileContent(tree, 'proxy.conf.js'); | ||
| expect(fileContent).toContain('https://vantage.url.io'); | ||
| }); | ||
|
|
||
| it('should import Vantage Auth modules to app.module.ts when sso option is selected by user', async () => { | ||
| const dependencyOptions: any = { ssoServerURL: 'https://vantage.url.io' }; | ||
| const tree: Tree = await testRunner.runSchematicAsync('ng-add', dependencyOptions, appTree).toPromise(); | ||
| const fileContent: string = getFileContent(tree, 'projects/ui-platform-workspace/src/app/app.module.ts'); | ||
| expect(fileContent).toContain('VantageAuthenticationModule'); | ||
| expect(fileContent).toContain('VantageAuthenticationInterceptor'); | ||
| expect(fileContent).toContain('VantageUserModule'); | ||
| expect(fileContent).toContain('CovalentHttpModule'); | ||
| }); | ||
|
|
||
| it('should create app.routes.ts when sso option is selected by user', async () => { | ||
| const dependencyOptions: any = { ssoServerURL: 'https://vantage.url.io' }; | ||
| const tree: Tree = await testRunner.runSchematicAsync('ng-add', dependencyOptions, appTree).toPromise(); | ||
| expect(tree.exists('src/app/app.routes.ts')).toBe(true); | ||
| const fileContent: string = getFileContent(tree, 'src/app/app.routes.ts'); | ||
| expect(fileContent).toContain('VantageAuthenticationGuard'); | ||
| }); | ||
|
|
||
| it('should import route provider to app.module.ts when sso option is selected by user', async () => { | ||
| const dependencyOptions: any = { ssoServerURL: 'https://vantage.url.io' }; | ||
| const tree: Tree = await testRunner.runSchematicAsync('ng-add', dependencyOptions, appTree).toPromise(); | ||
| const fileContent: string = getFileContent(tree, 'projects/ui-platform-workspace/src/app/app.module.ts'); | ||
| expect(fileContent).toContain('appRoutes'); | ||
| expect(fileContent).toContain('appRoutingProviders'); | ||
| }); | ||
|
|
||
| function expectVersionToBe(dependencies: any, name: string, expectedVersion: string): void { | ||
| expect(dependencies[name]).toBe( | ||
| expectedVersion, | ||
| 'Expected ' + name + ' package to have ' + `${expectedVersion}` + ' version.', | ||
| ); | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import { Rule, chain, Tree, mergeWith, url, apply, branchAndMerge, SchematicsException, template, UpdateRecorder } from '@angular-devkit/schematics'; | ||
| import { addPackageToPackageJson } from '@angular/material/schematics/ng-add/package-config'; | ||
| import { uiPlatformVersion } from '../version-names'; | ||
| import { ISchema } from './schema'; | ||
| import { strings } from '@angular-devkit/core'; | ||
|
|
||
| import { getProjectFromWorkspace, addModuleImportToRootModule } from '@angular/cdk/schematics'; | ||
| import { addProviderToModule } from '@schematics/angular/utility/ast-utils'; | ||
| import { InsertChange } from '@schematics/angular/utility/change'; | ||
| import { getAppModulePath } from '@schematics/angular/utility/ng-ast-utils'; | ||
| import { getWorkspace } from '@schematics/angular/utility/config'; | ||
| import { experimental } from '@angular-devkit/core'; | ||
| import { getSourceFile, getProjectMainFile } from '@angular/cdk/schematics/utils'; | ||
| import { SourceFile } from 'typescript'; | ||
| import { Change } from '@schematics/angular/utility/change'; | ||
|
|
||
| export function addDependenciesAndFiles(options: ISchema): Rule { | ||
| let addVantagePacakgeRule: Rule = (host: Tree) => { | ||
| addPackageToPackageJson(host, '@td-vantage/ui-platform', `${uiPlatformVersion}`); | ||
| }; | ||
|
|
||
| let ruleSet: Rule[] = [addVantagePacakgeRule]; | ||
|
|
||
| if (options.ssoServerURL && options.ssoServerURL.trim().length) { // enable SSO | ||
| ruleSet.push(mergeFiles(options)); | ||
| ruleSet.push(addSSOImports); | ||
| } | ||
| return chain(ruleSet); | ||
| } | ||
|
|
||
| function mergeFiles(options: ISchema): Rule { | ||
| const templateSource: any = apply(url('./files'), [ | ||
| template({ | ||
| ...strings, | ||
| ...options, | ||
| }), | ||
| ]); | ||
| return branchAndMerge(mergeWith(templateSource)); | ||
| } | ||
|
|
||
| function addSSOImports(): Rule { | ||
| return (host: Tree) => { | ||
| const workspace: experimental.workspace.WorkspaceSchema = getWorkspace(host); | ||
| const project: experimental.workspace.WorkspaceProject = getProjectFromWorkspace(workspace); | ||
| const replacementString: string = `CovalentHttpModule.forRoot({ | ||
| interceptors: [{ | ||
| interceptor: VantageAuthenticationInterceptor, paths: ['**'], | ||
| }], | ||
| })`; | ||
|
|
||
| addModuleImportToRootModule(host, 'VantageAuthenticationModule', '@td-vantage/ui-platform/auth', project); | ||
| addModuleImportToRootModule(host, 'VantageUserModule', '@td-vantage/ui-platform/user', project); | ||
| addModuleImportToRootModule(host, `CovalentHttpModule.forRoot()`, '@covalent/http', project); | ||
| replaceContentInAppModule(host, `CovalentHttpModule.forRoot()`, replacementString); | ||
| addModuleImportToRootModule(host, 'appRoutes', './app.routes', project); | ||
|
|
||
| addProvider(host, `VantageAuthenticationInterceptor`, '@td-vantage/ui-platform/auth'); | ||
| addProvider(host, `appRoutingProviders`, './app.routes'); | ||
| }; | ||
| } | ||
|
|
||
| function addProvider(host: Tree, classifiedName: string, importPath: string): void { | ||
| const workspace: experimental.workspace.WorkspaceSchema = getWorkspace(host); | ||
| const project: experimental.workspace.WorkspaceProject = getProjectFromWorkspace(workspace); | ||
| const modulePath: string = getAppModulePath(host, getProjectMainFile(project)); | ||
| const moduleSource: SourceFile = getSourceFile(host, modulePath); | ||
| const changes: Change[] = addProviderToModule(moduleSource, modulePath, classifiedName, importPath); | ||
| applyChanges(host, modulePath, changes); | ||
| } | ||
|
|
||
| function applyChanges(tree: Tree, path: string, changes: Change[]): void { | ||
| const recorder: UpdateRecorder = tree.beginUpdate(path); | ||
| for (const change of changes) { | ||
| if (change instanceof InsertChange) { | ||
| recorder.insertLeft(change.pos, change.toAdd); | ||
| } | ||
| } | ||
| tree.commitUpdate(recorder); | ||
| } | ||
|
|
||
| function replaceContentInAppModule(host: Tree, match: string, replacement: string): void { | ||
| const workspace: experimental.workspace.WorkspaceSchema = getWorkspace(host); | ||
| const project: experimental.workspace.WorkspaceProject = getProjectFromWorkspace(workspace); | ||
| const modulePath: string = getAppModulePath(host, getProjectMainFile(project)); | ||
| const content: string = host.get(modulePath).content.toString(); | ||
| host.overwrite(modulePath, content.replace(match, replacement)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "$schema": "http://json-schema.org/schema", | ||
| "id": "vantage-ui-platform-ng-add", | ||
| "title": "Vantage UI Platform ng-add schematic", | ||
| "type": "object", | ||
| "properties": { | ||
| "ssoServerURL": { | ||
| "type": "string", | ||
| "description": "Add SSO if user provides SSO server URL", | ||
| "x-prompt": "Add SSO server url to setup SSO or press enter to skip" | ||
| } | ||
| }, | ||
| "required": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export interface ISchema { | ||
| /** Whether SSO should be set up. */ | ||
| ssoServerURL: string; | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "compileOnSave": false, | ||
| "compilerOptions": { | ||
| "rootDir": "./", | ||
| "baseUrl": "./", | ||
| "declaration": false, | ||
| "emitDecoratorMetadata": true, | ||
| "experimentalDecorators": true, | ||
| "outDir": "../../../../deploy/ui-platform/schematics", | ||
| "lib": ["es2017", "dom"], | ||
| "moduleResolution": "node", | ||
| "sourceMap": true, | ||
| "target": "es5", | ||
| "typeRoots": ["./../../../../node_modules/@types"], | ||
| "noUnusedParameters": false, | ||
| "noUnusedLocals": false, | ||
| "allowUnreachableCode": false, | ||
| "pretty": true, | ||
| "importHelpers": true | ||
| }, | ||
| "include": ["**/*"], | ||
| "exclude": ["**/*.spec.ts", "**/files/**/*"] | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| { | ||
| "extends": "../../../tsconfig.json", | ||
| "compilerOptions": { | ||
| "baseUrl": ".", | ||
| "outDir": "./", | ||
| "lib": ["es6", "dom"], | ||
| "module": "commonjs", | ||
| "types": ["jasmine", "hammerjs", "node"] | ||
| }, | ||
| "include": ["**/*", "**/*.spec.ts"], | ||
| "exclude": ["*/files/**/*", "*/files/**/**/*"] | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const uiPlatformVersion: string = '1.0.0-beta.0'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be interpolated with the ssoServerURL options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if the quotes would be needed