auto detect workspace
This commit is contained in:
parent
9007a64178
commit
c99faadc2a
2 changed files with 43 additions and 12 deletions
|
@ -8,7 +8,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"make-link": "node ./scripts/make_dev_link.js",
|
"make-link": "node --no-warnings ./scripts/make_dev_link.js",
|
||||||
"dev": "vite build --watch",
|
"dev": "vite build --watch",
|
||||||
"build": "vite build"
|
"build": "vite build"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import readline from 'node:readline';
|
||||||
|
|
||||||
|
|
||||||
//************************************ Write you dir here ************************************
|
//************************************ Write you dir here ************************************
|
||||||
|
|
||||||
//Please write the "workspace/data/plugins" directory here
|
//Please write the "workspace/data/plugins" directory here
|
||||||
//请在这里填写你的 "workspace/data/plugins" 目录
|
//请在这里填写你的 "workspace/data/plugins" 目录
|
||||||
const targetDir = '';
|
let targetDir = '';
|
||||||
//Like this
|
//Like this
|
||||||
// const targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
|
// const targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
|
||||||
//********************************************************************************************
|
//********************************************************************************************
|
||||||
|
@ -28,19 +29,50 @@ async function getSiYuanDir() {
|
||||||
conf = await response.json();
|
conf = await response.json();
|
||||||
} else {
|
} else {
|
||||||
log(`HTTP-Error: ${response.status}`);
|
log(`HTTP-Error: ${response.status}`);
|
||||||
process.exit(1);
|
return null;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("Error:", e);
|
log("Error:", e);
|
||||||
process.exit(1);
|
return null;
|
||||||
}
|
}
|
||||||
return conf.data;
|
return conf.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function chooseTarget(workspaces) {
|
||||||
|
let count = workspaces.length;
|
||||||
|
log(`Got ${count} SiYuan ${count > 1 ? 'workspaces' : 'workspace'}`)
|
||||||
|
for (let i = 0; i < workspaces.length; i++) {
|
||||||
|
log(`[${i}] ${workspaces[i].path}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count == 1) {
|
||||||
|
return `${workspaces[0].path}/data/plugins`;
|
||||||
|
} else {
|
||||||
|
const rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout
|
||||||
|
});
|
||||||
|
let index = await new Promise((resolve, reject) => {
|
||||||
|
rl.question(`Please select a workspace[0-${count-1}]: `, (answer) => {
|
||||||
|
resolve(answer);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
rl.close();
|
||||||
|
return `${workspaces[index].path}/data/plugins`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (targetDir === '') {
|
if (targetDir === '') {
|
||||||
|
log('"targetDir" is empty, try to get SiYuan directory automatically....')
|
||||||
let res = await getSiYuanDir();
|
let res = await getSiYuanDir();
|
||||||
log(res);
|
|
||||||
process.exit(0);
|
if (res === null) {
|
||||||
|
log('Failed! Please set the plugin directory in scripts/make_dev_link.js');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
targetDir = await chooseTarget(res);
|
||||||
|
log(`Got target directory: ${targetDir}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check
|
//Check
|
||||||
|
@ -75,11 +107,10 @@ if (!fs.existsSync(devDir)) {
|
||||||
const targetPath = `${targetDir}/${name}`;
|
const targetPath = `${targetDir}/${name}`;
|
||||||
//如果已经存在,就退出
|
//如果已经存在,就退出
|
||||||
if (fs.existsSync(targetPath)) {
|
if (fs.existsSync(targetPath)) {
|
||||||
log('Failed! Target directory already exists');
|
log(`Failed! Target directory ${targetPath} already exists`);
|
||||||
process.exit(1);
|
} else {
|
||||||
|
//创建软链接
|
||||||
|
fs.symlinkSync(`${process.cwd()}/dev`, targetPath, 'junction');
|
||||||
|
log(`Done! Created symlink ${targetPath}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
//创建软链接
|
|
||||||
fs.symlinkSync(`${process.cwd()}/dev`, targetPath, 'junction');
|
|
||||||
log(`Done! Created symlink ${targetPath}`);
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue