From 63cc3ac0c2de3fcdcca3e4078373b9a23237bcd0 Mon Sep 17 00:00:00 2001 From: frostime Date: Sun, 8 Sep 2024 14:05:54 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=F0=9F=94=A7=20ci:=20add=20a=20script=20to?= =?UTF-8?q?=20update=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + scripts/update_version.js | 141 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 scripts/update_version.js diff --git a/package.json b/package.json index 971fd74..03a2a88 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "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", "dev": "vite build --watch", + "update-version": "node --no-warnings ./scripts/update_version.js", "build": "vite build", "make-install": "vite build && node --no-warnings ./scripts/make_install.js" }, 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); + } +})(); From 63ee8d92dc5a3deed82a929b1a9c0199c6d08b93 Mon Sep 17 00:00:00 2001 From: frostime Date: Tue, 10 Sep 2024 10:55:59 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=F0=9F=94=A7=20ci:=20tsconfig,=20include=20?= =?UTF-8?q?svelte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index e196929..0fcc1ad 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -47,7 +47,8 @@ "src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", - "src/**/*.vue" + "src/**/*.vue", + "src/**/*.svelte" ], "references": [ { From 19cae2eabdbd93f9cea368092da11cd85d855de2 Mon Sep 17 00:00:00 2001 From: frostime Date: Fri, 27 Sep 2024 18:15:23 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=F0=9F=93=9D=20doc:=20introduce=20to=20siyu?= =?UTF-8?q?an-plugin-cli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 8 ++++++++ README_zh_CN.md | 7 +++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index f0b2a1c..209f668 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,14 @@ 4. Provides a github action template to automatically generate package.zip and upload to new release +> ![TIP] +> You can also use our maintained [siyuan-plugin-cli](https://www.npmjs.com/package/siyuan-plugin-cli) command-line tool to directly build plugins in your local terminal. +> +> Additionally, for the `make-link` related commands mentioned in this plugin, all future updates will be made in [siyuan-plugin-cli](https://www.npmjs.com/package/siyuan-plugin-cli). +> +> The built-in `make-link` scripts may also be removed in a future version, in favor of using the `siyuan-plugin-cli` tool, aiming to simplify the workload of maintaining multiple plugin templates. + + ## Get started 1. Use the Use this template button to make a copy of this repo as a template. Note that the repository name should match the plugin name, and the default branch must be `main`. diff --git a/README_zh_CN.md b/README_zh_CN.md index e60f454..bc8667e 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -26,6 +26,13 @@ 5. 执行 `pnpm run dev` 进行实时编译 6. 在思源中打开集市并在下载选项卡中启用插件 +> ![TIP] +> 你也可以使用我们维护的 [siyuan-plugin-cli](https://www.npmjs.com/package/siyuan-plugin-cli) 命令行工具,在本地终端中直接构建插件。 +> +> 此外,对于本插件以下提及到的 `make-link` 相关的命令,后续所有更新将在 [siyuan-plugin-cli](https://www.npmjs.com/package/siyuan-plugin-cli) 中进行。 +> +> 模板内置的 `make-link` 脚本也可能会在未来某个版本中移除,转而使用 `siyuan-plugin-cli` 工具,意在简化同时维护多个插件模板的工作量。 + ### 设置 make-link 命令的目标目录 make-link 命令会创建符号链接将你的 `dev` 目录绑定到思源的插件目录下。你可以有三种方式来配置目标的思源工作空间并创建符号链接: From 4aee720da54a90582c29759741ea099747ba5311 Mon Sep 17 00:00:00 2001 From: frostime Date: Fri, 27 Sep 2024 18:25:34 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=F0=9F=93=9D=20doc:=20tip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- README_zh_CN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 209f668..648dcb7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ 4. Provides a github action template to automatically generate package.zip and upload to new release -> ![TIP] +> [!TIP] > You can also use our maintained [siyuan-plugin-cli](https://www.npmjs.com/package/siyuan-plugin-cli) command-line tool to directly build plugins in your local terminal. > > Additionally, for the `make-link` related commands mentioned in this plugin, all future updates will be made in [siyuan-plugin-cli](https://www.npmjs.com/package/siyuan-plugin-cli). diff --git a/README_zh_CN.md b/README_zh_CN.md index bc8667e..0ac9fca 100644 --- a/README_zh_CN.md +++ b/README_zh_CN.md @@ -26,7 +26,7 @@ 5. 执行 `pnpm run dev` 进行实时编译 6. 在思源中打开集市并在下载选项卡中启用插件 -> ![TIP] +> [!TIP] > 你也可以使用我们维护的 [siyuan-plugin-cli](https://www.npmjs.com/package/siyuan-plugin-cli) 命令行工具,在本地终端中直接构建插件。 > > 此外,对于本插件以下提及到的 `make-link` 相关的命令,后续所有更新将在 [siyuan-plugin-cli](https://www.npmjs.com/package/siyuan-plugin-cli) 中进行。 From 591cf2e95e345712ce6735543f953f791a78cdc3 Mon Sep 17 00:00:00 2001 From: frostime Date: Wed, 16 Oct 2024 14:43:56 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=F0=9F=94=A7=20ci:=20=E6=9B=B4=E6=96=B0=20v?= =?UTF-8?q?ite=20=E6=89=93=E5=8C=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 2 +- package.json | 19 +++--- plugin.json | 8 ++- public/i18n/zh_CN.json | 20 +++++++ public/i18n/zh_CN.yaml | 21 ------- src/hello.svelte | 8 +++ src/index.scss | 26 --------- src/libs/dialog.ts | 23 +++++--- src/libs/promise-pool.ts | 48 +++++++++++++++ vite.config.ts | 106 ++++++++++++---------------------- 10 files changed, 146 insertions(+), 135 deletions(-) create mode 100644 public/i18n/zh_CN.json delete mode 100644 public/i18n/zh_CN.yaml create mode 100644 src/libs/promise-pool.ts diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 36af5e0..49834e5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,4 +59,4 @@ jobs: artifactErrorsFailBuild: true artifacts: "package.zip" token: ${{ secrets.GITHUB_TOKEN }} - prerelease: true + prerelease: false diff --git a/package.json b/package.json index 03a2a88..2b7cdec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plugin-sample-vite-svelte", - "version": "0.3.5", + "version": "0.3.6", "type": "module", "description": "This is a sample plugin based on vite and svelte for Siyuan (https://b3log.org/siyuan)", "repository": "", @@ -8,29 +8,30 @@ "author": "frostime", "license": "MIT", "scripts": { + "dev": "cross-env NODE_ENV=development VITE_SOURCEMAP=inline vite build --watch", + "build": "cross-env NODE_ENV=production vite build", "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", - "dev": "vite build --watch", "update-version": "node --no-warnings ./scripts/update_version.js", - "build": "vite build", "make-install": "vite build && node --no-warnings ./scripts/make_install.js" }, "devDependencies": { - "@sveltejs/vite-plugin-svelte": "^3.0.0", + "@sveltejs/vite-plugin-svelte": "^3.1.0", "@tsconfig/svelte": "^4.0.1", "@types/node": "^20.3.0", + "cross-env": "^7.0.3", "fast-glob": "^3.2.12", - "glob": "^7.2.3", + "glob": "^10.0.0", "js-yaml": "^4.1.0", "minimist": "^1.2.8", "rollup-plugin-livereload": "^2.0.5", "sass": "^1.63.3", - "siyuan": "0.9.9", - "svelte": "^4.2.0", + "siyuan": "1.0.4", + "svelte": "^4.2.19", "ts-node": "^10.9.1", "typescript": "^5.1.3", - "vite": "^5.0.0", + "vite": "^5.2.9", "vite-plugin-static-copy": "^1.0.2", "vite-plugin-zip-pack": "^1.0.5" } -} +} \ No newline at end of file diff --git a/plugin.json b/plugin.json index 1af2cfe..44e3e10 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "name": "plugin-sample-vite-svelte", "author": "frostime", "url": "https://github.com/siyuan-note/plugin-sample-vite-svelte", - "version": "0.3.5", + "version": "0.3.6", "minAppVersion": "3.0.12", "backends": [ "windows", @@ -37,6 +37,8 @@ ] }, "keywords": [ - "plugin", "sample", "插件样例" + "plugin", + "sample", + "插件样例" ] -} +} \ No newline at end of file diff --git a/public/i18n/zh_CN.json b/public/i18n/zh_CN.json new file mode 100644 index 0000000..6600f6a --- /dev/null +++ b/public/i18n/zh_CN.json @@ -0,0 +1,20 @@ +{ + "addTopBarIcon": "使用插件添加一个顶栏按钮", + "cancel": "取消", + "save": "保存", + "byeMenu": "再见,菜单!", + "helloPlugin": "你好,插件!", + "byePlugin": "再见,插件!", + "showDialog": "弹出一个对话框", + "removedData": "数据已删除", + "confirmRemove": "确认删除 ${name} 中的数据?", + "insertEmoji": "插入表情", + "removeSpace": "移除空格", + "getTab": "在日志中打印出已打开的所有自定义页签", + "name": "思源", + "hello": { + "makesure": "使用这个模板之前,请阅读官方教程, 确保自己已经理解了插件的基本开发流程。" + }, + "hintTitle": "关于", + "hintDesc": "🔗 plugin-sample-vite-svelte
💻 @frostime
💻 @88250
💻 @zxkmm" +} \ No newline at end of file diff --git a/public/i18n/zh_CN.yaml b/public/i18n/zh_CN.yaml deleted file mode 100644 index 16099a3..0000000 --- a/public/i18n/zh_CN.yaml +++ /dev/null @@ -1,21 +0,0 @@ ---- -addTopBarIcon: 使用插件添加一个顶栏按钮 -cancel: 取消 -save: 保存 -byeMenu: 再见,菜单! -helloPlugin: 你好,插件! -byePlugin: 再见,插件! -showDialog: 弹出一个对话框 -removedData: 数据已删除 -confirmRemove: 确认删除 ${name} 中的数据? -insertEmoji: 插入表情 -removeSpace: 移除空格 -getTab: 在日志中打印出已打开的所有自定义页签 -name: 思源 -hello: - makesure: 使用这个模板之前,请阅读官方教程, - 确保自己已经理解了插件的基本开发流程。 -hintTitle: 关于 -hintDesc: "\U0001F517 - plugin-sample-vite-svelte
\U0001F4BB @frostime
\U0001F4BB @88250
\U0001F4BB - @zxkmm" diff --git a/src/hello.svelte b/src/hello.svelte index cc9f0dd..967c7f6 100644 --- a/src/hello.svelte +++ b/src/hello.svelte @@ -1,3 +1,11 @@ +