From 329e6dab88240bdd524b03f93dbddc5f76e1f518 Mon Sep 17 00:00:00 2001 From: xiangyu <3170102889@zju.edu.cn> Date: Thu, 5 Jan 2023 20:44:36 +0800 Subject: [PATCH] refactor: move scripts to ./scripts --- README.md | 7 ++++--- package.json | 10 +++++----- build.js => scripts/build.js | 2 +- restart.js => scripts/restart.js | 0 start.js => scripts/start.js | 0 scripts/stop.js | 10 ++++++++++ .../zotero-cmd-default.json | 5 +++-- stop.js | 6 ------ 8 files changed, 23 insertions(+), 17 deletions(-) rename build.js => scripts/build.js (99%) rename restart.js => scripts/restart.js (100%) rename start.js => scripts/start.js (100%) create mode 100644 scripts/stop.js rename zotero-cmd-default.json => scripts/zotero-cmd-default.json (56%) delete mode 100644 stop.js diff --git a/README.md b/README.md index ca1c422..540a500 100644 --- a/README.md +++ b/README.md @@ -69,11 +69,11 @@ Search `@example` in `src/examples.ts`. The examples are called in `src/hooks.ts > Be careful to set the addonID and addonRef to avoid confliction. - Run `npm install` to set up the plugin and install dependencies. If you don't have NodeJS installed, please download it [here](https://nodejs.org/en/); -- Run `npm run build` to build the plugin in production mode. Run `npm run build-dev` to build the plugin in development mode. The xpi for installation and the built code is under builds folder. +- Run `npm run build` to build the plugin in production mode. Run `npm run build-dev` to build the plugin in development mode. The xpi for installation and the built code is under `builds` folder. > What the difference between dev & prod? > -> - This environment variable is stored in `Zotero.AddonTemplate.env`. The outputs to console is disabled in prod mode. +> - This environment variable is stored in `Zotero.AddonTemplate.data.env`. The outputs to console is disabled in prod mode. > - You can decide what users cannot see/use based on this variable. ### About Hooks @@ -234,7 +234,8 @@ Alternatively, build it directly using build.js: `npm run build` 1. Copy zotero command line config file. Modify the commands. ```sh -cp zotero-cmd-default.json zotero-cmd.json +cp ./scripts/zotero-cmd-default.json ./scripts/zotero-cmd.json +vim ./scripts/zotero-cmd.json ``` 2. Setup addon development environment following this [link](https://www.zotero.org/support/dev/client_coding/plugin_development#setting_up_a_plugin_development_environment). diff --git a/package.json b/package.json index 7162bfc..0046937 100644 --- a/package.json +++ b/package.json @@ -11,12 +11,12 @@ }, "main": "src/index.ts", "scripts": { - "build-dev": "cross-env NODE_ENV=development node build.js", - "build": "cross-env NODE_ENV=production node build.js", - "start": "node start.js", - "stop": "node stop.js", + "build-dev": "cross-env NODE_ENV=development node scripts/build.js", + "build": "cross-env NODE_ENV=production node scripts/build.js", + "start": "node scripts/start.js", + "stop": "node scripts/stop.js", "prerestart": "npm run build-dev", - "restart": "node restart.js", + "restart": "node scripts/restart.js", "release": "release-it", "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/build.js b/scripts/build.js similarity index 99% rename from build.js rename to scripts/build.js index b2ff60d..7344c1c 100644 --- a/build.js +++ b/scripts/build.js @@ -11,7 +11,7 @@ const { homepage, version, config, -} = require("./package.json"); +} = require("../package.json"); function copyFileSync(source, target) { var targetFile = target; diff --git a/restart.js b/scripts/restart.js similarity index 100% rename from restart.js rename to scripts/restart.js diff --git a/start.js b/scripts/start.js similarity index 100% rename from start.js rename to scripts/start.js diff --git a/scripts/stop.js b/scripts/stop.js new file mode 100644 index 0000000..fa0a2b4 --- /dev/null +++ b/scripts/stop.js @@ -0,0 +1,10 @@ +const { execSync } = require("child_process"); +const { killZoteroWindows, killZoteroUnix } = require("./zotero-cmd.json"); + +try { + if (process.platform === "win32") { + execSync(killZoteroWindows); + } else { + execSync(killZoteroUnix); + } +} catch (e) {} diff --git a/zotero-cmd-default.json b/scripts/zotero-cmd-default.json similarity index 56% rename from zotero-cmd-default.json rename to scripts/zotero-cmd-default.json index ad72ffc..73a9c13 100644 --- a/zotero-cmd-default.json +++ b/scripts/zotero-cmd-default.json @@ -1,5 +1,6 @@ { "usage": "Copy and rename this file to zotero-cmd.json. Edit the cmd.", - "killZotero": "taskkill /f /im zotero.exe", + "killZoteroWindows": "taskkill /f /im zotero.exe", + "killZoteroUnix": "kill -9 $(ps -x | grep zotero)", "startZotero": "/path/to/zotero.exe --debugger --purgecaches" -} +} \ No newline at end of file diff --git a/stop.js b/stop.js deleted file mode 100644 index 50d11ab..0000000 --- a/stop.js +++ /dev/null @@ -1,6 +0,0 @@ -const { execSync } = require("child_process"); -const { killZotero } = require("./zotero-cmd.json"); - -try { - execSync(killZotero); -} catch (e) {}