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(build): Windows build #124

Merged
merged 1 commit into from
Sep 15, 2023
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
16 changes: 13 additions & 3 deletions packages/camel-catalog/src/json-schema-to-typescript.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
/**
* This script generates TypeScript types from the JSON schemas in the dist folder.
*/
import { JSONSchema, compile } from 'json-schema-to-typescript';
import { mkdir, writeFile } from 'fs/promises';
import { JSONSchema, compile } from 'json-schema-to-typescript';
import { pathToFileURL } from 'node:url';
import { resolve } from 'path';
import index from '../dist/index.json' assert { type: 'json' };
import { rimraf } from 'rimraf';
import index from '../dist/index.json' assert { type: 'json' };

/** Function to ensure the dist/types folder is created and empty */
const ensureTypesFolder = async () => {
Expand Down Expand Up @@ -54,7 +55,16 @@ async function main() {
console.log('---');
const schemaPromises = index.schemas.map(async (schema) => {
const schemaFile = resolve(`./dist/${schema.file}`);
const schemaContent = (await import(resolve(`./dist/${schema.file}`), { assert: { type: 'json' } })).default;

/**
* In windows, path starting with C:\ are not supported
* We need to add file:// to the path to make it work
* [pathToFileURL](https://nodejs.org/api/url.html#url_url_pathtofileurl_path)
* Related issue: https://github.com/nodejs/node/issues/31710
*/
const schemaFileUri = pathToFileURL(`./dist/${schema.file}`).toString();

const schemaContent = (await import(schemaFileUri, { assert: { type: 'json' } })).default;

let filename = schema.name;

Expand Down
Loading