zotero-plugin-scaffold 0.1.6 → 0.1.7

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.
@@ -4,9 +4,8 @@ import fs from 'fs-extra';
4
4
  import { globbySync } from 'globby';
5
5
  import mime from 'mime';
6
6
  import { Octokit } from 'octokit';
7
- import { R as ReleaseBase } from '../shared/zotero-plugin-scaffold.3e58ced7.mjs';
8
- import 'std-env';
9
- import '../shared/zotero-plugin-scaffold.c7c8af0c.mjs';
7
+ import { isCI } from 'std-env';
8
+ import { a as Base } from '../shared/zotero-plugin-scaffold.b59b2bc7.mjs';
10
9
  import 'c12';
11
10
  import 'es-toolkit';
12
11
  import 'hookable';
@@ -17,11 +16,30 @@ import 'replace-in-file';
17
16
  import 'web-ext';
18
17
  import 'node:crypto';
19
18
  import 'node:child_process';
20
- import 'conventional-changelog';
21
19
  import 'bumpp';
22
20
  import 'chokidar';
23
21
  import 'node:fs';
24
22
 
23
+ var __defProp$1 = Object.defineProperty;
24
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
25
+ var __publicField$1 = (obj, key, value) => {
26
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
27
+ return value;
28
+ };
29
+ class ReleaseBase extends Base {
30
+ constructor(ctx) {
31
+ super(ctx);
32
+ __publicField$1(this, "isCI");
33
+ this.isCI = isCI;
34
+ }
35
+ checkFiles() {
36
+ const { dist } = this.ctx;
37
+ if (globbySync(`${dist}/*.xpi`).length === 0) {
38
+ throw new Error("No xpi file found, are you sure you have run build?");
39
+ }
40
+ }
41
+ }
42
+
25
43
  var __defProp = Object.defineProperty;
26
44
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
27
45
  var __publicField = (obj, key, value) => {
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@
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, a as Build, S as Serve, R as Release } from './shared/zotero-plugin-scaffold.c7c8af0c.mjs';
5
+ import { L as Log, C as Config, B as Build, S as Serve, R as Release } from './shared/zotero-plugin-scaffold.b59b2bc7.mjs';
6
6
  import 'node:path';
7
7
  import 'c12';
8
8
  import 'es-toolkit';
@@ -17,13 +17,12 @@ import 'replace-in-file';
17
17
  import 'web-ext';
18
18
  import 'node:crypto';
19
19
  import 'node:child_process';
20
- import 'conventional-changelog';
21
20
  import 'bumpp';
22
21
  import 'chokidar';
23
22
  import 'node:fs';
24
23
 
25
24
  const name = "zotero-plugin-scaffold";
26
- const version = "0.1.6";
25
+ const version = "0.1.7";
27
26
 
28
27
  const logger = new Log();
29
28
  async function main() {
package/dist/index.d.mts CHANGED
@@ -522,14 +522,19 @@ interface ReleaseConfig {
522
522
  /**
523
523
  * Changelog.
524
524
  *
525
- * If a string is provided, it must be command line
526
- * and with changelog output to stdout.
525
+ * - "conventional-changelog": use conventional-changelog with angular preset,
526
+ * you must install "conventional-changelog" as an peer dependency.
527
+ * - string: a command line with changelog output to stdout.
527
528
  *
528
- * 如果提供了字符串,则必须为命令行,且变更日志输出到stdout
529
+ * 变更日志。
530
+ *
531
+ * - "conventional-changelog": 使用约定式变更日志,使用 angular 预设,
532
+ * 你需要手动安装 conventional-changelog 作为依赖项。
533
+ * - string: 命令行,变更日志输出到 stdout
529
534
  *
530
535
  * @default "git log {{previousTag}}..{{currentTag}}"
531
536
  */
532
- changelog: string | ((ctx: Context) => string);
537
+ changelog: "conventional-changelog" | string | ((ctx: Context) => string);
533
538
  /**
534
539
  * Release to GitHub.
535
540
  */
@@ -580,6 +585,8 @@ interface ReleaseConfig {
580
585
  };
581
586
  /**
582
587
  * Release to Gitee
588
+ *
589
+ * @todo Not implemented yet
583
590
  */
584
591
  gitee: ReleaseConfig["github"];
585
592
  hooks: Partial<ReleaseHooks>;
@@ -680,9 +687,9 @@ declare class Release extends Base {
680
687
  */
681
688
  run(): Promise<void>;
682
689
  getConventionalChangelog(): Promise<string>;
683
- getGitLog(currentTag: string): string;
684
- getFilteredChangelog(rawLog: string, commitMessage: string): string;
685
- getChangelog(): string;
690
+ getGitLog(): string;
691
+ getFilteredChangelog(rawLog: string): string;
692
+ getChangelog(): Promise<string>;
686
693
  private isEnabled;
687
694
  get resolvedCommitMessage(): string;
688
695
  }
package/dist/index.d.ts CHANGED
@@ -522,14 +522,19 @@ interface ReleaseConfig {
522
522
  /**
523
523
  * Changelog.
524
524
  *
525
- * If a string is provided, it must be command line
526
- * and with changelog output to stdout.
525
+ * - "conventional-changelog": use conventional-changelog with angular preset,
526
+ * you must install "conventional-changelog" as an peer dependency.
527
+ * - string: a command line with changelog output to stdout.
527
528
  *
528
- * 如果提供了字符串,则必须为命令行,且变更日志输出到stdout
529
+ * 变更日志。
530
+ *
531
+ * - "conventional-changelog": 使用约定式变更日志,使用 angular 预设,
532
+ * 你需要手动安装 conventional-changelog 作为依赖项。
533
+ * - string: 命令行,变更日志输出到 stdout
529
534
  *
530
535
  * @default "git log {{previousTag}}..{{currentTag}}"
531
536
  */
532
- changelog: string | ((ctx: Context) => string);
537
+ changelog: "conventional-changelog" | string | ((ctx: Context) => string);
533
538
  /**
534
539
  * Release to GitHub.
535
540
  */
@@ -580,6 +585,8 @@ interface ReleaseConfig {
580
585
  };
581
586
  /**
582
587
  * Release to Gitee
588
+ *
589
+ * @todo Not implemented yet
583
590
  */
584
591
  gitee: ReleaseConfig["github"];
585
592
  hooks: Partial<ReleaseHooks>;
@@ -680,9 +687,9 @@ declare class Release extends Base {
680
687
  */
681
688
  run(): Promise<void>;
682
689
  getConventionalChangelog(): Promise<string>;
683
- getGitLog(currentTag: string): string;
684
- getFilteredChangelog(rawLog: string, commitMessage: string): string;
685
- getChangelog(): string;
690
+ getGitLog(): string;
691
+ getFilteredChangelog(rawLog: string): string;
692
+ getChangelog(): Promise<string>;
686
693
  private isEnabled;
687
694
  get resolvedCommitMessage(): string;
688
695
  }
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { a as Build, C as Config, R as Release, S as Serve, d as defineConfig } from './shared/zotero-plugin-scaffold.c7c8af0c.mjs';
1
+ export { B as Build, C as Config, R as Release, S as Serve, d as defineConfig } from './shared/zotero-plugin-scaffold.b59b2bc7.mjs';
2
2
  import 'node:path';
3
3
  import 'c12';
4
4
  import 'es-toolkit';
@@ -14,7 +14,6 @@ import 'replace-in-file';
14
14
  import 'web-ext';
15
15
  import 'node:crypto';
16
16
  import 'node:child_process';
17
- import 'conventional-changelog';
18
17
  import 'bumpp';
19
18
  import 'chokidar';
20
19
  import 'node:fs';
@@ -13,7 +13,6 @@ import { replaceInFileSync } from 'replace-in-file';
13
13
  import webext from 'web-ext';
14
14
  import * as crypto from 'node:crypto';
15
15
  import { execSync, spawn } from 'node:child_process';
16
- import conventionalChangelog from 'conventional-changelog';
17
16
  import { versionBump, ProgressEvent } from 'bumpp';
18
17
  import chokidar from 'chokidar';
19
18
  import { existsSync } from 'node:fs';
@@ -311,6 +310,14 @@ function generateHashSync(filePath, algorithm) {
311
310
  return `${algorithm}:${hash}`;
312
311
  }
313
312
 
313
+ function getValidatedManifest(_sourceDir) {
314
+ return {
315
+ manifest_version: 2,
316
+ name: "zoterp-plugin-scaffold-fake-name",
317
+ version: "0.0.0.0"
318
+ };
319
+ }
320
+
314
321
  var __defProp$5 = Object.defineProperty;
315
322
  var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
316
323
  var __publicField$5 = (obj, key, value) => {
@@ -419,11 +426,6 @@ class Build extends Base {
419
426
  zotero: {
420
427
  id,
421
428
  update_url: updateURL
422
- },
423
- gecko: {
424
- id,
425
- update_url: updateURL,
426
- strict_min_version: "102"
427
429
  }
428
430
  }
429
431
  };
@@ -581,6 +583,8 @@ class Build extends Base {
581
583
  artifactsDir: dist,
582
584
  filename: `${xpiName}.xpi`,
583
585
  overwriteDest: true
586
+ }, {
587
+ manifestData: getValidatedManifest()
584
588
  });
585
589
  }
586
590
  }
@@ -680,35 +684,33 @@ class Release extends Base {
680
684
  await this.ctx.hooks.callHook("release:init", this.ctx);
681
685
  await new Bump(this.ctx).run();
682
686
  await this.ctx.hooks.callHook("release:push", this.ctx);
683
- this.ctx.release.changelog = this.getChangelog();
687
+ this.ctx.release.changelog = await this.getChangelog();
684
688
  if (isGitHubEnabled) {
685
689
  const { default: GitHub } = await import('../chunks/github.mjs');
686
690
  await new GitHub(this.ctx).run();
687
691
  }
688
- if (isGiteeEnabled) {
689
- const { default: Gitee } = await import('../chunks/gitee.mjs');
690
- await new Gitee(this.ctx).run();
691
- }
692
692
  await this.ctx.hooks.callHook("release:done", this.ctx);
693
693
  this.logger.success(
694
694
  `Done in ${(( new Date()).getTime() - t.getTime()) / 1e3} s.`
695
695
  );
696
696
  }
697
- getConventionalChangelog() {
697
+ async getConventionalChangelog() {
698
698
  const { version } = this.ctx;
699
+ const { default: conventionalChangelog } = await import('conventional-changelog');
699
700
  return new Promise((resolve, reject) => {
700
701
  let changelog = "";
701
- conventionalChangelog({ releaseCount: 2 }, { version }).on("data", (chunk) => {
702
+ conventionalChangelog({ releaseCount: 2, preset: "angular" }, { version }).on("data", (chunk) => {
702
703
  changelog += chunk.toString();
703
704
  }).on("end", () => {
704
- this.logger.debug("changelog:", changelog.trim());
705
- resolve(changelog.trim());
705
+ changelog = changelog.split("\n").filter((line) => !line.match(/^## .*/)).join("\n").trim();
706
+ resolve(changelog);
706
707
  }).on("error", (err) => {
707
708
  reject(err);
708
709
  });
709
710
  });
710
711
  }
711
- getGitLog(currentTag) {
712
+ getGitLog() {
713
+ const currentTag = this.ctx.release.bumpp.tag;
712
714
  const tags = execSync("git tag -l --sort=v:refname").toString().trim().split("\n");
713
715
  const currentTagIndex = tags.indexOf(currentTag);
714
716
  if (currentTagIndex === -1)
@@ -733,25 +735,27 @@ class Release extends Base {
733
735
  else
734
736
  return execSync(`git log --pretty=format:"* %s (%h)" ${currentTag}`).toString().trim();
735
737
  }
736
- getFilteredChangelog(rawLog, commitMessage) {
738
+ getFilteredChangelog(rawLog) {
739
+ const commitMessage = this.ctx.release.bumpp.commit;
737
740
  const filterRegex = new RegExp(escapeRegExp(commitMessage));
738
741
  const filteredLog = rawLog.split("\n").filter((line) => !filterRegex.test(line)).join("\n");
739
742
  if (filteredLog.replaceAll(" ", "") === "")
740
743
  return "_No significant changes._";
741
744
  return filteredLog;
742
745
  }
743
- getChangelog() {
746
+ async getChangelog() {
744
747
  let changelog;
745
748
  const changelogConfig = this.ctx.release.changelog;
746
749
  if (typeof changelogConfig == "function") {
747
750
  changelog = changelogConfig(this.ctx);
751
+ } else if (!!changelogConfig && changelogConfig === "conventional-changelog") {
752
+ const rawLog = await this.getConventionalChangelog();
753
+ changelog = this.getFilteredChangelog(rawLog);
748
754
  } else if (!!changelogConfig && typeof changelogConfig == "string") {
749
755
  changelog = execSync(changelogConfig).toString().trim();
750
756
  } else {
751
- const resolvedCurrentTag = this.ctx.release.bumpp.tag;
752
- const rawLog = this.getGitLog(resolvedCurrentTag);
753
- const resolvedCommitMessage = this.ctx.release.bumpp.commit;
754
- changelog = this.getFilteredChangelog(rawLog, resolvedCommitMessage);
757
+ const rawLog = this.getGitLog();
758
+ changelog = this.getFilteredChangelog(rawLog);
755
759
  }
756
760
  this.logger.debug(`Got changelog:
757
761
  ${changelog}
@@ -1026,7 +1030,8 @@ class RunnerWebExt extends ServeBase {
1026
1030
  // These are non CLI related options for each function.
1027
1031
  // You need to specify this one so that your NodeJS application
1028
1032
  // can continue running after web-ext is finished.
1029
- shouldExitProgram: false
1033
+ shouldExitProgram: false,
1034
+ getValidatedManifest
1030
1035
  }
1031
1036
  );
1032
1037
  this._runner = runner;
@@ -1125,4 +1130,4 @@ const Config = {
1125
1130
  loadConfig
1126
1131
  };
1127
1132
 
1128
- export { Base as B, Config as C, Log as L, Release as R, Serve as S, Build as a, defineConfig as d };
1133
+ export { Build as B, Config as C, Log as L, Release as R, Serve as S, Base as a, defineConfig as d };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
3
  "type": "module",
4
- "version": "0.1.6",
4
+ "version": "0.1.7",
5
5
  "description": "A scaffold for Zotero plugin development.",
6
6
  "author": "northword",
7
7
  "license": "AGPL-3.0-or-later",
@@ -50,18 +50,24 @@
50
50
  "lib": "dist",
51
51
  "doc": "docs"
52
52
  },
53
+ "peerDependencies": {
54
+ "conventional-changelog": "^6.0.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "conventional-changelog": {
58
+ "optional": true
59
+ }
60
+ },
53
61
  "dependencies": {
54
62
  "@commander-js/extra-typings": "^12.1.0",
55
- "@gitee/typescript-sdk-v5": "^5.4.85",
56
- "@inquirer/prompts": "^5.5.0",
57
- "bumpp": "^9.6.1",
58
- "c12": "^1.11.2",
63
+ "@inquirer/prompts": "^7.0.0",
64
+ "bumpp": "^9.7.1",
65
+ "c12": "^2.0.1",
59
66
  "chalk": "^5.3.0",
60
- "chokidar": "^3.6.0",
67
+ "chokidar": "^4.0.1",
61
68
  "commander": "^12.1.0",
62
- "conventional-changelog": "^6.0.0",
63
- "es-toolkit": "^1.22.0",
64
- "esbuild": "^0.23.1",
69
+ "es-toolkit": "^1.25.2",
70
+ "esbuild": "^0.24.0",
65
71
  "fs-extra": "^11.2.0",
66
72
  "globby": "^14.0.2",
67
73
  "hookable": "^5.5.3",
@@ -73,13 +79,13 @@
73
79
  "web-ext": "^8.3.0"
74
80
  },
75
81
  "devDependencies": {
76
- "@antfu/eslint-config": "^3.7.3",
82
+ "@antfu/eslint-config": "^3.8.0",
77
83
  "@types/fs-extra": "^11.0.4",
78
- "@types/node": "^20.16.10",
84
+ "@types/node": "^20.16.12",
79
85
  "@types/update-notifier": "^6.0.8",
80
- "eslint": "^9.11.1",
86
+ "eslint": "^9.12.0",
81
87
  "eslint-plugin-format": "^0.1.2",
82
- "typescript": "^5.6.2",
88
+ "typescript": "^5.6.3",
83
89
  "unbuild": "^2.0.0"
84
90
  },
85
91
  "scripts": {
@@ -1,127 +0,0 @@
1
- import fs from 'node:fs';
2
- import { join, basename } from 'node:path';
3
- import { env } from 'node:process';
4
- import { OpenAPI, RepositoriesService } from '@gitee/typescript-sdk-v5';
5
- import { globbySync } from 'globby';
6
- import { R as ReleaseBase } from '../shared/zotero-plugin-scaffold.3e58ced7.mjs';
7
- import 'std-env';
8
- import '../shared/zotero-plugin-scaffold.c7c8af0c.mjs';
9
- import 'c12';
10
- import 'es-toolkit';
11
- import 'fs-extra';
12
- import 'hookable';
13
- import 'node:readline';
14
- import 'chalk';
15
- import 'esbuild';
16
- import 'replace-in-file';
17
- import 'web-ext';
18
- import 'node:crypto';
19
- import 'node:child_process';
20
- import 'conventional-changelog';
21
- import 'bumpp';
22
- import 'chokidar';
23
-
24
- var __defProp = Object.defineProperty;
25
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
26
- var __publicField = (obj, key, value) => {
27
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
28
- return value;
29
- };
30
- class Gitee extends ReleaseBase {
31
- constructor() {
32
- super(...arguments);
33
- __publicField(this, "client", RepositoriesService);
34
- }
35
- async run() {
36
- OpenAPI.TOKEN = env.GITEE_TOKEN;
37
- if (!OpenAPI.TOKEN)
38
- throw new Error("No GITEE_TOKEN provided!");
39
- this.checkFiles();
40
- this.logger.info("Uploading XPI to Gitee...");
41
- await this.uploadXPI();
42
- this.logger.info("Refreshing update manifest...");
43
- await this.refreshUpdateManifest();
44
- }
45
- async uploadXPI() {
46
- const { version, dist, xpiName } = this.ctx;
47
- const release = await this.refreshRelease(
48
- this.ctx.release.bumpp.tag.toString().replaceAll("%s", version),
49
- `Release v${version}`,
50
- this.ctx.release.gitee.releaseNote(this.ctx)
51
- );
52
- await this.refreshAttach(release.id, join(dist, `${xpiName}.xpi`));
53
- }
54
- async refreshUpdateManifest() {
55
- const updater = this.ctx.release.gitee.updater;
56
- if (!updater) {
57
- this.logger.debug(
58
- `Skip refresh update.json because release.gitee.updater = false`
59
- );
60
- return;
61
- }
62
- const { dist, version } = this.ctx;
63
- const assets = globbySync(`${dist}/update*.json`).map((p) => basename(p));
64
- const release = await this.refreshRelease(
65
- updater,
66
- "Zotero Auto Update Manifest",
67
- `This release is used to host \`update.json\`, Updated in UTC ${( new Date()).toISOString()} for v${version}.`,
68
- true
69
- );
70
- for (const asset of assets)
71
- await this.refreshAttach(release.id, join(dist, asset));
72
- }
73
- async refreshRelease(tag, name, body, prerelease = false) {
74
- const old = await this.client.getV5ReposOwnerRepoReleasesTagsTag({
75
- ...this.remote,
76
- tag
77
- });
78
- if (old?.id) {
79
- return this.client.patchV5ReposOwnerRepoReleasesId({
80
- ...this.remote,
81
- name,
82
- body,
83
- prerelease,
84
- id: old.id,
85
- tagName: tag
86
- });
87
- }
88
- return this.client.postV5ReposOwnerRepoReleases({
89
- ...this.remote,
90
- name,
91
- body,
92
- prerelease,
93
- tagName: tag,
94
- targetCommitish: "main"
95
- });
96
- }
97
- async refreshAttach(releaseId, file) {
98
- const assets = await this.client.getV5ReposOwnerRepoReleasesReleaseIdAttachFiles({
99
- ...this.remote,
100
- releaseId
101
- });
102
- const fileBuffer = fs.readFileSync(file);
103
- for (const asset of assets) {
104
- if (asset.name === basename(file)) {
105
- await this.client.deleteV5ReposOwnerRepoReleasesReleaseIdAttachFilesAttachFileId({
106
- ...this.remote,
107
- releaseId,
108
- attachFileId: asset.id
109
- }).catch((e) => this.logger.error(e));
110
- }
111
- }
112
- this.client.postV5ReposOwnerRepoReleasesReleaseIdAttachFiles({
113
- ...this.remote,
114
- releaseId,
115
- file: new File([fileBuffer], basename(file), { type: "application/octet-stream" })
116
- });
117
- }
118
- get remote() {
119
- const [owner, repo] = this.ctx.release.gitee.repository.split("/");
120
- return {
121
- owner,
122
- repo
123
- };
124
- }
125
- }
126
-
127
- export { Gitee as default };
@@ -1,25 +0,0 @@
1
- import { globbySync } from 'globby';
2
- import { isCI } from 'std-env';
3
- import { B as Base } from './zotero-plugin-scaffold.c7c8af0c.mjs';
4
-
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => {
8
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- return value;
10
- };
11
- class ReleaseBase extends Base {
12
- constructor(ctx) {
13
- super(ctx);
14
- __publicField(this, "isCI");
15
- this.isCI = isCI;
16
- }
17
- checkFiles() {
18
- const { dist } = this.ctx;
19
- if (globbySync(`${dist}/*.xpi`).length === 0) {
20
- throw new Error("No xpi file found, are you sure you have run build?");
21
- }
22
- }
23
- }
24
-
25
- export { ReleaseBase as R };