From fcb37bec0104694135930eeaa93ad23a91043dfb Mon Sep 17 00:00:00 2001 From: Eunjae Lee Date: Mon, 2 May 2022 11:51:37 +0200 Subject: [PATCH] chore(ci): update cts and playground dependencies on release --- scripts/common.ts | 41 ++++++++++++++++++++++++++++++ scripts/release/process-release.ts | 5 ++++ scripts/types.ts | 4 +++ 3 files changed, 50 insertions(+) diff --git a/scripts/common.ts b/scripts/common.ts index 796e5bece4..91bbd3b073 100644 --- a/scripts/common.ts +++ b/scripts/common.ts @@ -15,6 +15,7 @@ import type { CheckForCacheOptions, Generator, RunOptions, + PackageLocationMap, } from './types'; export const MAIN_BRANCH = config.mainBranch; @@ -280,3 +281,43 @@ export async function emptyDirExceptForDotGit(dir: string): Promise { } } } + +export async function readPackageJson(dir: string): Promise { + const filePath = toAbsolutePath(`${dir}/package.json`); + return JSON.parse((await fsp.readFile(filePath)).toString()); +} + +export async function getPackageLocationMap(): Promise { + return (await run(`yarn workspaces list --json`)) + .split('\n') + .reduce((acc, item) => { + const { name, location } = JSON.parse(item); + return { + ...acc, + [name]: location, + }; + }, {}); +} + +export async function updateDependenciesToLocalVersions( + packageDir: string +): Promise { + const packageLocationMap = getPackageLocationMap(); + + const targetPackageJson = await readPackageJson(packageDir); + for (const packageName of targetPackageJson.dependencies) { + if (!packageLocationMap[packageName]) { + // Skip if it's not a local package. + continue; + } + + targetPackageJson.dependencies[packageName] = ( + await readPackageJson(packageLocationMap[packageName]) + ).version; + } + + await fsp.writeFile( + toAbsolutePath(`${packageDir}/package.json`), + `${JSON.stringify(targetPackageJson)}\n` + ); +} diff --git a/scripts/release/process-release.ts b/scripts/release/process-release.ts index 1156ba2ca4..cd7374c993 100755 --- a/scripts/release/process-release.ts +++ b/scripts/release/process-release.ts @@ -11,6 +11,7 @@ import openapitools from '../../openapitools.json'; import { ROOT_ENV_PATH, toAbsolutePath, + updateDependenciesToLocalVersions, run, exists, getGitHubUrl, @@ -44,6 +45,10 @@ const BEFORE_CLIENT_GENERATION: { } = { javascript: async ({ releaseType, dir }) => { await run(`yarn release:bump ${releaseType}`, { cwd: dir }); + + await updateDependenciesToLocalVersions('tests/output/javascript'); + await updateDependenciesToLocalVersions('playground/javascript/browser'); + await updateDependenciesToLocalVersions('playground/javascript/node'); }, }; diff --git a/scripts/types.ts b/scripts/types.ts index f36b75f84a..db71ada6de 100644 --- a/scripts/types.ts +++ b/scripts/types.ts @@ -48,6 +48,10 @@ export type Spec = { paths: Path[]; }; +export type PackageLocationMap = { + [packageName: string]: string; +}; + /** * Server of a spec. */