Add addon path file before start Zotero

This commit is contained in:
Northword 2023-07-12 21:25:10 +08:00
parent eeb1ace01d
commit e28af8724d
3 changed files with 53 additions and 30 deletions

View File

@ -1,20 +1,13 @@
import { exit, argv } from "process";
import minimist from "minimist";
import { exit } from "process";
import { execSync } from "child_process";
import details from "../package.json" assert { type: "json" };
const { addonID, addonName } = details.config;
const version = details.version;
import cmd from "./zotero-cmd.json" assert { type: "json" };
const { exec } = cmd;
// Run node reload.js -h for help
const args = minimist(argv.slice(2));
const { addonID, addonName } = details.config;
const { version } = details;
const { zoteroBinPath, profilePath } = cmd.exec;
const zoteroPath = exec[args.zotero || args.z || Object.keys(exec)[0]];
const profile = args.profile || args.p;
const startZotero = `${zoteroPath} --debugger --purgecaches ${
profile ? `-p ${profile}` : ""
}`;
const startZotero = `${zoteroBinPath} --debugger --purgecaches -profile ${profilePath}`;
const script = `
(async () => {

View File

@ -1,28 +1,46 @@
import process from "process";
import { execSync } from "child_process";
import { exit } from "process";
import minimist from "minimist";
import { existsSync, writeFileSync, readFileSync } from "fs";
import { join, resolve } from "path";
import details from "../package.json" assert { type: "json" };
import cmd from "./zotero-cmd.json" assert { type: "json" };
const { exec } = cmd;
// Run node start.js -h for help
const args = minimist(process.argv.slice(2));
const { addonID } = details.config;
const { zoteroBinPath, profilePath, dataDir } = cmd.exec;
if (args.help || args.h) {
console.log("Start Zotero Args:");
console.log(
"--zotero(-z): Zotero exec key in zotero-cmd.json. Default the first one."
);
console.log("--profile(-p): Zotero profile name.");
exit(0);
if (!existsSync(zoteroBinPath)) {
throw new Error("Zotero bin do no exist.");
}
const zoteroPath = exec[args.zotero || args.z || Object.keys(exec)[0]];
const profile = args.profile || args.p;
if (existsSync(profilePath)) {
const addonProxyFilePath = join(profilePath, `extensions/${addonID}`);
if (!existsSync(addonProxyFilePath)) {
console.log("Addon proxy file do not exist, creating it.");
writeFileSync(addonProxyFilePath, resolve("build/addon"));
}
const startZotero = `${zoteroPath} --debugger --purgecaches ${
profile ? `-p ${profile}` : ""
}`;
const prefsPath = join(profilePath, "prefs.js");
if (existsSync(prefsPath)) {
const PrefsLines = readFileSync(prefsPath, "utf-8").split("\n");
const filteredLines = PrefsLines.map((line) => {
if (
line.includes("extensions.lastAppBuildId") ||
line.includes("extensions.lastAppVersion")
) {
return;
}
if (line.includes("extensions.zotero.dataDir") && dataDir !== "") {
return `user_pref("extensions.zotero.dataDir", "${dataDir}");`;
}
return line;
});
const updatedPrefs = filteredLines.join("\n");
writeFileSync(prefsPath, updatedPrefs, "utf-8");
console.log("The <profile>/prefs.js modified.");
}
}
const startZotero = `"${zoteroBinPath}" --debugger --purgecaches -profile ${profilePath}`;
execSync(startZotero);
exit(0);

View File

@ -3,6 +3,18 @@
"killZoteroWindows": "taskkill /f /im zotero.exe",
"killZoteroUnix": "kill -9 $(ps -x | grep zotero)",
"exec": {
"7": "/path/to/zotero7.exe"
"@comment-zoteroBinPath": "Please input the path of the Zotero binary file in `zoteroBinPath`.",
"@comment-zoteroBinPath-tip": "The path delimiter should be escaped as `\\` for win32.",
"zoteroBinPath": "/path/to/zotero.exe",
"@comment-profilePath": "Please input the path of the profile used for development in `profilePath`.",
"@comment-profilePath-tip": "If this field is kept empty, Zotero will start with the default profile.",
"@comment-profilePath-see": "https://www.zotero.org/support/kb/profile_directory",
"profilePath": "/path/to/profile",
"@comment-dataDir": "Please input the directory where the database is located in dataDir",
"@comment-dataDir-tip": "If this field is kept empty, Zotero will start with the default date.",
"@comment-dataDir-see": "https://www.zotero.org/support/zotero_data",
"dataDir": ""
}
}