zotero-plugin-scaffold 0.0.29 → 0.0.31
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 +1 -1
- package/dist/index.d.mts +9 -6
- package/dist/index.d.ts +9 -6
- package/dist/index.mjs +19 -11
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
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
|
|
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
|
-
* @
|
|
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():
|
|
403
|
+
esbuild(): Promise<esbuild.BuildResult<esbuild.BuildOptions>[]> | undefined;
|
|
401
404
|
makeUpdateJson(): void;
|
|
402
405
|
pack(): Promise<void>;
|
|
403
406
|
}
|
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
|
|
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
|
-
* @
|
|
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():
|
|
403
|
+
esbuild(): Promise<esbuild.BuildResult<esbuild.BuildOptions>[]> | undefined;
|
|
401
404
|
makeUpdateJson(): void;
|
|
402
405
|
pack(): Promise<void>;
|
|
403
406
|
}
|
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 {
|
|
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,7 +126,7 @@ function resolveConfig(config) {
|
|
|
123
126
|
}
|
|
124
127
|
const getDefaultConfig = () => defaultConfig;
|
|
125
128
|
const defaultConfig = {
|
|
126
|
-
source:
|
|
129
|
+
source: "src",
|
|
127
130
|
dist: "build",
|
|
128
131
|
name: "",
|
|
129
132
|
id: "",
|
|
@@ -131,7 +134,7 @@ const defaultConfig = {
|
|
|
131
134
|
xpiDownloadLink: "https://github.com/{{owner}}/{{repo}}/releases/download/v{{version}}/{{xpiName}}.xpi",
|
|
132
135
|
updateURL: "https://github.com/{{owner}}/{{repo}}/releases/download/release/update.json",
|
|
133
136
|
build: {
|
|
134
|
-
assets:
|
|
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
|
});
|
|
@@ -334,6 +337,7 @@ class Build extends Base {
|
|
|
334
337
|
...userData,
|
|
335
338
|
...this.name && { name: this.name },
|
|
336
339
|
...this.version && { version: this.version },
|
|
340
|
+
manifest_version: 2,
|
|
337
341
|
applications: {
|
|
338
342
|
//@ts-ignore 此处不包含版本限制
|
|
339
343
|
zotero: {
|
|
@@ -363,7 +367,9 @@ class Build extends Base {
|
|
|
363
367
|
);
|
|
364
368
|
this.logger.debug("replace map: ", replaceMap);
|
|
365
369
|
const replaceResult = replaceInFile.sync({
|
|
366
|
-
files: this.ctx.build.assets.map(
|
|
370
|
+
files: toArray(this.ctx.build.assets).map(
|
|
371
|
+
(asset) => `${this.dist}/${asset}`
|
|
372
|
+
),
|
|
367
373
|
from: Array.from(replaceMap.keys()),
|
|
368
374
|
to: Array.from(replaceMap.values()),
|
|
369
375
|
countMatches: true
|
|
@@ -432,9 +438,11 @@ class Build extends Base {
|
|
|
432
438
|
esbuild() {
|
|
433
439
|
if (this.ctx.build.esbuildOptions.length == 0)
|
|
434
440
|
return;
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
441
|
+
return Promise.all(
|
|
442
|
+
this.ctx.build.esbuildOptions.map(
|
|
443
|
+
(esbuildOption) => build(esbuildOption)
|
|
444
|
+
)
|
|
445
|
+
);
|
|
438
446
|
}
|
|
439
447
|
makeUpdateJson() {
|
|
440
448
|
const manifest = fs.readJSONSync(
|
|
@@ -757,8 +765,8 @@ class Serve extends Base {
|
|
|
757
765
|
const onChange = debounce({ delay: 500 }, async (path2) => {
|
|
758
766
|
try {
|
|
759
767
|
await this.ctx.hooks.callHook("serve:onChanged", this.ctx, path2);
|
|
760
|
-
if (path2.endsWith(".ts")) {
|
|
761
|
-
this.builder.esbuild();
|
|
768
|
+
if (path2.endsWith(".ts") || path2.endsWith(".tsx")) {
|
|
769
|
+
await this.builder.esbuild();
|
|
762
770
|
} else {
|
|
763
771
|
await this.builder.run();
|
|
764
772
|
}
|