zotero-plugin-scaffold 0.0.6 → 0.0.8

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/dist/config.js CHANGED
@@ -55,7 +55,7 @@ export async function loadConfig(file) {
55
55
  ghOwner: owner,
56
56
  ghRepo: repo,
57
57
  addonRef: pkg.config?.addonRef || _.kebabCase(addonName),
58
- addonInstance: pkg.config?.addonInstence || _.camelCase(addonName),
58
+ addonInstance: pkg.config?.addonInstance || _.camelCase(addonName),
59
59
  prefsPrefix: `extensions.zotero.${addonRef}`,
60
60
  xpiName: xpiName,
61
61
  releasePage: releasePage,
@@ -134,19 +134,19 @@ export async function loadConfig(file) {
134
134
  extraBuilder: () => { },
135
135
  addonLint: {},
136
136
  release: {
137
- releaseIt: {
138
- preReleaseId: "beta",
139
- git: {
140
- tagName: "v${version}",
141
- requireCleanWorkingDir: false,
142
- },
143
- npm: {
144
- publish: false,
145
- },
146
- github: {
147
- assets: [`${userConfig.dist}/*.xpi`],
148
- },
149
- },
137
+ // releaseIt: {
138
+ // preReleaseId: "beta",
139
+ // git: {
140
+ // tagName: "v${version}",
141
+ // requireCleanWorkingDir: false,
142
+ // },
143
+ // npm: {
144
+ // publish: false,
145
+ // },
146
+ // github: {
147
+ // assets: [`${userConfig.dist}/*.xpi`],
148
+ // },
149
+ // },
150
150
  bumpp: {
151
151
  release: "prompt",
152
152
  preid: "beta",
@@ -22,7 +22,7 @@ export default class Release extends Base {
22
22
  /**
23
23
  * Create new release and upload XPI to asset
24
24
  */
25
- uploadXPI(): void;
25
+ uploadXPI(): Promise<void>;
26
26
  getReleaseByTag(tag: string): Promise<{
27
27
  url: string;
28
28
  html_url: string;
@@ -249,6 +249,7 @@ export default class Release extends Base {
249
249
  } | null;
250
250
  }>;
251
251
  uploadUpdateJSON(): Promise<void>;
252
+ getChangelog(): Promise<string>;
252
253
  getClient(): Octokit;
253
254
  get owner(): string;
254
255
  get repo(): string;
@@ -1,12 +1,12 @@
1
1
  import { Base } from "./base.js";
2
2
  import { Octokit } from "@octokit/rest";
3
+ import versionBump from "bumpp";
3
4
  import ci from "ci-info";
5
+ import conventionalChangelog from "conventional-changelog";
4
6
  import { default as glob } from "fast-glob";
5
7
  import fs from "fs-extra";
6
- import _ from "lodash";
7
8
  import mime from "mime";
8
9
  import path from "path";
9
- import releaseIt from "release-it";
10
10
  export default class Release extends Base {
11
11
  isCI;
12
12
  client;
@@ -40,30 +40,38 @@ export default class Release extends Base {
40
40
  * release: bump version, run build, git add, git commit, git tag, git push
41
41
  */
42
42
  bump() {
43
- // versionBump(this.config.release.bumpp);
44
- const releaseItConfig = {
45
- "only-version": true,
46
- };
47
- releaseIt(_.defaultsDeep(releaseItConfig, this.config.release.releaseIt));
43
+ versionBump(this.config.release.bumpp);
44
+ // const releaseItConfig: ReleaseItConfig = {
45
+ // "only-version": true,
46
+ // };
47
+ // releaseIt(_.defaultsDeep(releaseItConfig, this.config.release.releaseIt));
48
48
  }
49
49
  /**
50
50
  * Create new release and upload XPI to asset
51
51
  */
52
- uploadXPI() {
53
- const releaseItConfig = {
54
- increment: false,
55
- git: {
56
- commit: false,
57
- tag: false,
58
- push: false,
59
- },
60
- github: {
61
- release: true,
62
- },
63
- verbose: 2,
64
- ci: true,
65
- };
66
- releaseIt(_.defaultsDeep(releaseItConfig, this.config.release.releaseIt));
52
+ async uploadXPI() {
53
+ // const releaseItConfig: ReleaseItConfig = {
54
+ // increment: false,
55
+ // git: { commit: false, tag: false, push: false },
56
+ // github: {
57
+ // release: true,
58
+ // },
59
+ // verbose: 2,
60
+ // ci: true,
61
+ // };
62
+ // releaseIt(_.defaultsDeep(releaseItConfig, this.config.release.releaseIt));
63
+ const release = await this.creatRelease({
64
+ owner: this.owner,
65
+ repo: this.repo,
66
+ tag_name: `v${this.version}`,
67
+ name: `Release v${this.version}`,
68
+ body: await this.getChangelog(),
69
+ prerelease: this.version.includes("-"),
70
+ make_latest: "true",
71
+ });
72
+ if (!release)
73
+ throw new Error("Creat release failed!");
74
+ this.uploadAsset(release.id, path.join(this.config.dist, `${this.xpiName}.xpi`));
67
75
  }
68
76
  async getReleaseByTag(tag) {
69
77
  return await this.client.repos
@@ -119,12 +127,17 @@ export default class Release extends Base {
119
127
  owner: this.owner,
120
128
  repo: this.repo,
121
129
  tag_name: "release",
122
- name: "Release Manifest",
123
- body: `This release is used to host \`update.json\`, please do not delete or modify it! \n Updated in UTC ${new Date().toISOString()} for version ${this.version}`,
124
- make_latest: "false",
125
130
  }));
126
131
  if (!release)
127
132
  throw new Error("Get or create 'release' failed.");
133
+ await this.client.repos.updateRelease({
134
+ owner: this.owner,
135
+ repo: this.repo,
136
+ release_id: release.id,
137
+ name: "Release Manifest",
138
+ body: `This release is used to host \`update.json\`, please do not delete or modify it! \n Updated in UTC ${new Date().toISOString()} for version ${this.version}`,
139
+ make_latest: "false",
140
+ });
128
141
  const existAssets = await this.client.repos
129
142
  .listReleaseAssets({
130
143
  owner: this.owner,
@@ -147,6 +160,22 @@ export default class Release extends Base {
147
160
  await this.uploadAsset(release.id, path.join(this.config.dist, asset));
148
161
  }
149
162
  }
163
+ getChangelog() {
164
+ return new Promise((resolve, reject) => {
165
+ let changelog = "";
166
+ conventionalChangelog({ releaseCount: 2 }, { version: this.version })
167
+ .on("data", (chunk) => {
168
+ changelog += chunk.toString();
169
+ })
170
+ .on("end", () => {
171
+ this.logger.debug("changelog:", changelog);
172
+ resolve(changelog);
173
+ })
174
+ .on("error", (err) => {
175
+ reject(err);
176
+ });
177
+ });
178
+ }
150
179
  getClient() {
151
180
  if (!process.env.GITHUB_TOKEN)
152
181
  throw new Error("No GITHUB_TOKEN.");
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import { Config } from "../types.js";
2
3
  import { Base } from "./base.js";
3
4
  export default class Serve extends Base {
@@ -8,7 +9,7 @@ export default class Serve extends Base {
8
9
  * watch source dir and build when file changed
9
10
  */
10
11
  watch(): Promise<void>;
11
- startZotero(): void;
12
+ startZotero(): Promise<import("child_process").ChildProcessWithoutNullStreams>;
12
13
  /**
13
14
  * start zotero with plugin installed and reload when dist changed
14
15
  */
package/dist/lib/serve.js CHANGED
@@ -16,10 +16,10 @@ export default class Serve extends Base {
16
16
  }
17
17
  async run() {
18
18
  // build
19
- this.builder.run();
19
+ await this.builder.run();
20
20
  // start Zotero
21
- // this.startZotero();
22
- this.startZoteroWebExt();
21
+ this.startZotero();
22
+ // this.startZoteroWebExt();
23
23
  // watch
24
24
  await this.config.extraServer(this.config);
25
25
  await this.watch();
@@ -63,19 +63,33 @@ export default class Serve extends Base {
63
63
  this.logger.error("Server start failed!", err);
64
64
  });
65
65
  }
66
- startZotero() {
66
+ async startZotero() {
67
+ let isZoteroReady = false;
67
68
  if (!fs.existsSync(this.zoteroBinPath)) {
68
69
  throw new Error("Zotero binary does not exist.");
69
70
  }
70
71
  if (!fs.existsSync(this.profilePath)) {
71
72
  throw new Error("The given Zotero profile does not exist.");
72
73
  }
74
+ this.prepareDevEnv();
73
75
  const zoteroProcess = spawn(this.zoteroBinPath, [
74
76
  "--debugger",
75
77
  "--purgecaches",
76
78
  "-profile",
77
79
  this.profilePath,
78
80
  ]);
81
+ zoteroProcess.stdout?.on("data", (data) => {
82
+ if (!isZoteroReady &&
83
+ data
84
+ .toString()
85
+ .includes(`Calling bootstrap method 'startup' for plugin ${this.addonID}`)) {
86
+ console.log(data.toString());
87
+ isZoteroReady = true;
88
+ setTimeout(() => {
89
+ this.openDevTool();
90
+ }, 1000);
91
+ }
92
+ });
79
93
  zoteroProcess.on("close", (code) => {
80
94
  this.logger.info(`Zotero terminated with code ${code}.`);
81
95
  exit(0);
@@ -85,6 +99,7 @@ export default class Serve extends Base {
85
99
  zoteroProcess.kill();
86
100
  exit();
87
101
  });
102
+ return zoteroProcess;
88
103
  }
89
104
  /**
90
105
  * start zotero with plugin installed and reload when dist changed
@@ -221,11 +236,11 @@ export default class Serve extends Base {
221
236
  execSync(command);
222
237
  }
223
238
  get zoteroBinPath() {
224
- this.logger.debug("zoteroBinPath", process.env.zoteroBinPath);
239
+ // this.logger.debug("zoteroBinPath", process.env.zoteroBinPath);
225
240
  return process.env.zoteroBinPath ?? "";
226
241
  }
227
242
  get profilePath() {
228
- this.logger.debug("profilePath", process.env.profilePath);
243
+ // this.logger.debug("profilePath", process.env.profilePath);
229
244
  return process.env.profilePath ?? "";
230
245
  }
231
246
  get dataDir() {
package/dist/types.d.ts CHANGED
@@ -271,7 +271,6 @@ export interface ConfigBase {
271
271
  * 发布相关配置
272
272
  */
273
273
  release: {
274
- releaseIt: Partial<ReleaseItConfig>;
275
274
  bumpp: VersionBumpOptions;
276
275
  };
277
276
  /**
package/dist/utils/log.js CHANGED
@@ -42,8 +42,9 @@ export default class Log {
42
42
  this.log(chalk.green("INFO"), ...args);
43
43
  }
44
44
  debug(...args) {
45
+ // if (this.logLevel <= 1) this.log(chalk.grey("DEBUG"), ...args);
45
46
  if (this.logLevel <= 1)
46
- this.log(chalk.grey("DEBUG"), ...args);
47
+ this.log(...args);
47
48
  }
48
49
  trace(...args) {
49
50
  if (this.logLevel <= 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "A scaffold for Zotero plugin development.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -52,9 +52,12 @@
52
52
  "ci-info": "^4.0.0",
53
53
  "commander": "^11.1.0",
54
54
  "compressing": "^1.10.0",
55
+ "conventional-changelog": "^5.1.0",
56
+ "conventional-commits-detector": "^1.0.3",
55
57
  "cosmiconfig": "^9.0.0",
56
58
  "dotenv": "^16.4.1",
57
59
  "esbuild": "^0.19.12",
60
+ "execa": "^8.0.1",
58
61
  "fast-glob": "^3.3.2",
59
62
  "fs-extra": "^11.2.0",
60
63
  "lodash": "^4.17.21",
@@ -67,12 +70,13 @@
67
70
  },
68
71
  "devDependencies": {
69
72
  "@trivago/prettier-plugin-sort-imports": "^4.3.0",
73
+ "@types/conventional-changelog": "^3.1.5",
70
74
  "@types/fs-extra": "^11.0.4",
71
75
  "@types/lodash": "^4.14.202",
72
- "@types/node": "^20.11.9",
76
+ "@types/node": "^20.11.16",
73
77
  "@types/update-notifier": "^6.0.8",
74
- "@typescript-eslint/eslint-plugin": "^6.19.1",
75
- "@typescript-eslint/parser": "^6.19.1",
78
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
79
+ "@typescript-eslint/parser": "^6.20.0",
76
80
  "eslint": "^8.56.0",
77
81
  "eslint-config-prettier": "^9.1.0",
78
82
  "prettier": "^3.2.4",