log + error
This commit is contained in:
parent
e849287222
commit
ef0f739a98
1 changed files with 15 additions and 10 deletions
|
@ -11,7 +11,8 @@ let targetDir = '';
|
||||||
// const targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
|
// const targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
|
||||||
//********************************************************************************************
|
//********************************************************************************************
|
||||||
|
|
||||||
const log = console.log;
|
const log = (info) => console.log(`\x1B[36m%s\x1B[0m`, info);
|
||||||
|
const error = (info) => console.log(`\x1B[31m%s\x1B[0m`, info);
|
||||||
|
|
||||||
async function getSiYuanDir() {
|
async function getSiYuanDir() {
|
||||||
let url = 'http://127.0.0.1:6806/api/system/getWorkspaces';
|
let url = 'http://127.0.0.1:6806/api/system/getWorkspaces';
|
||||||
|
@ -28,12 +29,12 @@ async function getSiYuanDir() {
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
conf = await response.json();
|
conf = await response.json();
|
||||||
} else {
|
} else {
|
||||||
log(`HTTP-Error: ${response.status}`);
|
error(`HTTP-Error: ${response.status}`);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("Error:", e);
|
error("Error:", e);
|
||||||
log("Please make sure SiYuan is running!!!");
|
error("Please make sure SiYuan is running!!!");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return conf.data;
|
return conf.data;
|
||||||
|
@ -78,23 +79,27 @@ if (targetDir === '') {
|
||||||
|
|
||||||
//Check
|
//Check
|
||||||
if (!fs.existsSync(targetDir)) {
|
if (!fs.existsSync(targetDir)) {
|
||||||
log(`Failed! plugin directory not exists: "${targetDir}"`);
|
error(`Failed! plugin directory not exists: "${targetDir}"`);
|
||||||
log(`Please set the plugin directory in scripts/make_dev_link.js`);
|
error(`Please set the plugin directory in scripts/make_dev_link.js`);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//check if plugin.json exists
|
//check if plugin.json exists
|
||||||
if (!fs.existsSync('./plugin.json')) {
|
if (!fs.existsSync('./plugin.json')) {
|
||||||
console.error('Failed! plugin.json not found');
|
//change dir to parent
|
||||||
process.exit(1);
|
process.chdir('../');
|
||||||
|
if (!fs.existsSync('./plugin.json')) {
|
||||||
|
error('Failed! plugin.json not found');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//load plugin.json
|
//load plugin.json
|
||||||
const plugin = JSON.parse(fs.readFileSync('./plugin.json', 'utf8'));
|
const plugin = JSON.parse(fs.readFileSync('./plugin.json', 'utf8'));
|
||||||
const name = plugin?.name;
|
const name = plugin?.name;
|
||||||
if (!name || name === '') {
|
if (!name || name === '') {
|
||||||
log('Failed! Please set plugin name in plugin.json');
|
error('Failed! Please set plugin name in plugin.json');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,7 +113,7 @@ if (!fs.existsSync(devDir)) {
|
||||||
const targetPath = `${targetDir}/${name}`;
|
const targetPath = `${targetDir}/${name}`;
|
||||||
//如果已经存在,就退出
|
//如果已经存在,就退出
|
||||||
if (fs.existsSync(targetPath)) {
|
if (fs.existsSync(targetPath)) {
|
||||||
log(`Failed! Target directory ${targetPath} already exists`);
|
error(`Failed! Target directory ${targetPath} already exists`);
|
||||||
} else {
|
} else {
|
||||||
//创建软链接
|
//创建软链接
|
||||||
fs.symlinkSync(`${process.cwd()}/dev`, targetPath, 'junction');
|
fs.symlinkSync(`${process.cwd()}/dev`, targetPath, 'junction');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue