parent
ba8e431dec
commit
f45b02a156
5 changed files with 91 additions and 47 deletions
27
README.md
27
README.md
|
@ -4,7 +4,7 @@
|
||||||
[中文版](./README_zh_CN.md)
|
[中文版](./README_zh_CN.md)
|
||||||
|
|
||||||
1. Using vite for packaging
|
1. Using vite for packaging
|
||||||
2. Use soft linking instead of putting the project into the plugins directory program development
|
2. Use symbolic linking instead of putting the project into the plugins directory program development
|
||||||
3. Built-in support for the svelte framework
|
3. Built-in support for the svelte framework
|
||||||
4. Provides a github action template to automatically generate package.zip and upload to new release
|
4. Provides a github action template to automatically generate package.zip and upload to new release
|
||||||
|
|
||||||
|
@ -16,20 +16,29 @@
|
||||||
2. Clone your repo to a local development folder at any place
|
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.
|
- Notice: we **don't recommand** you to place the folder under your `{workspace}/data/plugins/` folder.
|
||||||
|
|
||||||
3. Create development soft links
|
3. Create development symbolic links
|
||||||
|
|
||||||
- It is recommended to create a symbolic link between your development directory and the plugins directory.
|
- It is recommended to create a symbolic link between your development directory and the plugins directory.
|
||||||
- If you have python environment in you device, run the command `python scripts/make_dev_link.py <plugin_dir>`, `<plugin_dir>` is the absolute path to the plugins directory, e.g.
|
- If you have python environment in you device, run the command `python scripts/make_dev_link.py`, input the `<plugin_dir>` i.e. the absolute path to the plugins directory, e.g.
|
||||||
|
|
||||||
```powershell
|
```powershell
|
||||||
>>> sudo python . \scripts\make_dev_link.py "H:\SiYuanDevSpace\data\plugins"
|
>>> python make_dev_link.py
|
||||||
|
Please input the directory of siyuan/data/plugins: H:\SiYuanDevSpace\data\plugins
|
||||||
Symlink created: H:\SiYuanDevSpace\data\plugins\plugin-sample
|
Symlink created: H:\SiYuanDevSpace\data\plugins\plugin-sample
|
||||||
```
|
```
|
||||||
- You may need to run it as administration, normal windows users can first open the command line as administrator and then run it. Or if you have scoop installed in you windows system, you install `scoop install sudo` and run with sudo.
|
- If you haven't intalled python, while you are an unix user, you can use `ln` command
|
||||||
- If you haven't installed python in your environment, you can also manually make a soft link
|
```sh
|
||||||
- Create directory `dev` in you workspace
|
ln -s ./dev "<plugin_dir>/<plugin_name>"
|
||||||
- Window user use [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink); and unix user use ln command
|
```
|
||||||
- Notice: make sure that the name of soft link is same as the name in your plugin.json
|
- Notice: make sure that the name of symbolic link is same as the name in your plugin.json
|
||||||
|
- If you haven't intalled python, while you are a windows user, you can download the `make_dev_link.exe` in release and run it in your workspace (as administrator)
|
||||||
|
- If you haven't intalled python, while you are a windows user, and you don't trust any other exe file, you can make the symlink by your self
|
||||||
|
1. Create a dev folder in your worksapce
|
||||||
|
2. Using use [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink) command to create symlink
|
||||||
|
```cmd
|
||||||
|
mklink /d "<plugin_dir>\<plugin_name>" "<project_dir>\dev"
|
||||||
|
```
|
||||||
|
- You may need to run it as administration.
|
||||||
- As the generated softlink is the same as the plugin name, **do not put the project directory under plugins** (this is contrary to the webpack version)
|
- As the generated softlink is the same as the plugin name, **do not put the project directory under plugins** (this is contrary to the webpack version)
|
||||||
|
|
||||||
4. Install NodeJS and pnpm, then run pnpm i in the command line under your repo folder
|
4. Install NodeJS and pnpm, then run pnpm i in the command line under your repo folder
|
||||||
|
|
|
@ -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,28 @@
|
||||||
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
|
||||||
- 首先手动在工作目录下创建 dev 目录
|
ln -s ./dev "<plugin_dir>/<plugin_name>"
|
||||||
- windows 用户请使用 [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink) 命令; unix 用户使用 ln 命令
|
```
|
||||||
- 注意:要确保软链接的名称和 plugin.json 中的 name 字段保持一致
|
- 注意:要确保符号链接的名称 `plugin_name` 和 plugin.json 中的 name 字段保持一致
|
||||||
由于生成的软链接和 plugin name 相同,所以不要把工程目录放在 plugins 下(这一点和 plugin-sample 模板相反)
|
- 如果您没有安装 python 环境,而且是 windows 用户, 您可以直接下载我们提供的 `make_dev_link.exe` 放在根目录下, 以管理员方式运行
|
||||||
|
- 如果您没有安装 python 环境,而且是 windows 用户, 而且对外来的 exe 不信任,你也可以手动创建符号链接
|
||||||
|
1. 首先手动在工作目录下创建 dev 目录
|
||||||
|
2. windows 用户请在**管理员** cmd 环境下 使用 [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink) 命令, 注意要使用绝对路径
|
||||||
|
```cmd
|
||||||
|
mklink /d "<plugin_dir>\<plugin_name>" "<project_dir>\dev"
|
||||||
|
```
|
||||||
|
- 可能需要使用**管理员身份**来运行上面的命令
|
||||||
|
- 注意: 由于生成的符号链接和 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
|
|
@ -1,32 +1,49 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import json
|
import json
|
||||||
from argparse import ArgumentParser
|
|
||||||
|
|
||||||
# 1. Read plugin_dir
|
def run():
|
||||||
parser = ArgumentParser()
|
# check path, must be in root folder
|
||||||
parser.add_argument('plugin_dir')
|
if not os.path.exists('plugin.json'):
|
||||||
args = parser.parse_args()
|
os.chdir('..')
|
||||||
plugin_dir = args.plugin_dir
|
if not os.path.exists('plugin.json'):
|
||||||
|
print('plugin.json not found, exit')
|
||||||
|
return
|
||||||
|
|
||||||
# 2. Read name in plugin.json
|
# 1. Read plugin_dir
|
||||||
with open('plugin.json', 'r', encoding='utf-8') as f:
|
plugin_dir = ''
|
||||||
content = json.load(f)
|
if len(sys.argv) > 1:
|
||||||
name = content.get('name')
|
plugin_dir = sys.argv[1]
|
||||||
|
while not os.path.exists(plugin_dir):
|
||||||
|
plugin_dir = input('Please input the directory of siyuan/data/plugins: ')
|
||||||
|
if plugin_dir == 'exit' or plugin_dir == 'quit' or plugin_dir == 'q':
|
||||||
|
return
|
||||||
|
if not os.path.exists(plugin_dir):
|
||||||
|
print('plugin_dir not found!')
|
||||||
|
continue
|
||||||
|
|
||||||
# ...error if name not found
|
# 2. Read name in plugin.json
|
||||||
if not name or name == '':
|
with open('plugin.json', 'r', encoding='utf-8') as f:
|
||||||
print('"name" in plugin.json not found, exit')
|
content = json.load(f)
|
||||||
exit()
|
name = content.get('name')
|
||||||
|
|
||||||
dev_dir = os.path.abspath('dev')
|
# ...error if name not found
|
||||||
if not os.path.exists(dev_dir):
|
if not name or name == '':
|
||||||
os.mkdir(dev_dir)
|
print('"name" in plugin.json not found, exit')
|
||||||
|
return
|
||||||
|
|
||||||
# 3. Create symlink
|
dev_dir = os.path.abspath('dev')
|
||||||
if not os.path.exists(os.path.join(plugin_dir, name)):
|
if not os.path.exists(dev_dir):
|
||||||
link = os.path.join(plugin_dir, name)
|
os.mkdir(dev_dir)
|
||||||
os.symlink(dev_dir, link)
|
|
||||||
print('Symlink created:', link)
|
# 3. Create symlink
|
||||||
else:
|
if not os.path.exists(os.path.join(plugin_dir, name)):
|
||||||
print('Folder already exists, exit')
|
link = os.path.join(plugin_dir, name)
|
||||||
exit()
|
os.symlink(dev_dir, link)
|
||||||
|
print('Symlink created:', link)
|
||||||
|
else:
|
||||||
|
print('Folder already exists, 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