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

Add Nx Code Generator for encapsulating ABP Schematics on NX repositories without 'angular.json' file #16685

Merged
merged 2 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions npm/ng-packs/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nx/javascript"],
"rules": {}
},
{
"files": "*.json",
"parser": "jsonc-eslint-parser",
"rules": {}
}
]
}
3 changes: 2 additions & 1 deletion npm/ng-packs/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@
"statusBarItem.hoverBackground": "#258ecd",
"statusBar.foreground": "#e7e7e7"
},
"peacock.color": "#1D70A2"
"peacock.color": "#1D70A2",
"eslint.validate": ["json"]
}
18 changes: 13 additions & 5 deletions npm/ng-packs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,18 @@
"@ng-bootstrap/ng-bootstrap": "^14.0.0",
"@ngneat/spectator": "^10.0.0",
"@ngx-validate/core": "^0.2.0",
"@nx/angular": "16.1.4",
"@nx/cypress": "16.1.4",
"@nx/eslint-plugin": "16.1.4",
"@nx/jest": "16.1.4",
"@nx/jest": "16.2.2",
"@nx/js": "16.2.2",
"@nx/linter": "16.1.4",
"@nx/workspace": "16.1.4",
"@popperjs/core": "~2.11.2",
"@schematics/angular": "~16.0.1",
"@swc-node/register": "~1.4.2",
"@swc/cli": "~0.1.62",
"@swc/core": "~1.3.51",
"@swimlane/ngx-datatable": "^20.0.0",
"@types/jest": "29.4.4",
"@types/node": "16.11.7",
Expand All @@ -106,6 +111,7 @@
"jest-canvas-mock": "^2.3.1",
"jest-environment-jsdom": "29.4.3",
"jest-preset-angular": "13.1.0",
"jsonc-eslint-parser": "^2.1.0",
"jsonc-parser": "^2.3.0",
"just-clone": "^6.1.1",
"just-compare": "^2.3.0",
Expand All @@ -129,14 +135,16 @@
"tslib": "^2.3.0",
"tslint": "~6.1.0",
"typescript": "5.0.4",
"zone.js": "~0.13.0",
"@nx/angular": "16.1.4"
"zone.js": "~0.13.0"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx,html,css,scss}": [
"npx prettier --write --config .prettierrc "
]
},
"dependencies": {}
"dependencies": {
"@nx/devkit": "16.2.2",
"@nx/plugin": "^16.2.2",
"@swc/helpers": "~0.5.0"
}
}

25 changes: 25 additions & 0 deletions npm/ng-packs/packages/generators/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
},
{
"files": ["./package.json", "./generators.json"],
"parser": "jsonc-eslint-parser",
"rules": {
"@nx/nx-plugin-checks": "error"
}
}
]
}
11 changes: 11 additions & 0 deletions npm/ng-packs/packages/generators/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# generators

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build generators` to build the library.

## Running unit tests

Run `nx test generators` to execute the unit tests via [Jest](https://jestjs.io).
9 changes: 9 additions & 0 deletions npm/ng-packs/packages/generators/generators.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"generators": {
"generate-proxy": {
"factory": "./src/generators/generate-proxy/generator",
"schema": "./src/generators/generate-proxy/schema.json",
"description": "generate-proxy generator"
}
}
}
10 changes: 10 additions & 0 deletions npm/ng-packs/packages/generators/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
export default {
displayName: 'generators',
preset: '../../jest.preset.js',
transform: {
'^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/packages/generators',
};
6 changes: 6 additions & 0 deletions npm/ng-packs/packages/generators/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@abp/generators",
"version": "0.0.1",
"type": "commonjs",
"generators": "./generators.json"
}
66 changes: 66 additions & 0 deletions npm/ng-packs/packages/generators/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "generators",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/generators/src",
"projectType": "library",
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/generators",
"main": "packages/generators/src/index.ts",
"tsConfig": "packages/generators/tsconfig.lib.json",
"assets": [
"packages/generators/*.md",
{
"input": "./packages/generators/src",
"glob": "**/!(*.ts)",
"output": "./src"
},
{
"input": "./packages/generators/src",
"glob": "**/*.d.ts",
"output": "./src"
},
{
"input": "./packages/generators",
"glob": "generators.json",
"output": "."
},
{
"input": "./packages/generators",
"glob": "executors.json",
"output": "."
}
]
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": ["{options.outputFile}"],
"options": {
"lintFilePatterns": [
"packages/generators/**/*.ts",
"packages/generators/package.json",
"packages/generators/generators.json"
]
}
},
"test": {
"executor": "@nx/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"options": {
"jestConfig": "packages/generators/jest.config.ts",
"passWithNoTests": true
},
"configurations": {
"ci": {
"ci": true,
"codeCoverage": true
}
}
}
},
"tags": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const variable = "<%= name %>";
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
import { Tree, readProjectConfiguration } from '@nx/devkit';

import { generateProxyGenerator } from './generator';
import { GenerateProxyGeneratorSchema } from './schema';

describe('generate-proxy generator', () => {
let tree: Tree;
const options: GenerateProxyGeneratorSchema = { name: 'test' };

beforeEach(() => {
tree = createTreeWithEmptyWorkspace();
});

it('should run successfully', async () => {
await generateProxyGenerator(tree, options);
const config = readProjectConfiguration(tree, 'test');
expect(config).toBeDefined();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { GenerateProxyGeneratorSchema } from './schema';
import { Tree } from '@nrwl/devkit';
import { wrapAngularDevkitSchematic } from '@nx/devkit/ngcli-adapter';

export default async function (host: Tree, schema: GenerateProxyGeneratorSchema) {
const runAngularLibrarySchematic = wrapAngularDevkitSchematic('@abp/ng.schematics', 'proxy-add');

await runAngularLibrarySchematic(host, {
...schema,
});

return () => {
console.log(`proxy added '${schema.target}`);
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface GenerateProxyGeneratorSchema {
module: string;
apiName: string;
source: string;
target: string;
url: string;
serviceType: string;
entryPoint: string;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"$schema": "https://json-schema.org/schema",
"$id": "GenerateProxy",
"title": "",
"type": "object",
"properties": {
"module": {
"description": "Backend module name",
"type": "string",
"$default": {
"$source": "argv",
"index": 0
},
"x-prompt": "Please enter backend module name. (default: \"app\")"
},
"apiName": {
"description": "Backend api name, a.k.a. remoteServiceName",
"type": "string",
"$default": {
"$source": "argv",
"index": 1
},
"x-prompt": "Please enter backend api name, a.k.a. remoteServiceName. (default: \"default\")"
},
"source": {
"description": "Source Angular project for API definition URL & root namespace resolution",
"type": "string",
"$default": {
"$source": "argv",
"index": 2
},
"x-prompt": "Please enter source Angular project for API definition URL & root namespace resolution. (default: workspace \"defaultProject\")"
},
"target": {
"description": "Target Angular project to place the generated code",
"type": "string",
"$default": {
"$source": "argv",
"index": 3
},
"x-prompt": "Please enter target Angular project to place the generated code. (default: workspace \"defaultProject\")"
},
"url": {
"description": "Url for API definition",
"type": "string",
"$default": {
"$source": "argv",
"index": 4
},
"x-prompt": "Please enter URL for API definition (default: API Name's url in environment file)"
},
"serviceType": {
"description": "Service type to the generated code",
"type": "string",
"$default": {
"$source": "argv",
"index": 5
},
"enum": [
"application",
"integration",
"all"
],
"x-prompt": {
"message": "Specifies the service type to generate. `application`, `integration` and `all`, Default value: `application`",
"type": "list",
"items": [
{
"value": "all",
"label": "All"
},
{
"value": "application",
"label": "Application"
},
{
"value": "integration",
"label": "Integration"
}
]
}
},
"entryPoint": {
"description": "Target Angular project to place the generated code",
"type": "string",
"$default": {
"$source": "argv",
"index": 6
},
"x-prompt": "Please enter target entry point to place the generated code. (default: null)"
}
},
"required": []
}
Empty file.
16 changes: 16 additions & 0 deletions npm/ng-packs/packages/generators/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"module": "commonjs"
},
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
10 changes: 10 additions & 0 deletions npm/ng-packs/packages/generators/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"declaration": true,
"types": ["node"]
},
"include": ["src/**/*.ts"],
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
}
9 changes: 9 additions & 0 deletions npm/ng-packs/packages/generators/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts", "src/**/*.d.ts"]
}
1 change: 1 addition & 0 deletions npm/ng-packs/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"baseUrl": "./",
"allowSyntheticDefaultImports": true,
"paths": {
"@abp/generators": ["packages/generators/src/index.ts"],
"@abp/ng.account": ["packages/account/src/public-api.ts"],
"@abp/ng.account.core": ["packages/account-core/src/public-api.ts"],
"@abp/ng.account.core/proxy": ["packages/account-core/proxy/src/public-api.ts"],
Expand Down