Skip to content

fix(script): restore previous CLI build logic #384

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

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 8 additions & 4 deletions clients/algoliasearch-client-javascript/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,18 @@ function getUtilConfigs() {
];
}

function isClientBuilt(client) {
function shouldBuildUtil(utilClient) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can rebase on #383 to avoid touching this file.
Or not if you want to merge fast

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what I did first but since @eunjae-lee is off and I want to keep working on JS client it's better for me to merge :D

if (process.env.SKIP_UTILS === 'true') {
return false;
}

// Checking existence of `dist` folder doesn't really guarantee the built files are up-to-date.
// However, on the CI, it's very likely.
// For the local environment, we simply return `false`, which will trigger unnecessary builds.
// We can come back here and improve this part (checking if `dist` folder exists and if it's up-to-date).
return process.env.CI
? fs.existsSync(path.resolve('packages', client, 'dist'))
: false;
? !fs.existsSync(path.resolve('packages', utilClient, 'dist'))
: true;
}

function getPackageConfigs() {
Expand Down Expand Up @@ -168,7 +172,7 @@ function getPackageConfigs() {
});

return [
...getUtilConfigs().filter((config) => !isClientBuilt(config.package)),
...getUtilConfigs().filter((config) => shouldBuildUtil(config.package)),
...configs,
];
}
Expand Down
103 changes: 57 additions & 46 deletions scripts/buildClients.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,40 @@
import {
createGeneratorKey,
GENERATORS,
LANGUAGES,
run,
toAbsolutePath,
} from './common';
import { run } from './common';
import { getLanguageFolder } from './config';
import { createSpinner } from './oraLog';
import type { Generator } from './types';

const multiBuildLanguage = new Set(['javascript']);

/**
* Build all client for a language at the same time, for those who live in the same folder.
* Build only a specific client for one language, used by javascript for example.
*/
async function buildPerLanguage({
language,
client,
verbose,
}: {
language: string;
client: string;
verbose: boolean;
}): Promise<void> {
const spinner = createSpinner(`building '${language}'`, verbose).start();
const cwd = toAbsolutePath(getLanguageFolder(language));
const generator =
client === 'all'
? null
: GENERATORS[createGeneratorKey({ language, client })];

async function buildPerClient(
{ language, key, additionalProperties: { packageName } }: Generator,
verbose: boolean
): Promise<void> {
const spinner = createSpinner(`building ${key}`, verbose).start();
switch (language) {
case 'javascript':
await run(`yarn clean`, { cwd, verbose });
await run(`yarn workspace ${packageName} clean`, { verbose });
await run(
`yarn build ${
client === 'all'
? ''
: generator?.additionalProperties.buildFile ?? client
}`,
{
cwd,
verbose,
}
`SKIP_UTILS=true yarn workspace algoliasearch-client-javascript build ${packageName}`,
{ verbose }
);
break;
default:
}
spinner.succeed();
}

/**
* Build all client for a language at the same time, for those who live in the same folder.
*/
async function buildAllClients(
language: string,
verbose: boolean
): Promise<void> {
const spinner = createSpinner(`building '${language}'`, verbose).start();
switch (language) {
case 'java':
await run(
`./gradle/gradlew --no-daemon -p ${getLanguageFolder(
Expand All @@ -60,19 +53,37 @@ async function buildPerLanguage({
}

export async function buildClients(
language: string,
client: string,
generators: Generator[],
verbose: boolean
): Promise<void> {
const languages = language === 'all' ? LANGUAGES : [language];
const langs = [...new Set(generators.map((gen) => gen.language))];

if (langs.includes('javascript')) {
const spinner = createSpinner(
"building 'JavaScript' utils",
verbose
).start();

await run('yarn workspace algoliasearch-client-javascript clean:utils', {
verbose,
});
await run('yarn workspace algoliasearch-client-javascript build:utils', {
verbose,
});

spinner.succeed();
}

await Promise.all(
languages.map((lang) =>
buildPerLanguage({
language: lang,
client,
verbose,
})
)
);
await Promise.all([
Promise.all(
generators
.filter(({ language }) => multiBuildLanguage.has(language))
.map((gen) => buildPerClient(gen, verbose))
),
Promise.all(
langs
.filter((lang) => !multiBuildLanguage.has(lang))
.map((lang) => buildAllClients(lang, verbose))
),
]);
}
11 changes: 6 additions & 5 deletions scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,14 @@ buildCommand
) => {
language = await promptLanguage(language, interactive);

const shouldBuildJs = language === 'javascript' || language === 'all';
const clientList = shouldBuildJs
? [...CLIENTS_JS_UTILS, ...CLIENTS_JS]
: CLIENTS;
const clientList =
language === 'javascript' || language === 'all' ? CLIENTS_JS : CLIENTS;
client = await promptClient(client, interactive, clientList);

await buildClients(language, client, Boolean(verbose));
await buildClients(
generatorList({ language, client, clientList }),
Boolean(verbose)
);
}
);

Expand Down