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