gtx-cli 2.5.21 → 2.5.22

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # gtx-cli
2
2
 
3
+ ## 2.5.22
4
+
5
+ ### Patch Changes
6
+
7
+ - [#870](https://github.com/generaltranslation/gt/pull/870) [`4291258`](https://github.com/generaltranslation/gt/commit/42912587a51da045c0b578ac71699fda4a8fcc26) Thanks [@fernando-aviles](https://github.com/fernando-aviles)! - Persist style of YAML frontmatter when applying Mintlify OpenAPI postprocessing
8
+
3
9
  ## 2.5.21
4
10
 
5
11
  ### Patch Changes
@@ -3,7 +3,7 @@ import path from 'node:path';
3
3
  import { unified } from 'unified';
4
4
  import remarkParse from 'remark-parse';
5
5
  import remarkFrontmatter from 'remark-frontmatter';
6
- import YAML from 'yaml';
6
+ import YAML, { isMap, isScalar } from 'yaml';
7
7
  import { logger } from '../console/logger.js';
8
8
  import { createFileMapping } from '../formats/files/fileMapping.js';
9
9
  const HTTP_METHODS = new Set([
@@ -184,18 +184,18 @@ function rewriteFrontmatter(content, filePath, locale, specs, fileMapping, warni
184
184
  const start = yamlNode.position.start.offset;
185
185
  const end = yamlNode.position.end.offset;
186
186
  const frontmatterRaw = yamlNode.value || '';
187
- let parsed;
188
- try {
189
- parsed = YAML.parse(frontmatterRaw, { prettyErrors: false }) || {};
190
- }
191
- catch {
187
+ const doc = YAML.parseDocument(frontmatterRaw, {
188
+ prettyErrors: false,
189
+ keepSourceTokens: true,
190
+ });
191
+ if (doc.errors?.length)
192
192
  return null;
193
- }
194
- if (!parsed || typeof parsed !== 'object')
193
+ if (!isMap(doc.contents))
195
194
  return null;
196
195
  let changed = false;
197
- if (typeof parsed.openapi === 'string') {
198
- const parsedValue = parseOpenApiValue(parsed.openapi);
196
+ const openapiNode = doc.get('openapi', true);
197
+ if (isScalar(openapiNode) && typeof openapiNode.value === 'string') {
198
+ const parsedValue = parseOpenApiValue(openapiNode.value);
199
199
  if (parsedValue) {
200
200
  const matchKey = parsedValue.kind === 'operation'
201
201
  ? {
@@ -208,22 +208,23 @@ function rewriteFrontmatter(content, filePath, locale, specs, fileMapping, warni
208
208
  const descriptor = formatOpenApiDescriptor(parsedValue);
209
209
  const localizedSpecPath = resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath);
210
210
  const newValue = `${localizedSpecPath} ${descriptor}`.trim();
211
- if (newValue !== parsed.openapi) {
212
- parsed.openapi = newValue;
211
+ if (newValue !== openapiNode.value) {
212
+ doc.set('openapi', newValue);
213
213
  changed = true;
214
214
  }
215
215
  }
216
216
  }
217
217
  }
218
- if (typeof parsed['openapi-schema'] === 'string') {
219
- const parsedValue = parseSchemaValue(parsed['openapi-schema']);
218
+ const schemaNode = doc.get('openapi-schema', true);
219
+ if (isScalar(schemaNode) && typeof schemaNode.value === 'string') {
220
+ const parsedValue = parseSchemaValue(schemaNode.value);
220
221
  if (parsedValue) {
221
222
  const spec = resolveSpec(parsedValue.specPath, specs, filePath, configDir, warnings, `schema "${parsedValue.schemaName}"`, { type: 'schema', key: parsedValue.schemaName });
222
223
  if (spec) {
223
224
  const localizedSpecPath = resolveLocalizedSpecPath(spec, locale, fileMapping, configDir, parsedValue.specPath || spec.configPath);
224
225
  const newValue = `${localizedSpecPath} ${parsedValue.schemaName}`.trim();
225
- if (newValue !== parsed['openapi-schema']) {
226
- parsed['openapi-schema'] = newValue;
226
+ if (newValue !== schemaNode.value) {
227
+ doc.set('openapi-schema', newValue);
227
228
  changed = true;
228
229
  }
229
230
  }
@@ -231,7 +232,7 @@ function rewriteFrontmatter(content, filePath, locale, specs, fileMapping, warni
231
232
  }
232
233
  if (!changed)
233
234
  return null;
234
- const fmString = YAML.stringify(parsed).trimEnd();
235
+ const fmString = doc.toString().trimEnd();
235
236
  const rebuilt = `${content.slice(0, start)}---\n${fmString}\n---${content.slice(end)}`;
236
237
  return { changed, content: rebuilt };
237
238
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gtx-cli",
3
- "version": "2.5.21",
3
+ "version": "2.5.22",
4
4
  "main": "dist/index.js",
5
5
  "bin": "dist/main.js",
6
6
  "files": [