commit
7ff5334444
1 changed files with 36 additions and 9 deletions
|
@ -8,23 +8,24 @@ import readline from 'node:readline';
|
|||
//请在这里填写你的 "workspace/data/plugins" 目录
|
||||
let targetDir = '';
|
||||
//Like this
|
||||
// const targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
|
||||
// let targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
|
||||
//********************************************************************************************
|
||||
|
||||
const log = (info) => console.log(`\x1B[36m%s\x1B[0m`, info);
|
||||
const error = (info) => console.log(`\x1B[31m%s\x1B[0m`, info);
|
||||
|
||||
let POST_HEADER = {
|
||||
// "Authorization": `Token ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
async function getSiYuanDir() {
|
||||
let url = 'http://127.0.0.1:6806/api/system/getWorkspaces';
|
||||
let header = {
|
||||
// "Authorization": `Token ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
let conf = {};
|
||||
try {
|
||||
let response = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: header
|
||||
headers: POST_HEADER
|
||||
});
|
||||
if (response.ok) {
|
||||
conf = await response.json();
|
||||
|
@ -104,19 +105,45 @@ if (!name || name === '') {
|
|||
}
|
||||
|
||||
//dev directory
|
||||
const devDir = `./dev`;
|
||||
const devDir = `${process.cwd()}/dev`;
|
||||
//mkdir if not exists
|
||||
if (!fs.existsSync(devDir)) {
|
||||
fs.mkdirSync(devDir);
|
||||
}
|
||||
|
||||
function cmpPath(path1, path2) {
|
||||
path1 = path1.replace(/\\/g, '/');
|
||||
path2 = path2.replace(/\\/g, '/');
|
||||
// sepertor at tail
|
||||
if (path1[path1.length - 1] !== '/') {
|
||||
path1 += '/';
|
||||
}
|
||||
if (path2[path2.length - 1] !== '/') {
|
||||
path2 += '/';
|
||||
}
|
||||
return path1 === path2;
|
||||
}
|
||||
|
||||
const targetPath = `${targetDir}/${name}`;
|
||||
//如果已经存在,就退出
|
||||
if (fs.existsSync(targetPath)) {
|
||||
error(`Failed! Target directory ${targetPath} already exists`);
|
||||
let isSymbol = fs.lstatSync(targetPath).isSymbolicLink();
|
||||
|
||||
if (isSymbol) {
|
||||
let srcPath = fs.readlinkSync(targetPath);
|
||||
|
||||
if (cmpPath(srcPath, devDir)) {
|
||||
log(`Good! ${targetPath} is already linked to ${devDir}`);
|
||||
} else {
|
||||
error(`Error! Already exists symbolic link ${targetPath}\nBut it links to ${srcPath}`);
|
||||
}
|
||||
} else {
|
||||
error(`Failed! ${targetPath} already exists and is not a symbolic link`);
|
||||
}
|
||||
|
||||
} else {
|
||||
//创建软链接
|
||||
fs.symlinkSync(`${process.cwd()}/dev`, targetPath, 'junction');
|
||||
fs.symlinkSync(devDir, targetPath, 'junction');
|
||||
log(`Done! Created symlink ${targetPath}`);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue