Skip to content

Commit

Permalink
🐛 fix: 删除笔记本后导致面板不显示 close #28
Browse files Browse the repository at this point in the history
  • Loading branch information
frostime committed Sep 8, 2024
1 parent f79f762 commit 09b3de4
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 8 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sy-bookmark-plus",
"version": "1.3.0",
"version": "1.3.1",
"type": "module",
"description": "A more powerful bookmark",
"repository": "",
Expand All @@ -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",
Expand All @@ -36,4 +37,4 @@
"dependencies": {
"solid-transition-group": "^0.2.3"
}
}
}
8 changes: 5 additions & 3 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,6 +28,8 @@
]
},
"keywords": [
"plugin", "书签", "Bookmark"
"plugin",
"书签",
"Bookmark"
]
}
}
141 changes: 141 additions & 0 deletions scripts/update_version.js
Original file line number Diff line number Diff line change
@@ -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);
}
})();
3 changes: 2 additions & 1 deletion src/components/item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ const Item: Component<IProps> = (props) => {
});

const notebook = createMemo(() => {
return getNotebook(item().box).name;
const notebook = getNotebook(item().box);
return notebook?.name ?? 'Box Not Found';
})

const hoverContext = createMemo(() => {
Expand Down
4 changes: 2 additions & 2 deletions src/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 09b3de4

Please sign in to comment.