update make-link

This commit is contained in:
frostime 2023-07-23 14:27:58 +08:00
parent e6f5580c26
commit d64c5b1c38
3 changed files with 32 additions and 16 deletions

View file

@ -47,9 +47,10 @@
Done! Created symlink H:/SiYuanDevSpace/data/plugins/plugin-sample-vite-svelte Done! Created symlink H:/SiYuanDevSpace/data/plugins/plugin-sample-vite-svelte
``` ```
5. **Create development symbolic links by using environment variable**
5. Execute pnpm run dev for real-time compilation - You can set environment variable `SIYUAN_PLUGIN_DIR` as `/data/plugins`
6. Open SiYuan marketplace and enable plugin in downloaded tab 6. Execute pnpm run dev for real-time compilation
7. Open SiYuan marketplace and enable plugin in downloaded tab
> 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. > 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.

View file

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

View file

@ -54,12 +54,12 @@ async function getSiYuanDir() {
if (response.ok) { if (response.ok) {
conf = await response.json(); conf = await response.json();
} else { } else {
error(`HTTP-Error: ${response.status}`); error(`\tHTTP-Error: ${response.status}`);
return null; return null;
} }
} catch (e) { } catch (e) {
error("Error:", e); error(`\tError: ${e}`);
error("Please make sure SiYuan is running!!!"); error("\tPlease make sure SiYuan is running!!!");
return null; return null;
} }
return conf.data; return conf.data;
@ -67,9 +67,9 @@ async function getSiYuanDir() {
async function chooseTarget(workspaces) { async function chooseTarget(workspaces) {
let count = workspaces.length; let count = workspaces.length;
log(`Got ${count} SiYuan ${count > 1 ? 'workspaces' : 'workspace'}`) log(`>>> Got ${count} SiYuan ${count > 1 ? 'workspaces' : 'workspace'}`)
for (let i = 0; i < workspaces.length; i++) { for (let i = 0; i < workspaces.length; i++) {
log(`[${i}] ${workspaces[i].path}`); log(`\t[${i}] ${workspaces[i].path}`);
} }
if (count == 1) { if (count == 1) {
@ -80,7 +80,7 @@ async function chooseTarget(workspaces) {
output: process.stdout output: process.stdout
}); });
let index = await new Promise((resolve, reject) => { let index = await new Promise((resolve, reject) => {
rl.question(`Please select a workspace[0-${count-1}]: `, (answer) => { rl.question(`\tPlease select a workspace[0-${count-1}]: `, (answer) => {
resolve(answer); resolve(answer);
}); });
}); });
@ -89,17 +89,30 @@ async function chooseTarget(workspaces) {
} }
} }
log('>>> Try to visit constant "targetDir" in make_dev_link.js...')
if (targetDir === '') { if (targetDir === '') {
log('"targetDir" is empty, try to get SiYuan directory automatically....') log('>>> Constant "targetDir" is empty, try to get SiYuan directory automatically....')
let res = await getSiYuanDir(); let res = await getSiYuanDir();
if (res === null || res === undefined || res.length === 0) { if (res === null || res === undefined || res.length === 0) {
log('Failed! You can set the plugin directory in scripts/make_dev_link.js and try again'); log('>>> Can not get SiYuan directory automatically, try to visit environment variable "SIYUAN_PLUGIN_DIR"....');
process.exit(1);
// console.log(process.env)
let env = process.env?.SIYUAN_PLUGIN_DIR;
if (env !== undefined && env !== null && env !== '') {
targetDir = env;
log(`\tGot target directory from environment variable "SIYUAN_PLUGIN_DIR": ${targetDir}`);
} else {
error('\tCan not get SiYuan directory from environment variable "SIYUAN_PLUGIN_DIR", failed!');
process.exit(1);
}
} else {
targetDir = await chooseTarget(res);
} }
targetDir = await chooseTarget(res);
log(`Got target directory: ${targetDir}`); log(`>>> Successfully got target directory: ${targetDir}`);
} }
//Check //Check