Skip to content

Commit fcb37be

Browse files
committed
chore(ci): update cts and playground dependencies on release
1 parent 56c17ce commit fcb37be

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

scripts/common.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
CheckForCacheOptions,
1616
Generator,
1717
RunOptions,
18+
PackageLocationMap,
1819
} from './types';
1920

2021
export const MAIN_BRANCH = config.mainBranch;
@@ -280,3 +281,43 @@ export async function emptyDirExceptForDotGit(dir: string): Promise<void> {
280281
}
281282
}
282283
}
284+
285+
export async function readPackageJson(dir: string): Promise<any> {
286+
const filePath = toAbsolutePath(`${dir}/package.json`);
287+
return JSON.parse((await fsp.readFile(filePath)).toString());
288+
}
289+
290+
export async function getPackageLocationMap(): Promise<PackageLocationMap> {
291+
return (await run(`yarn workspaces list --json`))
292+
.split('\n')
293+
.reduce((acc, item) => {
294+
const { name, location } = JSON.parse(item);
295+
return {
296+
...acc,
297+
[name]: location,
298+
};
299+
}, {});
300+
}
301+
302+
export async function updateDependenciesToLocalVersions(
303+
packageDir: string
304+
): Promise<void> {
305+
const packageLocationMap = getPackageLocationMap();
306+
307+
const targetPackageJson = await readPackageJson(packageDir);
308+
for (const packageName of targetPackageJson.dependencies) {
309+
if (!packageLocationMap[packageName]) {
310+
// Skip if it's not a local package.
311+
continue;
312+
}
313+
314+
targetPackageJson.dependencies[packageName] = (
315+
await readPackageJson(packageLocationMap[packageName])
316+
).version;
317+
}
318+
319+
await fsp.writeFile(
320+
toAbsolutePath(`${packageDir}/package.json`),
321+
`${JSON.stringify(targetPackageJson)}\n`
322+
);
323+
}

scripts/release/process-release.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import openapitools from '../../openapitools.json';
1111
import {
1212
ROOT_ENV_PATH,
1313
toAbsolutePath,
14+
updateDependenciesToLocalVersions,
1415
run,
1516
exists,
1617
getGitHubUrl,
@@ -44,6 +45,10 @@ const BEFORE_CLIENT_GENERATION: {
4445
} = {
4546
javascript: async ({ releaseType, dir }) => {
4647
await run(`yarn release:bump ${releaseType}`, { cwd: dir });
48+
49+
await updateDependenciesToLocalVersions('tests/output/javascript');
50+
await updateDependenciesToLocalVersions('playground/javascript/browser');
51+
await updateDependenciesToLocalVersions('playground/javascript/node');
4752
},
4853
};
4954

scripts/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ export type Spec = {
4848
paths: Path[];
4949
};
5050

51+
export type PackageLocationMap = {
52+
[packageName: string]: string;
53+
};
54+
5155
/**
5256
* Server of a spec.
5357
*/

0 commit comments

Comments
 (0)