From 61677b2ac4ac4b157cbc9e416eb36b9a0a3cb7d3 Mon Sep 17 00:00:00 2001 From: LongYinan Date: Thu, 1 Feb 2024 07:16:18 +0000 Subject: [PATCH] chore: change bump-blocksuite script to js (#5763) `./scripts/bump-blocksuite.js` --- scripts/bump-blocksuite.js | 3 + scripts/bump-blocksuite.sh | 13 ---- tools/bump-blocksuite/index.js | 45 ++++++++++---- tools/bump-blocksuite/package.json | 3 +- yarn.lock | 99 +++++++++++++++--------------- 5 files changed, 88 insertions(+), 75 deletions(-) create mode 100755 scripts/bump-blocksuite.js delete mode 100755 scripts/bump-blocksuite.sh diff --git a/scripts/bump-blocksuite.js b/scripts/bump-blocksuite.js new file mode 100755 index 0000000000..1a665bff4b --- /dev/null +++ b/scripts/bump-blocksuite.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +import('@affine/bump-blocksuite'); diff --git a/scripts/bump-blocksuite.sh b/scripts/bump-blocksuite.sh deleted file mode 100755 index 229af65b59..0000000000 --- a/scripts/bump-blocksuite.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -LATEST_NIGHTLY=$(npm view @blocksuite/presets@nightly version | cut -d ':' -f 2 | tr -d '[:space:]') -echo "Bump to latest BlockSuite nightly version: $LATEST_NIGHTLY" - -yarn up \ - "@blocksuite/store@${LATEST_NIGHTLY}" \ - "@blocksuite/blocks@${LATEST_NIGHTLY}" \ - "@blocksuite/presets@${LATEST_NIGHTLY}" \ - "@blocksuite/global@${LATEST_NIGHTLY}" \ - "@blocksuite/block-std@${LATEST_NIGHTLY}" \ - "@blocksuite/lit@${LATEST_NIGHTLY}" \ - "@blocksuite/inline@${LATEST_NIGHTLY}" diff --git a/tools/bump-blocksuite/index.js b/tools/bump-blocksuite/index.js index 23b41c1595..e05e21aee4 100644 --- a/tools/bump-blocksuite/index.js +++ b/tools/bump-blocksuite/index.js @@ -3,7 +3,14 @@ import { join } from 'node:path'; import { fileURLToPath } from 'node:url'; import { Clipboard } from '@napi-rs/clipboard'; -import { Repository, Sort } from '@napi-rs/simple-git'; +import { + FetchOptions, + ProxyOptions, + RemoteCallbacks, + Repository, + Sort, +} from '@napi-rs/simple-git'; +import chalk from 'chalk'; import corePackage from '../../packages/frontend/core/package.json' assert { type: 'json' }; @@ -20,6 +27,11 @@ const info = await fetch( const latestVersion = info['dist-tags'].nightly; const latestHash = latestVersion.split('-').pop(); +if (oldHash === latestHash) { + console.info(chalk.greenBright('Already updated')); + process.exit(0); +} + console.info(`Upgrade blocksuite from ${oldHash} -> ${latestHash}`); const blockSuiteDeps = execSync(`yarn info -A --name-only --json`, { @@ -38,7 +50,7 @@ const blocksuiteDepsList = blockSuiteDeps for (const pkg of blocksuiteDepsList) { const command = `yarn up ${pkg}@${latestVersion}`; - console.info(`Executing ${command}`); + console.info(chalk.bgCyan(`Executing ${command}`)); execSync(command, { stdio: 'inherit', }); @@ -50,16 +62,25 @@ const repo = new Repository( join(fileURLToPath(import.meta.url), '..', '..', '..', '..', 'BlockSuite') ); -repo.remote('origin').fetch(['master'], progress => { - if (progress.totalDeltas && progress.totalObjects) { - console.log( - `${( - (progress.receivedObjects / progress.totalObjects) * 50 + - (progress.indexedDeltas / progress.totalDeltas) * 50 - ).toFixed(2)}%` - ); - } -}); +const remote = repo.remoteAnonymous( + 'https://github.com/toeverything/BlockSuite.git' +); + +remote.fetch( + ['master'], + new FetchOptions().proxyOptions(new ProxyOptions().auto()).remoteCallback( + new RemoteCallbacks().transferProgress(progress => { + if (progress.totalDeltas && progress.totalObjects) { + console.log( + `${( + (progress.receivedObjects / progress.totalObjects) * 50 + + (progress.indexedDeltas / progress.totalDeltas) * 50 + ).toFixed(2)}%` + ); + } + }) + ) +); const latest = repo.findCommit(latestHash); diff --git a/tools/bump-blocksuite/package.json b/tools/bump-blocksuite/package.json index 72a09e5f3d..dc3aa93c28 100644 --- a/tools/bump-blocksuite/package.json +++ b/tools/bump-blocksuite/package.json @@ -7,6 +7,7 @@ "description": "Generate changelog from blocksuite version change", "dependencies": { "@napi-rs/clipboard": "^1.1.1", - "@napi-rs/simple-git": "^0.1.11" + "@napi-rs/simple-git": "^0.1.16", + "chalk": "^5.3.0" } } diff --git a/yarn.lock b/yarn.lock index f843228942..825c61a812 100644 --- a/yarn.lock +++ b/yarn.lock @@ -154,7 +154,8 @@ __metadata: resolution: "@affine/bump-blocksuite@workspace:tools/bump-blocksuite" dependencies: "@napi-rs/clipboard": "npm:^1.1.1" - "@napi-rs/simple-git": "npm:^0.1.11" + "@napi-rs/simple-git": "npm:^0.1.16" + chalk: "npm:^5.3.0" languageName: unknown linkType: soft @@ -7133,98 +7134,98 @@ __metadata: languageName: node linkType: hard -"@napi-rs/simple-git-android-arm-eabi@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-android-arm-eabi@npm:0.1.11" +"@napi-rs/simple-git-android-arm-eabi@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-android-arm-eabi@npm:0.1.16" conditions: os=android & cpu=arm languageName: node linkType: hard -"@napi-rs/simple-git-android-arm64@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-android-arm64@npm:0.1.11" +"@napi-rs/simple-git-android-arm64@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-android-arm64@npm:0.1.16" conditions: os=android & cpu=arm64 languageName: node linkType: hard -"@napi-rs/simple-git-darwin-arm64@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-darwin-arm64@npm:0.1.11" +"@napi-rs/simple-git-darwin-arm64@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-darwin-arm64@npm:0.1.16" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@napi-rs/simple-git-darwin-x64@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-darwin-x64@npm:0.1.11" +"@napi-rs/simple-git-darwin-x64@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-darwin-x64@npm:0.1.16" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@napi-rs/simple-git-linux-arm-gnueabihf@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-linux-arm-gnueabihf@npm:0.1.11" +"@napi-rs/simple-git-linux-arm-gnueabihf@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-linux-arm-gnueabihf@npm:0.1.16" conditions: os=linux & cpu=arm languageName: node linkType: hard -"@napi-rs/simple-git-linux-arm64-gnu@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-linux-arm64-gnu@npm:0.1.11" +"@napi-rs/simple-git-linux-arm64-gnu@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-linux-arm64-gnu@npm:0.1.16" conditions: os=linux & cpu=arm64 & libc=glibc languageName: node linkType: hard -"@napi-rs/simple-git-linux-arm64-musl@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-linux-arm64-musl@npm:0.1.11" +"@napi-rs/simple-git-linux-arm64-musl@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-linux-arm64-musl@npm:0.1.16" conditions: os=linux & cpu=arm64 & libc=musl languageName: node linkType: hard -"@napi-rs/simple-git-linux-x64-gnu@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-linux-x64-gnu@npm:0.1.11" +"@napi-rs/simple-git-linux-x64-gnu@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-linux-x64-gnu@npm:0.1.16" conditions: os=linux & cpu=x64 & libc=glibc languageName: node linkType: hard -"@napi-rs/simple-git-linux-x64-musl@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-linux-x64-musl@npm:0.1.11" +"@napi-rs/simple-git-linux-x64-musl@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-linux-x64-musl@npm:0.1.16" conditions: os=linux & cpu=x64 & libc=musl languageName: node linkType: hard -"@napi-rs/simple-git-win32-arm64-msvc@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-win32-arm64-msvc@npm:0.1.11" +"@napi-rs/simple-git-win32-arm64-msvc@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-win32-arm64-msvc@npm:0.1.16" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@napi-rs/simple-git-win32-x64-msvc@npm:0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git-win32-x64-msvc@npm:0.1.11" +"@napi-rs/simple-git-win32-x64-msvc@npm:0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git-win32-x64-msvc@npm:0.1.16" conditions: os=win32 & cpu=x64 languageName: node linkType: hard -"@napi-rs/simple-git@npm:^0.1.11": - version: 0.1.11 - resolution: "@napi-rs/simple-git@npm:0.1.11" +"@napi-rs/simple-git@npm:^0.1.16": + version: 0.1.16 + resolution: "@napi-rs/simple-git@npm:0.1.16" dependencies: - "@napi-rs/simple-git-android-arm-eabi": "npm:0.1.11" - "@napi-rs/simple-git-android-arm64": "npm:0.1.11" - "@napi-rs/simple-git-darwin-arm64": "npm:0.1.11" - "@napi-rs/simple-git-darwin-x64": "npm:0.1.11" - "@napi-rs/simple-git-linux-arm-gnueabihf": "npm:0.1.11" - "@napi-rs/simple-git-linux-arm64-gnu": "npm:0.1.11" - "@napi-rs/simple-git-linux-arm64-musl": "npm:0.1.11" - "@napi-rs/simple-git-linux-x64-gnu": "npm:0.1.11" - "@napi-rs/simple-git-linux-x64-musl": "npm:0.1.11" - "@napi-rs/simple-git-win32-arm64-msvc": "npm:0.1.11" - "@napi-rs/simple-git-win32-x64-msvc": "npm:0.1.11" + "@napi-rs/simple-git-android-arm-eabi": "npm:0.1.16" + "@napi-rs/simple-git-android-arm64": "npm:0.1.16" + "@napi-rs/simple-git-darwin-arm64": "npm:0.1.16" + "@napi-rs/simple-git-darwin-x64": "npm:0.1.16" + "@napi-rs/simple-git-linux-arm-gnueabihf": "npm:0.1.16" + "@napi-rs/simple-git-linux-arm64-gnu": "npm:0.1.16" + "@napi-rs/simple-git-linux-arm64-musl": "npm:0.1.16" + "@napi-rs/simple-git-linux-x64-gnu": "npm:0.1.16" + "@napi-rs/simple-git-linux-x64-musl": "npm:0.1.16" + "@napi-rs/simple-git-win32-arm64-msvc": "npm:0.1.16" + "@napi-rs/simple-git-win32-x64-msvc": "npm:0.1.16" dependenciesMeta: "@napi-rs/simple-git-android-arm-eabi": optional: true @@ -7248,7 +7249,7 @@ __metadata: optional: true "@napi-rs/simple-git-win32-x64-msvc": optional: true - checksum: 5802a96fb4152d3fd6cc28ebea56fd363d7055bb7a185289dab33954980d7114ee174290b8d12f4b5630a97dc4a443d24e5873417a3f9aa6877a5d3ec2f62165 + checksum: c847f5797dffad09115b2925a4e1964a9e61ae2ddca4e30f6bcc6fb8432a634625be71fcd79bb66379660b31171058969a61ad58e794197e143e7437db1fd852 languageName: node linkType: hard