Skip to content

Commit f45b02a

Browse files
authored
Link (#1)
* 更新 py 脚本的用法 * 更新了 py 脚本的用法,打包 exe,并更新 README * readme
1 parent ba8e431 commit f45b02a

File tree

5 files changed

+91
-47
lines changed

5 files changed

+91
-47
lines changed

README.md

+18-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[中文版](./README_zh_CN.md)
55

66
1. Using vite for packaging
7-
2. Use soft linking instead of putting the project into the plugins directory program development
7+
2. Use symbolic linking instead of putting the project into the plugins directory program development
88
3. Built-in support for the svelte framework
99
4. Provides a github action template to automatically generate package.zip and upload to new release
1010

@@ -16,20 +16,29 @@
1616
2. Clone your repo to a local development folder at any place
1717
- Notice: we **don't recommand** you to place the folder under your `{workspace}/data/plugins/` folder.
1818

19-
3. Create development soft links
19+
3. Create development symbolic links
2020

2121
- It is recommended to create a symbolic link between your development directory and the plugins directory.
22-
- 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.
22+
- 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.
2323

2424
```powershell
25-
>>> sudo python . \scripts\make_dev_link.py "H:\SiYuanDevSpace\data\plugins"
25+
>>> python make_dev_link.py
26+
Please input the directory of siyuan/data/plugins: H:\SiYuanDevSpace\data\plugins
2627
Symlink created: H:\SiYuanDevSpace\data\plugins\plugin-sample
2728
```
28-
- 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.
29-
- If you haven't installed python in your environment, you can also manually make a soft link
30-
- Create directory `dev` in you workspace
31-
- Window user use [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink); and unix user use ln command
32-
- Notice: make sure that the name of soft link is same as the name in your plugin.json
29+
- If you haven't intalled python, while you are an unix user, you can use `ln` command
30+
```sh
31+
ln -s ./dev "<plugin_dir>/<plugin_name>"
32+
```
33+
- Notice: make sure that the name of symbolic link is same as the name in your plugin.json
34+
- 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)
35+
- 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
36+
1. Create a dev folder in your worksapce
37+
2. Using use [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink) command to create symlink
38+
```cmd
39+
mklink /d "<plugin_dir>\<plugin_name>" "<project_dir>\dev"
40+
```
41+
- You may need to run it as administration.
3342
- 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)
3443
3544
4. Install NodeJS and pnpm, then run pnpm i in the command line under your repo folder

README_zh_CN.md

+21-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# 使用 vite + svelte 的思源笔记插件示例
44

55
1. 使用 vite 打包
6-
2. 使用软链接、而不是把项目放到插件目录下的模式进行开发
6+
2. 使用符号链接、而不是把项目放到插件目录下的模式进行开发
77
3. 内置对 svelte 框架的支持
88
4. 提供一个github action 模板,能自动生成package.zip并上传到新版本中
99

@@ -12,19 +12,28 @@
1212
1. 通过 <kbd>Use this template</kbd> 按钮将该库文件复制到你自己的库中,请注意库名必须和插件名称一致,默认分支必须为 `main`
1313
2. 将你的库克隆到本地开发文件夹中
1414
* 注意: 同 `plugin-sample` 不同, 本样例并不推荐直接把代码下载到 `{workspace}/data/plugins/`
15-
3. 创建开发需要的软链接
16-
- 推荐使用软链接来链接你的工作目录和插件目录
17-
- 如果你的设备安装了 python 环境,运行 `python scripts/make_dev_link.py <plugin_dir>` 命令,`<plugin_dir>`是插件目录的绝对路径,示例:
15+
3. 创建开发需要的符号链接
16+
- 推荐使用符号链接来链接你的工作目录和插件目录
17+
- 如果你的设备安装了 python 环境,运行 `python scripts/make_dev_link.py` 命令,然后输入插件目录的绝对路径,示例:
1818
```powershell
19-
>>> sudo python . \scripts\make_dev_link.py "H:\SiYuanDevSpace\data\plugins"
20-
Symlink created: H:\SiYuanDevSpace\data\plugins\plugin-sample
19+
>>> python make_dev_link.py
20+
Please input the directory of siyuan/data/plugins: H:\临时文件夹\SiYuanDevSpace\data\plugins
21+
Symlink created: H:\临时文件夹\SiYuanDevSpace\data\plugins\plugin-sample-vite-svelte
2122
```
22-
- 可能需要使用管理员身份来运行这个命令。对 windows 用户来讲可以首先使用管理员身份打开控制台,然后再运行脚本。如果你的 windows 设备上安装了 scoop 等软件,可以安装 `scoop install sudo` 然后使用 sudo 命令来运行上面的程序
23-
- 如果您的开发环境下没有安装 python,也可以自己手动创建软链接
24-
- 首先手动在工作目录下创建 dev 目录
25-
- windows 用户请使用 [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink) 命令; unix 用户使用 ln 命令
26-
- 注意:要确保软链接的名称和 plugin.json 中的 name 字段保持一致
27-
由于生成的软链接和 plugin name 相同,所以不要把工程目录放在 plugins 下(这一点和 plugin-sample 模板相反)
23+
- 如果您没有安装 python 环境但是是 unix 用户,可以直接使用 ln 命令创建符号链接
24+
```sh
25+
ln -s ./dev "<plugin_dir>/<plugin_name>"
26+
```
27+
- 注意:要确保符号链接的名称 `plugin_name` 和 plugin.json 中的 name 字段保持一致
28+
- 如果您没有安装 python 环境,而且是 windows 用户, 您可以直接下载我们提供的 `make_dev_link.exe` 放在根目录下, 以管理员方式运行
29+
- 如果您没有安装 python 环境,而且是 windows 用户, 而且对外来的 exe 不信任,你也可以手动创建符号链接
30+
1. 首先手动在工作目录下创建 dev 目录
31+
2. windows 用户请在**管理员** cmd 环境下 使用 [mklink](https://learn.microsoft.com/windows-server/administration/windows-commands/mklink) 命令, 注意要使用绝对路径
32+
```cmd
33+
mklink /d "<plugin_dir>\<plugin_name>" "<project_dir>\dev"
34+
```
35+
- 可能需要使用**管理员身份**来运行上面的命令
36+
- 注意: 由于生成的符号链接和 plugin name 相同,所以不要把工程目录放在 plugins 下(这一点和 plugin-sample 模板相反)
2837
2938
4. 安装 [NodeJS](https://nodejs.org/en/download) 和 [pnpm](https://pnpm.io/installation),然后在开发文件夹下执行 `pnpm i`
3039
5. 执行 `pnpm run dev` 进行实时编译

scripts/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.venv
2+
build
3+
dist
4+
*.exe
5+
*.spec

scripts/make_dev_link.py

+43-26
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,49 @@
11
import os
2+
import sys
23
import json
3-
from argparse import ArgumentParser
44

5-
# 1. Read plugin_dir
6-
parser = ArgumentParser()
7-
parser.add_argument('plugin_dir')
8-
args = parser.parse_args()
9-
plugin_dir = args.plugin_dir
5+
def run():
6+
# check path, must be in root folder
7+
if not os.path.exists('plugin.json'):
8+
os.chdir('..')
9+
if not os.path.exists('plugin.json'):
10+
print('plugin.json not found, exit')
11+
return
1012

11-
# 2. Read name in plugin.json
12-
with open('plugin.json', 'r', encoding='utf-8') as f:
13-
content = json.load(f)
14-
name = content.get('name')
13+
# 1. Read plugin_dir
14+
plugin_dir = ''
15+
if len(sys.argv) > 1:
16+
plugin_dir = sys.argv[1]
17+
while not os.path.exists(plugin_dir):
18+
plugin_dir = input('Please input the directory of siyuan/data/plugins: ')
19+
if plugin_dir == 'exit' or plugin_dir == 'quit' or plugin_dir == 'q':
20+
return
21+
if not os.path.exists(plugin_dir):
22+
print('plugin_dir not found!')
23+
continue
1524

16-
# ...error if name not found
17-
if not name or name == '':
18-
print('"name" in plugin.json not found, exit')
19-
exit()
20-
21-
dev_dir = os.path.abspath('dev')
22-
if not os.path.exists(dev_dir):
23-
os.mkdir(dev_dir)
25+
# 2. Read name in plugin.json
26+
with open('plugin.json', 'r', encoding='utf-8') as f:
27+
content = json.load(f)
28+
name = content.get('name')
2429

25-
# 3. Create symlink
26-
if not os.path.exists(os.path.join(plugin_dir, name)):
27-
link = os.path.join(plugin_dir, name)
28-
os.symlink(dev_dir, link)
29-
print('Symlink created:', link)
30-
else:
31-
print('Folder already exists, exit')
32-
exit()
30+
# ...error if name not found
31+
if not name or name == '':
32+
print('"name" in plugin.json not found, exit')
33+
return
34+
35+
dev_dir = os.path.abspath('dev')
36+
if not os.path.exists(dev_dir):
37+
os.mkdir(dev_dir)
38+
39+
# 3. Create symlink
40+
if not os.path.exists(os.path.join(plugin_dir, name)):
41+
link = os.path.join(plugin_dir, name)
42+
os.symlink(dev_dir, link)
43+
print('Symlink created:', link)
44+
else:
45+
print('Folder already exists, exit')
46+
return
47+
48+
run()
49+
os.system('pause')

scripts/py2exe.bat

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.venv/Script/activate
2+
pyinstaller --noconfirm --onefile --console "./make_dev_link.py"
3+
rm ./make_dev_link.exe
4+
mv ./dist/make_dev_link.exe .

0 commit comments

Comments
 (0)