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

chore: add clean models to preGen #271

Merged
merged 6 commits into from
Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
27 changes: 26 additions & 1 deletion scripts/generate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { buildJSClientUtils } from './buildClients';
import { buildSpecs } from './buildSpecs';
import { buildCustomGenerators, CI, run, runIfExists } from './common';
import {
buildCustomGenerators,
CI,
run,
runIfExists,
toAbsolutePath,
} from './common';
import { getCustomGenerator, getLanguageFolder } from './config';
import { formatter } from './formatter';
import { createSpinner } from './oraLog';
Expand All @@ -15,6 +21,25 @@ async function preGen(
verbose,
});

// We clean models to avoid outdated files.
let modelPath = '';
switch (language) {
case 'javascript':
modelPath = 'model';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first used workspace commands but went back to rm -rf to avoid impacting the package.json of the generated client.

break;
case 'java':
modelPath = `algoliasearch-core/com/algolia/model/${client}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if we move these to clients.config.json?

Copy link
Member Author

@shortcuts shortcuts Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

break;
default:
return;
}

if (modelPath) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small refacto, you could create a function removeExistingModels to return early and avoid this if

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean having an early if for php? Since we are actually re-adding models I thought it was not necessary to extract the logic, but lmk if this is not what you meant

Copy link
Member Author

@shortcuts shortcuts Mar 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it make sense coupled with Eunjae's suggestion, I'll do it!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

await run(`rm -rf ${toAbsolutePath(`${output}/${modelPath}`)}`, {
verbose,
});
}

await setHostsOptions({ client, key });
}

Expand Down
5 changes: 4 additions & 1 deletion scripts/pre-gen/setHostsOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ export async function setHostsOptions({
...additionalProperties,
};

await writeFile(openapitoolsPath, JSON.stringify(openapitools, null, 2));
await writeFile(
openapitoolsPath,
JSON.stringify(openapitools, null, 2).concat('\n')
shortcuts marked this conversation as resolved.
Show resolved Hide resolved
);
} catch (e) {
throw new Error(`Error reading yaml file ${generator}: ${e}`);
}
Expand Down