diff --git a/.eslintignore b/.eslintignore
deleted file mode 100644
index f06235c..0000000
--- a/.eslintignore
+++ /dev/null
@@ -1,2 +0,0 @@
-node_modules
-dist
diff --git a/.eslintrc.cjs b/.eslintrc.cjs
deleted file mode 100644
index 0781605..0000000
--- a/.eslintrc.cjs
+++ /dev/null
@@ -1,38 +0,0 @@
-module.exports = {
- extends: [
- "eslint:recommended",
- "plugin:@typescript-eslint/recommended",
- "plugin:svelte/recommended",
- "turbo",
- "prettier",
- ],
-
- parser: "@typescript-eslint/parser",
-
- overrides: [
- {
- files: ["*.svelte"],
- parser: "svelte-eslint-parser",
- // Parse the script in `.svelte` as TypeScript by adding the following configuration.
- parserOptions: {
- parser: "@typescript-eslint/parser",
- },
- },
- ],
-
- plugins: ["@typescript-eslint", "prettier"],
-
- rules: {
- // Note: you must disable the base rule as it can report incorrect errors
- semi: "off",
- quotes: "off",
- "no-undef": "off",
- "@typescript-eslint/no-var-requires": "off",
- "@typescript-eslint/no-this-alias": "off",
- "@typescript-eslint/no-non-null-assertion": "off",
- "@typescript-eslint/no-unused-vars": "off",
- "@typescript-eslint/no-explicit-any": "off",
- "turbo/no-undeclared-env-vars": "off",
- "prettier/prettier": "error",
- },
-}
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 7bd6c4e..49834e5 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -17,12 +17,12 @@ jobs:
- name: Install Node.js
uses: actions/setup-node@v3
with:
- node-version: 18
+ node-version: 20
registry-url: "https://registry.npmjs.org"
# Install pnpm
- name: Install pnpm
- uses: pnpm/action-setup@v2
+ uses: pnpm/action-setup@v4
id: pnpm-install
with:
version: 8
@@ -59,4 +59,4 @@ jobs:
artifactErrorsFailBuild: true
artifacts: "package.zip"
token: ${{ secrets.GITHUB_TOKEN }}
- prerelease: true
+ prerelease: false
diff --git a/.gitignore b/.gitignore
index 764e2d4..c2a2064 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@
.vscode
.DS_Store
pnpm-lock.yaml
+package-lock.json
package.zip
node_modules
dev
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7310325..af04807 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,68 @@
# Changelog
+## v0.3.5 2024-04-30
+
+* [Add `direction` to plugin method `Setting.addItem`](https://github.com/siyuan-note/siyuan/issues/11183)
+
+
+## 0.3.4 2024-02-20
+
+* [Add plugin event bus `click-flashcard-action`](https://github.com/siyuan-note/siyuan/issues/10318)
+
+## 0.3.3 2024-01-24
+
+* Update dock icon class
+
+## 0.3.2 2024-01-09
+
+* [Add plugin `protyleOptions`](https://github.com/siyuan-note/siyuan/issues/10090)
+* [Add plugin api `uninstall`](https://github.com/siyuan-note/siyuan/issues/10063)
+* [Add plugin method `updateCards`](https://github.com/siyuan-note/siyuan/issues/10065)
+* [Add plugin function `lockScreen`](https://github.com/siyuan-note/siyuan/issues/10063)
+* [Add plugin event bus `lock-screen`](https://github.com/siyuan-note/siyuan/pull/9967)
+* [Add plugin event bus `open-menu-inbox`](https://github.com/siyuan-note/siyuan/pull/9967)
+
+
+## 0.3.1 2023-12-06
+
+* [Support `Dock Plugin` and `Command Palette` on mobile](https://github.com/siyuan-note/siyuan/issues/9926)
+
+## 0.3.0 2023-12-05
+
+* Upgrade Siyuan to 0.9.0
+* Support more platforms
+
+## 0.2.9 2023-11-28
+
+* [Add plugin method `openMobileFileById`](https://github.com/siyuan-note/siyuan/issues/9738)
+
+
+## 0.2.8 2023-11-15
+
+* [`resize` cannot be triggered after dragging to unpin the dock](https://github.com/siyuan-note/siyuan/issues/9640)
+
+## 0.2.7 2023-10-31
+
+* [Export `Constants` to plugin](https://github.com/siyuan-note/siyuan/issues/9555)
+* [Add plugin `app.appId`](https://github.com/siyuan-note/siyuan/issues/9538)
+* [Add plugin event bus `switch-protyle`](https://github.com/siyuan-note/siyuan/issues/9454)
+
+## 0.2.6 2023-10-24
+
+* [Deprecated `loaded-protyle` use `loaded-protyle-static` instead](https://github.com/siyuan-note/siyuan/issues/9468)
+
+## 0.2.5 2023-10-10
+
+* [Add plugin event bus `open-menu-doctree`](https://github.com/siyuan-note/siyuan/issues/9351)
+
+## 0.2.4 2023-09-19
+
+* Supports use in windows
+* [Add plugin function `transaction`](https://github.com/siyuan-note/siyuan/issues/9172)
+
## 0.2.3 2023-09-05
+* [Add plugin function `transaction`](https://github.com/siyuan-note/siyuan/issues/9172)
* [Plugin API add openWindow and command.globalCallback](https://github.com/siyuan-note/siyuan/issues/9032)
## 0.2.2 2023-08-29
diff --git a/README.md b/README.md
index d4ddddb..648dcb7 100644
--- a/README.md
+++ b/README.md
@@ -3,27 +3,46 @@
[中文版](./README_zh_CN.md)
-> Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.2.3](https://github.com/siyuan-note/plugin-sample/tree/v0.2.3)
+> Consistent with [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.5](https://github.com/siyuan-note/plugin-sample/tree/v0.3.5)
1. Using vite for packaging
2. Use symbolic linking instead of putting the project into the plugins directory program development
3. Built-in support for the svelte framework
+
+ > **If don't want svelte, turn to this template**: [frostime/plugin-sample-vite](https://github.com/frostime/plugin-sample-vite)
+ >
+ > **We also provide with a vite+solidjs template**: [frostime/plugin-sample-vite-solidjs](https://github.com/frostime/plugin-sample-vite-solidjs)
+
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. Make a copy of this repo as a template with the `Use this template` button, please note that the repo name must be the same as the plugin name, the default branch must be `main`
+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`.
+2. Clone your repository to the local development folder.
+ * Note: Unlike `plugin-sample`, this example does not recommend directly downloading the code to `{workspace}/data/plugins/`.
+3. Install [NodeJS](https://nodejs.org/en/download) and [pnpm](https://pnpm.io/installation), then run `pnpm i` in the development folder to install the required dependencies.
+4. Run the `pnpm run make-link` command to create a symbolic link (Windows developers, please refer to the "make-link on Windows" section below).
+5. Execute `pnpm run dev` for real-time compilation.
+6. Open the marketplace in SiYuan and enable the plugin in the download tab.
-2. Clone your repo to a local development folder at any place
- - Notice: we **don't recommand** you to place the folder under your `{workspace}/data/plugins/` folder.
+### Setting the Target Directory for the make-link Command
-3. Install NodeJS and pnpm, then run pnpm i in the command line under your repo folder
-4. **Auto create development symbolic links**
- - Make sure that SiYuan is running
- - Run `pnpm run make-link`, the script will detect all the siyuan workspace, please select the targe workspace and the script will automatically create the symbolic link under the `{workspace}/data/plugins/` folder
+The `make-link` command creates a symbolic link that binds your `dev` directory to the SiYuan plugin directory. You can configure the target SiYuan workspace and create the symbolic link in three ways:
+
+1. **Select Workspace**
+ - Open SiYuan, ensure the SiYuan kernel is running.
+ - Run `pnpm run make-link`, the script will automatically detect all SiYuan workspaces, please manually enter the number to select the workspace.
```bash
>>> pnpm run make-link
> plugin-sample-vite-svelte@0.0.3 make-link H:\SrcCode\开源项目\plugin-sample-vite-svelte
@@ -37,22 +56,24 @@
Got target directory: H:\Media\SiYuan/data/plugins
Done! Created symlink H:\Media\SiYuan/data/plugins/plugin-sample-vite-svelte
```
-4. **Manually create development symbolic links**
- - Open `./scripts/make_dev_link.js` file, set `targetDir` to your SiYuan plugin directory `/data/plugins`
- - Run `pnpm run make-link`, succeed if following message is shown:
- ```bash
- >>> pnpm run make-link
- > plugin-sample-vite-svelte@0.0.1 make-link H:\SrcCode\plugin-sample-vite-svelte
- > node ./scripts/make_dev_link.js
+2. **Manually Configure Target Directory**
+ - Open the `./scripts/make_dev_link.js` file, change `targetDir` to the SiYuan plugin directory `/data/plugins`.
+ - Run the `pnpm run make-link` command. If you see a message similar to the one below, it indicates successful creation:
- Done! Created symlink H:/SiYuanDevSpace/data/plugins/plugin-sample-vite-svelte
- ```
-5. **Create development symbolic links by using environment variable**
- - You can set environment variable `SIYUAN_PLUGIN_DIR` as `/data/plugins`
-6. Execute pnpm run dev for real-time compilation
-7. Open SiYuan marketplace and enable plugin in downloaded tab
+3. **Set Environment Variable to Create Symbolic Link**
+ - Set the system environment variable `SIYUAN_PLUGIN_DIR` to the path `workspace/data/plugins`.
-> Notice: as the `make-link` script rely on the `fetch` function, please **ensure that at least version v18 of nodejs is installed** if you want to use make-link script.
+### make-link on Windows
+
+Due to SiYuan upgrading to Go 1.23, the old version of junction links cannot be recognized normally on Windows, so it has been changed to create `dir` symbolic links.
+
+> https://github.com/siyuan-note/siyuan/issues/12399
+
+However, creating directory symbolic links on Windows using NodeJs may require administrator privileges. You have the following options:
+
+1. Run `pnpm run make-link` in a command line with administrator privileges.
+2. Configure Windows settings, enable developer mode in [System Settings - Update & Security - Developer Mode] then run `pnpm run make-link`.
+3. Run `pnpm run make-link-win`, this command will use a PowerShell script to request administrator privileges, requiring the system to enable PowerShell script execution permissions.
## I18n
@@ -62,8 +83,11 @@ complete the following tasks:
* Meta information about the plugin itself, such as plugin description and readme
* `description` and `readme` fields in plugin.json, and the corresponding README*.md file
* Text used in the plugin, such as button text and tooltips
- * src/i18n/*.json language configuration files
+ * public/i18n/*.json language configuration files
* Use `this.i18.key` to get the text in the code
+* YAML Support
+ * This template specifically supports I18n based on YAML syntax, see `public/i18n/zh_CN.yaml`
+ * During compilation, the defined YAML files will be automatically translated into JSON files and placed in the dist or dev directory.
It is recommended that the plugin supports at least English and Simplified Chinese, so that more people can use it more
conveniently.
@@ -98,7 +122,10 @@ conveniently.
"custom": [
"https://ld246.com/sponsor"
]
- }
+ },
+ "keywords": [
+ "sample", "示例"
+ ]
}
```
@@ -137,6 +164,7 @@ conveniently.
* `patreon`: Patreon name
* `github`: GitHub login name
* `custom`: Custom sponsorship link list
+* `keywords`: Search keyword list, used for marketplace search function
## Package
@@ -204,6 +232,8 @@ The github action is included in this sample, you can use it to publish your new
## How to remove svelte dependencies
+> Pure vite without svelte: https://github.com/frostime/plugin-sample-vite
+
This plugin is packaged in vite and provides a dependency on the svelte framework. However, in practice some developers may not want to use svelte and only want to use the vite package.
In fact you can use this template without using svelte without any modifications at all. The compilation-related parts of the svelte compilation are loaded into the vite workflow as plugins, so even if you don't have svelte in your project, it won't matter much.
@@ -224,3 +254,25 @@ If you insist on removing all svelte dependencies so that they do not pollute yo
- Line 20: `svelte(),`
4. delete line 37 of `tsconfig.json` from `"svelte"` 5.
5. re-run `pnpm i`
+
+## Developer's Guide
+
+Developers of SiYuan need to pay attention to the following specifications.
+
+### 1. File Reading and Writing Specifications
+
+If plugins or external extensions require direct reading or writing of files under the `data` directory, please use the kernel API to achieve this. **Do not call `fs` or other electron or nodejs APIs directly**, as it may result in data loss during synchronization and cause damage to cloud data.
+
+Related APIs can be found at: `/api/file/*` (e.g., `/api/file/getFile`).
+
+### 2. Daily Note Attribute Specifications
+
+When creating a daily note in SiYuan, a custom-dailynote-yyyymmdd attribute will be automatically added to the document to distinguish it from regular documents.
+
+> For more details, please refer to [Github Issue #9807](https://github.com/siyuan-note/siyuan/issues/9807).
+
+Developers should pay attention to the following when developing the functionality to manually create Daily Notes:
+
+* If `/api/filetree/createDailyNote` is called to create a daily note, the attribute will be automatically added to the document, and developers do not need to handle it separately
+* If a document is created manually by developer's code (e.g., using the `createDocWithMd` API to create a daily note), please manually add this attribute to the document
+
diff --git a/README_zh_CN.md b/README_zh_CN.md
index c8ad1fd..0ac9fca 100644
--- a/README_zh_CN.md
+++ b/README_zh_CN.md
@@ -4,20 +4,40 @@
[English](./README.md)
-> 本例和 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.2.3](https://github.com/siyuan-note/plugin-sample/tree/v0.2.3)
+> 本例同 [siyuan/plugin-sample](https://github.com/siyuan-note/plugin-sample) [v0.3.5](https://github.com/siyuan-note/plugin-sample/tree/v0.3.5)
1. 使用 vite 打包
2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发
3. 内置对 svelte 框架的支持
+
+ > **如果不想要 svelte,请移步这个模板:** [frostime/plugin-sample-vite](https://github.com/frostime/plugin-sample-vite)
+ >
+ > **这里还提供了一个 vite+solidjs 的模板**: [frostime/plugin-sample-vite-solidjs](https://github.com/frostime/plugin-sample-vite-solidjs)
+
4. 提供一个github action 模板,能自动生成package.zip并上传到新版本中
## 开始
-1. 通过 Use this template 按钮将该库文件复制到你自己的库中,请注意库名必须和插件名称一致,默认分支必须为 `main`
+1. 通过 Use this template 按钮将该库文件复制到你自己的库中,请注意库名和插件名称一致,默认分支必须为 `main`
2. 将你的库克隆到本地开发文件夹中
* 注意: 同 `plugin-sample` 不同, 本样例并不推荐直接把代码下载到 `{workspace}/data/plugins/`
3. 安装 [NodeJS](https://nodejs.org/en/download) 和 [pnpm](https://pnpm.io/installation),然后在开发文件夹下执行 `pnpm i` 安装所需要的依赖
-3. **自动创建符号链接**
+4. 运行 `pnpm run make-link` 命令创建符号链接 (Windows 下的开发者请参阅下方「Windows 下的 make-link」小节)
+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` 目录绑定到思源的插件目录下。你可以有三种方式来配置目标的思源工作空间并创建符号链接:
+
+1. **选择工作空间**
- 打开思源笔记, 确保思源内核正在运行
- 运行 `pnpm run make-link`, 脚本会自动检测所有思源的工作空间, 请在命令行中手动输入序号以选择工作空间
```bash
@@ -33,23 +53,26 @@
Got target directory: H:\Media\SiYuan/data/plugins
Done! Created symlink H:\Media\SiYuan/data/plugins/plugin-sample-vite-svelte
```
-4. **手动创建符号链接**
+2. **手动配置目标目录**
- 打开 `./scripts/make_dev_link.js` 文件,更改 `targetDir` 为思源的插件目录 `/data/plugins`
- 运行 `pnpm run make-link` 命令, 如果看到类似以下的消息,说明创建成功:
- ```bash
- ❯❯❯ pnpm run make-link
- > plugin-sample-vite-svelte@0.0.1 make-link H:\SrcCode\plugin-sample-vite-svelte
- > node ./scripts/make_dev_link.js
- Done! Created symlink H:/SiYuanDevSpace/data/plugins/plugin-sample-vite-svelte
- ```
-5. **设置环境变量创建符号链接**
- - 你也可以设置系统的环境变量 `SIYUAN_PLUGIN_DIR` 为 `/data/plugins` 的路径
-6. 执行 `pnpm run dev` 进行实时编译
-7. 在思源中打开集市并在下载选项卡中启用插件
+3. **设置环境变量创建符号链接**
+ - 设置系统的环境变量 `SIYUAN_PLUGIN_DIR` 为 `工作空间/data/plugins` 的路径
-> 注意由于使用的 make-link 脚本依赖于 `fetch`,所以如果想要使用 make-link **请保证至少安装 v18 版本的 nodejs**
+### Windows 下的 make-link
+
+由于思源升级了 Go 1.23,旧版创建的 junction link 在 windows 下无法被正常识别,故而改为创建 `dir` 符号链接。
+
+> https://github.com/siyuan-note/siyuan/issues/12399
+
+
+不过 Windows 下使用 NodeJs 创建目录符号链接可能需要管理员权限,你可以有如下几种选择:
+
+1. 在具有管理员权限的命令行中运行 `pnpm run make-link`
+2. 配置 Windows 设置,在 [系统设置-更新与安全-开发者模式] 中启用开发者模式,然后再运行 `pnpm run make-link`
+3. 运行 `pnpm run make-link-win`,该命令会使用一个 powershell 脚本来寻求管理员权限,需要在系统中开启 PowerShell 脚本执行权限
## 国际化
@@ -59,9 +82,12 @@
* 插件自身的元信息,比如插件描述和自述文件
* plugin.json 中的 `description` 和 `readme` 字段,以及对应的 README*.md 文件
* 插件中使用的文本,比如按钮文字和提示信息
- * src/i18n/*.json 语言配置文件
+ * public/i18n/*.json 语言配置文件
* 代码中使用 `this.i18.key` 获取文本
* 最后在 plugin.json 中的 `i18n` 字段中声明该插件支持的语言
+* yaml 支持
+ * 本模板特别支持基于 Yaml 语法的 I18n,见 `public/i18n/zh_CN.yaml`
+ * 编译时,会自动把定义的 yaml 文件翻译成 json 文件放到 dist 或 dev 目录下
建议插件至少支持英文和简体中文,这样可以方便更多人使用。
@@ -95,7 +121,10 @@
"custom": [
"https://ld246.com/sponsor"
]
- }
+ },
+ "keywords": [
+ "sample", "示例"
+ ]
}
```
@@ -133,6 +162,7 @@
* `patreon`:Patreon 名称
* `github`:GitHub 登录名
* `custom`:自定义赞助链接列表
+* `keywords`:搜索关键字列表,用于集市搜索功能
## 打包
@@ -195,6 +225,8 @@ PR 社区集市仓库。
## 如何去掉 svelte 依赖
+> 无 Svelte 依赖版: https://github.com/frostime/plugin-sample-vite
+
本插件使用 vite 打包,并提供了 svelte 框架依赖。不过实际情况下可能有些开发者并不想要 svelte,只希望使用 vite 打包。
实际上你可以完全不做任何修改,就可以在不使用 svelte 的前提下使用这个模板。与 svelte 编译的编译相关的部分是以插件的形式载入到 vite 的工作流中,所以即使你的项目里面没有 svelte,也不会有太大的影响。
@@ -215,3 +247,25 @@ PR 社区集市仓库。
- 第二十行: `svelte(),`
4. 删掉 `tsconfig.json` 中 37 行 `"svelte"`
5. 重新执行 `pnpm i`
+
+
+## 开发者须知
+
+思源开发者需注意以下规范。
+
+### 1. 读写文件规范
+
+插件或者外部扩展如果有直接读取或者写入 data 下文件的需求,请通过调用内核 API 来实现,**不要自行调用 `fs` 或者其他 electron、nodejs API**,否则可能会导致数据同步时分块丢失,造成云端数据损坏。
+
+相关 API 见 `/api/file/*`(例如 `/api/file/getFile` 等)。
+
+### 2. Daily Note 属性规范
+
+思源在创建日记的时候会自动为文档添加 custom-dailynote-yyyymmdd 属性,以方便将日记文档同普通文档区分。
+
+> 详情请见 [Github Issue #9807](https://github.com/siyuan-note/siyuan/issues/9807)。
+
+开发者在开发手动创建 Daily Note 的功能时请注意:
+
+* 如果调用了 `/api/filetree/createDailyNote` 创建日记,那么文档会自动添加这个属性,无需开发者特别处理
+* 如果是开发者代码手动创建文档(例如使用 `createDocWithMd` API 创建日记),请手动为文档添加该属性
diff --git a/package.json b/package.json
index 528917a..2b7cdec 100644
--- a/package.json
+++ b/package.json
@@ -1,33 +1,37 @@
{
"name": "plugin-sample-vite-svelte",
- "version": "0.2.3",
+ "version": "0.3.6",
"type": "module",
- "description": "",
+ "description": "This is a sample plugin based on vite and svelte for Siyuan (https://b3log.org/siyuan)",
"repository": "",
"homepage": "",
- "author": "",
- "license": "GPL-3.0",
+ "author": "frostime",
+ "license": "MIT",
"scripts": {
- "make-link": "node --no-warnings ./scripts/make_dev_link.js",
- "dev": "vite build --watch",
- "build": "vite build"
+ "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",
+ "update-version": "node --no-warnings ./scripts/update_version.js",
+ "make-install": "vite build && node --no-warnings ./scripts/make_install.js"
},
"devDependencies": {
- "@sveltejs/vite-plugin-svelte": "^2.0.3",
+ "@sveltejs/vite-plugin-svelte": "^3.1.0",
"@tsconfig/svelte": "^4.0.1",
- "@types/node": "^20.2.0",
- "eslint": "^8.42.0",
+ "@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.62.1",
- "siyuan": "0.8.3",
- "svelte": "^3.57.0",
+ "sass": "^1.63.3",
+ "siyuan": "1.0.4",
+ "svelte": "^4.2.19",
"ts-node": "^10.9.1",
- "typescript": "^5.0.4",
- "vite": "^4.3.7",
- "vite-plugin-static-copy": "^0.15.0",
+ "typescript": "^5.1.3",
+ "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 41c9250..fd63a3c 100644
--- a/plugin.json
+++ b/plugin.json
@@ -2,10 +2,24 @@
"name": "plugin-sample-vite-svelte",
"author": "frostime",
"url": "https://github.com/siyuan-note/plugin-sample-vite-svelte",
- "version": "0.2.3",
- "minAppVersion": "2.10.3",
- "backends": ["all"],
- "frontends": ["all"],
+ "version": "0.3.6",
+ "minAppVersion": "3.0.12",
+ "backends": [
+ "windows",
+ "linux",
+ "darwin",
+ "ios",
+ "android",
+ "harmony",
+ "docker"
+ ],
+ "frontends": [
+ "desktop",
+ "mobile",
+ "browser-desktop",
+ "browser-mobile",
+ "desktop-window"
+ ],
"displayName": {
"en_US": "Plugin sample with vite and svelte",
"zh_CN": "插件样例 vite + svelte 版"
@@ -20,7 +34,12 @@
},
"funding": {
"custom": [
- "https://afdian.net/a/frostime"
+ ""
]
- }
+ },
+ "keywords": [
+ "plugin",
+ "sample",
+ "插件样例"
+ ]
}
diff --git a/public/i18n/README.md b/public/i18n/README.md
new file mode 100644
index 0000000..af8de98
--- /dev/null
+++ b/public/i18n/README.md
@@ -0,0 +1,12 @@
+思源支持的 i18n 文件范围,可以在控制台 `siyuan.config.langs` 中查看。以下是目前(2024-10-24)支持的语言方案:
+
+The range of i18n files supported by SiYuan can be viewed in the console under `siyuan.config.langs`. Below are the language schemes currently supported as of now (October 24, 2024) :
+
+```js
+>>> siyuan.config.langs.map( lang => lang.name)
+['de_DE', 'en_US', 'es_ES', 'fr_FR', 'he_IL', 'it_IT', 'ja_JP', 'pl_PL', 'ru_RU', 'zh_CHT', 'zh_CN']
+```
+
+在插件开发中,默认使用 JSON 格式作为国际化(i18n)的载体文件。如果您更喜欢使用 YAML 语法,可以将 JSON 文件替换为 YAML 文件(例如 `en_US.yaml`),并在其中编写 i18n 文本。本模板提供了相关的 Vite 插件,可以在编译时自动将 YAML 文件转换为 JSON 文件(请参见 `/yaml-plugin.js`)。本 MD 文件 和 YAML 文件会在 `npm run build` 时自动从 `dist` 目录下删除,仅保留必要的 JSON 文件共插件系统使用。
+
+In plugin development, JSON format is used by default as the carrier file for internationalization (i18n). If you prefer to use YAML syntax, you can replace the JSON file with a YAML file (e.g., `en_US.yaml`) and write the i18n text within it. This template provides a related Vite plugin that can automatically convert YAML files to JSON files during the compilation process (see `/yaml-plugin.js`). This markdown file and YAML files will be automatically removed from the `dist` directory during `npm run build`, leaving only the necessary JSON files for plugin system to use.
diff --git a/src/i18n/en_US.json b/public/i18n/en_US.json
similarity index 76%
rename from src/i18n/en_US.json
rename to public/i18n/en_US.json
index 4f21f86..7a11256 100644
--- a/src/i18n/en_US.json
+++ b/public/i18n/en_US.json
@@ -9,9 +9,12 @@
"removedData": "Data deleted",
"confirmRemove": "Confirm to delete the data in ${name}?",
"insertEmoji": "Insert Emoji",
+ "removeSpace": "Remove Space",
"getTab": "Print out all opened custom tabs in the debugger",
"name": "SiYuan",
"hello": {
"makesure": "Before using this template, please read the offical sample, make sure that you've known about the pipeline for plugin developing."
- }
+ },
+ "hintTitle":"About",
+ "hintDesc":"plugin-sample-vite-svelte @frostime @88250 @zxkmm"
}
\ No newline at end of file
diff --git a/src/i18n/zh_CN.json b/public/i18n/zh_CN.json
similarity index 74%
rename from src/i18n/zh_CN.json
rename to public/i18n/zh_CN.json
index 5a586e1..6600f6a 100644
--- a/src/i18n/zh_CN.json
+++ b/public/i18n/zh_CN.json
@@ -9,9 +9,12 @@
"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/scripts/elevate.ps1 b/scripts/elevate.ps1
new file mode 100644
index 0000000..151b8ba
--- /dev/null
+++ b/scripts/elevate.ps1
@@ -0,0 +1,24 @@
+# Copyright (c) 2024 by frostime. All Rights Reserved.
+# @Author : frostime
+# @Date : 2024-09-06 19:15:53
+# @FilePath : /scripts/elevate.ps1
+# @LastEditTime : 2024-09-06 19:39:13
+# @Description : Force to elevate the script to admin privilege.
+
+param (
+ [string]$scriptPath
+)
+
+$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
+$projectDir = Split-Path -Parent $scriptDir
+
+if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
+ $args = "-NoProfile -ExecutionPolicy Bypass -File `"" + $MyInvocation.MyCommand.Path + "`" -scriptPath `"" + $scriptPath + "`""
+ Start-Process powershell.exe -Verb RunAs -ArgumentList $args -WorkingDirectory $projectDir
+ exit
+}
+
+Set-Location -Path $projectDir
+& node $scriptPath
+
+pause
diff --git a/scripts/make_dev_link.js b/scripts/make_dev_link.js
index 845d298..2be3d2b 100644
--- a/scripts/make_dev_link.js
+++ b/scripts/make_dev_link.js
@@ -1,106 +1,29 @@
+/*
+ * Copyright (c) 2024 by frostime. All Rights Reserved.
+ * @Author : frostime
+ * @Date : 2023-07-15 15:31:31
+ * @FilePath : /scripts/make_dev_link.js
+ * @LastEditTime : 2024-09-06 18:13:53
+ * @Description :
+ */
+// make_dev_link.js
import fs from 'fs';
-import http from 'node:http';
-import readline from 'node:readline';
+import { log, error, getSiYuanDir, chooseTarget, getThisPluginName, makeSymbolicLink } from './utils.js';
-
-//************************************ Write you dir here ************************************
-
-//Please write the "workspace/data/plugins" directory here
-//请在这里填写你的 "workspace/data/plugins" 目录
let targetDir = '';
-//Like this
-// let targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
-//********************************************************************************************
-
-const log = (info) => console.log(`\x1B[36m%s\x1B[0m`, info);
-const error = (info) => console.log(`\x1B[31m%s\x1B[0m`, info);
-
-let POST_HEADER = {
- // "Authorization": `Token ${token}`,
- "Content-Type": "application/json",
-}
-
-async function myfetch(url, options) {
- //使用 http 模块,从而兼容那些不支持 fetch 的 nodejs 版本
- return new Promise((resolve, reject) => {
- let req = http.request(url, options, (res) => {
- let data = '';
- res.on('data', (chunk) => {
- data += chunk;
- });
- res.on('end', () => {
- resolve({
- ok: true,
- status: res.statusCode,
- json: () => JSON.parse(data)
- });
- });
- });
- req.on('error', (e) => {
- reject(e);
- });
- req.end();
- });
-}
-
-async function getSiYuanDir() {
- let url = 'http://127.0.0.1:6806/api/system/getWorkspaces';
- let conf = {};
- try {
- let response = await myfetch(url, {
- method: 'POST',
- headers: POST_HEADER
- });
- if (response.ok) {
- conf = await response.json();
- } else {
- error(`\tHTTP-Error: ${response.status}`);
- return null;
- }
- } catch (e) {
- error(`\tError: ${e}`);
- error("\tPlease make sure SiYuan is running!!!");
- return null;
- }
- return conf.data;
-}
-
-async function chooseTarget(workspaces) {
- let count = workspaces.length;
- log(`>>> Got ${count} SiYuan ${count > 1 ? 'workspaces' : 'workspace'}`)
- for (let i = 0; i < workspaces.length; i++) {
- log(`\t[${i}] ${workspaces[i].path}`);
- }
-
- if (count == 1) {
- return `${workspaces[0].path}/data/plugins`;
- } else {
- const rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout
- });
- let index = await new Promise((resolve, reject) => {
- rl.question(`\tPlease select a workspace[0-${count-1}]: `, (answer) => {
- resolve(answer);
- });
- });
- rl.close();
- return `${workspaces[index].path}/data/plugins`;
- }
-}
-
-log('>>> Try to visit constant "targetDir" in make_dev_link.js...')
+/**
+ * 1. Get the parent directory to install the plugin
+ */
+log('>>> Try to visit constant "targetDir" in make_dev_link.js...');
if (targetDir === '') {
- log('>>> Constant "targetDir" is empty, try to get SiYuan directory automatically....')
+ log('>>> Constant "targetDir" is empty, try to get SiYuan directory automatically....');
let res = await getSiYuanDir();
-
- if (res === null || res === undefined || res.length === 0) {
- log('>>> Can not get SiYuan directory automatically, try to visit environment variable "SIYUAN_PLUGIN_DIR"....');
- // console.log(process.env)
+ if (!res || res.length === 0) {
+ log('>>> Can not get SiYuan directory automatically, try to visit environment variable "SIYUAN_PLUGIN_DIR"....');
let env = process.env?.SIYUAN_PLUGIN_DIR;
- if (env !== undefined && env !== null && env !== '') {
+ if (env) {
targetDir = env;
log(`\tGot target directory from environment variable "SIYUAN_PLUGIN_DIR": ${targetDir}`);
} else {
@@ -111,76 +34,33 @@ if (targetDir === '') {
targetDir = await chooseTarget(res);
}
-
log(`>>> Successfully got target directory: ${targetDir}`);
}
-
-//Check
if (!fs.existsSync(targetDir)) {
- error(`Failed! plugin directory not exists: "${targetDir}"`);
- error(`Please set the plugin directory in scripts/make_dev_link.js`);
+ error(`Failed! Plugin directory not exists: "${targetDir}"`);
+ error('Please set the plugin directory in scripts/make_dev_link.js');
process.exit(1);
}
-
-//check if plugin.json exists
-if (!fs.existsSync('./plugin.json')) {
- //change dir to parent
- process.chdir('../');
- if (!fs.existsSync('./plugin.json')) {
- error('Failed! plugin.json not found');
- process.exit(1);
- }
-}
-
-//load plugin.json
-const plugin = JSON.parse(fs.readFileSync('./plugin.json', 'utf8'));
-const name = plugin?.name;
-if (!name || name === '') {
- error('Failed! Please set plugin name in plugin.json');
- process.exit(1);
-}
-
-//dev directory
+/**
+ * 2. The dev directory, which contains the compiled plugin code
+ */
const devDir = `${process.cwd()}/dev`;
-//mkdir if not exists
if (!fs.existsSync(devDir)) {
fs.mkdirSync(devDir);
}
-function cmpPath(path1, path2) {
- path1 = path1.replace(/\\/g, '/');
- path2 = path2.replace(/\\/g, '/');
- // sepertor at tail
- if (path1[path1.length - 1] !== '/') {
- path1 += '/';
- }
- if (path2[path2.length - 1] !== '/') {
- path2 += '/';
- }
- return path1 === path2;
-}
+/**
+ * 3. The target directory to make symbolic link to dev directory
+ */
+const name = getThisPluginName();
+if (name === null) {
+ process.exit(1);
+}
const targetPath = `${targetDir}/${name}`;
-//如果已经存在,就退出
-if (fs.existsSync(targetPath)) {
- let isSymbol = fs.lstatSync(targetPath).isSymbolicLink();
-
- if (isSymbol) {
- let srcPath = fs.readlinkSync(targetPath);
-
- if (cmpPath(srcPath, devDir)) {
- log(`Good! ${targetPath} is already linked to ${devDir}`);
- } else {
- error(`Error! Already exists symbolic link ${targetPath}\nBut it links to ${srcPath}`);
- }
- } else {
- error(`Failed! ${targetPath} already exists and is not a symbolic link`);
- }
-
-} else {
- //创建软链接
- fs.symlinkSync(devDir, targetPath, 'junction');
- log(`Done! Created symlink ${targetPath}`);
-}
+/**
+ * 4. Make symbolic link
+ */
+makeSymbolicLink(devDir, targetPath);
diff --git a/scripts/make_install.js b/scripts/make_install.js
new file mode 100644
index 0000000..cb2a4ac
--- /dev/null
+++ b/scripts/make_install.js
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2024 by frostime. All Rights Reserved.
+ * @Author : frostime
+ * @Date : 2024-03-28 20:03:59
+ * @FilePath : /scripts/make_install.js
+ * @LastEditTime : 2024-09-06 18:08:19
+ * @Description :
+ */
+// make_install.js
+import fs from 'fs';
+import { log, error, getSiYuanDir, chooseTarget, copyDirectory, getThisPluginName } from './utils.js';
+
+let targetDir = '';
+
+/**
+ * 1. Get the parent directory to install the plugin
+ */
+log('>>> Try to visit constant "targetDir" in make_install.js...');
+if (targetDir === '') {
+ log('>>> Constant "targetDir" is empty, try to get SiYuan directory automatically....');
+ let res = await getSiYuanDir();
+
+ if (res === null || res === undefined || res.length === 0) {
+ error('>>> Can not get SiYuan directory automatically');
+ process.exit(1);
+ } else {
+ targetDir = await chooseTarget(res);
+ }
+ log(`>>> Successfully got target directory: ${targetDir}`);
+}
+if (!fs.existsSync(targetDir)) {
+ error(`Failed! Plugin directory not exists: "${targetDir}"`);
+ error('Please set the plugin directory in scripts/make_install.js');
+ process.exit(1);
+}
+
+/**
+ * 2. The dist directory, which contains the compiled plugin code
+ */
+const distDir = `${process.cwd()}/dist`;
+if (!fs.existsSync(distDir)) {
+ fs.mkdirSync(distDir);
+}
+
+/**
+ * 3. The target directory to install the plugin
+ */
+const name = getThisPluginName();
+if (name === null) {
+ process.exit(1);
+}
+const targetPath = `${targetDir}/${name}`;
+
+/**
+ * 4. Copy the compiled plugin code to the target directory
+ */
+copyDirectory(distDir, targetPath);
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/scripts/utils.js b/scripts/utils.js
new file mode 100644
index 0000000..210b6b1
--- /dev/null
+++ b/scripts/utils.js
@@ -0,0 +1,182 @@
+/*
+ * Copyright (c) 2024 by frostime. All Rights Reserved.
+ * @Author : frostime
+ * @Date : 2024-09-06 17:42:57
+ * @FilePath : /scripts/utils.js
+ * @LastEditTime : 2024-09-06 19:23:12
+ * @Description :
+ */
+// common.js
+import fs from 'fs';
+import path from 'node:path';
+import http from 'node:http';
+import readline from 'node:readline';
+
+// Logging functions
+export const log = (info) => console.log(`\x1B[36m%s\x1B[0m`, info);
+export const error = (info) => console.log(`\x1B[31m%s\x1B[0m`, info);
+
+// HTTP POST headers
+export const POST_HEADER = {
+ "Content-Type": "application/json",
+};
+
+// Fetch function compatible with older Node.js versions
+export async function myfetch(url, options) {
+ return new Promise((resolve, reject) => {
+ let req = http.request(url, options, (res) => {
+ let data = '';
+ res.on('data', (chunk) => {
+ data += chunk;
+ });
+ res.on('end', () => {
+ resolve({
+ ok: true,
+ status: res.statusCode,
+ json: () => JSON.parse(data)
+ });
+ });
+ });
+ req.on('error', (e) => {
+ reject(e);
+ });
+ req.end();
+ });
+}
+
+/**
+ * Fetch SiYuan workspaces from port 6806
+ * @returns {Promise