@ama-sdk/core 10.4.0-prerelease.0 → 10.4.0-prerelease.10

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 CHANGED
@@ -69,3 +69,15 @@ function petApiFactory() {
69
69
  ```
70
70
 
71
71
  > *Note*: Adding a third-party logging service is optional. If undefined, the fallback is the console logger.
72
+
73
+ ### CLI
74
+
75
+ This package also comes with CLI scripts that can facilitate the upgrade and publication of an SDK.
76
+ Use --help on each command for more information
77
+
78
+ | Script | Description |
79
+ |-----------------------------|------------------------------------------------------------------------------------------------|
80
+ | amasdk-clear-index | Remove the index files that are no longer necessary after the deletion of the associated model |
81
+ | amasdk-files-pack | Prepare the dist folder for publication |
82
+ | amasdk-update-spec-from-npm | Update the OpenAPI spec from an NPM package |
83
+
package/cjs/fwk/index.js CHANGED
@@ -11,6 +11,7 @@ _export_star(require("./errors"), exports);
11
11
  _export_star(require("./ignore-enum.type"), exports);
12
12
  _export_star(require("./logger"), exports);
13
13
  _export_star(require("./mocks/index"), exports);
14
+ _export_star(require("./open-api-tools-configuration"), exports);
14
15
  _export_star(require("./Reviver"), exports);
15
16
  function _export_star(from, to) {
16
17
  Object.keys(from).forEach(function(k) {
@@ -0,0 +1,4 @@
1
+ /** Configuration of an Open API generator */ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
@@ -4,9 +4,18 @@
4
4
  * Remove deleted models' exports
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
+ const minimist = require("minimist");
7
8
  const node_fs_1 = require("node:fs");
8
9
  const node_path_1 = require("node:path");
10
+ const argv = minimist(process.argv.slice(2));
11
+ const { help } = argv;
9
12
  const baseDir = (0, node_path_1.resolve)(process.cwd(), 'src', 'models', 'base');
13
+ if (help) {
14
+ console.log(`Remove the index files that are no longer necessary after the deletion of the associated model.
15
+ Usage: amasdk-clear-index
16
+ `);
17
+ process.exit(0);
18
+ }
10
19
  void (async () => {
11
20
  const models = await node_fs_1.promises.readdir(baseDir);
12
21
  const shouldRemoveModels = (await Promise.all(models
@@ -12,7 +12,16 @@ const globby = require("globby");
12
12
  const argv = minimist(process.argv.slice(2));
13
13
  const distFolder = argv.dist || 'dist';
14
14
  const baseDir = argv.cwd && path.resolve(process.cwd(), argv.cwd) || process.cwd();
15
- const { watch, noExports } = argv;
15
+ const { help, watch, noExports } = argv;
16
+ if (help) {
17
+ console.log(`Prepare the dist folder for publication. This will copy necessary files from src and update the exports in package.json.
18
+ Usage: amasdk-files-pack [--exports] [--watch]
19
+
20
+ --exports Update the exports in package.json. (Default: true)
21
+ --watch Watch for files changes and run the updates
22
+ `);
23
+ process.exit(0);
24
+ }
16
25
  const files = [
17
26
  { glob: 'README.md', cwdForCopy: baseDir },
18
27
  { glob: 'LICENSE', cwdForCopy: baseDir },
@@ -66,10 +75,12 @@ void (async () => {
66
75
  const copies = files.map(async ({ glob, cwdForCopy }) => {
67
76
  return watch ?
68
77
  Promise.resolve().then(() => require('chokidar')).then((chokidar) => chokidar.watch(glob, { cwd: baseDir }))
69
- .then((watcher) => watcher.on('all', (event, file) => {
78
+ .then((watcher) => watcher.on('all', async (event, file) => {
70
79
  if (event !== 'unlink' && event !== 'unlinkDir') {
71
80
  copyToDist(file, cwdForCopy);
72
- return updateExports();
81
+ if (!noExports) {
82
+ await updateExports();
83
+ }
73
84
  }
74
85
  })) :
75
86
  globby.sync(glob)
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /*
4
+ * Update the OpenAPI spec from an NPM package
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const minimist = require("minimist");
8
+ const node_fs_1 = require("node:fs");
9
+ const node_module_1 = require("node:module");
10
+ const node_path_1 = require("node:path");
11
+ const promises_1 = require("node:fs/promises");
12
+ const argv = minimist(process.argv.slice(2));
13
+ const packageName = argv._[0];
14
+ const { help, output, 'package-path': packagePath, quiet } = argv;
15
+ const openApiConfigDefaultPath = './openapitools.json';
16
+ const supportedExtensions = ['json', 'yaml', 'yml'];
17
+ const noop = () => undefined;
18
+ const logger = quiet ? { error: noop, warn: noop, log: noop, info: noop, debug: noop } : console;
19
+ if (help) {
20
+ console.log(`This script can be used to update your local spec file from a given locally installed npm package.
21
+ Usage: amasdk-update-spec-from-npm <package-name> [--package-path] [--output] [--quiet]
22
+
23
+ package-name The full identifier of the npm package (e.g. @my-scope/my-package)
24
+ --package-path The relative path inside the npm package where to find the spec file (default: './openapi.yml')
25
+ --output The path where the spec file should be copied (default: './openapi.yml')
26
+ --quiet Don't log anything
27
+ `);
28
+ process.exit(0);
29
+ }
30
+ if (!packageName) {
31
+ logger.error('Need to provide packageName, use `amasdk-update-spec-from-npm --help` for more information');
32
+ process.exit(-1);
33
+ }
34
+ void (async () => {
35
+ let specSourcePath;
36
+ const appRequire = (0, node_module_1.createRequire)((0, node_path_1.join)(process.cwd(), 'package.json'));
37
+ const packageJsonPath = appRequire.resolve(`${packageName}/package.json`);
38
+ if (!packagePath) {
39
+ const packageJson = JSON.parse(await (0, promises_1.readFile)(packageJsonPath, { encoding: 'utf8' }));
40
+ const exportMatcher = new RegExp(`openapi\\.(?:${supportedExtensions.join('|')})$`);
41
+ const matchingExport = packageJson.exports && Object.keys(packageJson.exports).find((exportPath) => exportMatcher.test(exportPath));
42
+ if (matchingExport) {
43
+ specSourcePath = appRequire.resolve(`${packageName}/${matchingExport}`);
44
+ }
45
+ }
46
+ else {
47
+ specSourcePath = packageJsonPath.replace(/package.json$/, packagePath);
48
+ }
49
+ if (!specSourcePath || !(0, node_fs_1.existsSync)(specSourcePath)) {
50
+ logger.error(`Unable to find source spec from ${packageName}, please make sure it is correctly exported in package.json`);
51
+ process.exit(-2);
52
+ }
53
+ let specDestinationPath = output;
54
+ if (!specDestinationPath) {
55
+ const specSourceExtension = (0, node_path_1.extname)(specSourcePath);
56
+ specDestinationPath = `./openapi${specSourceExtension}`;
57
+ if ((0, node_fs_1.existsSync)(openApiConfigDefaultPath)) {
58
+ const openApiConfig = JSON.parse(await (0, promises_1.readFile)(openApiConfigDefaultPath, { encoding: 'utf8' }));
59
+ const generators = Object.values(openApiConfig['generator-cli']?.generators ?? {});
60
+ if (generators.length === 1 && generators[0].inputSpec && (0, node_path_1.extname)(generators[0].inputSpec) === specSourceExtension) {
61
+ specDestinationPath = generators[0].inputSpec;
62
+ }
63
+ }
64
+ }
65
+ logger.info(`Updating spec file from "${specSourcePath}" to "${specDestinationPath}" (CWD: "${process.cwd()}")`);
66
+ await (0, promises_1.copyFile)(specSourcePath, specDestinationPath);
67
+ })();
68
+ //# sourceMappingURL=update-spec-from-npm.cjs.map
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=update-spec-from-npm.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-spec-from-npm.d.cts","sourceRoot":"","sources":["../../cli/update-spec-from-npm.cts"],"names":[],"mappings":""}
@@ -7,4 +7,5 @@ export * from './errors';
7
7
  export * from './ignore-enum.type';
8
8
  export * from './logger';
9
9
  export * from './mocks/index';
10
+ export * from './open-api-tools-configuration';
10
11
  export * from './Reviver';
@@ -0,0 +1 @@
1
+ /** Configuration of an Open API generator */ /** Global configuration of Open API Tools */ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ama-sdk/core",
3
- "version": "10.4.0-prerelease.0",
3
+ "version": "10.4.0-prerelease.10",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -80,7 +80,7 @@
80
80
  "@angular-devkit/schematics": "~17.3.0",
81
81
  "@angular/cli": "~17.3.0",
82
82
  "@angular/common": "~17.3.0",
83
- "@o3r/schematics": "^10.4.0-prerelease.0",
83
+ "@o3r/schematics": "^10.4.0-prerelease.10",
84
84
  "@schematics/angular": "~17.3.0",
85
85
  "chokidar": "^3.5.2",
86
86
  "globby": "^11.1.0",
@@ -126,9 +126,9 @@
126
126
  "@angular/core": "~17.3.0",
127
127
  "@nx/eslint-plugin": "~18.3.0",
128
128
  "@nx/jest": "~18.3.0",
129
- "@o3r/build-helpers": "^10.4.0-prerelease.0",
130
- "@o3r/eslint-plugin": "^10.4.0-prerelease.0",
131
- "@o3r/test-helpers": "^10.4.0-prerelease.0",
129
+ "@o3r/build-helpers": "^10.4.0-prerelease.10",
130
+ "@o3r/eslint-plugin": "^10.4.0-prerelease.10",
131
+ "@o3r/test-helpers": "^10.4.0-prerelease.10",
132
132
  "@schematics/angular": "~17.3.0",
133
133
  "@stylistic/eslint-plugin-ts": "^1.5.4",
134
134
  "@swc/cli": "^0.3.0",
@@ -168,7 +168,8 @@
168
168
  "schematics": "./collection.json",
169
169
  "bin": {
170
170
  "amasdk-clear-index": "./cli/clear-index.cjs",
171
- "amasdk-files-pack": "./cli/files-pack.cjs"
171
+ "amasdk-files-pack": "./cli/files-pack.cjs",
172
+ "amasdk-update-spec-from-npm": "./cli/update-spec-from-npm.cjs"
172
173
  },
173
174
  "contributors": [
174
175
  {
@@ -7,5 +7,6 @@ export * from './errors';
7
7
  export * from './ignore-enum.type';
8
8
  export * from './logger';
9
9
  export * from './mocks/index';
10
+ export * from './open-api-tools-configuration';
10
11
  export * from './Reviver';
11
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fwk/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fwk/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,WAAW,CAAC"}
package/src/fwk/index.js CHANGED
@@ -7,5 +7,6 @@ export * from './errors';
7
7
  export * from './ignore-enum.type';
8
8
  export * from './logger';
9
9
  export * from './mocks/index';
10
+ export * from './open-api-tools-configuration';
10
11
  export * from './Reviver';
11
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fwk/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fwk/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC;AACnC,cAAc,UAAU,CAAC;AACzB,cAAc,eAAe,CAAC;AAC9B,cAAc,gCAAgC,CAAC;AAC/C,cAAc,WAAW,CAAC"}
@@ -0,0 +1,28 @@
1
+ /** Configuration of an Open API generator */
2
+ export interface OpenApiToolsGenerator {
3
+ /** Location of the OpenAPI spec, as URL or file */
4
+ inputSpec: string;
5
+ /** Output path for the generated SDK */
6
+ output: string;
7
+ /** Generator to use */
8
+ generatorName: string;
9
+ /** Path to configuration file. It can be JSON or YAML */
10
+ config?: string;
11
+ /** Sets specified global properties */
12
+ globalProperty?: string | Record<string, any>;
13
+ }
14
+ /** Global configuration of Open API generators */
15
+ export interface OpenApiToolsGeneratorCli {
16
+ /** Open API version */
17
+ version: string;
18
+ /** Location of the generator JAR file */
19
+ storageDir?: string;
20
+ /** Generators configuration */
21
+ generators: Record<string, OpenApiToolsGenerator>;
22
+ }
23
+ /** Global configuration of Open API Tools */
24
+ export interface OpenApiToolsConfiguration {
25
+ /** Generators CLI configuration */
26
+ 'generator-cli': OpenApiToolsGeneratorCli;
27
+ }
28
+ //# sourceMappingURL=open-api-tools-configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-api-tools-configuration.d.ts","sourceRoot":"","sources":["../../../src/fwk/open-api-tools-configuration.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,MAAM,WAAW,qBAAqB;IACpC,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;IAClB,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,aAAa,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/C;AAED,kDAAkD;AAClD,MAAM,WAAW,wBAAwB;IACvC,uBAAuB;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;CACnD;AAED,6CAA6C;AAC7C,MAAM,WAAW,yBAAyB;IACxC,mCAAmC;IAEnC,eAAe,EAAE,wBAAwB,CAAC;CAC3C"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=open-api-tools-configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"open-api-tools-configuration.js","sourceRoot":"","sources":["../../../src/fwk/open-api-tools-configuration.ts"],"names":[],"mappings":""}