mirror of https://github.com/abpframework/abp.git
committed by
GitHub
29 changed files with 495 additions and 102 deletions
@ -1,25 +1,20 @@ |
|||||
{ |
{ |
||||
"migrations": [ |
"migrations": [ |
||||
{ |
{ |
||||
"version": "16.0.0", |
"cli": "nx", |
||||
"factory": "./update-16/remove-default-project-option", |
"version": "16.2.0-beta.0", |
||||
"description": "Remove 'defaultProject' option from workspace configuration. The project to use will be determined from the current working directory.", |
"description": "Remove outputPath from run commands", |
||||
"package": "@angular/cli", |
"implementation": "./src/migrations/update-16-2-0/remove-run-commands-output-path", |
||||
"name": "remove-default-project-option" |
"package": "nx", |
||||
|
"name": "16.2.0-remove-output-path-from-run-commands" |
||||
}, |
}, |
||||
{ |
{ |
||||
"version": "16.0.0", |
"cli": "nx", |
||||
"factory": "./update-16/replace-default-collection-option", |
"version": "16.2.0-beta.0", |
||||
"description": "Replace removed 'defaultCollection' option in workspace configuration with 'schematicCollections'.", |
"description": "Normalize tsconfig.cy.json files to be located at '<projectRoot>/cypress/tsconfig.json'", |
||||
"package": "@angular/cli", |
"implementation": "./src/migrations/update-16-2-0/update-cy-tsconfig", |
||||
"name": "replace-default-collection-option" |
"package": "@nx/cypress", |
||||
}, |
"name": "update-16-2-0-normalize-tsconfigs" |
||||
{ |
|
||||
"version": "16.0.0", |
|
||||
"factory": "./update-16/update-server-builder-config", |
|
||||
"description": "Update the '@angular-devkit/build-angular:server' builder configuration to disable 'buildOptimizer' for non optimized builds.", |
|
||||
"package": "@angular/cli", |
|
||||
"name": "update-server-builder-config" |
|
||||
} |
} |
||||
] |
] |
||||
} |
} |
||||
|
|||||
@ -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" |
||||
|
} |
||||
|
} |
||||
|
] |
||||
|
} |
||||
@ -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). |
||||
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
"generators": { |
||||
|
"generate-proxy": { |
||||
|
"factory": "./src/generators/generate-proxy/generator", |
||||
|
"schema": "./src/generators/generate-proxy/schema.json", |
||||
|
"description": "generate-proxy generator" |
||||
|
}, |
||||
|
"update-version": { |
||||
|
"factory": "./src/generators/update-version/generator", |
||||
|
"schema": "./src/generators/update-version/schema.json", |
||||
|
"description": "update-version generator" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -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', |
||||
|
}; |
||||
@ -0,0 +1,6 @@ |
|||||
|
{ |
||||
|
"name": "@abp/nx.generators", |
||||
|
"version": "7.3.0-preview20230530", |
||||
|
"type": "commonjs", |
||||
|
"generators": "./generators.json" |
||||
|
} |
||||
@ -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": [] |
||||
|
} |
||||
@ -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}`); |
||||
|
}; |
||||
|
} |
||||
@ -0,0 +1,2 @@ |
|||||
|
export * from './schema'; |
||||
|
export * from './generator'; |
||||
@ -0,0 +1,9 @@ |
|||||
|
export interface GenerateProxyGeneratorSchema { |
||||
|
module: string; |
||||
|
apiName: string; |
||||
|
source: string; |
||||
|
target: string; |
||||
|
url: string; |
||||
|
serviceType: string; |
||||
|
entryPoint: string; |
||||
|
} |
||||
@ -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": [] |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
import { Tree, updateJson } from '@nx/devkit'; |
||||
|
import { UpdateVersionGeneratorSchema } from './schema'; |
||||
|
import { getPackageJsonList, getVersionByPackageNameFactory, semverRegex } from './utils'; |
||||
|
|
||||
|
export function updateVersionGenerator(tree: Tree, schema: UpdateVersionGeneratorSchema) { |
||||
|
const packageJsonList = getPackageJsonList(tree, schema.packages || []); |
||||
|
const getVersionNumberByPackageName = getVersionByPackageNameFactory( |
||||
|
schema.abpVersion, |
||||
|
schema.leptonXVersion, |
||||
|
); |
||||
|
packageJsonList.forEach(path => { |
||||
|
updateJson(tree, path, pkgJson => { |
||||
|
pkgJson.version = getVersionNumberByPackageName(pkgJson.name) || pkgJson.version; |
||||
|
console.log('\x1b[32m', `Updated ${pkgJson.name} version to ${pkgJson.version}`); |
||||
|
|
||||
|
Object.keys(pkgJson.dependencies || {}).forEach(key => { |
||||
|
const v = getVersionNumberByPackageName(key); |
||||
|
if (!v) { |
||||
|
return; |
||||
|
} |
||||
|
pkgJson.dependencies[key] = pkgJson.dependencies[key].replace(semverRegex, v); |
||||
|
console.log('\x1b[32m', `Updated ${key} version to ${v} in dependencies`); |
||||
|
}); |
||||
|
|
||||
|
Object.keys(pkgJson.peerDependencies || {}).forEach(key => { |
||||
|
const v = getVersionNumberByPackageName(key); |
||||
|
if (!v) { |
||||
|
return; |
||||
|
} |
||||
|
pkgJson.peerDependencies[key] = pkgJson.peerDependencies[key].replace(semverRegex, v); |
||||
|
console.log('\x1b[32m', `Updated ${key} version to ${schema.abpVersion} in peerDependencies`); |
||||
|
}); |
||||
|
|
||||
|
Object.keys(pkgJson.devDependencies || {}).forEach(key => { |
||||
|
const v = getVersionNumberByPackageName(key); |
||||
|
if (!v) { |
||||
|
return; |
||||
|
} |
||||
|
pkgJson.devDependencies[key] = pkgJson.devDependencies[key].replace(semverRegex, v); |
||||
|
console.log('\x1b[32m', `Updated ${key} version to ${schema.abpVersion} on devDependencies`); |
||||
|
}); |
||||
|
|
||||
|
return pkgJson; |
||||
|
}); |
||||
|
}); |
||||
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
|
return () => {}; |
||||
|
} |
||||
|
|
||||
|
export default updateVersionGenerator; |
||||
@ -0,0 +1,3 @@ |
|||||
|
export * from './generator'; |
||||
|
export * from './schema'; |
||||
|
export * from './utils' |
||||
@ -0,0 +1,5 @@ |
|||||
|
export interface UpdateVersionGeneratorSchema { |
||||
|
abpVersion:string; |
||||
|
leptonXVersion: string; |
||||
|
packages?: string[]; |
||||
|
} |
||||
@ -0,0 +1,22 @@ |
|||||
|
{ |
||||
|
"$schema": "http://json-schema.org/schema", |
||||
|
"$id": "UpdateVersion", |
||||
|
"title": "", |
||||
|
"type": "object", |
||||
|
"properties": { |
||||
|
"abpVersion": { |
||||
|
"type": "string", |
||||
|
"description": "", |
||||
|
"$default": { |
||||
|
"$source": "argv", |
||||
|
"index": 0 |
||||
|
}, |
||||
|
"x-prompt": "What ABP version would you like to use?" |
||||
|
}, |
||||
|
"leptonXVersion": { |
||||
|
"type": "string", |
||||
|
"description": "" |
||||
|
} |
||||
|
}, |
||||
|
"required": ["abpVersion"] |
||||
|
} |
||||
@ -0,0 +1,65 @@ |
|||||
|
import { getProjects, readJson, readProjectConfiguration, Tree } from '@nx/devkit'; |
||||
|
|
||||
|
export const IGNORED_PROJECT_NAMES = ['apex-chart-components', 'bs-components', 'workspace-plugin']; |
||||
|
|
||||
|
export function getPackageJsonList(tree: Tree, packages: string[]): string[] { |
||||
|
const project = getProjects(tree); |
||||
|
|
||||
|
const result = ['/package.json']; |
||||
|
project.forEach((value, key) => { |
||||
|
|
||||
|
if (value.projectType !== 'library') { |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
if (IGNORED_PROJECT_NAMES.some(x => x === key)) { |
||||
|
return; |
||||
|
} |
||||
|
const projectConfiguration = readProjectConfiguration(tree, key); |
||||
|
|
||||
|
if (packages.length && !packages.includes(value.name)) { |
||||
|
return; |
||||
|
} |
||||
|
result.push(projectConfiguration.root + '/package.json'); |
||||
|
}); |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
export function getPackageNameList(tree: Tree, packageJsonList: string[]) { |
||||
|
return packageJsonList.map(packageJson => { |
||||
|
const jsonFile = readJson(tree, packageJson); |
||||
|
return jsonFile.name; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
const leptonPackages = [ |
||||
|
'@abp/ng.theme.lepton-x', |
||||
|
'@volosoft/ngx-lepton-x', |
||||
|
'@volo/abp.ng.lepton-x.core', |
||||
|
'@volo/ngx-lepton-x.core', |
||||
|
'@volo/ngx-lepton-x.lite', |
||||
|
'@volosoft/abp.ng.theme.lepton-x', |
||||
|
]; |
||||
|
const abpPackageNameRegex = /^@(abp|volo|volosoft)\/.*/; |
||||
|
|
||||
|
export function isAbpPack(packageName) { |
||||
|
return abpPackageNameRegex.test(packageName) && !leptonPackages.includes(packageName); |
||||
|
} |
||||
|
export function functionisLeptonXPack(packageName) { |
||||
|
return leptonPackages.includes(packageName); |
||||
|
} |
||||
|
|
||||
|
export function getVersionByPackageNameFactory(abpVersionName: string, leptonXVersionName: string) { |
||||
|
return (packageName: string) => { |
||||
|
if (isAbpPack(packageName)) { |
||||
|
return abpVersionName; |
||||
|
} |
||||
|
if (functionisLeptonXPack(packageName)) { |
||||
|
return leptonXVersionName; |
||||
|
} |
||||
|
return ''; |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
export const semverRegex = |
||||
|
/\d+\.\d+\.\d+(?:-[a-zA-Z0-9]+(?:\.[a-zA-Z0-9-]+)*)?(?:\+[a-zA-Z0-9]+(?:\.[a-zA-Z0-9-]+)*)?$/; |
||||
@ -0,0 +1 @@ |
|||||
|
export * from './generators/generate-proxy' |
||||
@ -0,0 +1,16 @@ |
|||||
|
{ |
||||
|
"extends": "../../tsconfig.base.json", |
||||
|
"compilerOptions": { |
||||
|
"module": "commonjs" |
||||
|
}, |
||||
|
"files": [], |
||||
|
"include": [], |
||||
|
"references": [ |
||||
|
{ |
||||
|
"path": "./tsconfig.lib.json" |
||||
|
}, |
||||
|
{ |
||||
|
"path": "./tsconfig.spec.json" |
||||
|
} |
||||
|
] |
||||
|
} |
||||
@ -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"] |
||||
|
} |
||||
@ -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,34 +0,0 @@ |
|||||
import fse from 'fs-extra'; |
|
||||
import execa from 'execa'; |
|
||||
import program from 'commander'; |
|
||||
|
|
||||
program |
|
||||
.option( |
|
||||
'-v, --nextVersion <version>', |
|
||||
'next semantic version. Available versions: ["major", "minor", "patch", "premajor", "preminor", "prepatch", "prerelease", "or type a custom version"]', |
|
||||
); |
|
||||
program.parse(process.argv); |
|
||||
|
|
||||
|
|
||||
(async () => { |
|
||||
await updateVersion(program.nextVersion); |
|
||||
})(); |
|
||||
|
|
||||
|
|
||||
async function updateVersion(version: string) { |
|
||||
if(!version){ |
|
||||
console.error('Please provide a version with --nextVersion attribute'); |
|
||||
return; |
|
||||
} |
|
||||
await fse.rename('../lerna.version.json', '../lerna.json'); |
|
||||
|
|
||||
await execa( |
|
||||
'yarn', |
|
||||
['lerna', 'version', version, '--yes', '--no-commit-hooks', '--skip-git', '--force-publish'], |
|
||||
{ stdout: 'inherit', cwd: '../' }, |
|
||||
); |
|
||||
|
|
||||
await fse.rename('../lerna.json', '../lerna.version.json'); |
|
||||
|
|
||||
await execa('yarn', ['replace-with-tilde']); |
|
||||
} |
|
||||
Loading…
Reference in new issue