Skip to content

Commit b645047

Browse files
committed
Improved Windows compatibility for update:examples script
1 parent 1f6dea4 commit b645047

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

packages/openapi-typescript/scripts/update-examples.ts

+25-12
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,31 @@ async function generateSchemas() {
1515
const updateSchema = async (name: string, ext: string) => {
1616
const start = performance.now();
1717

18-
await execa(
19-
"./bin/cli.js",
20-
[`./examples/${name}${ext}`, "-o", `./examples/${name}.ts`],
21-
{ cwd },
22-
);
23-
24-
schemasDoneCount++;
25-
const timeMs = Math.round(performance.now() - start);
26-
27-
console.log(
28-
`✔︎ [${schemasDoneCount}/${schemaTotalCount}] Updated ${name} (${timeMs}ms)`,
29-
);
18+
try {
19+
await execa(
20+
"./bin/cli.js",
21+
[`./examples/${name}${ext}`, "-o", `./examples/${name}.ts`],
22+
{
23+
cwd:
24+
process.platform === "win32"
25+
? // execa/cross-spawn can not handle URL objects on Windows, so convert it to string and cut away the protocol
26+
cwd.toString().slice("file:///".length)
27+
: cwd,
28+
},
29+
);
30+
31+
schemasDoneCount++;
32+
const timeMs = Math.round(performance.now() - start);
33+
34+
console.log(
35+
`✔︎ [${schemasDoneCount}/${schemaTotalCount}] Updated ${name} (${timeMs}ms)`,
36+
);
37+
} catch (error) {
38+
console.error(
39+
`✘ [${schemasDoneCount}/${schemaTotalCount}] Failed to update ${name}`,
40+
{ error: error instanceof Error ? error.message : error },
41+
);
42+
}
3043
};
3144

3245
console.log("Updating examples...");

0 commit comments

Comments
 (0)