diff --git a/README.md b/README.md index fa20636..ae831f6 100644 --- a/README.md +++ b/README.md @@ -30,11 +30,13 @@ This is an addon/plugin template for [Zotero](https://www.zotero.org/). author, description, homepage, - releasepage, - updaterdf, - addonName, - addonID, - addonRef + config { + releasepage, + updaterdf, + addonName, + addonID, + addonRef + } ``` > Be careful to set the addonID and addonRef to avoid confliction. diff --git a/build.js b/build.js index ecb7f6f..d840aeb 100644 --- a/build.js +++ b/build.js @@ -9,12 +9,8 @@ const { author, description, homepage, - releasepage, - updaterdf, - addonName, - addonID, - addonRef, version, + config, } = require("./package.json"); function copyFileSync(source, target) { @@ -141,11 +137,11 @@ async function main() { author, description, homepage, - releasepage, - updaterdf, - addonName, - addonID, - addonRef, + config.releasepage, + config.updaterdf, + config.addonName, + config.addonID, + config.addonRef, version, buildTime, ], diff --git a/package.json b/package.json index 50f092a..781b060 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,15 @@ { "name": "zotero-addon-template", - "addonName": "Zotero Addon Template", - "addonID": "addontemplate@euclpts.com", - "addonRef": "addontemplate", "version": "0.0.4", "description": "Zotero Addon Template", - "main": "src/index.js", + "config": { + "addonName": "Zotero Addon Template", + "addonID": "addontemplate@euclpts.com", + "addonRef": "addontemplate", + "releasepage": "https://github.com/windingwind/zotero-addon-template/releases/latest/download/zotero-addon-template.xpi", + "updaterdf": "https://raw.githubusercontent.com/windingwind/zotero-addon-template/master/update.json" + }, + "main": "src/index.ts", "scripts": { "build": "node build.js", "start": "node start.js", @@ -25,8 +29,6 @@ "url": "https://github.com/windingwind/zotero-addon-template/issues" }, "homepage": "https://github.com/windingwind/zotero-addon-template#readme", - "releasepage": "https://github.com/windingwind/zotero-addon-template/releases/latest/download/zotero-addon-template.xpi", - "updaterdf": "https://raw.githubusercontent.com/windingwind/zotero-addon-template/master/update.json", "dependencies": { "zotero-plugin-toolkit": "^0.0.1" }, @@ -38,4 +40,4 @@ "release-it": "^14.14.0", "zotero-types": "^0.0.8" } -} \ No newline at end of file +} diff --git a/src/events.ts b/src/events.ts index 4e5abf5..17ef87e 100644 --- a/src/events.ts +++ b/src/events.ts @@ -1,6 +1,6 @@ import Addon from "./addon"; import AddonModule from "./module"; -import { addonName, addonID, addonRef } from "../package.json"; +import { config } from "../package.json"; class AddonEvents extends AddonModule { private notifierCallback: any; @@ -33,7 +33,7 @@ class AddonEvents extends AddonModule { // @ts-ignore this._Addon.rootURI = rootURI; // This function is the setup code of the addon - this._Addon.toolkit.Tool.log(`${addonName}: init called`); + this._Addon.toolkit.Tool.log(`${config.addonName}: init called`); // Register the callback in Zotero as an item observer let notifierID = Zotero.Notifier.registerObserver(this.notifierCallback, [ @@ -59,11 +59,11 @@ class AddonEvents extends AddonModule { public initPrefs() { this._Addon.toolkit.Tool.log(this._Addon.rootURI); const prefOptions = { - pluginID: addonID, + pluginID: config.addonID, src: this._Addon.rootURI + "chrome/content/preferences.xhtml", label: "Template", - image: `chrome://${addonRef}/content/icons/favicon.png`, - extraDTD: [`chrome://${addonRef}/locale/overlay.dtd`], + image: `chrome://${config.addonRef}/content/icons/favicon.png`, + extraDTD: [`chrome://${config.addonRef}/locale/overlay.dtd`], defaultXUL: true, onload: (win: Window) => { this._Addon.prefs.initPreferences(win); @@ -84,7 +84,7 @@ class AddonEvents extends AddonModule { public onUnInit(): void { const Zotero = this._Addon.Zotero; - this._Addon.toolkit.Tool.log(`${addonName}: uninit called`); + this._Addon.toolkit.Tool.log(`${config.addonName}: uninit called`); this.unInitPrefs(); // Remove elements and do clean up this._Addon.views.unInitViews(); diff --git a/src/prefs.ts b/src/prefs.ts index 19a53d3..577ad2e 100644 --- a/src/prefs.ts +++ b/src/prefs.ts @@ -1,6 +1,6 @@ import Addon from "./addon"; import AddonModule from "./module"; -import { addonName, addonRef } from "../package.json"; +import { config } from "../package.json"; class AddonPrefs extends AddonModule { private _window!: Window; @@ -11,7 +11,7 @@ class AddonPrefs extends AddonModule { // This function is called when the prefs window is opened // See addon/chrome/content/preferences.xul onpaneload this._window = _window; - this._Addon.toolkit.Tool.log(`${addonName}: init preferences`); + this._Addon.toolkit.Tool.log(`${config.addonName}: init preferences`); this.updatePrefsUI(); this.bindPrefEvents(); } @@ -20,12 +20,12 @@ class AddonPrefs extends AddonModule { // You can initialize some UI elements on prefs window // with this._window.document // Or bind some events to the elements - this._Addon.toolkit.Tool.log(`${addonName}: init preferences UI`); + this._Addon.toolkit.Tool.log(`${config.addonName}: init preferences UI`); } private bindPrefEvents() { this._window.document - .querySelector(`#zotero-prefpane-${addonRef}-enable`) + .querySelector(`#zotero-prefpane-${config.addonRef}-enable`) ?.addEventListener("command", (e) => { this._Addon.toolkit.Tool.log(e); this._window.alert( @@ -34,7 +34,7 @@ class AddonPrefs extends AddonModule { }); this._window.document - .querySelector(`#zotero-prefpane-${addonRef}-input`) + .querySelector(`#zotero-prefpane-${config.addonRef}-input`) ?.addEventListener("change", (e) => { this._Addon.toolkit.Tool.log(e); this._window.alert( diff --git a/src/views.ts b/src/views.ts index 7c2f546..95c73a2 100644 --- a/src/views.ts +++ b/src/views.ts @@ -1,6 +1,6 @@ import Addon from "./addon"; import AddonModule from "./module"; -const { addonRef } = require("../package.json"); +import { config } from "../package.json"; class AddonViews extends AddonModule { // You can store some element in the object attributes @@ -11,7 +11,7 @@ class AddonViews extends AddonModule { this.progressWindowIcon = { success: "chrome://zotero/skin/tick.png", fail: "chrome://zotero/skin/cross.png", - default: `chrome://${addonRef}/content/icons/favicon.png`, + default: `chrome://${config.addonRef}/content/icons/favicon.png`, }; }