Skip to content

Commit 9f7e31f

Browse files
committed
chore: add clean models to preGen
1 parent be08ed2 commit 9f7e31f

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

scripts/generate.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import { buildJSClientUtils } from './buildClients';
22
import { buildSpecs } from './buildSpecs';
3-
import { buildCustomGenerators, CI, run, runIfExists } from './common';
3+
import {
4+
buildCustomGenerators,
5+
CI,
6+
run,
7+
runIfExists,
8+
toAbsolutePath,
9+
} from './common';
410
import { getCustomGenerator, getLanguageFolder } from './config';
511
import { formatter } from './formatter';
612
import { createSpinner } from './oraLog';
@@ -15,6 +21,25 @@ async function preGen(
1521
verbose,
1622
});
1723

24+
// We clean models to avoid outdated files.
25+
let modelPath = '';
26+
switch (language) {
27+
case 'javascript':
28+
modelPath = 'model';
29+
break;
30+
case 'java':
31+
modelPath = `algoliasearch-core/com/algolia/model/${client}`;
32+
break;
33+
default:
34+
return;
35+
}
36+
37+
if (modelPath) {
38+
await run(`rm -rf ${toAbsolutePath(`${output}/${modelPath}`)}`, {
39+
verbose,
40+
});
41+
}
42+
1843
await setHostsOptions({ client, key });
1944
}
2045

scripts/pre-gen/setHostsOptions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ export async function setHostsOptions({
122122
...additionalProperties,
123123
};
124124

125-
await writeFile(openapitoolsPath, JSON.stringify(openapitools, null, 2));
125+
await writeFile(
126+
openapitoolsPath,
127+
JSON.stringify(openapitools, null, 2).concat('\n')
128+
);
126129
} catch (e) {
127130
throw new Error(`Error reading yaml file ${generator}: ${e}`);
128131
}

0 commit comments

Comments
 (0)