Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: JSON Schema Docgen doesn't work on Windows OS #66414

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions bin/api-docs/gen-theme-reference.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
import fs from 'node:fs/promises';
import $RefParser from '@apidevtools/json-schema-ref-parser';
import { fileURLToPath } from 'node:url';

/**
* @typedef {import('@apidevtools/json-schema-ref-parser').JSONSchema} JSONSchema
Expand All @@ -19,19 +20,20 @@ import $RefParser from '@apidevtools/json-schema-ref-parser';
*
* @type {URL}
*/
const THEME_JSON_SCHEMA_URL = new URL(
'../../schemas/json/theme.json',
import.meta.url
const THEME_JSON_SCHEMA_PATH = fileURLToPath(
new URL( '../../schemas/json/theme.json', import.meta.url )
);

/**
* Path to docs file.
*
* @type {URL}
*/
const REFERENCE_DOC_URL = new URL(
'../../docs/reference-guides/theme-json-reference/theme-json-living.md',
import.meta.url
const REFERENCE_DOC_PATH = fileURLToPath(
new URL(
'../../docs/reference-guides/theme-json-reference/theme-json-living.md',
import.meta.url
)
);

/**
Expand Down Expand Up @@ -265,15 +267,12 @@ function generateDocs( themeJson ) {
* Main function.
*/
async function main() {
const themeJson = await $RefParser.dereference(
THEME_JSON_SCHEMA_URL.pathname,
{
parse: { binary: false, text: false, yaml: false },
resolve: { external: false },
}
);
const themeJson = await $RefParser.dereference( THEME_JSON_SCHEMA_PATH, {
parse: { binary: false, text: false, yaml: false },
resolve: { external: false },
} );

const themeJsonReference = await fs.readFile( REFERENCE_DOC_URL, {
const themeJsonReference = await fs.readFile( REFERENCE_DOC_PATH, {
encoding: 'utf8',
flag: 'r',
} );
Expand All @@ -285,7 +284,7 @@ async function main() {
`${ START_TOKEN }\n${ generatedDocs }\n${ END_TOKEN }`
);

await fs.writeFile( REFERENCE_DOC_URL, updatedThemeJsonReference, {
await fs.writeFile( REFERENCE_DOC_PATH, updatedThemeJsonReference, {
encoding: 'utf8',
} );
}
Expand Down
Loading