@ama-sdk/schematics 9.0.0-alpha.9 → 9.1.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -14
- package/collection.json +0 -6
- package/package.json +15 -9
- package/schematics/code-generator/code-generator.d.ts +3 -1
- package/schematics/code-generator/code-generator.d.ts.map +1 -1
- package/schematics/code-generator/code-generator.js +2 -0
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.generator.d.ts +6 -2
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.generator.d.ts.map +1 -1
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.generator.js +13 -7
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.options.d.ts +2 -2
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.options.d.ts.map +1 -1
- package/schematics/code-generator/open-api-cli-generator/open-api-cli.options.js +2 -2
- package/schematics/code-generator/swagger-java-generator/swagger-java.options.js +1 -1
- package/schematics/helpers/node-install.d.ts +62 -0
- package/schematics/helpers/node-install.d.ts.map +1 -0
- package/schematics/helpers/node-install.js +67 -0
- package/schematics/java/client-core/index.js +2 -2
- package/schematics/java/client-core/schema.d.ts +1 -1
- package/schematics/java/client-core/schema.d.ts.map +1 -1
- package/schematics/java/client-core/schema.json +2 -2
- package/schematics/java/client-core/swagger-codegen-java-client/target/javaClient-swagger-codegen-tests.jar +0 -0
- package/schematics/java/client-core/swagger-codegen-java-client/target/javaClient-swagger-codegen.jar +0 -0
- package/schematics/ng-add/index.d.ts.map +1 -1
- package/schematics/ng-add/index.js +108 -54
- package/schematics/typescript/core/index.d.ts.map +1 -1
- package/schematics/typescript/core/index.js +19 -14
- package/schematics/typescript/core/openapi-codegen-typescript/target/typescriptFetch-openapi-generator-tests.jar +0 -0
- package/schematics/typescript/core/openapi-codegen-typescript/target/typescriptFetch-openapi-generator.jar +0 -0
- package/schematics/typescript/core/schema.d.ts +6 -0
- package/schematics/typescript/core/schema.d.ts.map +1 -1
- package/schematics/typescript/core/schema.json +20 -0
- package/schematics/typescript/shell/index.d.ts.map +1 -1
- package/schematics/typescript/shell/index.js +31 -3
- package/schematics/typescript/shell/schema.d.ts +6 -0
- package/schematics/typescript/shell/schema.d.ts.map +1 -1
- package/schematics/typescript/shell/schema.json +20 -1
- package/schematics/typescript/shell/templates/base/.gitignore.template +68 -0
- package/schematics/typescript/shell/templates/base/.vscode/settings.json +20 -0
- package/schematics/typescript/shell/templates/base/jest.config.js +1 -1
- package/schematics/typescript/shell/templates/base/openapitools.json +2 -1
- package/schematics/typescript/shell/templates/base/{package.json → package.json.template} +2 -2
- package/schematics/typescript/create/index.d.ts +0 -9
- package/schematics/typescript/create/index.d.ts.map +0 -1
- package/schematics/typescript/create/index.js +0 -17
- package/schematics/typescript/create/schema.d.ts +0 -5
- package/schematics/typescript/create/schema.d.ts.map +0 -1
- package/schematics/typescript/create/schema.js +0 -3
- package/schematics/typescript/create/schema.json +0 -40
- package/schematics/typescript/shell/templates/base/.yarnrc.yml +0 -6
- /package/schematics/typescript/shell/templates/base/{.eslintignore → .eslintignore.template} +0 -0
- /package/schematics/typescript/shell/templates/base/{.eslintrc.js → .eslintrc.js.template} +0 -0
- /package/schematics/typescript/shell/templates/base/{.openapi-codegen-ignore → .openapi-generator-ignore} +0 -0
|
@@ -2,39 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ngAdd = exports.updatePackageJsonScripts = void 0;
|
|
4
4
|
const core_1 = require("@angular-devkit/core");
|
|
5
|
-
const tasks_1 = require("@angular-devkit/schematics/tasks");
|
|
6
5
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
7
|
-
const options_1 = require("@angular-devkit/schematics/tasks/package-manager/options");
|
|
8
6
|
const path = require("node:path");
|
|
9
7
|
const node_fs_1 = require("node:fs");
|
|
10
8
|
const rxjs_1 = require("rxjs");
|
|
9
|
+
const node_install_1 = require("../helpers/node-install");
|
|
11
10
|
const packageJsonPath = '/package.json';
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* Note: it should not be moved to other packages as it should run before the installation
|
|
16
|
-
* of peer dependencies
|
|
17
|
-
*/
|
|
18
|
-
class DevInstall extends tasks_1.NodePackageInstallTask {
|
|
19
|
-
constructor() {
|
|
20
|
-
super(...arguments);
|
|
21
|
-
this.quiet = false;
|
|
22
|
-
}
|
|
23
|
-
/** @inheritdoc */
|
|
24
|
-
toConfiguration() {
|
|
25
|
-
const installOptions = process.env && process.env.npm_execpath && process.env.npm_execpath.indexOf('yarn') === -1 ? 'npm' : 'yarn';
|
|
26
|
-
return {
|
|
27
|
-
name: options_1.NodePackageName,
|
|
28
|
-
options: {
|
|
29
|
-
command: 'install',
|
|
30
|
-
quiet: this.quiet,
|
|
31
|
-
workingDirectory: this.workingDirectory,
|
|
32
|
-
packageName: `${this.packageName} ${installOptions === 'yarn' ? '--prefer-dev' : '-D'}`,
|
|
33
|
-
packageManager: installOptions
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
}
|
|
11
|
+
const swaggerIgnorePath = '/.swagger-codegen-ignore';
|
|
12
|
+
const openApiIgnorePath = '/.openapi-generator-ignore';
|
|
13
|
+
const openApiConfigPath = 'openapitools.json';
|
|
38
14
|
/**
|
|
39
15
|
* Rule to update package.json scripts using yeoman generator from `@ama-sdk/generator-sdk`
|
|
40
16
|
*
|
|
@@ -54,18 +30,19 @@ const updatePackageJsonScripts = (tree, context) => {
|
|
|
54
30
|
const scripts = Object.entries(packageJson.scripts).reduce((acc, [scriptName, cmd]) => {
|
|
55
31
|
if (typeof cmd === 'string') {
|
|
56
32
|
acc[scriptName] = cmd
|
|
33
|
+
.replace(
|
|
34
|
+
// Remove swagger config path if it is the default value
|
|
35
|
+
// eslint-disable-next-line max-len
|
|
36
|
+
/ --(swagger-config-path|swaggerConfigPath)[= ]?(\.\/)?node_modules\/@ama-sdk\/generator-sdk\/src\/generators\/java-client-core\/templates\/swagger-codegen-java-client\/config\/swagger-codegen-config.json/, '')
|
|
57
37
|
.replace(/\byo\b/g, 'schematics') // Migrate from yeoman to schematics
|
|
58
38
|
.replace(
|
|
59
39
|
// Change generator path to schematics collection:name
|
|
60
|
-
/(\$\(yarn resolve
|
|
40
|
+
/(\$\(yarn resolve )?(\.?\/?node_modules\/)?@ama-sdk\/generator-sdk\/(src\/)?generators\/([\w-]+)\)?(\s)?/g, '@ama-sdk/schematics:$4$5')
|
|
61
41
|
.replace(/@ama-sdk\/generator-sdk\/(src\/)?generators/g, '@ama-sdk/schematics/schematics') // Change relative path for swaggerConfigPath
|
|
62
42
|
.replace(/(@ama-sdk\/schematics\/schematics\/)java-client-core/g, '$1java/client-core') // Change java client core path
|
|
63
43
|
.replace(/@ama-sdk\/(schematics|generator-sdk):(core|shell|create|mock)/g, '@ama-sdk/schematics:typescript-$2') // Change typescript schematics name
|
|
64
|
-
.replaceAll(
|
|
65
|
-
.replaceAll('--swaggerConfigPath', '--
|
|
66
|
-
.replace(
|
|
67
|
-
// Remove swagger config path if it is the default value
|
|
68
|
-
/ --swagger-config-path[= ]?(\.\/)?node_modules\/@ama-sdk\/schematics\/schematics\/java\/client-core\/templates\/swagger-codegen-java-client\/config\/swagger-codegen-config.json/, '');
|
|
44
|
+
.replaceAll(/--(swaggerSpecPath|swagger-spec-path)/g, '--spec-path') // Schematics arguments should be kebab-case
|
|
45
|
+
.replaceAll('--swaggerConfigPath', '--spec-config-path'); // Schematics arguments should be kebab-case
|
|
69
46
|
}
|
|
70
47
|
return acc;
|
|
71
48
|
}, packageJson.scripts);
|
|
@@ -74,33 +51,110 @@ const updatePackageJsonScripts = (tree, context) => {
|
|
|
74
51
|
return tree;
|
|
75
52
|
};
|
|
76
53
|
exports.updatePackageJsonScripts = updatePackageJsonScripts;
|
|
54
|
+
/**
|
|
55
|
+
* Create or udpate the OpenApi configuration with the version supported by the application
|
|
56
|
+
* Set a storage directory for the generator jar to avoid any issue with pnp setups as it would try to install it directly in the node_module
|
|
57
|
+
*
|
|
58
|
+
* @param tree
|
|
59
|
+
*/
|
|
60
|
+
const createOpenApiToolsConfig = (tree) => {
|
|
61
|
+
const amaSdkSchematicsPackageJsonContent = JSON.parse((0, node_fs_1.readFileSync)(path.resolve(__dirname, '..', '..', 'package.json'), { encoding: 'utf-8' }));
|
|
62
|
+
const openApiGeneratorVersion = amaSdkSchematicsPackageJsonContent.openApiSupportedVersion.replace(/\^|~/, '');
|
|
63
|
+
const openApiDefaultStorageDir = '.openapi-generator';
|
|
64
|
+
if (tree.exists(openApiConfigPath)) {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
66
|
+
const openapitoolsConfig = tree.readJson(openApiConfigPath) || {};
|
|
67
|
+
openapitoolsConfig['generator-cli'] = { storageDir: openApiDefaultStorageDir, ...openapitoolsConfig['generator-cli'], version: openApiGeneratorVersion };
|
|
68
|
+
tree.overwrite(openApiConfigPath, JSON.stringify(openapitoolsConfig));
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
tree.create(openApiConfigPath, JSON.stringify({
|
|
72
|
+
$schema: 'https://raw.githubusercontent.com/OpenAPITools/openapi-generator-cli/master/apps/generator-cli/src/config.schema.json',
|
|
73
|
+
spaces: 2,
|
|
74
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
75
|
+
'generator-cli': {
|
|
76
|
+
version: openApiGeneratorVersion,
|
|
77
|
+
storageDir: openApiDefaultStorageDir
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
return tree;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Install the npm open api generator cli package
|
|
85
|
+
*
|
|
86
|
+
* @param tree
|
|
87
|
+
* @param context
|
|
88
|
+
*/
|
|
89
|
+
const installOpenApiToolsCli = async (tree, context) => {
|
|
90
|
+
const packageJsonContent = tree.readJson(packageJsonPath);
|
|
91
|
+
const amaSdkSchematicsPackageJsonContent = JSON.parse((0, node_fs_1.readFileSync)(path.resolve(__dirname, '..', '..', 'package.json'), { encoding: 'utf-8' }));
|
|
92
|
+
const amaSdkSchematicsOpenApiCliVersion = amaSdkSchematicsPackageJsonContent.peerDependencies?.['@openapitools/openapi-generator-cli'] || '';
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
94
|
+
packageJsonContent.devDependencies = { ...packageJsonContent.devDependencies, '@openapitools/openapi-generator-cli': amaSdkSchematicsOpenApiCliVersion };
|
|
95
|
+
context.addTask(new node_install_1.DevInstall({
|
|
96
|
+
packageName: `@openapitools/openapi-generator-cli@${amaSdkSchematicsOpenApiCliVersion}`,
|
|
97
|
+
hideOutput: false,
|
|
98
|
+
quiet: false
|
|
99
|
+
}));
|
|
100
|
+
await (0, rxjs_1.lastValueFrom)(context.engine.executePostTasks());
|
|
101
|
+
tree.overwrite(packageJsonPath, JSON.stringify(packageJsonContent, null, 2));
|
|
102
|
+
return () => tree;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Replace the swagger ignore file with an openapi one
|
|
106
|
+
*
|
|
107
|
+
* @param tree
|
|
108
|
+
*/
|
|
109
|
+
const replaceSwaggerIgnore = (tree) => {
|
|
110
|
+
const swaggerIgnoreContent = tree.exists(swaggerIgnorePath) && tree.readText(swaggerIgnorePath);
|
|
111
|
+
if (swaggerIgnoreContent && !tree.exists(openApiIgnorePath)) {
|
|
112
|
+
tree.create(openApiIgnorePath, swaggerIgnoreContent);
|
|
113
|
+
tree.delete(swaggerIgnorePath);
|
|
114
|
+
}
|
|
115
|
+
return tree;
|
|
116
|
+
};
|
|
117
|
+
const registerPackageSchematics = async (tree, context) => {
|
|
118
|
+
if (!tree.exists('angular.json')) {
|
|
119
|
+
return () => tree;
|
|
120
|
+
}
|
|
121
|
+
const amaSdkSchematicsPackageJsonContent = JSON.parse((0, node_fs_1.readFileSync)(path.resolve(__dirname, '..', '..', 'package.json'), { encoding: 'utf-8' }));
|
|
122
|
+
const amaSdkSchematicsVersion = amaSdkSchematicsPackageJsonContent.version?.replace(/^v/, '');
|
|
123
|
+
const schematicsDependencies = ['@o3r/dev-tools', '@o3r/schematics'];
|
|
124
|
+
for (const dependency of schematicsDependencies) {
|
|
125
|
+
context.addTask(new node_install_1.DevInstall({
|
|
126
|
+
packageName: dependency + (amaSdkSchematicsVersion ? `@${amaSdkSchematicsVersion}` : ''),
|
|
127
|
+
hideOutput: false,
|
|
128
|
+
quiet: false
|
|
129
|
+
}));
|
|
130
|
+
const packageJsonContent = tree.readJson('package.json');
|
|
131
|
+
packageJsonContent.devDependencies = { ...packageJsonContent.devDependencies, [dependency]: amaSdkSchematicsVersion };
|
|
132
|
+
tree.overwrite('package.json', JSON.stringify(packageJsonContent, null, 2));
|
|
133
|
+
await (0, rxjs_1.lastValueFrom)(context.engine.executePostTasks());
|
|
134
|
+
}
|
|
135
|
+
return () => (0, schematics_1.chain)([
|
|
136
|
+
...schematicsDependencies.map((dep) => (0, schematics_1.externalSchematic)(dep, 'ng-add', {})),
|
|
137
|
+
async (t, c) => {
|
|
138
|
+
const { registerPackageCollectionSchematics } = await Promise.resolve().then(() => require('@o3r/schematics'));
|
|
139
|
+
return () => registerPackageCollectionSchematics(amaSdkSchematicsPackageJsonContent)(t, c);
|
|
140
|
+
}
|
|
141
|
+
]);
|
|
142
|
+
};
|
|
77
143
|
/**
|
|
78
144
|
* Add Otter ama-sdk-schematics to a Project
|
|
79
145
|
*
|
|
80
146
|
* @param options
|
|
81
147
|
*/
|
|
82
148
|
function ngAdd() {
|
|
83
|
-
return
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
hideOutput: false,
|
|
91
|
-
quiet: false
|
|
92
|
-
}));
|
|
93
|
-
await (0, rxjs_1.lastValueFrom)(context.engine.executePostTasks());
|
|
149
|
+
return (tree, context) => (0, schematics_1.chain)([
|
|
150
|
+
registerPackageSchematics,
|
|
151
|
+
exports.updatePackageJsonScripts,
|
|
152
|
+
(t) => {
|
|
153
|
+
const packageJson = tree.readText(packageJsonPath);
|
|
154
|
+
const needsToInstallOpenApiGeneratorCli = /@ama-sdk\/schematics:typescript-/.test(packageJson);
|
|
155
|
+
return needsToInstallOpenApiGeneratorCli ? (0, schematics_1.chain)([replaceSwaggerIgnore, installOpenApiToolsCli, createOpenApiToolsConfig]) : t;
|
|
94
156
|
}
|
|
95
|
-
|
|
96
|
-
...schematicsDependencies.map((dep) => (0, schematics_1.externalSchematic)(dep, 'ng-add', {})),
|
|
97
|
-
async (t, c) => {
|
|
98
|
-
const { registerPackageCollectionSchematics } = await Promise.resolve().then(() => require('@o3r/schematics'));
|
|
99
|
-
return () => registerPackageCollectionSchematics(amaSdkSchematicsPackageJsonContent)(t, c);
|
|
100
|
-
},
|
|
101
|
-
exports.updatePackageJsonScripts
|
|
102
|
-
])(tree, context);
|
|
103
|
-
};
|
|
157
|
+
])(tree, context);
|
|
104
158
|
}
|
|
105
159
|
exports.ngAdd = ngAdd;
|
|
106
160
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,IAAI,EAKL,MAAM,4BAA4B,CAAC;AASpC,OAAO,EAAE,2CAA2C,EAAE,MAAM,UAAU,CAAC;AAgBvE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,2CAA2C,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,IAAI,EAKL,MAAM,4BAA4B,CAAC;AASpC,OAAO,EAAE,2CAA2C,EAAE,MAAM,UAAU,CAAC;AAgBvE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,2CAA2C,GAAG,IAAI,CA+GlG"}
|
|
@@ -12,7 +12,7 @@ const getRegexpTemplate = (regexp) => `new RegExp('${regexp.toString().replace(/
|
|
|
12
12
|
const getPathObjectTemplate = (pathObj) => {
|
|
13
13
|
return `{
|
|
14
14
|
${Object.keys(pathObj).map((propName) => {
|
|
15
|
-
const value = propName === 'regexp' ? getRegexpTemplate(pathObj[propName]) : JSON.stringify(pathObj[propName]);
|
|
15
|
+
const value = (propName) === 'regexp' ? getRegexpTemplate(pathObj[propName]) : JSON.stringify(pathObj[propName]);
|
|
16
16
|
return `${propName}: ${value}`;
|
|
17
17
|
}).join(',')}
|
|
18
18
|
}`;
|
|
@@ -24,6 +24,7 @@ const getPathObjectTemplate = (pathObj) => {
|
|
|
24
24
|
*/
|
|
25
25
|
function ngGenerateTypescriptSDK(options) {
|
|
26
26
|
const specPath = path.resolve(process.cwd(), options.specPath);
|
|
27
|
+
const targetPath = options.directory || '/';
|
|
27
28
|
const generateOperationFinder = async () => {
|
|
28
29
|
const swayOptions = {
|
|
29
30
|
definition: path.resolve(options.specPath)
|
|
@@ -49,10 +50,10 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
49
50
|
* @param _context
|
|
50
51
|
*/
|
|
51
52
|
const clearGeneratedCode = (tree, _context) => {
|
|
52
|
-
(0, tree_glob_1.treeGlob)(tree, path.join('src', 'api', '**', '*.ts')).forEach((file) => tree.delete(file));
|
|
53
|
-
(0, tree_glob_1.treeGlob)(tree, path.join('src', 'api', '**', '*.ts')).forEach((file) => tree.delete(file));
|
|
54
|
-
(0, tree_glob_1.treeGlob)(tree, path.join('src', 'models', 'base', '**', '!(index).ts')).forEach((file) => tree.delete(file));
|
|
55
|
-
(0, tree_glob_1.treeGlob)(tree, path.join('src', 'spec', '!(operation-adapter|index).ts')).forEach((file) => tree.delete(file));
|
|
53
|
+
(0, tree_glob_1.treeGlob)(tree, path.join(targetPath, 'src', 'api', '**', '*.ts')).forEach((file) => tree.delete(file));
|
|
54
|
+
(0, tree_glob_1.treeGlob)(tree, path.join(targetPath, 'src', 'api', '**', '*.ts')).forEach((file) => tree.delete(file));
|
|
55
|
+
(0, tree_glob_1.treeGlob)(tree, path.join(targetPath, 'src', 'models', 'base', '**', '!(index).ts')).forEach((file) => tree.delete(file));
|
|
56
|
+
(0, tree_glob_1.treeGlob)(tree, path.join(targetPath, 'src', 'spec', '!(operation-adapter|index).ts')).forEach((file) => tree.delete(file));
|
|
56
57
|
return tree;
|
|
57
58
|
};
|
|
58
59
|
/**
|
|
@@ -70,7 +71,7 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
70
71
|
swayOperationAdapter,
|
|
71
72
|
empty: ''
|
|
72
73
|
}),
|
|
73
|
-
(0, schematics_1.move)(
|
|
74
|
+
(0, schematics_1.move)(targetPath),
|
|
74
75
|
(0, schematics_1.renameTemplateFiles)()
|
|
75
76
|
]), schematics_1.MergeStrategy.Overwrite);
|
|
76
77
|
};
|
|
@@ -81,19 +82,20 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
81
82
|
* @param _context
|
|
82
83
|
*/
|
|
83
84
|
const updateSpec = (tree, _context) => {
|
|
85
|
+
const readmeFile = path.join(targetPath, 'readme.md');
|
|
84
86
|
const specContent = (0, node_fs_1.readFileSync)(specPath).toString();
|
|
85
|
-
if (tree.exists(
|
|
87
|
+
if (tree.exists(readmeFile)) {
|
|
86
88
|
const swaggerVersion = /version: ([0-9]+\.[0-9]+\.[0-9]+)/.exec(specContent);
|
|
87
89
|
if (swaggerVersion) {
|
|
88
|
-
const readmeContent = tree.read(
|
|
89
|
-
tree.overwrite(
|
|
90
|
+
const readmeContent = tree.read(readmeFile).toString('utf8');
|
|
91
|
+
tree.overwrite(readmeFile, readmeContent.replace(/Based on Swagger spec .*/i, `Based on Swagger spec ${swaggerVersion[1]}`));
|
|
90
92
|
}
|
|
91
93
|
}
|
|
92
|
-
if (tree.exists('
|
|
93
|
-
tree.overwrite('
|
|
94
|
+
if (tree.exists(path.join(targetPath, 'swagger-spec.yaml'))) {
|
|
95
|
+
tree.overwrite(path.join(targetPath, 'swagger-spec.yaml'), specContent);
|
|
94
96
|
}
|
|
95
97
|
else {
|
|
96
|
-
tree.create('
|
|
98
|
+
tree.create(path.join(targetPath, 'swagger-spec.yaml'), specContent);
|
|
97
99
|
}
|
|
98
100
|
return () => tree;
|
|
99
101
|
};
|
|
@@ -103,7 +105,7 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
103
105
|
const packageOpenApiSupportedVersion = packageJsonFile.openApiSupportedVersion?.replace(/\^|~/, '');
|
|
104
106
|
let openApiVersion = '';
|
|
105
107
|
try {
|
|
106
|
-
openApiVersion = tree.readJson('openapitools.json')?.['generator-cli']?.version;
|
|
108
|
+
openApiVersion = tree.readJson(path.join(targetPath, 'openapitools.json'))?.['generator-cli']?.version;
|
|
107
109
|
}
|
|
108
110
|
catch {
|
|
109
111
|
context.logger.warn('No openapitools.json file found in the project');
|
|
@@ -111,7 +113,10 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
111
113
|
if (!!packageOpenApiSupportedVersion && semver.valid(packageOpenApiSupportedVersion) && (!packageOpenApiSupportedVersion || !semver.satisfies(openApiVersion, packageOpenApiSupportedVersion))) {
|
|
112
114
|
generatorOptions.generatorVersion = packageOpenApiSupportedVersion;
|
|
113
115
|
}
|
|
114
|
-
|
|
116
|
+
if (options.specConfigPath) {
|
|
117
|
+
generatorOptions.specConfigPath = options.specConfigPath;
|
|
118
|
+
}
|
|
119
|
+
return () => (new open_api_cli_generator_1.OpenApiCliGenerator(options)).getGeneratorRunSchematic(generatorOptions, { rootDirectory: options.directory || undefined });
|
|
115
120
|
};
|
|
116
121
|
return (0, schematics_1.chain)([
|
|
117
122
|
clearGeneratedCode,
|
|
Binary file
|
|
Binary file
|
|
@@ -2,5 +2,11 @@ import type { JsonObject } from '@angular-devkit/core';
|
|
|
2
2
|
export interface NgGenerateTypescriptSDKCoreSchematicsSchema extends JsonObject {
|
|
3
3
|
/** Path to the swagger specification used to generate the SDK */
|
|
4
4
|
specPath: string;
|
|
5
|
+
/** Directory where to generate the SDK */
|
|
6
|
+
directory: string;
|
|
7
|
+
/** Package manager to be used in the generated SDK */
|
|
8
|
+
packageManager: 'npm' | 'yarn' | '';
|
|
9
|
+
/** Path to the spec generation configuration */
|
|
10
|
+
specConfigPath: string;
|
|
5
11
|
}
|
|
6
12
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,2CAA4C,SAAQ,UAAU;IAC7E,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,2CAA4C,SAAQ,UAAU;IAC7E,iEAAiE;IACjE,QAAQ,EAAE,MAAM,CAAC;IAEjB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAElB,sDAAsD;IACtD,cAAc,EAAE,KAAK,GAAG,MAAM,GAAG,EAAE,CAAC;IAEpC,gDAAgD;IAChD,cAAc,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -12,6 +12,26 @@
|
|
|
12
12
|
"$source": "argv",
|
|
13
13
|
"index": 0
|
|
14
14
|
}
|
|
15
|
+
},
|
|
16
|
+
"specConfigPath": {
|
|
17
|
+
"type": "string",
|
|
18
|
+
"description": "Spec config file\nMore info: https://openapi-generator.tech/docs/generators/typescript/#config-options",
|
|
19
|
+
"default": ""
|
|
20
|
+
},
|
|
21
|
+
"directory": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Directory where to generate the SDK",
|
|
24
|
+
"default": ""
|
|
25
|
+
},
|
|
26
|
+
"packageManager": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"enum": [
|
|
29
|
+
"",
|
|
30
|
+
"npm",
|
|
31
|
+
"yarn"
|
|
32
|
+
],
|
|
33
|
+
"description": "Package manager to be used in the generated SDK",
|
|
34
|
+
"default": ""
|
|
15
35
|
}
|
|
16
36
|
},
|
|
17
37
|
"additionalProperties": true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/shell/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/shell/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,IAAI,EAIL,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,4CAA4C,EAAE,MAAM,UAAU,CAAC;AAI7E;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,4CAA4C,GAAG,IAAI,CAiFnG"}
|
|
@@ -2,12 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ngGenerateTypescriptSDK = void 0;
|
|
4
4
|
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
+
const js_yaml_1 = require("js-yaml");
|
|
5
6
|
const read_package_1 = require("../../helpers/read-package");
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
|
+
const node_install_1 = require("../../helpers/node-install");
|
|
6
9
|
/**
|
|
7
10
|
* @param options
|
|
8
11
|
*/
|
|
9
12
|
function ngGenerateTypescriptSDK(options) {
|
|
10
|
-
|
|
13
|
+
const installRule = (_tree, context) => {
|
|
14
|
+
const workingDirectory = options.directory ? ((0, node_path_1.isAbsolute)(options.directory) ? (0, node_path_1.relative)(process.cwd(), options.directory) : options.directory) : '.';
|
|
15
|
+
const installTask = new node_install_1.NpmInstall({ workingDirectory, packageManager: options.packageManager, allowScripts: false });
|
|
16
|
+
context.addTask(installTask);
|
|
17
|
+
};
|
|
18
|
+
const setupRule = async (tree, context) => {
|
|
11
19
|
const amaSdkSchematicsPackageJson = await (0, read_package_1.readPackageJson)();
|
|
12
20
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
13
21
|
const versions = {
|
|
@@ -48,13 +56,33 @@ function ngGenerateTypescriptSDK(options) {
|
|
|
48
56
|
engineVersions,
|
|
49
57
|
empty: ''
|
|
50
58
|
};
|
|
59
|
+
const yarnrcPath = '.yarnrc.yml';
|
|
60
|
+
const yarnrc = ((0, js_yaml_1.load)(tree.exists(yarnrcPath) ? tree.readText(yarnrcPath) : '') || {});
|
|
61
|
+
yarnrc.nodeLinker ||= 'pnp';
|
|
62
|
+
yarnrc.packageExtensions ||= {};
|
|
63
|
+
yarnrc.packageExtensions['@ama-sdk/schematics@*'] = {
|
|
64
|
+
dependencies: {
|
|
65
|
+
'isomorphic-fetch': '~2.2.1'
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
if (tree.exists(yarnrcPath)) {
|
|
69
|
+
tree.overwrite(yarnrcPath, (0, js_yaml_1.dump)(yarnrc, { indent: 2 }));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
tree.create(yarnrcPath, (0, js_yaml_1.dump)(yarnrc, { indent: 2 }));
|
|
73
|
+
}
|
|
74
|
+
const targetPath = options.directory || tree.root.path;
|
|
51
75
|
const baseRule = (0, schematics_1.mergeWith)((0, schematics_1.apply)((0, schematics_1.url)('./templates/base'), [
|
|
52
76
|
(0, schematics_1.template)(properties),
|
|
53
|
-
(0, schematics_1.move)(
|
|
77
|
+
(0, schematics_1.move)(targetPath),
|
|
54
78
|
(0, schematics_1.renameTemplateFiles)()
|
|
55
79
|
]), schematics_1.MergeStrategy.Overwrite);
|
|
56
|
-
return baseRule;
|
|
80
|
+
return baseRule(tree, context);
|
|
57
81
|
};
|
|
82
|
+
return (0, schematics_1.chain)([
|
|
83
|
+
setupRule,
|
|
84
|
+
...(options.skipInstall ? [] : [installRule])
|
|
85
|
+
]);
|
|
58
86
|
}
|
|
59
87
|
exports.ngGenerateTypescriptSDK = ngGenerateTypescriptSDK;
|
|
60
88
|
//# sourceMappingURL=index.js.map
|
|
@@ -6,5 +6,11 @@ export interface NgGenerateTypescriptSDKShellSchematicsSchema extends JsonObject
|
|
|
6
6
|
package: string;
|
|
7
7
|
/** Project description */
|
|
8
8
|
description: string;
|
|
9
|
+
/** Directory where to generate the SDK */
|
|
10
|
+
directory: string;
|
|
11
|
+
/** Package manager to be used in the generated SDK */
|
|
12
|
+
packageManager: 'npm' | 'yarn' | '';
|
|
13
|
+
/** Skip NPM install */
|
|
14
|
+
skipInstall: boolean;
|
|
9
15
|
}
|
|
10
16
|
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/shell/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,4CAA6C,SAAQ,UAAU;IAC9E,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IAEb,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAEhB,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/shell/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,4CAA6C,SAAQ,UAAU;IAC9E,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IAEb,mBAAmB;IACnB,OAAO,EAAE,MAAM,CAAC;IAEhB,0BAA0B;IAC1B,WAAW,EAAE,MAAM,CAAC;IAEpB,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAElB,sDAAsD;IACtD,cAAc,EAAE,KAAK,GAAG,MAAM,GAAG,EAAE,CAAC;IAEpC,uBAAuB;IACvB,WAAW,EAAE,OAAO,CAAC;CACtB"}
|
|
@@ -17,9 +17,28 @@
|
|
|
17
17
|
},
|
|
18
18
|
"description": {
|
|
19
19
|
"type": "string",
|
|
20
|
-
"alias": "package",
|
|
21
20
|
"description": "Project description",
|
|
22
21
|
"default": ""
|
|
22
|
+
},
|
|
23
|
+
"directory": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"description": "Directory where to generate the SDK",
|
|
26
|
+
"default": ""
|
|
27
|
+
},
|
|
28
|
+
"skipInstall": {
|
|
29
|
+
"type": "boolean",
|
|
30
|
+
"description": "Skip NPM install",
|
|
31
|
+
"default": false
|
|
32
|
+
},
|
|
33
|
+
"packageManager": {
|
|
34
|
+
"type": "string",
|
|
35
|
+
"enum": [
|
|
36
|
+
"",
|
|
37
|
+
"npm",
|
|
38
|
+
"yarn"
|
|
39
|
+
],
|
|
40
|
+
"description": "Package manager to be used in the generated SDK",
|
|
41
|
+
"default": ""
|
|
23
42
|
}
|
|
24
43
|
},
|
|
25
44
|
"additionalProperties": true,
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Build results
|
|
2
|
+
/dist-*
|
|
3
|
+
/dist
|
|
4
|
+
/test-*
|
|
5
|
+
/test
|
|
6
|
+
/generated-*
|
|
7
|
+
/build
|
|
8
|
+
|
|
9
|
+
# Local configurations
|
|
10
|
+
.custom.yo-rc.json
|
|
11
|
+
|
|
12
|
+
# Open API
|
|
13
|
+
.openapi-generator
|
|
14
|
+
|
|
15
|
+
# Optional eslint cache
|
|
16
|
+
.eslintcache
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Intellij ###
|
|
20
|
+
.idea/
|
|
21
|
+
|
|
22
|
+
### VisualStudioCode ###
|
|
23
|
+
.vscode/*
|
|
24
|
+
!.vscode/settings.json
|
|
25
|
+
!.vscode/tasks.json
|
|
26
|
+
!.vscode/launch.json
|
|
27
|
+
!.vscode/extensions.json
|
|
28
|
+
!.vscode/*.code-snippets
|
|
29
|
+
|
|
30
|
+
# Local History for Visual Studio Code
|
|
31
|
+
.history/
|
|
32
|
+
|
|
33
|
+
# Built Visual Studio Code Extensions
|
|
34
|
+
*.vsix
|
|
35
|
+
|
|
36
|
+
### VisualStudioCode Patch ###
|
|
37
|
+
# Ignore all local history of files
|
|
38
|
+
.history
|
|
39
|
+
.ionide
|
|
40
|
+
|
|
41
|
+
# Support for Project snippet scope
|
|
42
|
+
|
|
43
|
+
### yarn ###
|
|
44
|
+
# https://yarnpkg.com/getting-started/qa#which-files-should-be-gitignored
|
|
45
|
+
|
|
46
|
+
.yarn/*
|
|
47
|
+
!.yarn/releases
|
|
48
|
+
!.yarn/patches
|
|
49
|
+
!.yarn/plugins
|
|
50
|
+
!.yarn/sdks
|
|
51
|
+
!.yarn/versions
|
|
52
|
+
|
|
53
|
+
# if you are NOT using Zero-installs, then:
|
|
54
|
+
# comment the following lines
|
|
55
|
+
.yarn/cache
|
|
56
|
+
|
|
57
|
+
# and uncomment the following lines
|
|
58
|
+
.pnp.*
|
|
59
|
+
|
|
60
|
+
### Yeoman ###
|
|
61
|
+
node_modules/
|
|
62
|
+
bower_components/
|
|
63
|
+
*.log
|
|
64
|
+
|
|
65
|
+
build/
|
|
66
|
+
dist/
|
|
67
|
+
|
|
68
|
+
# End of https://www.toptal.com/developers/gitignore/api/yeoman,visualstudiocode,yarn
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"typescript.preferences.importModuleSpecifier": "relative",
|
|
3
|
+
"typescript.preferences.quoteStyle": "single",
|
|
4
|
+
"jest.jestCommandLine": "yarn jest",
|
|
5
|
+
"jest.autoRun": {
|
|
6
|
+
"watch": false,
|
|
7
|
+
"onSave": "test-file"
|
|
8
|
+
},
|
|
9
|
+
"files.readonlyFromPermissions": true,
|
|
10
|
+
"files.readonlyInclude": {
|
|
11
|
+
"**/.cache/**": true,
|
|
12
|
+
"**/.pnp.*": true,
|
|
13
|
+
"**/.yarn/**": true,
|
|
14
|
+
"**/node_modules/**": true,
|
|
15
|
+
"src/base/*/*.ts": true
|
|
16
|
+
},
|
|
17
|
+
"files.readonlyExclude": {
|
|
18
|
+
"src/base/*/index.ts": true
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
"$schema": "https://raw.githubusercontent.com/OpenAPITools/openapi-generator-cli/master/apps/generator-cli/src/config.schema.json",
|
|
3
3
|
"spaces": 2,
|
|
4
4
|
"generator-cli": {
|
|
5
|
-
"version": "<%= openApiSupportedVersion %>"
|
|
5
|
+
"version": "<%= openApiSupportedVersion %>",
|
|
6
|
+
"storageDir": ".openapi-generator"
|
|
6
7
|
}
|
|
7
8
|
}
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"@o3r/eslint-plugin": "^<%= sdkCoreVersion %>",
|
|
83
83
|
"@openapitools/openapi-generator-cli": "<%= versions['@openapitools/openapi-generator-cli'] %>",
|
|
84
84
|
"@swc/cli": "^0.1.57",
|
|
85
|
-
"@swc/core": "^1.
|
|
85
|
+
"@swc/core": "^1.3.66",
|
|
86
86
|
"@types/jest": "<%= versions['@types/jest'] %>",
|
|
87
87
|
"@types/node": "<%= versions['@types/node'] %>",
|
|
88
88
|
"@typescript-eslint/eslint-plugin": "<%= versions['@typescript-eslint/eslint-plugin'] %>",
|
|
@@ -116,5 +116,5 @@
|
|
|
116
116
|
"npm": "<%= engineVersions['npm'] %>",
|
|
117
117
|
"yarn": "<%= engineVersions['yarn'] %>"
|
|
118
118
|
},
|
|
119
|
-
"packageManager": "yarn@3.6.
|
|
119
|
+
"packageManager": "yarn@3.6.1"
|
|
120
120
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Rule } from '@angular-devkit/schematics';
|
|
2
|
-
import { NgGenerateTypescriptSDKCreateSchematicsSchema } from './schema';
|
|
3
|
-
/**
|
|
4
|
-
* Generate a typescript SDK repository and source code base on swagger specification
|
|
5
|
-
*
|
|
6
|
-
* @param options
|
|
7
|
-
*/
|
|
8
|
-
export declare function ngGenerateTypescriptSDK(options: NgGenerateTypescriptSDKCreateSchematicsSchema): Rule;
|
|
9
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/create/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,IAAI,EAAa,MAAM,4BAA4B,CAAC;AAGpE,OAAO,EAAE,6CAA6C,EAAE,MAAM,UAAU,CAAC;AAEzE;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,6CAA6C,GAAG,IAAI,CAKpG"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ngGenerateTypescriptSDK = void 0;
|
|
4
|
-
const schematics_1 = require("@angular-devkit/schematics");
|
|
5
|
-
/**
|
|
6
|
-
* Generate a typescript SDK repository and source code base on swagger specification
|
|
7
|
-
*
|
|
8
|
-
* @param options
|
|
9
|
-
*/
|
|
10
|
-
function ngGenerateTypescriptSDK(options) {
|
|
11
|
-
return (0, schematics_1.chain)([
|
|
12
|
-
(0, schematics_1.schematic)('typescript-shell', options),
|
|
13
|
-
(0, schematics_1.schematic)('typescript-core', options)
|
|
14
|
-
]);
|
|
15
|
-
}
|
|
16
|
-
exports.ngGenerateTypescriptSDK = ngGenerateTypescriptSDK;
|
|
17
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { NgGenerateTypescriptSDKCoreSchematicsSchema } from '../core/schema';
|
|
2
|
-
import { NgGenerateTypescriptSDKShellSchematicsSchema } from '../shell/schema';
|
|
3
|
-
export interface NgGenerateTypescriptSDKCreateSchematicsSchema extends NgGenerateTypescriptSDKCoreSchematicsSchema, NgGenerateTypescriptSDKShellSchematicsSchema {
|
|
4
|
-
}
|
|
5
|
-
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/create/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,2CAA2C,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,4CAA4C,EAAE,MAAM,iBAAiB,CAAC;AAE/E,MAAM,WAAW,6CAA8C,SAAQ,2CAA2C,EAAE,4CAA4C;CAE/J"}
|