diff --git a/package.json b/package.json index b04aebb..b46ef02 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "author": "", "license": "GPL-3.0", "scripts": { + "make-link": "node ./scripts/make_dev_link.js", "dev": "vite build --watch", "build": "vite build" }, diff --git a/scripts/make_dev_link.js b/scripts/make_dev_link.js new file mode 100644 index 0000000..ca4c28a --- /dev/null +++ b/scripts/make_dev_link.js @@ -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}`); + diff --git a/scripts/make_dev_link.py b/scripts/make_dev_link.py deleted file mode 100644 index e45e495..0000000 --- a/scripts/make_dev_link.py +++ /dev/null @@ -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') diff --git a/scripts/py2exe.bat b/scripts/py2exe.bat deleted file mode 100644 index 4d1224d..0000000 --- a/scripts/py2exe.bat +++ /dev/null @@ -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 .