gtx-cli 2.5.29-alpha.1 → 2.5.29
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/CHANGELOG.md +6 -0
- package/dist/main.js +1 -208115
- package/dist/utils/processOpenApi.js +47 -8
- package/package.json +2 -8
- package/dist/main.js.map +0 -1
|
@@ -251,7 +251,14 @@ function parseOpenApiValue(value) {
|
|
|
251
251
|
return null;
|
|
252
252
|
let cursor = 0;
|
|
253
253
|
let specPath;
|
|
254
|
-
|
|
254
|
+
const first = tokens[0];
|
|
255
|
+
const second = tokens[1];
|
|
256
|
+
const methodCandidate = second?.toUpperCase();
|
|
257
|
+
const firstLooksLikeSpec = first.toLowerCase().endsWith('.json') ||
|
|
258
|
+
(second &&
|
|
259
|
+
(second.toLowerCase() === 'webhook' ||
|
|
260
|
+
(methodCandidate && HTTP_METHODS.has(methodCandidate))));
|
|
261
|
+
if (firstLooksLikeSpec) {
|
|
255
262
|
specPath = tokens[0];
|
|
256
263
|
cursor = 1;
|
|
257
264
|
}
|
|
@@ -260,9 +267,13 @@ function parseOpenApiValue(value) {
|
|
|
260
267
|
const keyword = tokens[cursor];
|
|
261
268
|
if (keyword.toLowerCase() === 'webhook') {
|
|
262
269
|
const name = tokens.slice(cursor + 1).join(' ');
|
|
270
|
+
if (!name)
|
|
271
|
+
return null;
|
|
263
272
|
return { kind: 'webhook', specPath, name };
|
|
264
273
|
}
|
|
265
274
|
const method = keyword.toUpperCase();
|
|
275
|
+
if (!HTTP_METHODS.has(method))
|
|
276
|
+
return null;
|
|
266
277
|
const operationPath = tokens.slice(cursor + 1).join(' ');
|
|
267
278
|
if (!operationPath)
|
|
268
279
|
return null;
|
|
@@ -300,14 +311,38 @@ function resolveSpec(explicitPath, specs, filePath, configDir, warnings, refDesc
|
|
|
300
311
|
if (!specs.length)
|
|
301
312
|
return null;
|
|
302
313
|
if (explicitPath) {
|
|
303
|
-
const normalizedExplicit = explicitPath.replace(/^\.?\/+/, '');
|
|
314
|
+
const normalizedExplicit = normalizeSlashes(explicitPath.replace(/^\.?\/+/, ''));
|
|
304
315
|
const candidates = [
|
|
305
316
|
path.resolve(configDir, normalizedExplicit),
|
|
306
317
|
path.resolve(path.dirname(filePath), normalizedExplicit),
|
|
307
318
|
];
|
|
308
|
-
const foundSpec = specs.find((spec) =>
|
|
319
|
+
const foundSpec = specs.find((spec) => {
|
|
320
|
+
const normalizedSpecPath = normalizeSlashes(spec.absPath);
|
|
321
|
+
return candidates.some((candidate) => samePath(candidate, normalizedSpecPath));
|
|
322
|
+
});
|
|
309
323
|
if (foundSpec)
|
|
310
324
|
return foundSpec;
|
|
325
|
+
const explicitWithoutExt = stripExtension(normalizedExplicit);
|
|
326
|
+
const explicitBase = path.basename(normalizedExplicit);
|
|
327
|
+
const explicitBaseWithoutExt = stripExtension(explicitBase);
|
|
328
|
+
const matches = specs.filter((spec) => {
|
|
329
|
+
const configPath = normalizeSlashes(spec.configPath).replace(/^\.?\/+/, '');
|
|
330
|
+
const configBase = path.basename(configPath);
|
|
331
|
+
const configPathNoExt = stripExtension(configPath);
|
|
332
|
+
const configBaseNoExt = stripExtension(configBase);
|
|
333
|
+
return (configPath === normalizedExplicit ||
|
|
334
|
+
configPathNoExt === explicitWithoutExt ||
|
|
335
|
+
configBase === explicitBase ||
|
|
336
|
+
configBaseNoExt === explicitBaseWithoutExt);
|
|
337
|
+
});
|
|
338
|
+
if (matches.length === 1)
|
|
339
|
+
return matches[0];
|
|
340
|
+
if (matches.length > 1) {
|
|
341
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} matches multiple specs (${matches
|
|
342
|
+
.map((m) => m.configPath)
|
|
343
|
+
.join(', ')}). Using the first configured match (${matches[0].configPath}).`);
|
|
344
|
+
return matches[0];
|
|
345
|
+
}
|
|
311
346
|
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} points to an unconfigured spec (${explicitPath}). Skipping localization for this reference.`);
|
|
312
347
|
return null;
|
|
313
348
|
}
|
|
@@ -325,12 +360,11 @@ function resolveSpec(explicitPath, specs, filePath, configDir, warnings, refDesc
|
|
|
325
360
|
if (matches.length === 1)
|
|
326
361
|
return matches[0];
|
|
327
362
|
if (matches.length > 1) {
|
|
328
|
-
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} is available in multiple specs.
|
|
329
|
-
return
|
|
363
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} is available in multiple specs. Skipping localization for this reference.`);
|
|
364
|
+
return null;
|
|
330
365
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
return specs[0];
|
|
366
|
+
warnings.add(`OpenAPI reference ${refDescription} in ${filePath} was not found in any configured spec. Skipping localization for this reference.`);
|
|
367
|
+
return null;
|
|
334
368
|
}
|
|
335
369
|
/**
|
|
336
370
|
* Map a spec to the locale-specific file path when available and normalize it
|
|
@@ -377,6 +411,11 @@ function describeOpenApiRef(value) {
|
|
|
377
411
|
return `webhook ${value.name}`;
|
|
378
412
|
return `${value.method.toUpperCase()} ${value.operationPath}`;
|
|
379
413
|
}
|
|
414
|
+
/** Remove a single trailing file extension while preserving directory segments. */
|
|
415
|
+
function stripExtension(p) {
|
|
416
|
+
const parsed = path.parse(p);
|
|
417
|
+
return normalizeSlashes(path.join(parsed.dir, parsed.name));
|
|
418
|
+
}
|
|
380
419
|
/** Normalize separators for stable comparisons and output. */
|
|
381
420
|
function normalizeSlashes(p) {
|
|
382
421
|
return p.replace(/\\/g, '/');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gtx-cli",
|
|
3
|
-
"version": "2.5.29
|
|
3
|
+
"version": "2.5.29",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"bin": "dist/main.js",
|
|
6
6
|
"files": [
|
|
@@ -110,11 +110,6 @@
|
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@babel/types": "^7.28.4",
|
|
112
112
|
"@biomejs/biome": "^1.9.4",
|
|
113
|
-
"@rollup/plugin-commonjs": "^29.0.0",
|
|
114
|
-
"@rollup/plugin-json": "^6.1.0",
|
|
115
|
-
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
116
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
117
|
-
"@rollup/plugin-typescript": "^12.3.0",
|
|
118
113
|
"@types/babel__generator": "^7.27.0",
|
|
119
114
|
"@types/babel__traverse": "^7.20.6",
|
|
120
115
|
"@types/figlet": "^1.7.0",
|
|
@@ -129,13 +124,12 @@
|
|
|
129
124
|
"mdast-util-mdx-jsx": "^3.2.0",
|
|
130
125
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
131
126
|
"prettier": "^3.4.2",
|
|
132
|
-
"rollup": "^4.53.3",
|
|
133
127
|
"ts-node": "^10.9.2",
|
|
134
128
|
"tslib": "^2.8.1",
|
|
135
129
|
"typescript": "^5.5.4"
|
|
136
130
|
},
|
|
137
131
|
"scripts": {
|
|
138
|
-
"build": "tsc
|
|
132
|
+
"build": "tsc",
|
|
139
133
|
"build:clean": "sh ../../scripts/clean.sh && pnpm run build",
|
|
140
134
|
"build:release": "pnpm run build:clean",
|
|
141
135
|
"lint": "eslint \"src/**/*.{js,ts}\" \"./**/__tests__/**/*.{js,ts}\"",
|