Change the way to create symbolic link
This commit is contained in:
parent
0f049cc461
commit
b4e58d5650
4 changed files with 56 additions and 53 deletions
|
@ -8,6 +8,7 @@
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"make-link": "node ./scripts/make_dev_link.js",
|
||||||
"dev": "vite build --watch",
|
"dev": "vite build --watch",
|
||||||
"build": "vite build"
|
"build": "vite build"
|
||||||
},
|
},
|
||||||
|
|
55
scripts/make_dev_link.js
Normal file
55
scripts/make_dev_link.js
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
|
|
||||||
|
//************************************ Write you dir here ************************************
|
||||||
|
|
||||||
|
//Please write the "workspace/data/plugins" directory here
|
||||||
|
//请在这里填写你的 "workspace/data/plugins" 目录
|
||||||
|
const targetDir = '';
|
||||||
|
//Like this
|
||||||
|
// const targetDir = `H:\\SiYuanDevSpace\\data\\plugins`;
|
||||||
|
//********************************************************************************************
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Check
|
||||||
|
if (!fs.existsSync(targetDir)) {
|
||||||
|
console.log(`Failed! plugin directory not exists: "${targetDir}"`);
|
||||||
|
console.log(`Please set the plugin directory in scripts/make_dev_link.js`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//check if plugin.json exists
|
||||||
|
if (!fs.existsSync('./plugin.json')) {
|
||||||
|
console.error('Failed! plugin.json not found');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//load plugin.json
|
||||||
|
const plugin = JSON.parse(fs.readFileSync('./plugin.json', 'utf8'));
|
||||||
|
const name = plugin?.name;
|
||||||
|
if (!name || name === '') {
|
||||||
|
console.log('Failed! Please set plugin name in plugin.json');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//dev directory
|
||||||
|
const devDir = `./dev`;
|
||||||
|
//mkdir if not exists
|
||||||
|
if (!fs.existsSync(devDir)) {
|
||||||
|
fs.mkdirSync(devDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
const targetPath = `${targetDir}/${name}`;
|
||||||
|
//如果已经存在,就退出
|
||||||
|
if (fs.existsSync(targetPath)) {
|
||||||
|
console.log('Failed! Target directory already exists');
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
//创建软链接
|
||||||
|
fs.symlinkSync(process.cwd(), targetPath, 'junction');
|
||||||
|
console.log(`Done! Created symlink ${targetPath}`);
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import json
|
|
||||||
|
|
||||||
def run():
|
|
||||||
# check path, must be in root folder
|
|
||||||
if not os.path.exists('plugin.json'):
|
|
||||||
os.chdir('..')
|
|
||||||
if not os.path.exists('plugin.json'):
|
|
||||||
print('plugin.json not found, exit')
|
|
||||||
return
|
|
||||||
|
|
||||||
# 1. Read plugin_dir
|
|
||||||
plugin_dir = ''
|
|
||||||
if len(sys.argv) > 1:
|
|
||||||
plugin_dir = sys.argv[1]
|
|
||||||
while not os.path.exists(plugin_dir):
|
|
||||||
plugin_dir = input('Please input the directory of siyuan/data/plugins: ')
|
|
||||||
if plugin_dir == 'exit' or plugin_dir == 'quit' or plugin_dir == 'q':
|
|
||||||
return
|
|
||||||
if not os.path.exists(plugin_dir):
|
|
||||||
print('plugin_dir not found!')
|
|
||||||
continue
|
|
||||||
|
|
||||||
# 2. Read name in plugin.json
|
|
||||||
with open('plugin.json', 'r', encoding='utf-8') as f:
|
|
||||||
content = json.load(f)
|
|
||||||
name = content.get('name')
|
|
||||||
|
|
||||||
# ...error if name not found
|
|
||||||
if not name or name == '':
|
|
||||||
print('"name" in plugin.json not found, exit')
|
|
||||||
return
|
|
||||||
|
|
||||||
dev_dir = os.path.abspath('dev')
|
|
||||||
if not os.path.exists(dev_dir):
|
|
||||||
os.mkdir(dev_dir)
|
|
||||||
|
|
||||||
# 3. Create symlink
|
|
||||||
if not os.path.exists(os.path.join(plugin_dir, name)):
|
|
||||||
link = os.path.join(plugin_dir, name)
|
|
||||||
os.symlink(dev_dir, link)
|
|
||||||
print('Symlink created:', link)
|
|
||||||
else:
|
|
||||||
print('Folder already exists, exit')
|
|
||||||
return
|
|
||||||
|
|
||||||
run()
|
|
||||||
os.system('pause')
|
|
|
@ -1,4 +0,0 @@
|
||||||
.venv/Script/activate
|
|
||||||
pyinstaller --noconfirm --onefile --console "./make_dev_link.py"
|
|
||||||
rm ./make_dev_link.exe
|
|
||||||
mv ./dist/make_dev_link.exe .
|
|
Loading…
Add table
Add a link
Reference in a new issue