Skip to content

Commit c89b45e

Browse files
committed
chore(scripts): allow variadic compilation for javascript
1 parent 06c4854 commit c89b45e

File tree

3 files changed

+45
-36
lines changed

3 files changed

+45
-36
lines changed

playground/javascript/node/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"private": true,
55
"type": "module",
66
"scripts": {
7-
"start": "tsc && node --env-file=../../.env dist/$0.js",
8-
"build": "tsc"
7+
"start": "tsc && node --env-file=../../.env dist/$0.js"
98
},
109
"dependencies": {
1110
"@algolia/client-abtesting": "link:../../../clients/algoliasearch-client-javascript/packages/client-abtesting",

scripts/buildLanguages.ts

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ async function buildLanguage(language: Language, gens: Generator[], buildType: B
4848
packageName === 'algoliasearch' ? packageName : `@algolia/${packageName}`,
4949
);
5050
await run(`yarn build:many '{${packageNames.join(',')},}'`, { cwd, language });
51-
} else if (buildType === 'playground') {
52-
await run('yarn build', { cwd: `${cwd}/node`, language });
53-
} else {
54-
await run('yarn tsc --noEmit', { cwd, language });
51+
break;
5552
}
5653

54+
await run(`yarn tsc ${gens.reduce((prev, curr) => `${prev} ${curr.client}.ts`, '')} --noEmit`, {
55+
cwd: buildType === 'playground' ? `${cwd}/node` : cwd,
56+
language,
57+
});
58+
5759
break;
5860
case 'java':
5961
case 'kotlin':
@@ -89,40 +91,30 @@ async function buildLanguage(language: Language, gens: Generator[], buildType: B
8991
spinner.succeed();
9092
}
9193

92-
export async function buildClients(generators: Generator[]): Promise<void> {
94+
export async function buildLanguages(generators: Generator[], scope: BuildType): Promise<void> {
9395
const langs = [...new Set(generators.map((gen) => gen.language))];
9496
const generatorsMap = generators.reduce(
9597
(map, gen) => {
9698
if (!(gen.language in map)) {
9799
map[gen.language] = [];
98100
}
99101

102+
// there is no monitoring client for now
103+
if (gen.client === 'monitoring') {
104+
return map;
105+
}
106+
107+
// TODO: remove this when guides are mandatory and implemented in every clients
108+
if (scope === 'guides' && !existsSync(toAbsolutePath(`docs/guides/${gen.language}`))) {
109+
return map;
110+
}
111+
100112
map[gen.language].push(gen);
101113

102114
return map;
103115
},
104116
{} as Record<Language, Generator[]>,
105117
);
106118

107-
await Promise.all(langs.map((lang) => buildLanguage(lang, generatorsMap[lang], 'client')));
108-
}
109-
110-
export async function buildPlaygrounds(languages: Language[]): Promise<void> {
111-
await Promise.all(languages.map((lang) => buildLanguage(lang, [], 'playground')));
112-
}
113-
114-
export async function buildSnippets(languages: Language[]): Promise<void> {
115-
await Promise.all(languages.map((lang) => buildLanguage(lang, [], 'snippets')));
116-
}
117-
118-
export async function buildGuides(languages: Language[]): Promise<void> {
119-
await Promise.all(
120-
languages.map((lang) => {
121-
if (!existsSync(toAbsolutePath(`docs/guides/${lang}`))) {
122-
return Promise.resolve();
123-
}
124-
125-
return buildLanguage(lang, [], 'guides');
126-
}),
127-
);
119+
await Promise.all(langs.map((lang) => buildLanguage(lang, generatorsMap[lang], scope)));
128120
}

scripts/cli/index.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Argument, program } from 'commander';
22
import semver from 'semver';
33

4-
import { buildClients, buildGuides, buildPlaygrounds, buildSnippets } from '../buildLanguages.js';
4+
import { buildLanguages } from '../buildLanguages.js';
55
import { CI, CLIENTS, LANGUAGES, run, setVerbose, toAbsolutePath } from '../common.js';
66
import { getLanguageFolder } from '../config.js';
77
import { ctsGenerateMany } from '../cts/generate.js';
@@ -82,40 +82,58 @@ buildCommand
8282

8383
setVerbose(Boolean(verbose));
8484

85-
await buildClients(generatorList({ language, client, clientList }));
85+
await buildLanguages(generatorList({ language, client, clientList }), 'client');
8686
});
8787

8888
buildCommand
8989
.command('playground')
9090
.description('Build a specified playground')
9191
.addArgument(args.language)
92+
.addArgument(args.clients)
9293
.option(flags.verbose.flag, flags.verbose.description)
93-
.action(async (langArg: LangArg, { verbose }) => {
94+
.action(async (langArg: LangArg, clientArg: string[], { verbose }) => {
95+
const { language, client, clientList } = transformSelection({
96+
langArg,
97+
clientArg,
98+
});
99+
94100
setVerbose(Boolean(verbose));
95101

96-
await buildPlaygrounds(langArg === ALL || langArg === undefined ? LANGUAGES : [langArg]);
102+
await buildLanguages(generatorList({ language, client, clientList }), 'playground');
97103
});
98104

99105
buildCommand
100106
.command('snippets')
101107
.description('Build a specified snippets')
102108
.addArgument(args.language)
109+
.addArgument(args.clients)
103110
.option(flags.verbose.flag, flags.verbose.description)
104-
.action(async (langArg: LangArg, { verbose }) => {
111+
.action(async (langArg: LangArg, clientArg: string[], { verbose }) => {
112+
const { language, client, clientList } = transformSelection({
113+
langArg,
114+
clientArg,
115+
});
116+
105117
setVerbose(Boolean(verbose));
106118

107-
await buildSnippets(langArg === ALL || langArg === undefined ? LANGUAGES : [langArg]);
119+
await buildLanguages(generatorList({ language, client, clientList }), 'snippets');
108120
});
109121

110122
buildCommand
111123
.command('guides')
112124
.description('Build a specified guides')
113125
.addArgument(args.language)
126+
.addArgument(args.clients)
114127
.option(flags.verbose.flag, flags.verbose.description)
115-
.action(async (langArg: LangArg, { verbose }) => {
128+
.action(async (langArg: LangArg, clientArg: string[], { verbose }) => {
129+
const { language, client, clientList } = transformSelection({
130+
langArg,
131+
clientArg,
132+
});
133+
116134
setVerbose(Boolean(verbose));
117135

118-
await buildGuides(langArg === ALL || langArg === undefined ? LANGUAGES : [langArg]);
136+
await buildLanguages(generatorList({ language, client, clientList }), 'guides');
119137
});
120138

121139
buildCommand

0 commit comments

Comments
 (0)