Skip to content

Commit

Permalink
feat: move sdk gen clis from core to shematics
Browse files Browse the repository at this point in the history
  • Loading branch information
mrednic-1A committed Jun 18, 2024
1 parent 6620e3a commit 288937c
Show file tree
Hide file tree
Showing 26 changed files with 66 additions and 51 deletions.
1 change: 0 additions & 1 deletion packages/@ama-sdk/core/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {
'tsconfig.build.json',
'tsconfig.builders.json',
'tsconfig.spec.json',
'tsconfig.cli.json',
'tsconfig.eslint.json'
],
'sourceType': 'module'
Expand Down
13 changes: 1 addition & 12 deletions packages/@ama-sdk/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,11 @@
"build:esm2020": "tsc -b tsconfig.build.json",
"postbuild": "yarn cpy './package.json' dist && patch-package-json-main",
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' dist/schematics && yarn cpy 'collection.json' dist",
"build:cli": "tsc -b tsconfig.cli.json --pretty && yarn generate-cjs-manifest",
"build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest",
"prepare:publish": "prepare-publish ./dist"
},
"dependencies": {
"@swc/helpers": "~0.5.0",
"chokidar": "^3.5.2",
"minimist": "^1.2.6",
"tslib": "^2.6.2",
"uuid": "^9.0.0"
},
Expand All @@ -84,7 +81,6 @@
"@angular/common": "~17.3.0",
"@o3r/schematics": "workspace:^",
"@schematics/angular": "~17.3.0",
"globby": "^11.1.0",
"isomorphic-fetch": "^3.0.0",
"rxjs": "^7.8.1",
"typescript": "~5.4.2"
Expand Down Expand Up @@ -131,7 +127,6 @@
"@swc/cli": "~0.3.0",
"@swc/core": "~1.5.24",
"@types/jest": "~29.5.2",
"@types/minimist": "^1.2.2",
"@types/node": "^20.0.0",
"@types/uuid": "^9.0.0",
"@typescript-eslint/eslint-plugin": "^7.2.0",
Expand All @@ -144,7 +139,6 @@
"eslint-plugin-jsdoc": "~48.2.1",
"eslint-plugin-prefer-arrow": "~1.2.3",
"eslint-plugin-unicorn": "^51.0.1",
"globby": "^11.1.0",
"isomorphic-fetch": "~3.0.0",
"jest": "~29.7.0",
"jest-junit": "~16.0.0",
Expand All @@ -163,10 +157,5 @@
"engines": {
"node": ">=18.0.0"
},
"schematics": "./collection.json",
"bin": {
"amasdk-clear-index": "./dist/cli/clear-index.cjs",
"amasdk-files-pack": "./dist/cli/files-pack.cjs",
"amasdk-update-spec-from-npm": "./dist/cli/update-spec-from-npm.cjs"
}
"schematics": "./collection.json"
}
9 changes: 1 addition & 8 deletions packages/@ama-sdk/core/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"build-builders",
"compile",
"build-esm2015",
"build-cjs",
"build-cli"
"build-cjs"
]
},
"build-esm2015": {
Expand Down Expand Up @@ -79,12 +78,6 @@
"options": {
"script": "build:builders"
}
},
"build-cli": {
"executor": "nx:run-script",
"options": {
"script": "build:cli"
}
}
},
"tags": []
Expand Down
1 change: 0 additions & 1 deletion packages/@ama-sdk/core/src/fwk/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ export * from './errors';
export * from './ignore-enum.type';
export * from './logger';
export * from './mocks/index';
export * from './open-api-tools-configuration';
export * from './Reviver';
1 change: 0 additions & 1 deletion packages/@ama-sdk/core/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export * from './ie11';
export * from './json-token';
export * from './mime-types';
export * from './generic-api';
export * from './generators';
3 changes: 0 additions & 3 deletions packages/@ama-sdk/core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
},
{
"path": "./tsconfig.build.json"
},
{
"path": "./tsconfig.cli.json"
}
]
}
2 changes: 1 addition & 1 deletion packages/@ama-sdk/create/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { execSync, spawnSync } from 'node:child_process';
import { dirname, extname, join, parse, relative, resolve } from 'node:path';
import * as minimist from 'minimist';
import { LOCAL_SPEC_FILENAME, SPEC_JSON_EXTENSION, SPEC_YAML_EXTENSION } from '@ama-sdk/core';
import { LOCAL_SPEC_FILENAME, SPEC_JSON_EXTENSION, SPEC_YAML_EXTENSION } from '@ama-sdk/schematics';

const packageManagerEnv = process.env.npm_config_user_agent?.split('/')[0];
const binPath = resolve(require.resolve('@angular-devkit/schematics-cli/package.json'), '../bin/schematics.js');
Expand Down
3 changes: 2 additions & 1 deletion packages/@ama-sdk/schematics/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
'project': [
'tsconfig.builders.json',
'tsconfig.spec.json',
'tsconfig.eslint.json'
'tsconfig.eslint.json',
'tsconfig.cli.json'
],
'sourceType': 'module'
},
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { createRequire } from 'node:module';
import { extname, posix } from 'node:path';
import { copyFile, readFile } from 'node:fs/promises';
import type { PackageJson } from 'type-fest';
import type { OpenApiToolsConfiguration, OpenApiToolsGenerator } from '@ama-sdk/core';
import { LOCAL_SPEC_FILENAME, SPEC_JSON_EXTENSION, SPEC_YAML_EXTENSION } from '@ama-sdk/core';
import type { OpenApiToolsConfiguration, OpenApiToolsGenerator } from '@ama-sdk/schematics';
import { LOCAL_SPEC_FILENAME, SPEC_JSON_EXTENSION, SPEC_YAML_EXTENSION } from '@ama-sdk/schematics';

const argv = minimist(process.argv.slice(2));
const packageName = argv._[0];
Expand Down
14 changes: 13 additions & 1 deletion packages/@ama-sdk/schematics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,28 @@
},
"description": "Swagger specification SDK Generator by schematics",
"typings": "./src/public_api.d.ts",
"main": "./src/public_api.js",
"types": "./src/public_api.d.ts",
"scripts": {
"nx": "nx",
"ng": "yarn nx",
"test": "yarn nx test ama-sdk-schematics",
"prepare:build:builders": "yarn cpy 'schematics/**/*.json' 'schematics/**/templates/**' 'schematics/**/*.jar' dist/schematics && yarn cpy '{package,collection,migration}.json' dist",
"build": "yarn nx build ama-sdk-schematics",
"postbuild": "patch-package-json-main",
"build:builders": "tsc -b tsconfig.builders.json --pretty && yarn generate-cjs-manifest",
"install-swagger-cli": "mvn install:install-file -DgroupId=io.swagger -DartifactId=swagger-codegen-cli -Dversion=2.4.0-AMADEUS -Dpackaging=jar -Dfile=./schematics/resources/swagger-codegen-cli.jar",
"build:swagger": "yarn install-swagger-cli && run-p 'build:swagger-*' 'build:openapi-*'",
"build:openapi-typescript-gen": "mvn clean package -f ./schematics/typescript/core/openapi-codegen-typescript/pom.xml",
"build:swagger-java-client-gen": "mvn clean package -f ./schematics/java/client-core/swagger-codegen-java-client/pom.xml",
"build:cli": "tsc -b tsconfig.cli.json --pretty && yarn generate-cjs-manifest",
"prepare:publish": "prepare-publish ./dist"
},
"bin": {
"amasdk-clear-index": "./dist/cli/clear-index.cjs",
"amasdk-files-pack": "./dist/cli/files-pack.cjs",
"amasdk-update-spec-from-npm": "./dist/cli/update-spec-from-npm.cjs"
},
"ng-update": {
"migrations": "./migration.json",
"packageGroup": [
Expand Down Expand Up @@ -60,8 +69,11 @@
"dependencies": {
"@angular-devkit/core": "~17.3.0",
"@angular-devkit/schematics": "~17.3.0",
"chokidar": "^3.5.2",
"globby": "^11.1.0",
"js-yaml": "^4.1.0",
"minimatch": "~9.0.3",
"minimist": "^1.2.6",
"rxjs": "^7.8.1",
"semver": "^7.5.2",
"tslib": "^2.6.2"
Expand All @@ -83,6 +95,7 @@
"@types/jest": "~29.5.2",
"@types/js-yaml": "^4.0.5",
"@types/minimatch": "^5.1.2",
"@types/minimist": "^1.2.2",
"@types/node": "^20.0.0",
"@types/pid-from-port": "^1.1.0",
"@types/semver": "^7.3.13",
Expand All @@ -97,7 +110,6 @@
"eslint-plugin-jsdoc": "~48.2.1",
"eslint-plugin-prefer-arrow": "~1.2.3",
"eslint-plugin-unicorn": "^51.0.1",
"globby": "^11.1.0",
"isomorphic-fetch": "~3.0.0",
"jest": "~29.7.0",
"jest-junit": "~16.0.0",
Expand Down
20 changes: 18 additions & 2 deletions packages/@ama-sdk/schematics/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@
"prefix": "o3r",
"targets": {
"build": {
"executor": "nx:noop",
"dependsOn": ["build-builders"]
"executor": "nx:run-script",
"outputs": ["{projectRoot}/dist/package.json"],
"options": {
"script": "postbuild"
},
"dependsOn": [
"build-builders",
"build-cli"
]
},
"prepare-build-builders": {
"executor": "nx:run-script",
Expand All @@ -32,6 +39,15 @@
"script": "build:builders"
}
},
"build-cli": {
"executor": "nx:run-script",
"options": {
"script": "build:cli"
},
"dependsOn": [
"build-builders"
]
},
"lint": {
"options": {
"eslintConfig": "packages/@ama-sdk/schematics/.eslintrc.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/@ama-sdk/schematics/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OpenApiToolsConfiguration } from '@ama-sdk/core';
import type { OpenApiToolsConfiguration } from '../helpers/open-api-tools-configuration';
import { isJsonObject } from '@angular-devkit/core';
import { chain, externalSchematic, Rule, SchematicContext, Tree } from '@angular-devkit/schematics';
import * as path from 'node:path';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ The following scripts of this folder are not used anymore, if there is no custom
*/
export const addCpyDependencies = (): Rule => async (_, context) => {
const amaSdkSchematicsPackageJson = await readPackageJson();
context.addTask(new DevInstall({ packageName: `globby@${amaSdkSchematicsPackageJson.devDependencies!.globby as string}` }));
context.addTask(new DevInstall({ packageName: `globby@${amaSdkSchematicsPackageJson.dependencies!.globby as string}` }));
context.addTask(new DevInstall({ packageName: `cpy-cli@${amaSdkSchematicsPackageJson.devDependencies!['cpy-cli'] as string}` }));
return noop;
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { OpenApiToolsConfiguration } from '@ama-sdk/core';
import type { OpenApiToolsConfiguration } from '@ama-sdk/schematics';
import { Tree } from '@angular-devkit/schematics';
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
import * as path from 'node:path';
import { LOCAL_SPEC_FILENAME, SPEC_JSON_EXTENSION, SPEC_YAML_EXTENSION } from '@ama-sdk/core';
import { LOCAL_SPEC_FILENAME, SPEC_JSON_EXTENSION, SPEC_YAML_EXTENSION } from '@ama-sdk/schematics';
import type { JsonObject } from 'type-fest';

const collectionPath = path.join(__dirname, '..', '..', '..', 'collection.json');
Expand Down Expand Up @@ -35,6 +35,7 @@ describe('Typescript Core Generator', () => {
const tree = await runner.runSchematic('typescript-core', {
specPath: path.join(__dirname, '..', '..', '..', 'testing', 'MOCK_swagger.yaml')
}, baseTree);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-redundant-type-constituents
const content = tree.readJson('/openapitools.json') as JsonObject & OpenApiToolsConfiguration;

expect(content['generator-cli'].generators['test-sdk-sdk'].inputSpec.endsWith(`${LOCAL_SPEC_FILENAME}.${SPEC_YAML_EXTENSION}`)).toBe(true);
Expand All @@ -46,6 +47,7 @@ describe('Typescript Core Generator', () => {
const tree = await runner.runSchematic('typescript-core', {
specPath: path.join(__dirname, '..', '..', '..', 'testing', 'MOCK_swagger.json')
}, baseTree);
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-redundant-type-constituents
const content = tree.readJson('/openapitools.json') as JsonObject & OpenApiToolsConfiguration;

expect(content['generator-cli'].generators['test-sdk-sdk'].inputSpec.endsWith(`${LOCAL_SPEC_FILENAME}.${SPEC_JSON_EXTENSION}`)).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { OpenApiToolsConfiguration, OpenApiToolsGenerator, PathObject } from '@ama-sdk/core';
import { LOCAL_SPEC_FILENAME, SPEC_JSON_EXTENSION, SPEC_YAML_EXTENSION } from '@ama-sdk/core';
import type { PathObject } from '@ama-sdk/core';
import type { OpenApiToolsConfiguration, OpenApiToolsGenerator } from '../../helpers/open-api-tools-configuration';
import { LOCAL_SPEC_FILENAME, SPEC_JSON_EXTENSION, SPEC_YAML_EXTENSION } from '../../helpers/generators';
import {
apply,
chain,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { OpenApiToolsConfiguration } from '@ama-sdk/core';
import type { OpenApiToolsConfiguration } from '@ama-sdk/schematics';
import {Tree} from '@angular-devkit/schematics';
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
import * as path from 'node:path';
Expand Down Expand Up @@ -99,6 +99,7 @@ describe('Typescript Shell Generator', () => {
});

it('should generate correct openapitools.json', () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-redundant-type-constituents
const openApiTools = yarnTree.readJson('/openapitools.json') as JsonObject & OpenApiToolsConfiguration;
// eslint-disable-next-line @typescript-eslint/naming-convention
expect(openApiTools['generator-cli'].generators).toEqual(expect.objectContaining({'test-scope-test-sdk': expect.anything()}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function ngGenerateTypescriptSDKFn(options: NgGenerateTypescriptSDKShellSchemati
'eslint-plugin-prefer-arrow': amaSdkSchematicsPackageJson.devDependencies!['eslint-plugin-prefer-arrow'],
'eslint-plugin-unicorn': amaSdkSchematicsPackageJson.devDependencies!['eslint-plugin-unicorn'],
'eslint': amaSdkSchematicsPackageJson.devDependencies!.eslint,
'globby': amaSdkSchematicsPackageJson.devDependencies!.globby,
'globby': amaSdkSchematicsPackageJson.dependencies!.globby,
'isomorphic-fetch': amaSdkSchematicsPackageJson.devDependencies!['isomorphic-fetch'],
'jest': amaSdkSchematicsPackageJson.devDependencies!.jest,
'rxjs': amaSdkSchematicsPackageJson.dependencies!.rxjs,
Expand Down
4 changes: 4 additions & 0 deletions packages/@ama-sdk/schematics/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export * from '../schematics/helpers/generators';
export type * from '../schematics/helpers/open-api-tools-configuration';
export type * from '../schematics/typescript/core/schema';
export type * from '../schematics/typescript/mock/schema';
export type * from '../schematics/typescript/shell/schema';


Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
},
"references": [
{
"path": "./tsconfig.build.json"
"path": "./tsconfig.builders.json"
}
],
"include": [
Expand Down
3 changes: 3 additions & 0 deletions packages/@ama-sdk/schematics/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
},
{
"path": "./tsconfig.spec.json"
},
{
"path": "./tsconfig.cli.json"
}
]
}
2 changes: 1 addition & 1 deletion tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"packages/@ama-sdk/create"
],
"@ama-sdk/schematics": [
"packages/@ama-sdk/schematics"
"packages/@ama-sdk/schematics/src/public_api"
],
"@ama-sdk/showcase-sdk": [
"packages/@ama-sdk/showcase-sdk/src"
Expand Down
Loading

0 comments on commit 288937c

Please sign in to comment.