refactor: move scripts to ./scripts

This commit is contained in:
xiangyu 2023-01-05 20:44:36 +08:00
parent 84beaab5fd
commit 329e6dab88
8 changed files with 23 additions and 17 deletions

View File

@ -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).

View File

@ -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"
},

View File

@ -11,7 +11,7 @@ const {
homepage,
version,
config,
} = require("./package.json");
} = require("../package.json");
function copyFileSync(source, target) {
var targetFile = target;

10
scripts/stop.js Normal file
View File

@ -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) {}

View File

@ -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"
}
}

View File

@ -1,6 +0,0 @@
const { execSync } = require("child_process");
const { killZotero } = require("./zotero-cmd.json");
try {
execSync(killZotero);
} catch (e) {}