Skip to content

Commit 3b0b43b

Browse files
authored
fix(script): add common cache, add skipCache option (#196)
1 parent 9e5250c commit 3b0b43b

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

scripts/buildSpecs.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ async function buildSpec(
1313
): Promise<void> {
1414
createSpinner(`'${client}' spec`, verbose).start().info();
1515
const cacheFile = toAbsolutePath(`specs/dist/${client}.cache`);
16+
let hash = '';
17+
1618
if (useCache) {
1719
const spinner = createSpinner(
1820
`checking cache for '${client}'`,
@@ -21,7 +23,11 @@ async function buildSpec(
2123
// check if file and cache exist
2224
if (await exists(toAbsolutePath(`specs/bundled/${client}.yml`))) {
2325
// compare with stored cache
24-
const hash = (await hashElement(toAbsolutePath(`specs/${client}`))).hash;
26+
const specHash = (await hashElement(toAbsolutePath(`specs/${client}`)))
27+
.hash;
28+
const commonHash = (await hashElement(toAbsolutePath(`specs/common`)))
29+
.hash;
30+
hash = `${specHash}-${commonHash}`;
2531
if (await exists(cacheFile)) {
2632
const storedHash = (await fsp.readFile(cacheFile)).toString();
2733
if (storedHash === hash) {
@@ -45,14 +51,18 @@ async function buildSpec(
4551
{ verbose }
4652
);
4753

48-
spinner.text = `validating '${client}' spec`;
54+
spinner.text = `validating '${client}' bundled spec`;
4955
await run(`yarn openapi lint specs/bundled/${client}.${outputFormat}`, {
5056
verbose,
5157
});
5258

53-
spinner.text = `storing ${client} spec cache`;
54-
const hash = (await hashElement(toAbsolutePath(`specs/${client}`))).hash;
55-
await fsp.writeFile(cacheFile, hash);
59+
spinner.text = `linting '${client}' bundled spec`;
60+
await run(`yarn specs:lint bundled/${client}.${outputFormat}`, { verbose });
61+
62+
if (hash) {
63+
spinner.text = `storing ${client} spec cache`;
64+
await fsp.writeFile(cacheFile, hash);
65+
}
5666

5767
spinner.succeed(`building complete for '${client}' spec`);
5868
}

scripts/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ buildCommand
169169
)
170170
.option('-v, --verbose', 'make the verification verbose')
171171
.option('-i, --interactive', 'open prompt to query parameters')
172+
.option('-s, --skip-cache', 'skip cache checking to force building specs')
172173
.action(
173174
async (
174175
client: string | undefined,
175176
outputFormat: 'json' | 'yml' | undefined,
176-
{ verbose, interactive }
177+
{ verbose, interactive, skipCache }
177178
) => {
178179
client = await promptClient(client, interactive);
179180

@@ -186,7 +187,12 @@ buildCommand
186187
clientsTodo = CLIENTS;
187188
}
188189
// ignore cache when building from cli
189-
await buildSpecs(clientsTodo, outputFormat!, Boolean(verbose), false);
190+
await buildSpecs(
191+
clientsTodo,
192+
outputFormat!,
193+
Boolean(verbose),
194+
!skipCache
195+
);
190196
}
191197
);
192198

0 commit comments

Comments
 (0)