diff --git a/desktop/scripts/bump-versions.ts b/desktop/scripts/bump-versions.ts index 2f2bf18f7..8cfbd7a9c 100644 --- a/desktop/scripts/bump-versions.ts +++ b/desktop/scripts/bump-versions.ts @@ -14,6 +14,7 @@ const argv = yargs .usage('$0 [args]') .options({ newVersion: {key: 'new-version', alias: 'v', type: 'string'}, + dryRun: {key: 'dry-run', alias: 'd', type: 'boolean'}, }) .help().argv; diff --git a/desktop/scripts/publish-packages.ts b/desktop/scripts/publish-packages.ts index acc69b22a..e68696c36 100644 --- a/desktop/scripts/publish-packages.ts +++ b/desktop/scripts/publish-packages.ts @@ -15,6 +15,7 @@ const argv = yargs .options({ newVersion: {key: 'new-version', alias: 'v', type: 'string'}, proxy: {key: 'proxy', alias: 'p', type: 'string'}, + dryRun: {key: 'dry-run', alias: 'd', type: 'boolean'}, }) .help().argv; diff --git a/desktop/scripts/workspaces.ts b/desktop/scripts/workspaces.ts index 8ad524f11..6c700dc59 100644 --- a/desktop/scripts/workspaces.ts +++ b/desktop/scripts/workspaces.ts @@ -60,8 +60,14 @@ export async function getWorkspaces(): Promise { }; } -export async function bumpVersions({newVersion}: {newVersion?: string}) { - return await bumpWorkspaceVersions(await getWorkspaces(), newVersion); +export async function bumpVersions({ + newVersion, + dryRun, +}: { + newVersion?: string; + dryRun?: boolean; +}) { + return await bumpWorkspaceVersions(await getWorkspaces(), newVersion, dryRun); } async function savePackageJson({dir, json}: Package) { @@ -71,6 +77,7 @@ async function savePackageJson({dir, json}: Package) { } function updateDependencies( + name: string, dependencies: {[key: string]: string}, packagesToUpdate: string[], newVersion: string, @@ -84,6 +91,9 @@ function updateDependencies( dependencies[packageName] !== undefined && dependencies[packageName] !== newVersion ) { + console.log( + `Updated dependency of ${name}: ${packageName} from version ${dependencies[packageName]} to version ${newVersion}`, + ); dependencies[packageName] = newVersion; updated = true; } @@ -94,6 +104,7 @@ function updateDependencies( async function bumpWorkspaceVersions( {rootPackage, packages}: Workspaces, newVersion?: string, + dryRun?: boolean, ): Promise { newVersion = newVersion || (rootPackage.json.version as string); const allPackages = [rootPackage, ...packages]; @@ -104,24 +115,51 @@ async function bumpWorkspaceVersions( const {dir, json} = pkg; let changed = false; if (json.version !== newVersion && !isPlugin(dir)) { + console.log( + `Bumping version of ${pkg.json.name} from ${json.version} to ${newVersion}`, + ); json.version = newVersion; changed = true; } - if (updateDependencies(json.dependencies, localPackageNames, newVersion)) { - changed = true; - } if ( - updateDependencies(json.devDependencies, localPackageNames, newVersion) + updateDependencies( + json.name, + json.dependencies, + localPackageNames, + newVersion, + ) ) { changed = true; } if ( - updateDependencies(json.peerDependencies, localPackageNames, newVersion) + updateDependencies( + json.name, + json.devDependencies, + localPackageNames, + newVersion, + ) + ) { + changed = true; + } + if ( + updateDependencies( + json.name, + json.peerDependencies, + localPackageNames, + newVersion, + ) ) { changed = true; } if (changed) { - await savePackageJson(pkg); + if (dryRun) { + console.log( + `DRYRUN: skipping saving changed package.json for ${pkg.json.name}`, + ); + } else { + console.log(`Saving changed package.json for ${pkg.json.name}`); + await savePackageJson(pkg); + } } } return newVersion; @@ -130,19 +168,25 @@ async function bumpWorkspaceVersions( export async function publishPackages({ newVersion, proxy, + dryRun, }: { newVersion?: string; proxy?: string; + dryRun?: boolean; }) { const workspaces = await getWorkspaces(); - const version = await bumpWorkspaceVersions(workspaces, newVersion); + const version = await bumpWorkspaceVersions(workspaces, newVersion, dryRun); let cmd = `yarn publish --new-version ${version}`; if (proxy) { cmd += ` --http-proxy ${proxy} --https-proxy ${proxy}`; } const publicPackages = workspaces.packages.filter((pkg) => !pkg.json.private); for (const pkg of publicPackages) { - console.log(`Publishing ${pkg.json.name}...`); - execSync(cmd, {cwd: pkg.dir, stdio: 'inherit'}); + if (dryRun) { + console.log(`DRYRUN: Skipping npm publishing for ${pkg.json.name}`); + } else { + console.log(`Publishing ${pkg.json.name}...`); + execSync(cmd, {cwd: pkg.dir, stdio: 'inherit'}); + } } }