@ama-sdk/schematics 11.2.0-prerelease.31 → 11.2.0-prerelease.32

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ama-sdk/schematics",
3
- "version": "11.2.0-prerelease.31",
3
+ "version": "11.2.0-prerelease.32",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -57,12 +57,12 @@
57
57
  }
58
58
  },
59
59
  "peerDependencies": {
60
- "@ama-sdk/core": "^11.2.0-prerelease.31",
60
+ "@ama-sdk/core": "^11.2.0-prerelease.32",
61
61
  "@angular-devkit/core": "~18.1.0",
62
62
  "@angular-devkit/schematics": "~18.1.0",
63
63
  "@angular-devkit/schematics-cli": "^18.0.5",
64
64
  "@angular/cli": "~18.1.0",
65
- "@o3r/schematics": "^11.2.0-prerelease.31",
65
+ "@o3r/schematics": "^11.2.0-prerelease.32",
66
66
  "@openapitools/openapi-generator-cli": "~2.13.0",
67
67
  "@schematics/angular": "~18.1.0"
68
68
  },
@@ -79,16 +79,16 @@
79
79
  "tslib": "^2.6.2"
80
80
  },
81
81
  "devDependencies": {
82
- "@ama-sdk/core": "^11.2.0-prerelease.31",
82
+ "@ama-sdk/core": "^11.2.0-prerelease.32",
83
83
  "@angular-devkit/schematics-cli": "^18.0.5",
84
84
  "@angular-eslint/eslint-plugin": "~18.1.0",
85
85
  "@angular/cli": "~18.1.0",
86
86
  "@nx/eslint-plugin": "~19.5.0",
87
87
  "@nx/jest": "~19.5.0",
88
- "@o3r/build-helpers": "^11.2.0-prerelease.31",
89
- "@o3r/eslint-plugin": "^11.2.0-prerelease.31",
90
- "@o3r/schematics": "^11.2.0-prerelease.31",
91
- "@o3r/test-helpers": "^11.2.0-prerelease.31",
88
+ "@o3r/build-helpers": "^11.2.0-prerelease.32",
89
+ "@o3r/eslint-plugin": "^11.2.0-prerelease.32",
90
+ "@o3r/schematics": "^11.2.0-prerelease.32",
91
+ "@o3r/test-helpers": "^11.2.0-prerelease.32",
92
92
  "@openapitools/openapi-generator-cli": "~2.13.0",
93
93
  "@schematics/angular": "~18.1.0",
94
94
  "@stylistic/eslint-plugin-ts": "~2.4.0",
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Replace all the local relative references using the new base relative path
3
+ * @param specContent
4
+ * @param newBaseRelativePath
5
+ */
6
+ export declare function updateLocalRelativeRefs(specContent: string, newBaseRelativePath: string): string;
7
+ /**
8
+ * Copy the local files referenced in the input spec file to the output directory
9
+ * @param specFilePath
10
+ * @param outputDirectory
11
+ */
12
+ export declare function copyReferencedFiles(specFilePath: string, outputDirectory: string): Promise<string>;
13
+ //# sourceMappingURL=copy-referenced-files.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copy-referenced-files.d.ts","sourceRoot":"","sources":["../../../../../schematics/typescript/core/helpers/copy-referenced-files.ts"],"names":[],"mappings":"AA6CA;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,EAAE,mBAAmB,EAAE,MAAM,UAQvF;AAED;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,mBA2BtF"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateLocalRelativeRefs = updateLocalRelativeRefs;
4
+ exports.copyReferencedFiles = copyReferencedFiles;
5
+ const node_fs_1 = require("node:fs");
6
+ const promises_1 = require("node:fs/promises");
7
+ const node_path_1 = require("node:path");
8
+ const refMatcher = /\B['"]?[$]ref['"]?\s*:\s*([^#\n]+)/g;
9
+ /**
10
+ * Extract the list of local references from a single spec file content
11
+ * @param specContent
12
+ * @param basePath
13
+ */
14
+ function extractRefPaths(specContent, basePath) {
15
+ const refs = specContent.match(refMatcher);
16
+ return refs ?
17
+ refs
18
+ .map((capture) => capture.replace(refMatcher, '$1').replace(/['"]/g, ''))
19
+ .filter((refPath) => refPath.startsWith('.'))
20
+ .map((refPath) => (0, node_path_1.join)(basePath, refPath))
21
+ : [];
22
+ }
23
+ /**
24
+ * Recursively extract the list of local references starting from the input spec file
25
+ * @param specFilePath
26
+ * @param referenceFilePath
27
+ * @param visited
28
+ */
29
+ async function extractRefPathRecursive(specFilePath, referenceFilePath, visited) {
30
+ const resolvedFilePath = (0, node_path_1.resolve)(specFilePath);
31
+ if (!visited.has(resolvedFilePath)) {
32
+ visited.add(resolvedFilePath);
33
+ const specContent = await (0, promises_1.readFile)(specFilePath, { encoding: 'utf8' });
34
+ const refPaths = extractRefPaths(specContent, (0, node_path_1.relative)((0, node_path_1.dirname)(referenceFilePath), (0, node_path_1.dirname)(specFilePath)));
35
+ const recursiveRefPaths = await Promise.all(refPaths.map((refPath) => extractRefPathRecursive((0, node_path_1.join)((0, node_path_1.dirname)(referenceFilePath), refPath), referenceFilePath, visited)));
36
+ return [
37
+ ...refPaths,
38
+ ...recursiveRefPaths.flat()
39
+ ];
40
+ }
41
+ return [];
42
+ }
43
+ /**
44
+ * Replace all the local relative references using the new base relative path
45
+ * @param specContent
46
+ * @param newBaseRelativePath
47
+ */
48
+ function updateLocalRelativeRefs(specContent, newBaseRelativePath) {
49
+ const formatPath = (inputPath) => (inputPath.startsWith('.') ? inputPath : `./${inputPath}`).replace(/\\+/g, '/');
50
+ return specContent.replace(refMatcher, (match, ref) => {
51
+ const refPath = ref.replace(/['"]/g, '');
52
+ return refPath.startsWith('.') ?
53
+ match.replace(refPath, formatPath((0, node_path_1.normalize)(node_path_1.posix.join(newBaseRelativePath.replaceAll(node_path_1.sep, node_path_1.posix.sep), refPath))))
54
+ : match;
55
+ });
56
+ }
57
+ /**
58
+ * Copy the local files referenced in the input spec file to the output directory
59
+ * @param specFilePath
60
+ * @param outputDirectory
61
+ */
62
+ async function copyReferencedFiles(specFilePath, outputDirectory) {
63
+ const dedupe = (paths) => ([...new Set(paths)]);
64
+ const allRefPaths = await extractRefPathRecursive(specFilePath, specFilePath, new Set());
65
+ const refPaths = dedupe(allRefPaths);
66
+ if (refPaths.length) {
67
+ if ((0, node_fs_1.existsSync)(outputDirectory)) {
68
+ await (0, promises_1.rm)(outputDirectory, { recursive: true });
69
+ }
70
+ // Calculate the lowest level base path to keep the same directory structure
71
+ const maxDepth = Math.max(...refPaths.map((refPath) => refPath.split('..').length));
72
+ const basePath = (0, node_path_1.join)(specFilePath, '../'.repeat(maxDepth));
73
+ const baseRelativePath = (0, node_path_1.relative)(basePath, (0, node_path_1.dirname)(specFilePath));
74
+ // Copy the files
75
+ await Promise.all(refPaths.map(async (refPath) => {
76
+ const sourcePath = (0, node_path_1.join)((0, node_path_1.dirname)(specFilePath), refPath);
77
+ const destPath = (0, node_path_1.join)(outputDirectory, baseRelativePath, refPath);
78
+ if (!(0, node_fs_1.existsSync)((0, node_path_1.dirname)(destPath))) {
79
+ await (0, promises_1.mkdir)((0, node_path_1.dirname)(destPath), { recursive: true });
80
+ }
81
+ await (0, promises_1.copyFile)(sourcePath, destPath);
82
+ }));
83
+ return (0, node_path_1.join)(outputDirectory, baseRelativePath);
84
+ }
85
+ return '';
86
+ }
87
+ //# sourceMappingURL=copy-referenced-files.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAOL,IAAI,EAKL,MAAM,4BAA4B,CAAC;AASpC,OAAO,EAAE,2CAA2C,EAAE,MAAM,UAAU,CAAC;AAgPvE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,YAAa,2CAA2C,wBAG3F,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../schematics/typescript/core/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAOL,IAAI,EAKL,MAAM,4BAA4B,CAAC;AASpC,OAAO,EAAE,2CAA2C,EAAE,MAAM,UAAU,CAAC;AA2PvE;;;GAGG;AACH,eAAO,MAAM,uBAAuB,YAAa,2CAA2C,wBAG3F,CAAC"}
@@ -9,6 +9,7 @@ const node_url_1 = require("node:url");
9
9
  const semver = require("semver");
10
10
  const tree_glob_1 = require("../../helpers/tree-glob");
11
11
  const open_api_cli_generator_1 = require("../../code-generator/open-api-cli-generator/open-api-cli.generator");
12
+ const copy_referenced_files_1 = require("./helpers/copy-referenced-files");
12
13
  const path_extractor_1 = require("./helpers/path-extractor");
13
14
  const JAVA_OPTIONS = ['specPath', 'specConfigPath', 'globalProperty', 'outputPath'];
14
15
  const OPEN_API_TOOLS_OPTIONS = ['generatorName', 'output', 'inputSpec', 'config', 'globalProperty'];
@@ -123,11 +124,20 @@ function ngGenerateTypescriptSDKFn(options) {
123
124
  let specContent;
124
125
  if (node_url_1.URL.canParse(generatorOptions.specPath) && (new node_url_1.URL(generatorOptions.specPath)).protocol.startsWith('http')) {
125
126
  specContent = await (await fetch(generatorOptions.specPath)).text();
127
+ specContent = (0, copy_referenced_files_1.updateLocalRelativeRefs)(specContent, path.dirname(generatorOptions.specPath));
126
128
  }
127
129
  else {
128
130
  const specPath = path.isAbsolute(generatorOptions.specPath) || !options.directory ?
129
131
  generatorOptions.specPath : path.join(options.directory, generatorOptions.specPath);
130
132
  specContent = (0, node_fs_1.readFileSync)(specPath, { encoding: 'utf-8' }).toString();
133
+ if (path.relative(process.cwd(), specPath).startsWith('..')) {
134
+ // TODO would be better to create files on tree instead of FS
135
+ // https://github.com/AmadeusITGroup/otter/issues/2078
136
+ const newRelativePath = await (0, copy_referenced_files_1.copyReferencedFiles)(specPath, './spec-local-references');
137
+ if (newRelativePath) {
138
+ specContent = (0, copy_referenced_files_1.updateLocalRelativeRefs)(specContent, newRelativePath);
139
+ }
140
+ }
131
141
  }
132
142
  try {
133
143
  JSON.parse(specContent);