Skip to content

Commit 59be865

Browse files
authored
fix(script): use process.cwd() instead of __dirname (#142)
* fix(scripts): use process.cwd() instead of __dirname * chore: add comment * chore: throw error when file not found
1 parent 8a38fe6 commit 59be865

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

scripts/pre-gen/setHostsOptions.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ type AdditionalProperties = Partial<{
3232
}>;
3333

3434
async function setHostsOptions(): Promise<void> {
35-
const openapitoolsPath = path.join(__dirname, '../../openapitools.json');
35+
const openapitoolsPath = path.join(process.cwd(), '../openapitools.json');
36+
if (!(await stat(openapitoolsPath))) {
37+
throw new Error(
38+
`File not found ${openapitoolsPath}.\nMake sure your run scripts from the root directory using yarn workspace.`
39+
);
40+
}
3641
const openapitools = JSON.parse(await readFile(openapitoolsPath, 'utf-8'));
3742

3843
const [language, client] = process.argv.slice(2);
@@ -43,10 +48,12 @@ async function setHostsOptions(): Promise<void> {
4348
throw new Error(`Generator not found: ${generator}`);
4449
}
4550

46-
const specPath = path.join(__dirname, `../../specs/bundled/${client}.yml`);
51+
const specPath = path.join(process.cwd(), `../specs/bundled/${client}.yml`);
4752

4853
if (!(await stat(specPath))) {
49-
throw new Error(`File not found ${specPath}`);
54+
throw new Error(
55+
`File not found ${specPath}.\nMake sure your run scripts from the root directory using yarn workspace.`
56+
);
5057
}
5158

5259
try {

0 commit comments

Comments
 (0)