zotero-plugin-scaffold 0.0.28 → 0.0.30

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/cli.mjs CHANGED
@@ -24,7 +24,7 @@ import 'chokidar';
24
24
  import 'process';
25
25
 
26
26
  const name = "zotero-plugin-scaffold";
27
- const version = "0.0.28";
27
+ const version = "0.0.30";
28
28
  const description = "A scaffold for Zotero plugin development.";
29
29
  const scripts = {
30
30
  dev: "unbuild --stub",
package/dist/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { VersionBumpOptions } from 'bumpp';
2
+ import * as esbuild from 'esbuild';
2
3
  import { BuildOptions } from 'esbuild';
3
4
  import { Hookable } from 'hookable';
4
5
  import { ConsolaInstance } from 'consola';
@@ -71,9 +72,9 @@ interface Config$1 {
71
72
  *
72
73
  * 可以是多个目录,将在 `server` 运行时监听这些目录的变更。
73
74
  *
74
- * @default ["src"]
75
+ * @default "src"
75
76
  */
76
- source: string[];
77
+ source: string | string[];
77
78
  /**
78
79
  * The build directories.
79
80
  *
@@ -162,9 +163,11 @@ interface BuildConfig {
162
163
  *
163
164
  * @see {@link https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax | Pattern syntax | 语法说明 }
164
165
  *
165
- * @default `["src/**\/*.*", "!src/**\/*.ts"]` (no `\`)
166
+ * @example `["src/**\/*.*", "!src/**\/*.ts"]` (no `\`)
167
+ *
168
+ * @default "addon/**\/*.*" (no `\`)
166
169
  */
167
- assets: string[];
170
+ assets: string | string[];
168
171
  /**
169
172
  * placeholders to replace in static assets
170
173
  *
@@ -363,7 +366,7 @@ declare abstract class Base {
363
366
  logger: ConsolaInstance;
364
367
  constructor(ctx: Context);
365
368
  get dist(): string;
366
- get src(): string[];
369
+ get src(): string | string[];
367
370
  get version(): string;
368
371
  get name(): string;
369
372
  get id(): string;
@@ -397,7 +400,7 @@ declare class Build extends Base {
397
400
  */
398
401
  replaceString(): void;
399
402
  prepareLocaleFiles(): void;
400
- esbuild(): void;
403
+ esbuild(): Promise<esbuild.BuildResult<esbuild.BuildOptions>[]> | undefined;
401
404
  makeUpdateJson(): void;
402
405
  pack(): Promise<void>;
403
406
  }
@@ -518,7 +521,7 @@ declare class Release extends Base {
518
521
  rocket: number;
519
522
  } | undefined;
520
523
  } | undefined>;
521
- creatRelease(options: Parameters<Octokit["rest"]["repos"]["createRelease"]>[0]): Promise<{
524
+ createRelease(options: Parameters<Octokit["rest"]["repos"]["createRelease"]>[0]): Promise<{
522
525
  url: string;
523
526
  html_url: string;
524
527
  assets_url: string;
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { VersionBumpOptions } from 'bumpp';
2
+ import * as esbuild from 'esbuild';
2
3
  import { BuildOptions } from 'esbuild';
3
4
  import { Hookable } from 'hookable';
4
5
  import { ConsolaInstance } from 'consola';
@@ -71,9 +72,9 @@ interface Config$1 {
71
72
  *
72
73
  * 可以是多个目录,将在 `server` 运行时监听这些目录的变更。
73
74
  *
74
- * @default ["src"]
75
+ * @default "src"
75
76
  */
76
- source: string[];
77
+ source: string | string[];
77
78
  /**
78
79
  * The build directories.
79
80
  *
@@ -162,9 +163,11 @@ interface BuildConfig {
162
163
  *
163
164
  * @see {@link https://github.com/mrmlnc/fast-glob?tab=readme-ov-file#pattern-syntax | Pattern syntax | 语法说明 }
164
165
  *
165
- * @default `["src/**\/*.*", "!src/**\/*.ts"]` (no `\`)
166
+ * @example `["src/**\/*.*", "!src/**\/*.ts"]` (no `\`)
167
+ *
168
+ * @default "addon/**\/*.*" (no `\`)
166
169
  */
167
- assets: string[];
170
+ assets: string | string[];
168
171
  /**
169
172
  * placeholders to replace in static assets
170
173
  *
@@ -363,7 +366,7 @@ declare abstract class Base {
363
366
  logger: ConsolaInstance;
364
367
  constructor(ctx: Context);
365
368
  get dist(): string;
366
- get src(): string[];
369
+ get src(): string | string[];
367
370
  get version(): string;
368
371
  get name(): string;
369
372
  get id(): string;
@@ -397,7 +400,7 @@ declare class Build extends Base {
397
400
  */
398
401
  replaceString(): void;
399
402
  prepareLocaleFiles(): void;
400
- esbuild(): void;
403
+ esbuild(): Promise<esbuild.BuildResult<esbuild.BuildOptions>[]> | undefined;
401
404
  makeUpdateJson(): void;
402
405
  pack(): Promise<void>;
403
406
  }
@@ -518,7 +521,7 @@ declare class Release extends Base {
518
521
  rocket: number;
519
522
  } | undefined;
520
523
  } | undefined>;
521
- creatRelease(options: Parameters<Octokit["rest"]["repos"]["createRelease"]>[0]): Promise<{
524
+ createRelease(options: Parameters<Octokit["rest"]["repos"]["createRelease"]>[0]): Promise<{
522
525
  url: string;
523
526
  html_url: string;
524
527
  assets_url: string;
package/dist/index.mjs CHANGED
@@ -8,7 +8,7 @@ import { createHooks } from 'hookable';
8
8
  import path, { join, basename } from 'path';
9
9
  import { dash, template, assign, debounce } from 'radash';
10
10
  import * as crypto from 'crypto';
11
- import { buildSync } from 'esbuild';
11
+ import { build } from 'esbuild';
12
12
  import glob from 'fast-glob';
13
13
  import replaceInFile from 'replace-in-file';
14
14
  import webext from 'web-ext';
@@ -76,6 +76,9 @@ function dateFormat(fmt, date) {
76
76
  }
77
77
  return fmt;
78
78
  }
79
+ function toArray(value) {
80
+ return Array.isArray(value) ? value : [value];
81
+ }
79
82
 
80
83
  const defineConfig = (userConfig) => {
81
84
  return userConfig;
@@ -123,15 +126,15 @@ function resolveConfig(config) {
123
126
  }
124
127
  const getDefaultConfig = () => defaultConfig;
125
128
  const defaultConfig = {
126
- source: ["src"],
129
+ source: "src",
127
130
  dist: "build",
128
131
  name: "",
129
132
  id: "",
130
133
  namespace: "",
131
- xpiDownloadLink: "https://github.com/{{owner}}/{{repo}}/release/download/v{{version}}/{{xpiName}}.xpi",
132
- updateURL: "https://github.com/{{owner}}/{{repo}}/release/download/release/update.json",
134
+ xpiDownloadLink: "https://github.com/{{owner}}/{{repo}}/releases/download/v{{version}}/{{xpiName}}.xpi",
135
+ updateURL: "https://github.com/{{owner}}/{{repo}}/releases/download/release/update.json",
133
136
  build: {
134
- assets: ["src/**/*.*", "!src/**/*.ts"],
137
+ assets: "addon/**/*.*",
135
138
  define: {},
136
139
  fluent: {
137
140
  prefixFluentMessages: true,
@@ -292,7 +295,7 @@ class Build extends Base {
292
295
  this.replaceString();
293
296
  await this.ctx.hooks.callHook("build:replace", this.ctx);
294
297
  this.logger.info("Running esbuild");
295
- this.esbuild();
298
+ await this.esbuild();
296
299
  await this.ctx.hooks.callHook("build:bundle", this.ctx);
297
300
  this.logger.info("Addon prepare OK.");
298
301
  if (process.env.NODE_ENV === "production") {
@@ -314,7 +317,7 @@ class Build extends Base {
314
317
  copyAssets() {
315
318
  const files = glob.sync(this.ctx.build.assets);
316
319
  files.forEach((file) => {
317
- const newPath = `${this.dist}/addon/${file.replace(new RegExp(this.src.join("|")), "")}`;
320
+ const newPath = `${this.dist}/addon/${file.replace(new RegExp(toArray(this.src).join("|")), "")}`;
318
321
  this.logger.debug(`Copy ${file} to ${newPath}`);
319
322
  fs.copySync(file, newPath);
320
323
  });
@@ -363,7 +366,9 @@ class Build extends Base {
363
366
  );
364
367
  this.logger.debug("replace map: ", replaceMap);
365
368
  const replaceResult = replaceInFile.sync({
366
- files: this.ctx.build.assets.map((asset) => `${this.dist}/${asset}`),
369
+ files: toArray(this.ctx.build.assets).map(
370
+ (asset) => `${this.dist}/${asset}`
371
+ ),
367
372
  from: Array.from(replaceMap.keys()),
368
373
  to: Array.from(replaceMap.values()),
369
374
  countMatches: true
@@ -432,9 +437,11 @@ class Build extends Base {
432
437
  esbuild() {
433
438
  if (this.ctx.build.esbuildOptions.length == 0)
434
439
  return;
435
- this.ctx.build.esbuildOptions.forEach(async (esbuildOption) => {
436
- buildSync(esbuildOption);
437
- });
440
+ return Promise.all(
441
+ this.ctx.build.esbuildOptions.map(
442
+ (esbuildOption) => build(esbuildOption)
443
+ )
444
+ );
438
445
  }
439
446
  makeUpdateJson() {
440
447
  const manifest = fs.readJSONSync(
@@ -538,7 +545,7 @@ class Release extends Base {
538
545
  * Create new release and upload XPI to asset
539
546
  */
540
547
  async uploadXPI() {
541
- const release = await this.creatRelease({
548
+ const release = await this.createRelease({
542
549
  owner: this.owner,
543
550
  repo: this.repo,
544
551
  tag_name: this.ctx.release.bumpp.tag.toString().replaceAll("%s", this.version),
@@ -566,7 +573,7 @@ class Release extends Base {
566
573
  }
567
574
  });
568
575
  }
569
- async creatRelease(options) {
576
+ async createRelease(options) {
570
577
  this.logger.debug("Creating release...", options);
571
578
  return await this.client.rest.repos.createRelease(options).catch((e) => {
572
579
  this.logger.error(e);
@@ -594,7 +601,7 @@ class Release extends Base {
594
601
  }
595
602
  async refreshUpdateManifest() {
596
603
  const assets = glob.globSync(`${this.dist}/*.json`).map((p) => basename(p));
597
- const release = await this.getReleaseByTag("release") ?? await this.creatRelease({
604
+ const release = await this.getReleaseByTag("release") ?? await this.createRelease({
598
605
  owner: this.owner,
599
606
  repo: this.repo,
600
607
  tag_name: "release",
@@ -758,7 +765,7 @@ class Serve extends Base {
758
765
  try {
759
766
  await this.ctx.hooks.callHook("serve:onChanged", this.ctx, path2);
760
767
  if (path2.endsWith(".ts")) {
761
- this.builder.esbuild();
768
+ await this.builder.esbuild();
762
769
  } else {
763
770
  await this.builder.run();
764
771
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "description": "A scaffold for Zotero plugin development.",
5
5
  "type": "module",
6
6
  "exports": {