mirror of
https://github.com/siyuan-note/plugin-sample-vite-svelte.git
synced 2025-08-02 17:00:23 +00:00
更新了 py 脚本的用法,打包 exe,并更新 README
This commit is contained in:
parent
d8287067d2
commit
efd5d9e945
4 changed files with 70 additions and 47 deletions
|
@ -3,7 +3,7 @@
|
||||||
# 使用 vite + svelte 的思源笔记插件示例
|
# 使用 vite + svelte 的思源笔记插件示例
|
||||||
|
|
||||||
1. 使用 vite 打包
|
1. 使用 vite 打包
|
||||||
2. 使用软链接、而不是把项目放到插件目录下的模式进行开发
|
2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发
|
||||||
3. 内置对 svelte 框架的支持
|
3. 内置对 svelte 框架的支持
|
||||||
4. 提供一个github action 模板,能自动生成package.zip并上传到新版本中
|
4. 提供一个github action 模板,能自动生成package.zip并上传到新版本中
|
||||||
|
|
||||||
|
@ -12,19 +12,29 @@
|
||||||
1. 通过 <kbd>Use this template</kbd> 按钮将该库文件复制到你自己的库中,请注意库名必须和插件名称一致,默认分支必须为 `main`
|
1. 通过 <kbd>Use this template</kbd> 按钮将该库文件复制到你自己的库中,请注意库名必须和插件名称一致,默认分支必须为 `main`
|
||||||
2. 将你的库克隆到本地开发文件夹中
|
2. 将你的库克隆到本地开发文件夹中
|
||||||
* 注意: 同 `plugin-sample` 不同, 本样例并不推荐直接把代码下载到 `{workspace}/data/plugins/`
|
* 注意: 同 `plugin-sample` 不同, 本样例并不推荐直接把代码下载到 `{workspace}/data/plugins/`
|
||||||
3. 创建开发需要的软链接
|
3. 创建开发需要的符号链接
|
||||||
- 推荐使用软链接来链接你的工作目录和插件目录
|
- 推荐使用符号链接来链接你的工作目录和插件目录
|
||||||
- 如果你的设备安装了 python 环境,运行 `python scripts/make_dev_link.py <plugin_dir>` 命令,`<plugin_dir>`是插件目录的绝对路径,示例:
|
- 如果你的设备安装了 python 环境,运行 `python scripts/make_dev_link.py` 命令,然后输入插件目录的绝对路径,示例:
|
||||||
```powershell
|
```powershell
|
||||||
>>> sudo python . \scripts\make_dev_link.py "H:\SiYuanDevSpace\data\plugins"
|
>>> python make_dev_link.py
|
||||||
Symlink created: H:\SiYuanDevSpace\data\plugins\plugin-sample
|
Please input the directory of siyuan/data/plugins: H:\临时文件夹\SiYuanDevSpace\data\plugins
|
||||||
|
Symlink created: H:\临时文件夹\SiYuanDevSpace\data\plugins\plugin-sample-vite-svelte
|
||||||
```
|
```
|
||||||
- 可能需要使用管理员身份来运行这个命令。对 windows 用户来讲可以首先使用管理员身份打开控制台,然后再运行脚本。如果你的 windows 设备上安装了 scoop 等软件,可以安装 `scoop install sudo` 然后使用 sudo 命令来运行上面的程序
|
- 如果您没有安装 python 环境但是是 unix 用户,可以直接使用 ln 命令创建符号链接
|
||||||
- 如果您的开发环境下没有安装 python,也可以自己手动创建软链接
|
```sh
|
||||||
|
ln -s ./dev "<plugin_dir>/<plugin_name>"
|
||||||
|
```
|
||||||
|
- 注意:要确保符号链接的名称 `plugin_name` 和 plugin.json 中的 name 字段保持一致
|
||||||
|
- 如果您没有安装 python 环境,而且是 windows 用户
|
||||||
|
- 您可以直接下载我们提供的 `make_dev_link.exe` 放在根目录下, 以管理员方式运行
|
||||||
|
- 如果您没有安装 python 环境,而且是 windows 用户, 而且对外来的 exe 不信任,你也可以手动创建符号链接
|
||||||
- 首先手动在工作目录下创建 dev 目录
|
- 首先手动在工作目录下创建 dev 目录
|
||||||
- windows 用户请使用 [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink) 命令; unix 用户使用 ln 命令
|
- windows 用户请在**管理员** cmd 环境下 使用 [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink) 命令, 注意要使用绝对路径
|
||||||
- 注意:要确保软链接的名称和 plugin.json 中的 name 字段保持一致
|
```cmd
|
||||||
由于生成的软链接和 plugin name 相同,所以不要把工程目录放在 plugins 下(这一点和 plugin-sample 模板相反)
|
mklink /d "<plugin_dir>\<plugin_name>" "<project_dir>\dev"
|
||||||
|
```
|
||||||
|
- 可能需要使用**管理员身份来运行**上面的命令。unix 用户可以直接 sudo 运行, windows 用户可以首先使用管理员身份打开控制台,然后再运行命令
|
||||||
|
- 注意: 由于生成的符号链接和 plugin name 相同,所以不要把工程目录放在 plugins 下(这一点和 plugin-sample 模板相反)
|
||||||
|
|
||||||
4. 安装 [NodeJS](https://nodejs.org/en/download) 和 [pnpm](https://pnpm.io/installation),然后在开发文件夹下执行 `pnpm i`
|
4. 安装 [NodeJS](https://nodejs.org/en/download) 和 [pnpm](https://pnpm.io/installation),然后在开发文件夹下执行 `pnpm i`
|
||||||
5. 执行 `pnpm run dev` 进行实时编译
|
5. 执行 `pnpm run dev` 进行实时编译
|
||||||
|
|
5
scripts/.gitignore
vendored
Normal file
5
scripts/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
.venv
|
||||||
|
build
|
||||||
|
dist
|
||||||
|
*.exe
|
||||||
|
*.spec
|
|
@ -2,44 +2,48 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
# check path, must be in root folder
|
def run():
|
||||||
if not os.path.exists('plugin.json'):
|
# check path, must be in root folder
|
||||||
|
if not os.path.exists('plugin.json'):
|
||||||
os.chdir('..')
|
os.chdir('..')
|
||||||
if not os.path.exists('plugin.json'):
|
if not os.path.exists('plugin.json'):
|
||||||
print('plugin.json not found, exit')
|
print('plugin.json not found, exit')
|
||||||
sys.exit()
|
return
|
||||||
|
|
||||||
# 1. Read plugin_dir
|
# 1. Read plugin_dir
|
||||||
plugin_dir = ''
|
plugin_dir = ''
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
plugin_dir = sys.argv[1]
|
plugin_dir = sys.argv[1]
|
||||||
while not os.path.exists(plugin_dir):
|
while not os.path.exists(plugin_dir):
|
||||||
plugin_dir = input('Please input the directory of siyuan/data/plugins: ')
|
plugin_dir = input('Please input the directory of siyuan/data/plugins: ')
|
||||||
if plugin_dir == 'exit' or plugin_dir == 'quit' or plugin_dir == 'q':
|
if plugin_dir == 'exit' or plugin_dir == 'quit' or plugin_dir == 'q':
|
||||||
sys.exit()
|
return
|
||||||
if not os.path.exists(plugin_dir):
|
if not os.path.exists(plugin_dir):
|
||||||
print('plugin_dir not found!')
|
print('plugin_dir not found!')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# 2. Read name in plugin.json
|
# 2. Read name in plugin.json
|
||||||
with open('plugin.json', 'r', encoding='utf-8') as f:
|
with open('plugin.json', 'r', encoding='utf-8') as f:
|
||||||
content = json.load(f)
|
content = json.load(f)
|
||||||
name = content.get('name')
|
name = content.get('name')
|
||||||
|
|
||||||
# ...error if name not found
|
# ...error if name not found
|
||||||
if not name or name == '':
|
if not name or name == '':
|
||||||
print('"name" in plugin.json not found, exit')
|
print('"name" in plugin.json not found, exit')
|
||||||
sys.exit()
|
return
|
||||||
|
|
||||||
dev_dir = os.path.abspath('dev')
|
dev_dir = os.path.abspath('dev')
|
||||||
if not os.path.exists(dev_dir):
|
if not os.path.exists(dev_dir):
|
||||||
os.mkdir(dev_dir)
|
os.mkdir(dev_dir)
|
||||||
|
|
||||||
# 3. Create symlink
|
# 3. Create symlink
|
||||||
if not os.path.exists(os.path.join(plugin_dir, name)):
|
if not os.path.exists(os.path.join(plugin_dir, name)):
|
||||||
link = os.path.join(plugin_dir, name)
|
link = os.path.join(plugin_dir, name)
|
||||||
os.symlink(dev_dir, link)
|
os.symlink(dev_dir, link)
|
||||||
print('Symlink created:', link)
|
print('Symlink created:', link)
|
||||||
else:
|
else:
|
||||||
print('Folder already exists, exit')
|
print('Folder already exists, exit')
|
||||||
sys.exit()
|
return
|
||||||
|
|
||||||
|
run()
|
||||||
|
os.system('pause')
|
||||||
|
|
4
scripts/py2exe.bat
Normal file
4
scripts/py2exe.bat
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
.venv/Script/activate
|
||||||
|
pyinstaller --noconfirm --onefile --console "./make_dev_link.py"
|
||||||
|
rm ./make_dev_link.exe
|
||||||
|
mv ./dist/make_dev_link.exe .
|
Loading…
Add table
Add a link
Reference in a new issue