From 09b3de4fbd5b9cda54aae5e5575276e53170d031 Mon Sep 17 00:00:00 2001 From: frostime Date: Sun, 8 Sep 2024 14:08:38 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E7=AC=94=E8=AE=B0=E6=9C=AC=E5=90=8E=E5=AF=BC=E8=87=B4=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E4=B8=8D=E6=98=BE=E7=A4=BA=20close=20#28?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 5 +- plugin.json | 8 ++- scripts/update_version.js | 141 ++++++++++++++++++++++++++++++++++++++ src/components/item.tsx | 3 +- src/model/index.ts | 4 +- 5 files changed, 153 insertions(+), 8 deletions(-) create mode 100644 scripts/update_version.js diff --git a/package.json b/package.json index 0c9fca1..fcec297 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sy-bookmark-plus", - "version": "1.3.0", + "version": "1.3.1", "type": "module", "description": "A more powerful bookmark", "repository": "", @@ -10,6 +10,7 @@ "scripts": { "make-link": "node --no-warnings ./scripts/make_dev_link.js", "make-link-win": "powershell.exe -NoProfile -ExecutionPolicy Bypass -File ./scripts/elevate.ps1 -scriptPath ./scripts/make_dev_link.js", + "update-version": "node --no-warnings ./scripts/update_version.js", "dev": "vite build --watch", "dev-srcmap": "vite build --watch --sourcemap=inline", "build": "vite build", @@ -36,4 +37,4 @@ "dependencies": { "solid-transition-group": "^0.2.3" } -} +} \ No newline at end of file diff --git a/plugin.json b/plugin.json index 7ac3c68..3baa6cb 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "name": "sy-bookmark-plus", "author": "frostime", "url": "https://github.com/frostime/sy-bookmark-plus", - "version": "1.3.0", + "version": "1.3.1", "minAppVersion": "3.0.12", "backends": [ "all" @@ -28,6 +28,8 @@ ] }, "keywords": [ - "plugin", "书签", "Bookmark" + "plugin", + "书签", + "Bookmark" ] -} +} \ No newline at end of file diff --git a/scripts/update_version.js b/scripts/update_version.js new file mode 100644 index 0000000..775c98a --- /dev/null +++ b/scripts/update_version.js @@ -0,0 +1,141 @@ +// const fs = require('fs'); +// const path = require('path'); +// const readline = require('readline'); +import fs from 'node:fs'; +import path from 'node:path'; +import readline from 'node:readline'; + +// Utility to read JSON file +function readJsonFile(filePath) { + return new Promise((resolve, reject) => { + fs.readFile(filePath, 'utf8', (err, data) => { + if (err) return reject(err); + try { + const jsonData = JSON.parse(data); + resolve(jsonData); + } catch (e) { + reject(e); + } + }); + }); +} + +// Utility to write JSON file +function writeJsonFile(filePath, jsonData) { + return new Promise((resolve, reject) => { + fs.writeFile(filePath, JSON.stringify(jsonData, null, 2), 'utf8', (err) => { + if (err) return reject(err); + resolve(); + }); + }); +} + +// Utility to prompt the user for input +function promptUser(query) { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout + }); + return new Promise((resolve) => rl.question(query, (answer) => { + rl.close(); + resolve(answer); + })); +} + +// Function to parse the version string +function parseVersion(version) { + const [major, minor, patch] = version.split('.').map(Number); + return { major, minor, patch }; +} + +// Function to auto-increment version parts +function incrementVersion(version, type) { + let { major, minor, patch } = parseVersion(version); + + switch (type) { + case 'major': + major++; + minor = 0; + patch = 0; + break; + case 'minor': + minor++; + patch = 0; + break; + case 'patch': + patch++; + break; + default: + break; + } + + return `${major}.${minor}.${patch}`; +} + +// Main script +(async function () { + try { + const pluginJsonPath = path.join(process.cwd(), 'plugin.json'); + const packageJsonPath = path.join(process.cwd(), 'package.json'); + + // Read both JSON files + const pluginData = await readJsonFile(pluginJsonPath); + const packageData = await readJsonFile(packageJsonPath); + + // Get the current version from both files (assuming both have the same version) + const currentVersion = pluginData.version || packageData.version; + console.log(`\n🌟 Current version: \x1b[36m${currentVersion}\x1b[0m\n`); + + // Calculate potential new versions for auto-update + const newPatchVersion = incrementVersion(currentVersion, 'patch'); + const newMinorVersion = incrementVersion(currentVersion, 'minor'); + const newMajorVersion = incrementVersion(currentVersion, 'major'); + + // Prompt the user with formatted options + console.log('🔄 How would you like to update the version?\n'); + console.log(` 1️⃣ Auto update \x1b[33mpatch\x1b[0m version (new version: \x1b[32m${newPatchVersion}\x1b[0m)`); + console.log(` 2️⃣ Auto update \x1b[33mminor\x1b[0m version (new version: \x1b[32m${newMinorVersion}\x1b[0m)`); + console.log(` 3️⃣ Auto update \x1b[33mmajor\x1b[0m version (new version: \x1b[32m${newMajorVersion}\x1b[0m)`); + console.log(` 4️⃣ Input version \x1b[33mmanually\x1b[0m`); + // Press 0 to skip version update + console.log(' 0️⃣ Quit without updating\n'); + + const updateChoice = await promptUser('👉 Please choose (1/2/3/4): '); + + let newVersion; + + switch (updateChoice.trim()) { + case '1': + newVersion = newPatchVersion; + break; + case '2': + newVersion = newMinorVersion; + break; + case '3': + newVersion = newMajorVersion; + break; + case '4': + newVersion = await promptUser('✍️ Please enter the new version (in a.b.c format): '); + break; + case '0': + console.log('\n🛑 Skipping version update.'); + return; + default: + console.log('\n❌ Invalid option, no version update.'); + return; + } + + // Update the version in both plugin.json and package.json + pluginData.version = newVersion; + packageData.version = newVersion; + + // Write the updated JSON back to files + await writeJsonFile(pluginJsonPath, pluginData); + await writeJsonFile(packageJsonPath, packageData); + + console.log(`\n✅ Version successfully updated to: \x1b[32m${newVersion}\x1b[0m\n`); + + } catch (error) { + console.error('❌ Error:', error); + } +})(); diff --git a/src/components/item.tsx b/src/components/item.tsx index 696b95a..c33d903 100644 --- a/src/components/item.tsx +++ b/src/components/item.tsx @@ -88,7 +88,8 @@ const Item: Component = (props) => { }); const notebook = createMemo(() => { - return getNotebook(item().box).name; + const notebook = getNotebook(item().box); + return notebook?.name ?? 'Box Not Found'; }) const hoverContext = createMemo(() => { diff --git a/src/model/index.ts b/src/model/index.ts index 749b08b..f38add6 100644 --- a/src/model/index.ts +++ b/src/model/index.ts @@ -214,8 +214,8 @@ export class BookmarkDataModel { let allIds = []; //一般调用 updateItems 之前会已经调用过 update dynamic group; 如果再次更新就有些冗余了 //不这么做似乎会造成 item 404 的 bug - const staticGroups = groups.filter(g => g.type !== 'dynamic'); - staticGroups.filter(g => g.hidden === false).forEach(g => { + const staticGroups = groups.filter(g => g.type !== 'dynamic' && g.hidden !== true); + staticGroups.forEach(g => { allIds = allIds.concat(g.items.map(it => it.id)); }) let allIdsSet = new Set(allIds);