Skip to content

Commit 718b3f2

Browse files
authored
chore(scripts): use spinnies for multi spinner (#1365)
1 parent 58b1af1 commit 718b3f2

16 files changed

+216
-251
lines changed

scripts/buildClients.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
/* eslint-disable no-case-declarations */
22
import { run } from './common';
33
import { getClientsConfigField, getLanguageFolder } from './config';
4-
import { createSpinner } from './oraLog';
4+
import { createSpinner } from './spinners';
55
import type { Generator, Language } from './types';
66

77
/**
88
* Build client for a language at the same time, for those who live in the same folder.
99
*/
1010
async function buildClient(
1111
language: Language,
12-
gens: Generator[],
13-
{ verbose }: { verbose: boolean; skipUtils: boolean }
12+
gens: Generator[]
1413
): Promise<void> {
1514
const cwd = getLanguageFolder(language);
16-
const spinner = createSpinner(`building '${language}'`, verbose).start();
15+
const spinner = createSpinner(`building '${language}'`);
1716
switch (language) {
1817
case 'java':
19-
await run(`./gradle/gradlew --no-daemon -p ${cwd} assemble`, {
20-
verbose,
21-
});
18+
await run(`./gradle/gradlew --no-daemon -p ${cwd} assemble`);
2219
break;
2320
case 'php':
2421
break;
@@ -32,7 +29,6 @@ async function buildClient(
3229
);
3330

3431
await run(`yarn build:many '{${packageNames.join(',')},}'`, {
35-
verbose: true,
3632
cwd,
3733
});
3834

@@ -42,10 +38,7 @@ async function buildClient(
4238
spinner.succeed();
4339
}
4440

45-
export async function buildClients(
46-
generators: Generator[],
47-
options: { verbose: boolean; skipUtils: boolean }
48-
): Promise<void> {
41+
export async function buildClients(generators: Generator[]): Promise<void> {
4942
const langs = [...new Set(generators.map((gen) => gen.language))];
5043
const generatorsMap = generators.reduce((map, gen) => {
5144
if (!(gen.language in map)) {
@@ -59,6 +52,6 @@ export async function buildClients(
5952
}, {} as Record<Language, Generator[]>);
6053

6154
await Promise.all(
62-
langs.map((lang) => buildClient(lang, generatorsMap[lang], options))
55+
langs.map((lang) => buildClient(lang, generatorsMap[lang]))
6356
);
6457
}

scripts/buildSpecs.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
run,
1010
toAbsolutePath,
1111
} from './common';
12-
import { createSpinner } from './oraLog';
12+
import { createSpinner } from './spinners';
1313
import type { Spec } from './types';
1414

1515
const ALGOLIASEARCH_LITE_OPERATIONS = ['search', 'post'];
@@ -109,8 +109,8 @@ async function transformBundle({
109109
}
110110
}
111111

112-
async function lintCommon(verbose: boolean, useCache: boolean): Promise<void> {
113-
const spinner = createSpinner('linting common spec', verbose).start();
112+
async function lintCommon(useCache: boolean): Promise<void> {
113+
const spinner = createSpinner('linting common spec');
114114

115115
let hash = '';
116116
const cacheFile = toAbsolutePath(`specs/dist/common.cache`);
@@ -130,10 +130,10 @@ async function lintCommon(verbose: boolean, useCache: boolean): Promise<void> {
130130
hash = newCache;
131131
}
132132

133-
await run(`yarn specs:lint common`, { verbose });
133+
await run(`yarn specs:lint common`);
134134

135135
if (hash) {
136-
spinner.text = `storing common spec cache`;
136+
spinner.text = 'storing common spec cache';
137137
await fsp.writeFile(cacheFile, hash);
138138
}
139139

@@ -191,7 +191,6 @@ async function buildLiteSpec({
191191
async function buildSpec(
192192
spec: string,
193193
outputFormat: string,
194-
verbose: boolean,
195194
useCache: boolean
196195
): Promise<void> {
197196
const isAlgoliasearch = spec === 'algoliasearch';
@@ -200,7 +199,7 @@ async function buildSpec(
200199
const cacheFile = toAbsolutePath(`specs/dist/${spec}.cache`);
201200
let hash = '';
202201

203-
const spinner = createSpinner(`starting '${spec}' spec`, verbose).start();
202+
const spinner = createSpinner(`starting '${spec}' spec`);
204203

205204
if (useCache) {
206205
spinner.text = `checking cache for '${specBase}'`;
@@ -223,13 +222,12 @@ async function buildSpec(
223222

224223
// First linting the base
225224
spinner.text = `linting '${spec}' spec`;
226-
await run(`yarn specs:fix ${specBase}`, { verbose });
225+
await run(`yarn specs:fix ${specBase}`);
227226

228227
// Then bundle the file
229228
const bundledPath = `specs/bundled/${spec}.${outputFormat}`;
230229
await run(
231-
`yarn openapi bundle specs/${specBase}/spec.yml -o ${bundledPath} --ext ${outputFormat}`,
232-
{ verbose }
230+
`yarn openapi bundle specs/${specBase}/spec.yml -o ${bundledPath} --ext ${outputFormat}`
233231
);
234232

235233
// Add the correct tags to be able to generate the proper client
@@ -249,12 +247,10 @@ async function buildSpec(
249247

250248
// Validate and lint the final bundle
251249
spinner.text = `validating '${spec}' bundled spec`;
252-
await run(`yarn openapi lint specs/bundled/${spec}.${outputFormat}`, {
253-
verbose,
254-
});
250+
await run(`yarn openapi lint specs/bundled/${spec}.${outputFormat}`);
255251

256252
spinner.text = `linting '${spec}' bundled spec`;
257-
await run(`yarn specs:fix bundled/${spec}.${outputFormat}`, { verbose });
253+
await run(`yarn specs:fix bundled/${spec}.${outputFormat}`);
258254

259255
if (hash) {
260256
spinner.text = `storing '${spec}' spec cache`;
@@ -267,14 +263,13 @@ async function buildSpec(
267263
export async function buildSpecs(
268264
clients: string[],
269265
outputFormat: 'json' | 'yml',
270-
verbose: boolean,
271266
useCache: boolean
272267
): Promise<void> {
273268
await fsp.mkdir(toAbsolutePath('specs/dist'), { recursive: true });
274269

275-
await lintCommon(verbose, useCache);
270+
await lintCommon(useCache);
276271

277272
await Promise.all(
278-
clients.map((client) => buildSpec(client, outputFormat, verbose, useCache))
273+
clients.map((client) => buildSpec(client, outputFormat, useCache))
279274
);
280275
}

scripts/cli/index.ts

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Argument, program } from 'commander';
22

33
import { buildClients } from '../buildClients';
44
import { buildSpecs } from '../buildSpecs';
5-
import { CI, DOCKER, LANGUAGES } from '../common';
5+
import { CI, DOCKER, LANGUAGES, setVerbose } from '../common';
66
import { ctsGenerateMany } from '../cts/generate';
77
import { runCts } from '../cts/runCts';
88
import { formatter } from '../formatter';
@@ -49,10 +49,6 @@ const flags = {
4949
flag: '-s, --skip-cache',
5050
description: 'skip cache checking to force building specs',
5151
},
52-
skipUtils: {
53-
flag: '-su, --skip-utils',
54-
description: 'skip utils build when building a JavaScript client',
55-
},
5652
outputType: {
5753
flag: '-json, --output-json',
5854
description: 'outputs the spec in JSON instead of yml',
@@ -76,10 +72,9 @@ program
7672
interactive,
7773
});
7874

79-
await generate(
80-
generatorList({ language, client, clientList }),
81-
Boolean(verbose)
82-
);
75+
setVerbose(Boolean(verbose));
76+
77+
await generate(generatorList({ language, client, clientList }));
8378
}
8479
);
8580

@@ -92,23 +87,17 @@ buildCommand
9287
.addArgument(args.clients)
9388
.option(flags.verbose.flag, flags.verbose.description)
9489
.option(flags.interactive.flag, flags.interactive.description)
95-
.option(flags.skipUtils.flag, flags.skipUtils.description)
9690
.action(
97-
async (
98-
langArg: LangArg,
99-
clientArg: string[],
100-
{ verbose, interactive, skipUtils }
101-
) => {
91+
async (langArg: LangArg, clientArg: string[], { verbose, interactive }) => {
10292
const { language, client, clientList } = await prompt({
10393
langArg,
10494
clientArg,
10595
interactive,
10696
});
10797

108-
await buildClients(generatorList({ language, client, clientList }), {
109-
verbose: Boolean(verbose),
110-
skipUtils: Boolean(skipUtils),
111-
});
98+
setVerbose(Boolean(verbose));
99+
100+
await buildClients(generatorList({ language, client, clientList }));
112101
}
113102
);
114103

@@ -131,13 +120,14 @@ buildCommand
131120
interactive,
132121
});
133122

123+
setVerbose(Boolean(verbose));
124+
134125
const outputFormat = outputJson ? 'json' : 'yml';
135126

136127
// ignore cache when building from cli
137128
await buildSpecs(
138129
client[0] === ALL ? clientList : client,
139130
outputFormat,
140-
Boolean(verbose),
141131
!skipCache
142132
);
143133
}
@@ -160,10 +150,9 @@ ctsCommand
160150
interactive,
161151
});
162152

163-
await ctsGenerateMany(
164-
generatorList({ language, client, clientList }),
165-
Boolean(verbose)
166-
);
153+
setVerbose(Boolean(verbose));
154+
155+
await ctsGenerateMany(generatorList({ language, client, clientList }));
167156
}
168157
);
169158

@@ -180,7 +169,9 @@ ctsCommand
180169
interactive,
181170
});
182171

183-
await runCts(language === ALL ? LANGUAGES : [language], Boolean(verbose));
172+
setVerbose(Boolean(verbose));
173+
174+
await runCts(language === ALL ? LANGUAGES : [language]);
184175
});
185176

186177
program
@@ -196,6 +187,8 @@ program
196187
interactive,
197188
});
198189

190+
setVerbose(false);
191+
199192
await playground({
200193
language,
201194
client: client[0],
@@ -209,7 +202,9 @@ program
209202
.argument('folder', 'The folder to format')
210203
.option(flags.verbose.flag, flags.verbose.description)
211204
.action(async (language: string, folder: string, { verbose }) => {
212-
await formatter(language, folder, verbose);
205+
setVerbose(Boolean(verbose));
206+
207+
await formatter(language, folder);
213208
});
214209

215210
program.parse();

scripts/common.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { remove } from 'fs-extra';
99
import openapiConfig from '../config/openapitools.json';
1010
import releaseConfig from '../config/release.config.json';
1111

12-
import { createSpinner } from './oraLog';
12+
import { createSpinner } from './spinners';
1313
import type {
1414
CheckForCache,
1515
CheckForCacheOptions,
@@ -76,11 +76,11 @@ export const CLIENTS_JS_UTILS = [
7676

7777
export async function run(
7878
command: string,
79-
{ errorMessage, verbose, cwd }: RunOptions = {}
79+
{ errorMessage, cwd }: RunOptions = {}
8080
): Promise<string> {
8181
const realCwd = path.resolve(ROOT_DIR, cwd ?? '.');
8282
try {
83-
if (verbose) {
83+
if (isVerbose()) {
8484
return (
8585
(
8686
await execa.command(command, {
@@ -187,8 +187,8 @@ export async function checkForCache({
187187
return cache;
188188
}
189189

190-
export async function buildCustomGenerators(verbose: boolean): Promise<void> {
191-
const spinner = createSpinner('building custom generators', verbose).start();
190+
export async function buildCustomGenerators(): Promise<void> {
191+
const spinner = createSpinner('building custom generators');
192192

193193
const cacheFile = toAbsolutePath('generators/.cache');
194194
const { cacheExists, hash } = await checkForCache({
@@ -203,9 +203,7 @@ export async function buildCustomGenerators(verbose: boolean): Promise<void> {
203203
return;
204204
}
205205

206-
await run('./gradle/gradlew --no-daemon -p generators assemble', {
207-
verbose,
208-
});
206+
await run('./gradle/gradlew --no-daemon -p generators assemble');
209207

210208
if (hash) {
211209
spinner.text = 'storing custom generators cache';
@@ -227,13 +225,10 @@ export async function emptyDirExceptForDotGit(dir: string): Promise<void> {
227225
}
228226
}
229227

230-
export async function runComposerUpdate(verbose: boolean): Promise<void> {
228+
export async function runComposerUpdate(): Promise<void> {
231229
if (!CI) {
232230
await run(
233-
'composer update --working-dir=clients/algoliasearch-client-php && composer dump-autoload --working-dir=clients/algoliasearch-client-php',
234-
{
235-
verbose,
236-
}
231+
'composer update --working-dir=clients/algoliasearch-client-php && composer dump-autoload --working-dir=clients/algoliasearch-client-php'
237232
);
238233
}
239234
}
@@ -289,3 +284,12 @@ export function camelize(str: string, delimiter: string = '-'): string {
289284
export function capitalize(str: string): string {
290285
return str.charAt(0).toUpperCase() + str.slice(1);
291286
}
287+
288+
let verbose = false;
289+
export function setVerbose(v: boolean): void {
290+
verbose = v;
291+
}
292+
293+
export function isVerbose(): boolean {
294+
return verbose;
295+
}

0 commit comments

Comments
 (0)