Skip to content

Commit

Permalink
fix(script): use process.cwd() instead of __dirname (#142)
Browse files Browse the repository at this point in the history
* fix(scripts): use process.cwd() instead of __dirname

* chore: add comment

* chore: throw error when file not found
  • Loading branch information
eunjae-lee authored Feb 18, 2022
1 parent 8a38fe6 commit 59be865
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions scripts/pre-gen/setHostsOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ type AdditionalProperties = Partial<{
}>;

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

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

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

if (!(await stat(specPath))) {
throw new Error(`File not found ${specPath}`);
throw new Error(
`File not found ${specPath}.\nMake sure your run scripts from the root directory using yarn workspace.`
);
}

try {
Expand Down

0 comments on commit 59be865

Please sign in to comment.