zotero-plugin-scaffold 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -23,8 +23,6 @@ pnpm dlx zotero-plugin create
23
23
 
24
24
  #### From NPM
25
25
 
26
- > WIP
27
-
28
26
  ```bash
29
27
  npm install -D zotero-plugin-scaffold
30
28
 
@@ -66,7 +64,7 @@ You can import `defineConfig` in js module to get type hints. If no value is spe
66
64
  import { defineConfig } from "zotero-plugin-scaffold";
67
65
 
68
66
  export default defineConfig({
69
- placeholders: {
67
+ define: {
70
68
  addonName: "Test Addon for Zotero",
71
69
  addonID: "",
72
70
  addonRef: "",
@@ -137,7 +135,7 @@ import { Build, Config } from "zotero-plugin-scaffold";
137
135
 
138
136
  const config = await Config.loadConfig();
139
137
 
140
- const Builder = new Build(config, "production");
138
+ const Builder = new Build(config);
141
139
  await Builder.run();
142
140
  ```
143
141
 
package/dist/config.js CHANGED
@@ -28,8 +28,7 @@ export async function loadConfig(file) {
28
28
  const dotenvResult = dotenv.config({
29
29
  path: path.resolve(process.cwd(), userConfig.dotEnvPath ?? ".env"),
30
30
  }).parsed;
31
- if (!dotenvResult)
32
- throw new Error(".env file not found");
31
+ // if (!dotenvResult) throw new Error(".env file not found");
33
32
  // Load user's package.json
34
33
  const pkg = fs.readJsonSync(path.join("package.json"), {
35
34
  encoding: "utf-8",
@@ -160,11 +159,6 @@ export async function loadConfig(file) {
160
159
  },
161
160
  logLevel: "info",
162
161
  dotEnvPath: ".env",
163
- cmd: {
164
- zoteroBinPath: dotenvResult["zoteroBinPath"],
165
- profilePath: dotenvResult["profilePath"],
166
- dataDir: dotenvResult["dataDir"],
167
- },
168
162
  pkgUser: pkg,
169
163
  pkgAbsolute: path.join(path.dirname(fileURLToPath(import.meta.url)), "../"),
170
164
  };
@@ -1,6 +1,6 @@
1
1
  import { Config } from "../types.js";
2
- import Log from "./log.js";
3
- export declare abstract class LibBase {
2
+ import Log from "../utils/log.js";
3
+ export declare abstract class Base {
4
4
  config: Config;
5
5
  logger: InstanceType<typeof Log>;
6
6
  constructor(config: Config);
@@ -1,5 +1,5 @@
1
- import Log from "./log.js";
2
- export class LibBase {
1
+ import Log from "../utils/log.js";
2
+ export class Base {
3
3
  config;
4
4
  logger;
5
5
  constructor(config) {
@@ -1,6 +1,6 @@
1
1
  import { Config } from "../types.js";
2
- import { LibBase } from "../utils/libBase.js";
3
- export default class Build extends LibBase {
2
+ import { Base } from "./base.js";
3
+ export default class Build extends Base {
4
4
  private buildTime;
5
5
  private isPreRelease;
6
6
  constructor(config: Config);
package/dist/lib/build.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { generateHashSync } from "../utils/crypto.js";
2
- import { LibBase } from "../utils/libBase.js";
3
2
  import { dateFormat } from "../utils/string.js";
3
+ import { Base } from "./base.js";
4
4
  import chalk from "chalk";
5
5
  import { zip } from "compressing";
6
6
  import { buildSync } from "esbuild";
@@ -9,11 +9,12 @@ import fs from "fs-extra";
9
9
  import path from "path";
10
10
  import replaceInFile from "replace-in-file";
11
11
  const { replaceInFileSync } = replaceInFile;
12
- export default class Build extends LibBase {
12
+ export default class Build extends Base {
13
13
  buildTime;
14
14
  isPreRelease;
15
15
  constructor(config) {
16
16
  super(config);
17
+ process.env.NODE_ENV ??= "production";
17
18
  this.buildTime = "";
18
19
  this.isPreRelease = this.version.includes("-");
19
20
  }
@@ -1,7 +1,7 @@
1
1
  import { Config } from "../types.js";
2
- import { LibBase } from "../utils/libBase.js";
2
+ import { Base } from "./base.js";
3
3
  import { Octokit } from "@octokit/rest";
4
- export default class Release extends LibBase {
4
+ export default class Release extends Base {
5
5
  isCI: boolean;
6
6
  client: Octokit;
7
7
  constructor(config: Config);
@@ -1,4 +1,4 @@
1
- import { LibBase } from "../utils/libBase.js";
1
+ import { Base } from "./base.js";
2
2
  import { Octokit } from "@octokit/rest";
3
3
  import ci from "ci-info";
4
4
  import { default as glob } from "fast-glob";
@@ -7,7 +7,7 @@ import _ from "lodash";
7
7
  import mime from "mime";
8
8
  import path from "path";
9
9
  import releaseIt from "release-it";
10
- export default class Release extends LibBase {
10
+ export default class Release extends Base {
11
11
  isCI;
12
12
  client;
13
13
  constructor(config) {
@@ -1,6 +1,6 @@
1
1
  import { Config } from "../types.js";
2
- import { LibBase } from "../utils/libBase.js";
3
- export default class Serve extends LibBase {
2
+ import { Base } from "./base.js";
3
+ export default class Serve extends Base {
4
4
  private builder;
5
5
  constructor(config: Config);
6
6
  run(): Promise<void>;
package/dist/lib/serve.js CHANGED
@@ -1,4 +1,4 @@
1
- import { LibBase } from "../utils/libBase.js";
1
+ import { Base } from "./base.js";
2
2
  import Build from "./build.js";
3
3
  import { execSync, spawn } from "child_process";
4
4
  import chokidar from "chokidar";
@@ -7,10 +7,11 @@ import _ from "lodash";
7
7
  import path from "path";
8
8
  import { exit } from "process";
9
9
  import webext from "web-ext";
10
- export default class Serve extends LibBase {
10
+ export default class Serve extends Base {
11
11
  builder;
12
12
  constructor(config) {
13
13
  super(config);
14
+ process.env.NODE_ENV ??= "development";
14
15
  this.builder = new Build(config);
15
16
  }
16
17
  async run() {
@@ -90,8 +91,8 @@ export default class Serve extends LibBase {
90
91
  */
91
92
  async startZoteroWebExt() {
92
93
  await webext.cmd.run({
93
- firefox: this.config.cmd.zoteroBinPath,
94
- firefoxProfile: this.config.cmd.profilePath,
94
+ firefox: this.zoteroBinPath,
95
+ firefoxProfile: this.profilePath,
95
96
  sourceDir: path.resolve(`${this.config.dist}/addon`),
96
97
  keepProfileChanges: true,
97
98
  args: ["--debugger", "--purgecaches"],
package/dist/types.d.ts CHANGED
@@ -282,11 +282,6 @@ export interface ConfigBase {
282
282
  logLevel: "trace" | "debug" | "info" | "warn" | "error";
283
283
  }
284
284
  export interface Config extends ConfigBase {
285
- cmd: {
286
- zoteroBinPath: string;
287
- profilePath: string;
288
- dataDir: string;
289
- };
290
285
  pkgUser: any;
291
286
  pkgAbsolute: string;
292
287
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "A scaffold for Zotero plugin development.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "files": [
32
32
  "bin/**/*",
33
- "dist/**/*.d.ts",
34
- "dist/**/*.js",
33
+ "dist/**/*",
34
+ "template/**/*",
35
35
  "docs/**/*",
36
36
  "types/**/*.d.ts"
37
37
  ],
@@ -0,0 +1,56 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags:
6
+ - v**
7
+
8
+ permissions:
9
+ contents: write
10
+ issues: write
11
+ pull-requests: write
12
+
13
+ jobs:
14
+ release-it:
15
+ runs-on: ubuntu-latest
16
+ env:
17
+ GITHUB_TOKEN: ${{ secrets.GitHub_TOKEN }}
18
+ steps:
19
+ - name: Checkout
20
+ uses: actions/checkout@v4
21
+ with:
22
+ fetch-depth: 0
23
+
24
+ # - name: Setup pnpm
25
+ # uses: pnpm/action-setup@v2
26
+ # with:
27
+ # version: 8.12.1
28
+
29
+ - name: Setup Node.js
30
+ uses: actions/setup-node@v4
31
+ with:
32
+ node-version: 20
33
+
34
+ - name: Install deps
35
+ run: |
36
+ npm install
37
+ # echo "public-hoist-pattern[]=@types*" >> .npmrc
38
+ # pnpm install
39
+
40
+ - name: Build
41
+ run: |
42
+ npm run build
43
+
44
+ - name: Release to GitHub
45
+ run: |
46
+ npx release-it -- --no-increment --no-git --no-npm.publish --github.release --ci --VV
47
+ # pnpm dlx release-it --no-increment --no-git --no-npm.publish --github.release --ci --VV
48
+ sleep 1s
49
+
50
+ - name: Notify release
51
+ uses: apexskier/github-release-commenter@v1
52
+ continue-on-error: true
53
+ with:
54
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55
+ comment-template: |
56
+ :rocket: _This ticket has been resolved in {release_tag}. See {release_link} for release notes._
File without changes
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Most of this code is from Zotero team's official Make It Red example[1]
3
+ * or the Zotero 7 documentation[2].
4
+ * [1] https://github.com/zotero/make-it-red
5
+ * [2] https://www.zotero.org/support/dev/zotero_7_for_developers
6
+ */
7
+
8
+ var chromeHandle;
9
+
10
+ function install(data, reason) {}
11
+
12
+ async function startup({ id, version, resourceURI, rootURI }, reason) {
13
+ await Zotero.initializationPromise;
14
+
15
+ // String 'rootURI' introduced in Zotero 7
16
+ if (!rootURI) {
17
+ rootURI = resourceURI.spec;
18
+ }
19
+
20
+ var aomStartup = Components.classes[
21
+ "@mozilla.org/addons/addon-manager-startup;1"
22
+ ].getService(Components.interfaces.amIAddonManagerStartup);
23
+ var manifestURI = Services.io.newURI(rootURI + "manifest.json");
24
+ chromeHandle = aomStartup.registerChrome(manifestURI, [
25
+ ["content", "__addonRef__", rootURI + "chrome/content/"],
26
+ ]);
27
+
28
+ /**
29
+ * Global variables for plugin code.
30
+ * The `_globalThis` is the global root variable of the plugin sandbox environment
31
+ * and all child variables assigned to it is globally accessible.
32
+ * See `src/index.ts` for details.
33
+ */
34
+ const ctx = {
35
+ rootURI,
36
+ };
37
+ ctx._globalThis = ctx;
38
+
39
+ Services.scriptloader.loadSubScript(
40
+ `${rootURI}/chrome/content/scripts/__addonRef__.js`,
41
+ ctx,
42
+ );
43
+ Zotero.__addonInstance__.hooks.onStartup();
44
+ }
45
+
46
+ async function onMainWindowLoad({ window }, reason) {
47
+ Zotero.__addonInstance__?.hooks.onMainWindowLoad(window);
48
+ }
49
+
50
+ async function onMainWindowUnload({ window }, reason) {
51
+ Zotero.__addonInstance__?.hooks.onMainWindowUnload(window);
52
+ }
53
+
54
+ function shutdown({ id, version, resourceURI, rootURI }, reason) {
55
+ if (reason === APP_SHUTDOWN) {
56
+ return;
57
+ }
58
+
59
+ if (typeof Zotero === "undefined") {
60
+ Zotero = Components.classes["@zotero.org/Zotero;1"].getService(
61
+ Components.interfaces.nsISupports,
62
+ ).wrappedJSObject;
63
+ }
64
+ Zotero.__addonInstance__?.hooks.onShutdown();
65
+
66
+ Cc["@mozilla.org/intl/stringbundle;1"]
67
+ .getService(Components.interfaces.nsIStringBundleService)
68
+ .flushBundles();
69
+
70
+ Cu.unload(`${rootURI}/chrome/content/scripts/__addonRef__.js`);
71
+
72
+ if (chromeHandle) {
73
+ chromeHandle.destruct();
74
+ chromeHandle = null;
75
+ }
76
+ }
77
+
78
+ function uninstall(data, reason) {}
File without changes