Skip to content

Commit

Permalink
Fix: JSON Schema Docgen doesn't work on Windows OS (#66414)
Browse files Browse the repository at this point in the history
* Fix: JSON Schema Docgen doesn't work on Windows OS

* Update bin/api-docs/gen-theme-reference.mjs

Co-authored-by: Jon Surrell <[email protected]>

* Lint

---------

Co-authored-by: t-hamano <[email protected]>
Co-authored-by: sirreal <[email protected]>
  • Loading branch information
3 people authored and swissspidy committed Oct 25, 2024
1 parent 06e345e commit 8f99999
Showing 1 changed file with 14 additions and 15 deletions.
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

0 comments on commit 8f99999

Please sign in to comment.