From 614b1d3790df1e2a6078221f928bd3775ac2bf6a Mon Sep 17 00:00:00 2001 From: Soltus Date: Wed, 12 Jun 2024 14:20:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B1=90=E6=B4=9BVSC=E6=89=A9=E5=B1=95add=5Fta?= =?UTF-8?q?sk=5F=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E8=A1=A5=E5=85=A8=E4=BA=8C=E6=AE=B5=E7=89=88=E6=9C=AC=E5=8F=B7?= =?UTF-8?q?=20#824?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/extensions/Sillot/package.json | 2 +- ...64\346\226\260\347\211\210\346\234\254.ts" | 179 ++++++++++-------- app/package.json | 2 +- docs/starlight/package.json | 2 +- package.json | 2 +- 5 files changed, 101 insertions(+), 86 deletions(-) diff --git a/.vscode/extensions/Sillot/package.json b/.vscode/extensions/Sillot/package.json index 7219186da2..9a8b730598 100644 --- a/.vscode/extensions/Sillot/package.json +++ b/.vscode/extensions/Sillot/package.json @@ -2,7 +2,7 @@ "name": "sillot", "displayName": "汐洛 Sillot", "description": "汐洛彖夲肜矩阵(Sillot T☳Converbenk Matrix)为智慧新彖务服务。此插件为汐洛官方插件,提供多功能一体化集成。", - "version": "0.35.3100", + "version": "0.35.20240612140342", "preview": true, "repository": "https://github.com/Hi-Windom/Sillot", "publisher": "Hi-Windom", diff --git "a/.vscode/extensions/Sillot/src/task/\345\220\214\346\255\245\346\233\264\346\226\260\347\211\210\346\234\254.ts" "b/.vscode/extensions/Sillot/src/task/\345\220\214\346\255\245\346\233\264\346\226\260\347\211\210\346\234\254.ts" index bcf2111dc3..ff6e251a65 100644 --- "a/.vscode/extensions/Sillot/src/task/\345\220\214\346\255\245\346\233\264\346\226\260\347\211\210\346\234\254.ts" +++ "b/.vscode/extensions/Sillot/src/task/\345\220\214\346\255\245\346\233\264\346\226\260\347\211\210\346\234\254.ts" @@ -1,82 +1,97 @@ -import * as vscode from "vscode"; -import fs from "fs-extra"; -import path, { resolve } from "path"; -import { Log } from "../utils/log"; -import { C } from "../extension.const"; -import { loadCompletionItemsFromFile } from "../utils/json"; - -export function add_task_同步更新版本(context: vscode.ExtensionContext) { - const TAG = "汐洛.同步更新版本"; - const disposable = vscode.commands.registerCommand(TAG, async () => { - const wname = vscode.workspace.name; - if (wname && vscode.workspace.workspaceFile) { - const pkgMapFile = `${path.dirname(vscode.workspace.workspaceFile.fsPath)}/${C.PackageJsonMapping}`; - Log.d(wname, pkgMapFile); - if (!(await fs.exists(pkgMapFile))) { - vscode.window.showWarningMessage("package.json 映射不存在,请先添加"); - return; - } - const pkgMap: { [key: string]: any } = await loadCompletionItemsFromFile(pkgMapFile); - const paths: string[] = pkgMap[wname]; - - // 创建快速选择框 - const quickPick = vscode.window.createQuickPick(); - quickPick.title = "选择要更新版本的文件"; - quickPick.items = paths.map(path => ({ label: path })); - quickPick.canSelectMany = true; // 允许多选 - - // 显示快速选择框并等待用户选择 - const selectedOptions: string[] = await new Promise(resolve => { - quickPick.onDidAccept(() => { - resolve(quickPick.selectedItems.map(item => item.label)); - quickPick.dispose(); - }); - quickPick.onDidHide(() => { - resolve([]); - quickPick.dispose(); - }); - quickPick.show(); - }); - - if (selectedOptions.length === 0) { - // 如果用户没有选择任何选项,则直接返回 - return; - } - - // 获取用户选择的路径的版本号 - const versionPromises = selectedOptions.map(async (value: string) => { - if (await fs.exists(value)) { - const pkgContent = fs.readJSONSync(value); - return pkgContent.version; - } - return null; // 如果文件不存在,返回null - }); - - Promise.all(versionPromises).then(versions => { - // 过滤掉null值 - const validVersions = versions.filter(version => version !== null); - vscode.window.showInputBox({ prompt: `输入新版本: (当前版本: ${validVersions.join(", ")})` }).then(async version => { - if (version) { - // 遍历映射并更新版本号 - selectedOptions.forEach(async (value: string, index: number) => { - Log.d(TAG, value); - if (await fs.exists(value)) { - const pkgContent = fs.readJSONSync(value); - pkgContent.version = version; - fs.writeFileSync(value, JSON.stringify(pkgContent, null, 2)); - Log.d(`${version} ->${value}`); - } else { - vscode.window.showWarningMessage(`已跳过无效映射 ${value}`); - } - }); - vscode.window.showInformationMessage("所有 package.json 文件的版本已更新。"); - } - }); - }); - } else { - vscode.window.showWarningMessage("当前不在工作区环境"); - } - }); - - context.subscriptions.push(disposable); -} +import * as vscode from "vscode"; +import fs from "fs-extra"; +import path, { resolve } from "path"; +import { Log } from "../utils/log"; +import { C } from "../extension.const"; +import { loadCompletionItemsFromFile } from "../utils/json"; +import { formatDate } from "sofill/mid"; + +export function add_task_同步更新版本(context: vscode.ExtensionContext) { + const TAG = "汐洛.同步更新版本"; + const disposable = vscode.commands.registerCommand(TAG, async () => { + const wname = vscode.workspace.name; + if (wname && vscode.workspace.workspaceFile) { + const pkgMapFile = `${path.dirname(vscode.workspace.workspaceFile.fsPath)}/${C.PackageJsonMapping}`; + Log.d(wname, pkgMapFile); + if (!(await fs.exists(pkgMapFile))) { + vscode.window.showWarningMessage("package.json 映射不存在,请先添加"); + return; + } + const pkgMap: { [key: string]: any } = await loadCompletionItemsFromFile(pkgMapFile); + const paths: string[] = pkgMap[wname]; + + // 创建快速选择框 + const quickPick = vscode.window.createQuickPick(); + quickPick.title = "选择要更新版本的文件"; + quickPick.items = paths.map(path => ({ label: path })); + quickPick.canSelectMany = true; // 允许多选 + + // 显示快速选择框并等待用户选择 + const selectedOptions: string[] = await new Promise(resolve => { + quickPick.onDidAccept(() => { + resolve(quickPick.selectedItems.map(item => item.label)); + quickPick.dispose(); + }); + quickPick.onDidHide(() => { + resolve([]); + quickPick.dispose(); + }); + quickPick.show(); + }); + + if (selectedOptions.length === 0) { + // 如果用户没有选择任何选项,则直接返回 + return; + } + + // 获取用户选择的路径的版本号 + const versionPromises = selectedOptions.map(async (value: string) => { + if (await fs.exists(value)) { + const pkgContent = fs.readJSONSync(value); + return pkgContent.version; + } + return null; // 如果文件不存在,返回null + }); + + Promise.all(versionPromises).then(versions => { + // 过滤掉null值 + const validVersions = versions.filter(version => version !== null); + vscode.window + .showInputBox({ + title: "请输入新版本号", + value: validVersions[0], + placeHolder: "如果是二段版本号会被使用格式化时间填充为三段版本号", + prompt: `旧版本号: ${validVersions.join(", ")})`, + }) + .then(async version => { + if (version) { + // 检查 version 是否只有两段 + const versionParts = version.split("."); + if (versionParts.length === 2) { + // 使用当前时间生成第三段版本号 + const timestamp = formatDate(new Date(), "yyyyMMddHHmmss"); + version = `${version}.${timestamp}`; + } + // 遍历映射并更新版本号 + selectedOptions.forEach(async (value: string, index: number) => { + Log.d(TAG, value); + if (await fs.exists(value)) { + const pkgContent = fs.readJSONSync(value); + pkgContent.version = version; + fs.writeFileSync(value, JSON.stringify(pkgContent, null, 2)); + Log.d(`${version} ->${value}`); + } else { + vscode.window.showWarningMessage(`已跳过无效映射 ${value}`); + } + }); + vscode.window.showInformationMessage("所有 package.json 文件的版本已更新。"); + } + }); + }); + } else { + vscode.window.showWarningMessage("当前不在工作区环境"); + } + }); + + context.subscriptions.push(disposable); +} diff --git a/app/package.json b/app/package.json index 812f566457..f5d566b5a4 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "sillot", - "version": "0.35.3100", + "version": "0.35.20240612140342", "syv": "3.1.0", "sypv": "[3.0.16, 3.0.17]", "description": "Build Your Eternal Digital Garden", diff --git a/docs/starlight/package.json b/docs/starlight/package.json index a1214ed4c0..d9b46befff 100644 --- a/docs/starlight/package.json +++ b/docs/starlight/package.json @@ -1,7 +1,7 @@ { "name": "starlight", "type": "module", - "version": "0.35.3100", + "version": "0.35.20240612140342", "scripts": { "test": "echo 'Test your sister day by day'", "dev": "astro dev", diff --git a/package.json b/package.json index 089992f582..26084ae632 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Sillot-workspace", - "version": "0.35.3100", + "version": "0.35.20240612140342", "description": "汐洛 pnpm 工作区", "packageManager": "pnpm@9.3.0", "scripts": {