zotero-plugin-scaffold 0.1.2 → 0.1.3

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
@@ -4,6 +4,7 @@
4
4
  [![NPM Downloads](https://img.shields.io/npm/dm/zotero-plugin-scaffold)](https://www.npmjs.com/package/zotero-plugin-scaffold)
5
5
  ![NPM Unpacked Size](https://img.shields.io/npm/unpacked-size/zotero-plugin-scaffold)
6
6
  ![GitHub License](https://img.shields.io/github/license/northword/zotero-plugin-scaffold)
7
+ [![code style](https://antfu.me/badge-code-style.svg)](https://github.com/antfu/eslint-config)
7
8
 
8
9
  This is an npm package designed to assist in the development of Zotero plugins. It provides features such as compiling plugins, starting Zotero and installing plugins from source code, reloading plugins when the source code changes, and releasing plugins, and so on.
9
10
 
package/dist/cli.mjs CHANGED
@@ -2,12 +2,12 @@
2
2
  import process, { exit, env } from 'node:process';
3
3
  import { Command } from '@commander-js/extra-typings';
4
4
  import updateNotifier from 'update-notifier';
5
- import { L as Log, C as Config, B as Build, S as Serve, R as Release } from './shared/zotero-plugin-scaffold.2dde82f3.mjs';
5
+ import { L as Log, C as Config, B as Build, S as Serve, R as Release } from './shared/zotero-plugin-scaffold.242aa92d.mjs';
6
6
  import 'node:path';
7
7
  import 'c12';
8
+ import 'es-toolkit';
8
9
  import 'fs-extra';
9
10
  import 'hookable';
10
- import 'es-toolkit';
11
11
  import 'node:readline';
12
12
  import 'chalk';
13
13
  import 'std-env';
@@ -19,13 +19,14 @@ import 'node:crypto';
19
19
  import 'node:child_process';
20
20
  import 'conventional-changelog';
21
21
  import 'bumpp';
22
+ import 'node:fs';
23
+ import '@gitee/typescript-sdk-v5';
22
24
  import 'mime';
23
25
  import 'octokit';
24
26
  import 'chokidar';
25
- import 'node:fs';
26
27
 
27
28
  const name = "zotero-plugin-scaffold";
28
- const version = "0.1.2";
29
+ const version = "0.1.3";
29
30
 
30
31
  const logger = new Log();
31
32
  async function main() {
package/dist/index.d.mts CHANGED
@@ -591,7 +591,7 @@ interface Context extends Config$1 {
591
591
  version: string;
592
592
  hooks: Hookable<Hooks>;
593
593
  logger: InstanceType<typeof Log>;
594
- templateDate: {
594
+ templateData: {
595
595
  [placeholder: string]: string;
596
596
  };
597
597
  }
package/dist/index.d.ts CHANGED
@@ -591,7 +591,7 @@ interface Context extends Config$1 {
591
591
  version: string;
592
592
  hooks: Hookable<Hooks>;
593
593
  logger: InstanceType<typeof Log>;
594
- templateDate: {
594
+ templateData: {
595
595
  [placeholder: string]: string;
596
596
  };
597
597
  }
package/dist/index.mjs CHANGED
@@ -1,11 +1,11 @@
1
- export { B as Build, C as Config, R as Release, S as Serve, d as defineConfig } from './shared/zotero-plugin-scaffold.2dde82f3.mjs';
1
+ export { B as Build, C as Config, R as Release, S as Serve, d as defineConfig } from './shared/zotero-plugin-scaffold.242aa92d.mjs';
2
2
  import 'node:path';
3
3
  import 'c12';
4
+ import 'es-toolkit';
4
5
  import 'fs-extra';
5
6
  import 'hookable';
6
- import 'es-toolkit';
7
- import 'node:readline';
8
7
  import 'node:process';
8
+ import 'node:readline';
9
9
  import 'chalk';
10
10
  import 'std-env';
11
11
  import 'esbuild';
@@ -16,7 +16,8 @@ import 'node:crypto';
16
16
  import 'node:child_process';
17
17
  import 'conventional-changelog';
18
18
  import 'bumpp';
19
+ import 'node:fs';
20
+ import '@gitee/typescript-sdk-v5';
19
21
  import 'mime';
20
22
  import 'octokit';
21
23
  import 'chokidar';
22
- import 'node:fs';
@@ -1,10 +1,10 @@
1
1
  import path, { join, basename, resolve } from 'node:path';
2
2
  import { loadConfig as loadConfig$1 } from 'c12';
3
+ import { isPlainObject, kebabCase, mapValues, toMerged, escapeRegExp, debounce } from 'es-toolkit';
3
4
  import fs from 'fs-extra';
4
5
  import { createHooks } from 'hookable';
5
- import { isPlainObject, kebabCase, mapValues, toMerged, debounce } from 'es-toolkit';
6
+ import process, { env, platform, exit } from 'node:process';
6
7
  import readline from 'node:readline';
7
- import process, { env, exit, platform } from 'node:process';
8
8
  import chalk from 'chalk';
9
9
  import { isCI, isDebug, isWindows, isMacOS, isLinux } from 'std-env';
10
10
  import { build } from 'esbuild';
@@ -15,10 +15,11 @@ import * as crypto from 'node:crypto';
15
15
  import { execSync, spawn } from 'node:child_process';
16
16
  import conventionalChangelog from 'conventional-changelog';
17
17
  import { versionBump, ProgressEvent } from 'bumpp';
18
+ import fs$1, { existsSync } from 'node:fs';
19
+ import { OpenAPI, RepositoriesService } from '@gitee/typescript-sdk-v5';
18
20
  import mime from 'mime';
19
21
  import { Octokit } from 'octokit';
20
22
  import chokidar from 'chokidar';
21
- import { existsSync } from 'node:fs';
22
23
 
23
24
  var __defProp$9 = Object.defineProperty;
24
25
  var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -148,11 +149,6 @@ function template(str, data, regex = /\{\{(.+?)\}\}/g) {
148
149
  return acc.replace(match[0], data[match[1]]);
149
150
  }, str);
150
151
  }
151
- function escapeRegExp(string) {
152
- const reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
153
- const reHasRegExpChar = RegExp(reRegExpChar.source);
154
- return string && reHasRegExpChar.test(string) ? string.replace(reRegExpChar, "\\$&") : string || "";
155
- }
156
152
  function parseRepoUrl(url) {
157
153
  if (!url)
158
154
  throw new Error("Parse repository URL failed.");
@@ -190,7 +186,7 @@ function resolveConfig(config) {
190
186
  config.namespace || (config.namespace = config.name);
191
187
  config.xpiName || (config.xpiName = kebabCase(config.name));
192
188
  const isPreRelease = version.includes("-");
193
- const templateDate = {
189
+ const templateData = {
194
190
  owner,
195
191
  repo,
196
192
  version,
@@ -199,9 +195,9 @@ function resolveConfig(config) {
199
195
  xpiName: config.xpiName,
200
196
  buildTime: dateFormat("YYYY-mm-dd HH:MM:SS", /* @__PURE__ */ new Date())
201
197
  };
202
- config.updateURL = template(config.updateURL, templateDate);
203
- config.xpiDownloadLink = template(config.xpiDownloadLink, templateDate);
204
- config.build.define = mapValues(config.build.define, (v) => template(v, templateDate));
198
+ config.updateURL = template(config.updateURL, templateData);
199
+ config.xpiDownloadLink = template(config.xpiDownloadLink, templateData);
200
+ config.build.define = mapValues(config.build.define, (v) => template(v, templateData));
205
201
  const hooks = createHooks();
206
202
  hooks.addHooks(config.build.hooks);
207
203
  hooks.addHooks(config.server.hooks);
@@ -212,7 +208,7 @@ function resolveConfig(config) {
212
208
  version,
213
209
  hooks,
214
210
  logger,
215
- templateDate
211
+ templateData
216
212
  };
217
213
  return ctx;
218
214
  }
@@ -607,10 +603,10 @@ class ReleaseBase extends Base {
607
603
  }
608
604
  }
609
605
  get owner() {
610
- return this.ctx.templateDate.owner;
606
+ return this.ctx.templateData.owner;
611
607
  }
612
608
  get repo() {
613
- return this.ctx.templateDate.repo;
609
+ return this.ctx.templateData.repo;
614
610
  }
615
611
  }
616
612
 
@@ -680,10 +676,112 @@ var __publicField$5 = (obj, key, value) => {
680
676
  __defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
681
677
  return value;
682
678
  };
679
+ class Gitee extends ReleaseBase {
680
+ constructor() {
681
+ super(...arguments);
682
+ __publicField$5(this, "client", RepositoriesService);
683
+ }
684
+ async run() {
685
+ OpenAPI.TOKEN = env.GITEE_TOKEN;
686
+ if (!OpenAPI.TOKEN)
687
+ throw new Error("No GITEE_TOKEN provided!");
688
+ this.checkFiles();
689
+ this.logger.info("Uploading XPI to Gitee...");
690
+ await this.uploadXPI();
691
+ this.logger.info("Refreshing update manifest...");
692
+ await this.refreshUpdateManifest();
693
+ }
694
+ async uploadXPI() {
695
+ const { version, dist, xpiName } = this.ctx;
696
+ const release = await this.refreshRelease(
697
+ this.ctx.release.bumpp.tag.toString().replaceAll("%s", version),
698
+ `Release v${version}`,
699
+ this.ctx.release.gitee.releaseNote(this.ctx)
700
+ );
701
+ await this.refreshAttach(release.id, join(dist, `${xpiName}.xpi`));
702
+ }
703
+ async refreshUpdateManifest() {
704
+ const updater = this.ctx.release.gitee.updater;
705
+ if (!updater) {
706
+ this.logger.debug(
707
+ `Skip refresh update.json because release.gitee.updater = false`
708
+ );
709
+ return;
710
+ }
711
+ const { dist, version } = this.ctx;
712
+ const assets = globbySync(`${dist}/update*.json`).map((p) => basename(p));
713
+ const release = await this.refreshRelease(
714
+ updater,
715
+ "Zotero Auto Update Manifest",
716
+ `This release is used to host \`update.json\`, Updated in UTC ${( new Date()).toISOString()} for v${version}.`,
717
+ true
718
+ );
719
+ for (const asset of assets)
720
+ await this.refreshAttach(release.id, join(dist, asset));
721
+ }
722
+ async refreshRelease(tag, name, body, prerelease = false) {
723
+ const old = await this.client.getV5ReposOwnerRepoReleasesTagsTag({
724
+ owner: this.owner,
725
+ repo: this.repo,
726
+ tag
727
+ });
728
+ if (old?.id) {
729
+ return this.client.patchV5ReposOwnerRepoReleasesId({
730
+ owner: this.owner,
731
+ repo: this.repo,
732
+ name,
733
+ body,
734
+ prerelease,
735
+ id: old.id,
736
+ tagName: tag
737
+ });
738
+ }
739
+ return this.client.postV5ReposOwnerRepoReleases({
740
+ owner: this.owner,
741
+ repo: this.repo,
742
+ name,
743
+ body,
744
+ prerelease,
745
+ tagName: tag,
746
+ targetCommitish: "main"
747
+ });
748
+ }
749
+ async refreshAttach(releaseId, file) {
750
+ const assets = await this.client.getV5ReposOwnerRepoReleasesReleaseIdAttachFiles({
751
+ owner: this.owner,
752
+ repo: this.repo,
753
+ releaseId
754
+ });
755
+ const fileBuffer = fs$1.readFileSync(file);
756
+ for (const asset of assets) {
757
+ if (asset.name === basename(file)) {
758
+ await this.client.deleteV5ReposOwnerRepoReleasesReleaseIdAttachFilesAttachFileId({
759
+ owner: this.owner,
760
+ repo: this.repo,
761
+ releaseId,
762
+ attachFileId: asset.id
763
+ }).catch((e) => this.logger.error(e));
764
+ }
765
+ }
766
+ this.client.postV5ReposOwnerRepoReleasesReleaseIdAttachFiles({
767
+ owner: this.owner,
768
+ repo: this.repo,
769
+ releaseId,
770
+ file: new File([fileBuffer], basename(file), { type: "application/octet-stream" })
771
+ });
772
+ }
773
+ }
774
+
775
+ var __defProp$4 = Object.defineProperty;
776
+ var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
777
+ var __publicField$4 = (obj, key, value) => {
778
+ __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
779
+ return value;
780
+ };
683
781
  class GitHub extends ReleaseBase {
684
782
  constructor(ctx) {
685
783
  super(ctx);
686
- __publicField$5(this, "client");
784
+ __publicField$4(this, "client");
687
785
  this.client = this.getClient();
688
786
  }
689
787
  async run() {
@@ -824,31 +922,6 @@ class GitHub extends ReleaseBase {
824
922
  }
825
923
  }
826
924
 
827
- var __defProp$4 = Object.defineProperty;
828
- var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
829
- var __publicField$4 = (obj, key, value) => {
830
- __defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
831
- return value;
832
- };
833
- class Gitee extends ReleaseBase {
834
- constructor(ctx) {
835
- super(ctx);
836
- __publicField$4(this, "client");
837
- this.client = this.getClient();
838
- }
839
- async run() {
840
- this.checkFiles();
841
- this.logger.error("Release to Gitee has not yet been implemented.");
842
- }
843
- async uploadXPI() {
844
- }
845
- async refreshUpdateManifest() {
846
- }
847
- getClient() {
848
- return "";
849
- }
850
- }
851
-
852
925
  class Release extends Base {
853
926
  constructor(ctx) {
854
927
  super(ctx);
@@ -972,6 +1045,53 @@ ${changelog}
972
1045
  }
973
1046
  }
974
1047
 
1048
+ function isRunning(query) {
1049
+ let cmd = "";
1050
+ switch (platform) {
1051
+ case "win32":
1052
+ cmd = `tasklist`;
1053
+ break;
1054
+ case "darwin":
1055
+ cmd = `ps -ax | grep ${query}`;
1056
+ break;
1057
+ case "linux":
1058
+ cmd = `ps -A`;
1059
+ break;
1060
+ }
1061
+ try {
1062
+ const stdout = execSync(cmd, { encoding: "utf8" });
1063
+ return stdout.toLowerCase().includes(query.toLowerCase());
1064
+ } catch {
1065
+ return false;
1066
+ }
1067
+ }
1068
+
1069
+ function killZotero() {
1070
+ const logger = new Log();
1071
+ function kill() {
1072
+ try {
1073
+ if (env.ZOTERO_PLUGIN_KILL_COMMAND) {
1074
+ execSync(env.ZOTERO_PLUGIN_KILL_COMMAND);
1075
+ } else if (isWindows) {
1076
+ execSync("taskkill /f /im zotero.exe");
1077
+ } else if (isMacOS) {
1078
+ execSync("kill -9 $(ps -x | grep zotero)");
1079
+ } else if (isLinux) {
1080
+ execSync("kill -9 $(ps -x | grep zotero)");
1081
+ } else {
1082
+ logger.error("No commands found for this operating system.");
1083
+ }
1084
+ } catch {
1085
+ logger.fail("Kill Zotero failed.");
1086
+ }
1087
+ }
1088
+ if (isRunning("zotero")) {
1089
+ kill();
1090
+ } else {
1091
+ logger.fail("No Zotero instance is currently running.");
1092
+ }
1093
+ }
1094
+
975
1095
  var __defProp$3 = Object.defineProperty;
976
1096
  var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
977
1097
  var __publicField$3 = (obj, key, value) => {
@@ -1194,53 +1314,6 @@ class RunnerWebExt extends ServeBase {
1194
1314
  }
1195
1315
  }
1196
1316
 
1197
- function isRunning(query) {
1198
- let cmd = "";
1199
- switch (platform) {
1200
- case "win32":
1201
- cmd = `tasklist`;
1202
- break;
1203
- case "darwin":
1204
- cmd = `ps -ax | grep ${query}`;
1205
- break;
1206
- case "linux":
1207
- cmd = `ps -A`;
1208
- break;
1209
- }
1210
- try {
1211
- const stdout = execSync(cmd, { encoding: "utf8" });
1212
- return stdout.toLowerCase().includes(query.toLowerCase());
1213
- } catch {
1214
- return false;
1215
- }
1216
- }
1217
-
1218
- function killZotero() {
1219
- const logger = new Log();
1220
- function kill() {
1221
- try {
1222
- if (env.ZOTERO_PLUGIN_KILL_COMMAND) {
1223
- execSync(env.ZOTERO_PLUGIN_KILL_COMMAND);
1224
- } else if (isWindows) {
1225
- execSync("taskkill /f /im zotero.exe");
1226
- } else if (isMacOS) {
1227
- execSync("kill -9 $(ps -x | grep zotero)");
1228
- } else if (isLinux) {
1229
- execSync("kill -9 $(ps -x | grep zotero)");
1230
- } else {
1231
- logger.error("No commands found for this operating system.");
1232
- }
1233
- } catch {
1234
- logger.fail("Kill Zotero failed.");
1235
- }
1236
- }
1237
- if (isRunning("zotero")) {
1238
- kill();
1239
- } else {
1240
- logger.fail("No Zotero instance is currently running.");
1241
- }
1242
- }
1243
-
1244
1317
  var __defProp = Object.defineProperty;
1245
1318
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1246
1319
  var __publicField = (obj, key, value) => {
@@ -1,6 +1,6 @@
1
- import * as esm from 'fs-extra/esm';
2
- export { esm as fse };
3
1
  import * as esToolkit from 'es-toolkit';
4
2
  export { esToolkit };
3
+ import * as esm from 'fs-extra/esm';
4
+ export { esm as fse };
5
5
  import * as replaceInFile from 'replace-in-file';
6
6
  export { replaceInFile };
@@ -1,6 +1,6 @@
1
- import * as esm from 'fs-extra/esm';
2
- export { esm as fse };
3
1
  import * as esToolkit from 'es-toolkit';
4
2
  export { esToolkit };
3
+ import * as esm from 'fs-extra/esm';
4
+ export { esm as fse };
5
5
  import * as replaceInFile from 'replace-in-file';
6
6
  export { replaceInFile };
@@ -1,6 +1,6 @@
1
- import * as esm from 'fs-extra/esm';
2
- export { esm as fse };
3
1
  import * as esToolkit from 'es-toolkit';
4
2
  export { esToolkit };
3
+ import * as esm from 'fs-extra/esm';
4
+ export { esm as fse };
5
5
  import * as replaceInFile from 'replace-in-file';
6
6
  export { replaceInFile };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
3
  "type": "module",
4
- "version": "0.1.2",
4
+ "version": "0.1.3",
5
5
  "description": "A scaffold for Zotero plugin development.",
6
6
  "author": "northword",
7
7
  "license": "AGPL-3.0-or-later",
@@ -52,14 +52,15 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@commander-js/extra-typings": "^12.1.0",
55
- "@inquirer/prompts": "^5.3.8",
55
+ "@gitee/typescript-sdk-v5": "^5.4.85",
56
+ "@inquirer/prompts": "^5.5.0",
56
57
  "bumpp": "^9.5.2",
57
- "c12": "^1.11.1",
58
+ "c12": "^1.11.2",
58
59
  "chalk": "^5.3.0",
59
60
  "chokidar": "^3.6.0",
60
61
  "commander": "^12.1.0",
61
62
  "conventional-changelog": "^6.0.0",
62
- "es-toolkit": "^1.16.0",
63
+ "es-toolkit": "^1.18.0",
63
64
  "esbuild": "^0.23.1",
64
65
  "fs-extra": "^11.2.0",
65
66
  "globby": "^14.0.2",
@@ -68,17 +69,17 @@
68
69
  "octokit": "^4.0.2",
69
70
  "replace-in-file": "^8.1.0",
70
71
  "std-env": "^3.7.0",
71
- "update-notifier": "^7.2.0",
72
+ "update-notifier": "^7.3.1",
72
73
  "web-ext": "^8.2.0"
73
74
  },
74
75
  "devDependencies": {
75
- "@antfu/eslint-config": "^3.0.0",
76
+ "@antfu/eslint-config": "^3.6.0",
76
77
  "@types/fs-extra": "^11.0.4",
77
- "@types/node": "^20.16.1",
78
+ "@types/node": "^20.16.5",
78
79
  "@types/update-notifier": "^6.0.8",
79
- "eslint": "^9.9.1",
80
+ "eslint": "^9.10.0",
80
81
  "eslint-plugin-format": "^0.1.2",
81
- "typescript": "^5.5.4",
82
+ "typescript": "^5.6.2",
82
83
  "unbuild": "^2.0.0"
83
84
  },
84
85
  "scripts": {