Skip to content

Commit d64c5b1

Browse files
committed
update make-link
1 parent e6f5580 commit d64c5b1

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@
4747
4848
Done! Created symlink H:/SiYuanDevSpace/data/plugins/plugin-sample-vite-svelte
4949
```
50-
51-
5. Execute pnpm run dev for real-time compilation
52-
6. Open SiYuan marketplace and enable plugin in downloaded tab
50+
5. **Create development symbolic links by using environment variable**
51+
- You can set environment variable `SIYUAN_PLUGIN_DIR` as `/data/plugins`
52+
6. Execute pnpm run dev for real-time compilation
53+
7. Open SiYuan marketplace and enable plugin in downloaded tab
5354
5455
> 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.
5556

README_zh_CN.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343

4444
Done! Created symlink H:/SiYuanDevSpace/data/plugins/plugin-sample-vite-svelte
4545
```
46-
5. 执行 `pnpm run dev` 进行实时编译
47-
6. 在思源中打开集市并在下载选项卡中启用插件
46+
5. **设置环境变量创建符号链接**
47+
- 你也可以设置系统的环境变量 `SIYUAN_PLUGIN_DIR``/data/plugins` 的路径
48+
6. 执行 `pnpm run dev` 进行实时编译
49+
7. 在思源中打开集市并在下载选项卡中启用插件
4850
4951
5052
> 注意由于使用的 make-link 脚本依赖于 `fetch`,所以如果想要使用 make-link **请保证至少安装 v18 版本的 nodejs**

scripts/make_dev_link.js

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,22 @@ async function getSiYuanDir() {
5454
if (response.ok) {
5555
conf = await response.json();
5656
} else {
57-
error(`HTTP-Error: ${response.status}`);
57+
error(`\tHTTP-Error: ${response.status}`);
5858
return null;
5959
}
6060
} catch (e) {
61-
error("Error:", e);
62-
error("Please make sure SiYuan is running!!!");
61+
error(`\tError: ${e}`);
62+
error("\tPlease make sure SiYuan is running!!!");
6363
return null;
6464
}
6565
return conf.data;
6666
}
6767

6868
async function chooseTarget(workspaces) {
6969
let count = workspaces.length;
70-
log(`Got ${count} SiYuan ${count > 1 ? 'workspaces' : 'workspace'}`)
70+
log(`>>> Got ${count} SiYuan ${count > 1 ? 'workspaces' : 'workspace'}`)
7171
for (let i = 0; i < workspaces.length; i++) {
72-
log(`[${i}] ${workspaces[i].path}`);
72+
log(`\t[${i}] ${workspaces[i].path}`);
7373
}
7474

7575
if (count == 1) {
@@ -80,7 +80,7 @@ async function chooseTarget(workspaces) {
8080
output: process.stdout
8181
});
8282
let index = await new Promise((resolve, reject) => {
83-
rl.question(`Please select a workspace[0-${count-1}]: `, (answer) => {
83+
rl.question(`\tPlease select a workspace[0-${count-1}]: `, (answer) => {
8484
resolve(answer);
8585
});
8686
});
@@ -89,17 +89,30 @@ async function chooseTarget(workspaces) {
8989
}
9090
}
9191

92+
log('>>> Try to visit constant "targetDir" in make_dev_link.js...')
93+
9294
if (targetDir === '') {
93-
log('"targetDir" is empty, try to get SiYuan directory automatically....')
95+
log('>>> Constant "targetDir" is empty, try to get SiYuan directory automatically....')
9496
let res = await getSiYuanDir();
9597

9698
if (res === null || res === undefined || res.length === 0) {
97-
log('Failed! You can set the plugin directory in scripts/make_dev_link.js and try again');
98-
process.exit(1);
99+
log('>>> Can not get SiYuan directory automatically, try to visit environment variable "SIYUAN_PLUGIN_DIR"....');
100+
101+
// console.log(process.env)
102+
let env = process.env?.SIYUAN_PLUGIN_DIR;
103+
if (env !== undefined && env !== null && env !== '') {
104+
targetDir = env;
105+
log(`\tGot target directory from environment variable "SIYUAN_PLUGIN_DIR": ${targetDir}`);
106+
} else {
107+
error('\tCan not get SiYuan directory from environment variable "SIYUAN_PLUGIN_DIR", failed!');
108+
process.exit(1);
109+
}
110+
} else {
111+
targetDir = await chooseTarget(res);
99112
}
100113

101-
targetDir = await chooseTarget(res);
102-
log(`Got target directory: ${targetDir}`);
114+
115+
log(`>>> Successfully got target directory: ${targetDir}`);
103116
}
104117

105118
//Check

0 commit comments

Comments
 (0)