Skip to content
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

Replaced Angular Client Proxy Generation code with Angular Schematics #5137

Merged
merged 97 commits into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
9dbae3a
build: add dependencies for schematics
armanozak Aug 12, 2020
9641e4c
chore: make VS Code ignore template files
armanozak Aug 12, 2020
50407d1
build: add build scripts for schematics
armanozak Aug 12, 2020
bdb8217
feat: add an empty schematics project
armanozak Aug 12, 2020
0b4c7e3
build: add schematics library to angular.json
armanozak Aug 12, 2020
863d66e
chore: add mock api-definition.json to schematics
armanozak Aug 12, 2020
aa38af0
chore: copy angular internal schematics to utils
armanozak Aug 12, 2020
f6e1c4f
feat: add clearly named text utils
armanozak Aug 12, 2020
caef401
feat: add exceptions as enum
armanozak Aug 12, 2020
0b9fb48
feat: add utility function to read workspace schema
armanozak Aug 12, 2020
9d6d7e4
feat: add utility function to resolve project definition
armanozak Aug 12, 2020
e00b09b
feat: add project parameter to proxy command
armanozak Aug 12, 2020
a9a48f4
build: add got as dependency of schematics
armanozak Aug 12, 2020
a961d5d
chore: add a generic ignore pattern
armanozak Aug 12, 2020
5235423
feat: add common utils to schematics
armanozak Aug 12, 2020
949e732
feat: update schematics exceptions
armanozak Aug 12, 2020
cd2bdda
feat: add functions to resolve environment and source url
armanozak Aug 12, 2020
e8d5afb
feat: get source json for proxy generation
armanozak Aug 12, 2020
91bf432
feat: update proxy schema
armanozak Aug 12, 2020
b8991e1
feat: add includeTypes query param to api definition request
armanozak Aug 13, 2020
586f0b6
feat: add models for api definition
armanozak Aug 13, 2020
e51382e
Merge branch 'dev' of github.com:abpframework/abp into feat/4881
armanozak Aug 13, 2020
596e717
fix: add endpoint to resolved source url in schematics
armanozak Aug 13, 2020
19f272c
feat: handle redirects in api definition request
armanozak Aug 13, 2020
e5ca84e
build: update lint rules for schematics
armanozak Aug 13, 2020
0e78078
build: clear previous schematics build artifacts
armanozak Aug 14, 2020
ab5a5a4
feat: modify schematics params according to new contract
armanozak Aug 14, 2020
5358d5b
feat: parse controller and create service path
armanozak Aug 15, 2020
e8354ee
feat: update ApiDefinition interface
armanozak Aug 17, 2020
92484c3
feat: update schematics text utils
armanozak Aug 17, 2020
c1807a4
feat: add NoApiDefinition exception to schematics
armanozak Aug 17, 2020
bf1ba4c
feat: add rule creators for saving and reading api definition
armanozak Aug 17, 2020
1e41f48
feat: divide proxy schematics into two steps
armanozak Aug 17, 2020
6339adc
feat: remove any solution name variation from namespace
armanozak Aug 18, 2020
994c141
feat: add invalid module to schematics exceptions
armanozak Aug 18, 2020
1435ee1
feat: add binding source id enum to schematics
armanozak Aug 18, 2020
d2af128
feat: update api definition model in schematics
armanozak Aug 18, 2020
05a1a78
feat: add import keyword enum to schematics
armanozak Aug 18, 2020
2b3b5d2
feat: add method modifier enum to schematics
armanozak Aug 18, 2020
325c02d
feat: add Omissible utility type to schematics
armanozak Aug 18, 2020
3cc9359
feat: add parseNamespace utility fn to schematics
armanozak Aug 18, 2020
8968d3e
feat: add import model to schematics
armanozak Aug 18, 2020
eb170e7
feat: add method model to schematics
armanozak Aug 18, 2020
5c5c9e3
feat: add service model to schematics
armanozak Aug 18, 2020
a18643a
feat: add service utility functions to schematics
armanozak Aug 18, 2020
5785987
feat: use utility functions in schematics api command
armanozak Aug 18, 2020
ab71082
feat: add relativePathFromServiceToModel utility fn
armanozak Aug 18, 2020
4927378
feat: use relative path in service imports
armanozak Aug 18, 2020
faffc8c
feat: add imports for generic types in schematics
armanozak Aug 18, 2020
c4f60f3
feat: add serializeParameters utility fn to schematics
armanozak Aug 18, 2020
dc17cf6
feat: add template for service in schematics
armanozak Aug 18, 2020
56bf0e6
feat: add a tree structure for generic types
armanozak Aug 19, 2020
c6a4a3a
feat: collect refs to generic types in service schematics
armanozak Aug 19, 2020
6e5c426
feat: sort service imports and methods in schematics
armanozak Aug 19, 2020
cf99dd3
feat: use destructuring in service schematics template
armanozak Aug 19, 2020
bf017bb
feat: add a base for model generation in schematics
armanozak Aug 19, 2020
8753450
feat: group import refs before mapping them to models
armanozak Aug 19, 2020
b3db883
feat: add system type map as constant to schematics
armanozak Aug 19, 2020
dc60ff5
refactor: move schematics type simplifier to separate file
armanozak Aug 19, 2020
e195959
feat: collect interfaces from types based on importRefs
armanozak Aug 19, 2020
90ad89c
refactor: make importRef to interface mapper separate fn
armanozak Aug 19, 2020
460f217
refactor: make schematics service imports reducer reusable
armanozak Aug 19, 2020
f467dc7
refactor: make schematics import sort fn reusable
armanozak Aug 19, 2020
d31aee3
feat: handle model imports in model schematics
armanozak Aug 19, 2020
61cc1f6
fix: check list types before splitting them in schematics
armanozak Aug 19, 2020
d41e621
fix: parse namespaces after removing type modifiers
armanozak Aug 19, 2020
82967a8
refactor: simplify merging of baseType w/ properties
armanozak Aug 19, 2020
0c9c5da
fix: avoid union types to be imported in schematics
armanozak Aug 19, 2020
7d27295
fix: avoid importing modified types in schematics
armanozak Aug 19, 2020
198ea43
feat: handle enum imports in schematics
armanozak Aug 19, 2020
c0aa472
fix: replace double slashes with single slashes
armanozak Aug 19, 2020
a70cfd6
fix: avoid creating interfaces for enums in schematics
armanozak Aug 19, 2020
6f10a83
feat: import ObjectExtending namespace from core package
armanozak Aug 19, 2020
5561509
feat: create interfaces for self imports in schematics
armanozak Aug 20, 2020
a8c1a49
feat: create enums and enum options with schematics
armanozak Aug 20, 2020
5bfc5dc
fix: add imports for referred types in model schematics
armanozak Aug 20, 2020
a3108f8
refactor: move generation rules to separate functions
armanozak Aug 20, 2020
d4044c6
feat: generate referred models recursively in schematics
armanozak Aug 20, 2020
adeab8a
feat: generate interfaces recursively in model schematics
armanozak Aug 20, 2020
4a6b9b4
feat: map System.Net.HttpStatusCode to number in schematics
armanozak Aug 20, 2020
2fc7161
fix: add comma after params in service schematics
armanozak Aug 20, 2020
1dc58c5
refactor: unify reduction of refs to imports & interfaces
armanozak Aug 20, 2020
12c20fd
feat: add volo regex as constant to schematics
armanozak Aug 21, 2020
654cdb6
fix: improve recursive model lookup in schematics
armanozak Aug 21, 2020
832692a
fix: avoid importing generic type placeholders in schematics
armanozak Aug 21, 2020
a1ae2d9
fix: remove condition blocking enum generation in schematics
armanozak Aug 21, 2020
edadf0e
fix: avoid lint errors in schematics
armanozak Aug 21, 2020
7423b1c
fix: add property type definition control back
armanozak Aug 21, 2020
2e82d0a
fix: generate interface for base types too
armanozak Aug 21, 2020
283c04c
feat: handle complex union types in schematics
armanozak Aug 21, 2020
5be8544
fix: cut out generics from base type for better parsing
armanozak Aug 21, 2020
7422c46
Merge branch 'dev' of github.com:abpframework/abp into feat/4881
armanozak Aug 21, 2020
c90f70e
build: exclude @abp/schematics pakage
mehmet-erim Aug 21, 2020
105d440
chore: add build property with options property to schematics package…
mehmet-erim Aug 21, 2020
8b968e6
chore: add an ng-package.json for schematics
mehmet-erim Aug 21, 2020
2bfb053
fix: remove sass from env
bnymncoskuner Aug 21, 2020
109e3f5
build: fix build-schematics script to copy correct folders
armanozak Aug 21, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion npm/ng-packs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

# generic ignore files
*.gitignore.*

# compiled output
/tmp
/out-tsc
Expand Down Expand Up @@ -46,4 +49,4 @@ testem.log
Thumbs.db

!**/[Pp]ackages/*
*.internal.*
*.internal.*
18 changes: 18 additions & 0 deletions npm/ng-packs/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
{
"[typescriptreact]": {
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.organizeImports": false
}
},
"[xml]": {
"editor.formatOnSave": false,
"editor.codeActionsOnSave": {
"source.fixAll": false,
"source.organizeImports": false
}
},
"files.associations": {
"*.ts.template": "typescriptreact",
"*.html.template": "xml"
},
"search.exclude": {
"**/dist": true
},
Expand Down
23 changes: 23 additions & 0 deletions npm/ng-packs/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,29 @@
}
}
},
"schematics": {
"projectType": "library",
"root": "packages/schematics",
"sourceRoot": "packages/schematics/src",
"prefix": "abp",
"architect": {
"test": {
"builder": "@angular-builders/jest:run",
"options": {
"tsConfig": "tsconfig.json",
"coverage": true,
"passWithNoTests": true
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": ["packages/schematics/tsconfig.json"],
"exclude": ["**/node_modules/**"]
}
}
}
},
"dev-app": {
"projectType": "application",
"schematics": {
Expand Down
3 changes: 3 additions & 0 deletions npm/ng-packs/apps/dev-app/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ export const environment = {
default: {
url: 'https://localhost:44305',
},
saas: {
url: 'https://localhost:44305',
},
bnymncoskuner marked this conversation as resolved.
Show resolved Hide resolved
},
} as Config.Environment;
5 changes: 5 additions & 0 deletions npm/ng-packs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"test": "ng test --watchAll --runInBand",
"commit": "git-cz",
"lint": "ng lint",
"build:schematics": "cd scripts && yarn && yarn build:schematics && cd ..",
"dev:schematics": "tsc -p packages/schematics/tsconfig.json -w",
"scripts:build": "cd scripts && yarn && yarn build",
"prepare:workspace": "yarn scripts:build --noInstall",
"ci": "yarn ng lint && yarn prepare:workspace && yarn ci:test && yarn ci:build",
Expand Down Expand Up @@ -57,6 +59,7 @@
"@ngxs/router-plugin": "^3.6.2",
"@ngxs/storage-plugin": "^3.6.2",
"@ngxs/store": "^3.6.2",
"@schematics/angular": "~10.0.5",
"@swimlane/ngx-datatable": "^17.1.0",
"@types/jest": "^25.2.3",
"@types/node": "^12.11.1",
Expand All @@ -67,9 +70,11 @@
"conventional-changelog-cli": "^2.0.31",
"cz-conventional-changelog": "3.0.2",
"font-awesome": "^4.7.0",
"got": "^11.5.2",
"jest": "^25.0.0",
"jest-canvas-mock": "^2.2.0",
"jest-preset-angular": "^8.2.0",
"jsonc-parser": "^2.3.0",
"just-clone": "^3.1.0",
"just-compare": "^1.3.0",
"lerna": "^3.19.0",
Expand Down
18 changes: 18 additions & 0 deletions npm/ng-packs/packages/schematics/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Outputs
src/**/*.js
src/**/*.js.map
src/**/*.d.ts

# IDEs
.idea/
jsconfig.json
.vscode/

# Misc
node_modules/
npm-debug.log*
yarn-error.log*

# Mac OSX Finder files.
**/.DS_Store
.DS_Store
3 changes: 3 additions & 0 deletions npm/ng-packs/packages/schematics/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignores TypeScript files, but keeps definitions.
*.ts
!*.d.ts
3 changes: 3 additions & 0 deletions npm/ng-packs/packages/schematics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ABP Suite Schematics

TODO: Add usage and development information
7 changes: 7 additions & 0 deletions npm/ng-packs/packages/schematics/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const jestConfig = require('../../jest.config');

module.exports = {
...jestConfig,
name: 'schematics',
testMatch: ['<rootDir>/packages/schematics/**/+(*.)+(spec).+(ts)'],
};
24 changes: 24 additions & 0 deletions npm/ng-packs/packages/schematics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@abp/ng.schematics",
"version": "3.0.5",
"description": "Schematics that works with ABP Suite",
"keywords": [
"schematics"
],
"author": "",
"license": "MIT",
"schematics": "./src/collection.json",
"dependencies": {
"@angular-devkit/core": "~10.0.3",
"@angular-devkit/schematics": "~10.0.3",
"got": "^11.5.2",
"typescript": "~3.9.2"
},
"devDependencies": {
"@types/node": "^12.11.1",
"@types/jest": "^26.0.0",
"jest": "^26.0.0",
"jest-preset-angular": "^8.2.0",
"@schematics/angular": "~10.0.3"
}
}
14 changes: 14 additions & 0 deletions npm/ng-packs/packages/schematics/src/collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"schematics": {
"proxy": {
"description": "ABP Proxy Generator Schematics",
"factory": "./commands/proxy",
"schema": "./commands/proxy/schema.json"
},
"api": {
"description": "ABP API Generator Schematics",
"factory": "./commands/api",
"schema": "./commands/api/schema.json"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { mapEnumToOptions } from '@abp/ng.core';

export enum <%= name %> {<%
for (let member of members) { %>
<%= member.key %> = <%= member.value %>,<% } %>
}

export const <%= camel(name) %>Options = mapEnumToOptions(<%= name %>);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<%
for (const {keyword, specifiers, path} of imports) {
%><%= keyword %> { <%= specifiers.join(', ') %> } from '<%= path %>';
<% }
for (let {base, identifier, properties} of interfaces) { %>
export interface <%= identifier %> <%= base ? `extends ${base} ` : '' %>{<%
for (let {name, optional, type} of properties) { %>
<%= name + optional %>: <%= type %>;<% } %>
}
<% } %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<% for (const {keyword, specifiers, path} of imports) {
%><%= keyword %> { <%= specifiers.join(', ') %> } from '<%= path %>';
<% } %>
@Injectable({
providedIn: 'root',
})
export class <%= name %>Service {
apiName = '<%= apiName %>';<%
for (let {body, signature} of methods) { %>

<%= camel(signature.name) %> = (<%= serializeParameters(signature.parameters) %>) =>
this.restService.request<<%= body.requestType %>, <%= body.responseType %>>({
method: '<%= body.method %>',
url: `/<%= body.url %>`,<%
if (body.params.length) { %>
params: { <%= body.params.join(', ') %> },<% }
if (body.body) { %>
body: <%= body.body %>,<% } %>
},
{ apiName: this.apiName });<% } %>

constructor(private restService: RestService) {}
}
157 changes: 157 additions & 0 deletions npm/ng-packs/packages/schematics/src/commands/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import { normalize, strings } from '@angular-devkit/core';
import {
applyTemplates,
branchAndMerge,
chain,
move,
SchematicContext,
SchematicsException,
Tree,
url,
} from '@angular-devkit/schematics';
import { Exception } from '../../enums';
import { ServiceGeneratorParams } from '../../models';
import {
applyWithOverwrite,
buildDefaultPath,
createApiDefinitionReader,
createControllerToServiceMapper,
createImportRefsToModelReducer,
createImportRefToEnumMapper,
EnumGeneratorParams,
getEnumNamesFromImports,
interpolate,
ModelGeneratorParams,
resolveProject,
serializeParameters,
} from '../../utils';
import * as cases from '../../utils/text';
import { Schema as GenerateProxySchema } from './schema';

export default function(params: GenerateProxySchema) {
const solution = params.solution;
const moduleName = strings.camelize(params.module || 'app');

return chain([
async (tree: Tree, _context: SchematicContext) => {
const target = await resolveProject(tree, params.target!);
const targetPath = buildDefaultPath(target.definition);
const readApiDefinition = createApiDefinitionReader(
`${targetPath}/shared/api-definition.json`,
);
const data = readApiDefinition(tree);
const types = data.types;
const definition = data.modules[moduleName];
if (!definition)
throw new SchematicsException(interpolate(Exception.InvalidModule, moduleName));

const apiName = definition.remoteServiceName;
const controllers = Object.values(definition.controllers || {});
const serviceImports: Record<string, string[]> = {};
const generateServices = createServiceGenerator({
targetPath,
solution,
types,
apiName,
controllers,
serviceImports,
});

const modelImports: Record<string, string[]> = {};
const generateModels = createModelGenerator({
targetPath,
solution,
types,
serviceImports,
modelImports,
});

const generateEnums = createEnumGenerator({
targetPath,
solution,
types,
serviceImports,
modelImports,
});

return branchAndMerge(chain([generateServices, generateModels, generateEnums]));
},
]);
}

function createEnumGenerator(params: EnumGeneratorParams) {
const { targetPath, serviceImports, modelImports } = params;
const mapImportRefToEnum = createImportRefToEnumMapper(params);
const enumRefs = [
...new Set([
...getEnumNamesFromImports(serviceImports),
...getEnumNamesFromImports(modelImports),
]),
];

return chain(
enumRefs.map(ref => {
return applyWithOverwrite(url('./files-enum'), [
applyTemplates({
...cases,
...mapImportRefToEnum(ref),
}),
move(normalize(targetPath)),
]);
}),
);
}

function createModelGenerator(params: ModelGeneratorParams) {
const { targetPath, serviceImports, modelImports } = params;
const reduceImportRefsToModels = createImportRefsToModelReducer(params);
const models = Object.values(serviceImports).reduce(reduceImportRefsToModels, []);
models.forEach(({ imports }) =>
imports.forEach(({ refs, path }) =>
refs.forEach(ref => {
if (path === '@abp/ng.core') return;
if (!modelImports[path]) return (modelImports[path] = [ref]);
modelImports[path] = [...new Set([...modelImports[path], ref])];
}),
),
);

return chain(
models.map(model =>
applyWithOverwrite(url('./files-model'), [
applyTemplates({
...cases,
...model,
}),
move(normalize(targetPath)),
]),
),
);
}

function createServiceGenerator(params: ServiceGeneratorParams) {
const { targetPath, controllers, serviceImports } = params;
const mapControllerToService = createControllerToServiceMapper(params);

return chain(
controllers.map(controller => {
const service = mapControllerToService(controller);
service.imports.forEach(({ refs, path }) =>
refs.forEach(ref => {
if (path === '@abp/ng.core') return;
if (!serviceImports[path]) return (serviceImports[path] = [ref]);
serviceImports[path] = [...new Set([...serviceImports[path], ref])];
}),
);

return applyWithOverwrite(url('./files-service'), [
applyTemplates({
...cases,
serializeParameters,
...service,
}),
move(normalize(targetPath)),
]);
}),
);
}
Loading