zotero-plugin-scaffold 0.2.3 → 0.2.6
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.d.mts +2 -2
- package/dist/cli.d.ts +2 -2
- package/dist/cli.mjs +11 -8
- package/dist/index.d.mts +42 -27
- package/dist/index.d.ts +42 -27
- package/dist/index.mjs +1 -1
- package/dist/shared/{zotero-plugin-scaffold.BglL0tS0.mjs → zotero-plugin-scaffold.BfbnPYjV.mjs} +191 -115
- package/package.json +3 -3
package/dist/cli.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function
|
|
1
|
+
declare function mainWithErrorHandler(): Promise<void>;
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { mainWithErrorHandler as default };
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
declare function
|
|
1
|
+
declare function mainWithErrorHandler(): Promise<void>;
|
|
2
2
|
|
|
3
|
-
export {
|
|
3
|
+
export { mainWithErrorHandler as default };
|
package/dist/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import process from 'node:process';
|
|
2
|
-
import { Command } from '
|
|
3
|
-
import { E as ExitSignals, l as logger, C as Config, B as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { E as ExitSignals, l as logger, C as Config, B as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.BfbnPYjV.mjs';
|
|
4
4
|
import { readFile, writeFile } from 'node:fs/promises';
|
|
5
5
|
import { pathExists, ensureFile } from 'fs-extra';
|
|
6
6
|
import tinyUpdateNotifier from 'tiny-update-notifier';
|
|
@@ -32,8 +32,8 @@ import 'xvfb-ts';
|
|
|
32
32
|
|
|
33
33
|
const name = "zotero-plugin-scaffold";
|
|
34
34
|
const type = "module";
|
|
35
|
-
const version = "0.2.
|
|
36
|
-
const packageManager = "pnpm@
|
|
35
|
+
const version = "0.2.6";
|
|
36
|
+
const packageManager = "pnpm@10.2.0";
|
|
37
37
|
const description = "A scaffold for Zotero plugin development.";
|
|
38
38
|
const author = "northword";
|
|
39
39
|
const license = "AGPL-3.0-or-later";
|
|
@@ -100,8 +100,7 @@ const peerDependenciesMeta = {
|
|
|
100
100
|
}
|
|
101
101
|
};
|
|
102
102
|
const dependencies = {
|
|
103
|
-
"@
|
|
104
|
-
"@swc/core": "^1.10.12",
|
|
103
|
+
"@swc/core": "^1.10.14",
|
|
105
104
|
"adm-zip": "^0.5.16",
|
|
106
105
|
bumpp: "^10.0.1",
|
|
107
106
|
c12: "^2.0.1",
|
|
@@ -119,6 +118,7 @@ const dependencies = {
|
|
|
119
118
|
"xvfb-ts": "^1.1.0"
|
|
120
119
|
};
|
|
121
120
|
const devDependencies = {
|
|
121
|
+
"@commander-js/extra-typings": "^13.1.0",
|
|
122
122
|
"@types/adm-zip": "^0.5.7",
|
|
123
123
|
"@types/fs-extra": "^11.0.4"
|
|
124
124
|
};
|
|
@@ -225,7 +225,7 @@ async function main() {
|
|
|
225
225
|
});
|
|
226
226
|
cli.parse();
|
|
227
227
|
}
|
|
228
|
-
async function
|
|
228
|
+
async function mainWithErrorHandler() {
|
|
229
229
|
main().then(() => {
|
|
230
230
|
checkGitIgnore();
|
|
231
231
|
}).catch(onError);
|
|
@@ -233,7 +233,10 @@ async function run() {
|
|
|
233
233
|
}
|
|
234
234
|
function onError(err) {
|
|
235
235
|
logger.error(err);
|
|
236
|
+
if (err.output) {
|
|
237
|
+
logger.log(err.output.stderr);
|
|
238
|
+
}
|
|
236
239
|
process.exit(1);
|
|
237
240
|
}
|
|
238
241
|
|
|
239
|
-
export {
|
|
242
|
+
export { mainWithErrorHandler as default };
|
package/dist/index.d.mts
CHANGED
|
@@ -3,39 +3,54 @@ import * as esbuild from 'esbuild';
|
|
|
3
3
|
import { BuildOptions } from 'esbuild';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Log level
|
|
6
|
+
* Log level enumeration
|
|
7
7
|
*/
|
|
8
8
|
declare enum LOG_LEVEL {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
TRACE = 0,
|
|
10
|
+
DEBUG = 1,
|
|
11
|
+
INFO = 2,
|
|
12
|
+
WARN = 3,
|
|
13
|
+
ERROR = 4
|
|
14
14
|
}
|
|
15
15
|
type LogLevelType = keyof typeof LOG_LEVEL;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
interface LoggerOptions {
|
|
17
|
+
space?: number;
|
|
18
|
+
newLine?: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare class Logger {
|
|
20
21
|
private static instance;
|
|
21
|
-
private
|
|
22
|
-
constructor(
|
|
23
|
-
|
|
22
|
+
private currentLogLevel;
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Determine the appropriate log level
|
|
26
|
+
*/
|
|
27
|
+
private determineLogLevel;
|
|
28
|
+
static getInstance(): Logger;
|
|
24
29
|
setLogLevel(level: LogLevelType): void;
|
|
25
|
-
get level():
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
get level(): LOG_LEVEL;
|
|
31
|
+
/**
|
|
32
|
+
* Generic log formatting logic
|
|
33
|
+
*/
|
|
34
|
+
private formatContent;
|
|
35
|
+
private formatError;
|
|
36
|
+
/**
|
|
37
|
+
* Core logging method
|
|
38
|
+
*/
|
|
39
|
+
private logInternal;
|
|
40
|
+
error(content: unknown, options?: LoggerOptions): void;
|
|
41
|
+
warn(content: unknown, options?: LoggerOptions): void;
|
|
42
|
+
tip(content: unknown, options?: LoggerOptions): void;
|
|
43
|
+
info(content: unknown, options?: LoggerOptions): void;
|
|
44
|
+
debug(content: unknown, options?: LoggerOptions): void;
|
|
45
|
+
success(content: unknown, options?: LoggerOptions): void;
|
|
46
|
+
fail(content: unknown, options?: LoggerOptions): void;
|
|
47
|
+
ready(content: unknown): void;
|
|
37
48
|
clear(): void;
|
|
38
49
|
newLine(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Direct passthrough to console.log
|
|
52
|
+
*/
|
|
53
|
+
log(content: unknown): void;
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
interface Manifest {
|
|
@@ -771,7 +786,7 @@ interface Context extends Config$1 {
|
|
|
771
786
|
pkgUser: any;
|
|
772
787
|
version: string;
|
|
773
788
|
hooks: Hookable<Hooks>;
|
|
774
|
-
logger:
|
|
789
|
+
logger: Logger;
|
|
775
790
|
templateData: TemplateData;
|
|
776
791
|
}
|
|
777
792
|
interface TemplateData {
|
|
@@ -802,7 +817,7 @@ declare abstract class Base {
|
|
|
802
817
|
ctx: Context;
|
|
803
818
|
constructor(ctx: Context);
|
|
804
819
|
abstract run(): any;
|
|
805
|
-
get logger():
|
|
820
|
+
get logger(): Logger;
|
|
806
821
|
}
|
|
807
822
|
|
|
808
823
|
declare class Build extends Base {
|
package/dist/index.d.ts
CHANGED
|
@@ -3,39 +3,54 @@ import * as esbuild from 'esbuild';
|
|
|
3
3
|
import { BuildOptions } from 'esbuild';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Log level
|
|
6
|
+
* Log level enumeration
|
|
7
7
|
*/
|
|
8
8
|
declare enum LOG_LEVEL {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
TRACE = 0,
|
|
10
|
+
DEBUG = 1,
|
|
11
|
+
INFO = 2,
|
|
12
|
+
WARN = 3,
|
|
13
|
+
ERROR = 4
|
|
14
14
|
}
|
|
15
15
|
type LogLevelType = keyof typeof LOG_LEVEL;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
interface LoggerOptions {
|
|
17
|
+
space?: number;
|
|
18
|
+
newLine?: boolean;
|
|
19
|
+
}
|
|
20
|
+
declare class Logger {
|
|
20
21
|
private static instance;
|
|
21
|
-
private
|
|
22
|
-
constructor(
|
|
23
|
-
|
|
22
|
+
private currentLogLevel;
|
|
23
|
+
private constructor();
|
|
24
|
+
/**
|
|
25
|
+
* Determine the appropriate log level
|
|
26
|
+
*/
|
|
27
|
+
private determineLogLevel;
|
|
28
|
+
static getInstance(): Logger;
|
|
24
29
|
setLogLevel(level: LogLevelType): void;
|
|
25
|
-
get level():
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
30
|
+
get level(): LOG_LEVEL;
|
|
31
|
+
/**
|
|
32
|
+
* Generic log formatting logic
|
|
33
|
+
*/
|
|
34
|
+
private formatContent;
|
|
35
|
+
private formatError;
|
|
36
|
+
/**
|
|
37
|
+
* Core logging method
|
|
38
|
+
*/
|
|
39
|
+
private logInternal;
|
|
40
|
+
error(content: unknown, options?: LoggerOptions): void;
|
|
41
|
+
warn(content: unknown, options?: LoggerOptions): void;
|
|
42
|
+
tip(content: unknown, options?: LoggerOptions): void;
|
|
43
|
+
info(content: unknown, options?: LoggerOptions): void;
|
|
44
|
+
debug(content: unknown, options?: LoggerOptions): void;
|
|
45
|
+
success(content: unknown, options?: LoggerOptions): void;
|
|
46
|
+
fail(content: unknown, options?: LoggerOptions): void;
|
|
47
|
+
ready(content: unknown): void;
|
|
37
48
|
clear(): void;
|
|
38
49
|
newLine(): void;
|
|
50
|
+
/**
|
|
51
|
+
* Direct passthrough to console.log
|
|
52
|
+
*/
|
|
53
|
+
log(content: unknown): void;
|
|
39
54
|
}
|
|
40
55
|
|
|
41
56
|
interface Manifest {
|
|
@@ -771,7 +786,7 @@ interface Context extends Config$1 {
|
|
|
771
786
|
pkgUser: any;
|
|
772
787
|
version: string;
|
|
773
788
|
hooks: Hookable<Hooks>;
|
|
774
|
-
logger:
|
|
789
|
+
logger: Logger;
|
|
775
790
|
templateData: TemplateData;
|
|
776
791
|
}
|
|
777
792
|
interface TemplateData {
|
|
@@ -802,7 +817,7 @@ declare abstract class Base {
|
|
|
802
817
|
ctx: Context;
|
|
803
818
|
constructor(ctx: Context);
|
|
804
819
|
abstract run(): any;
|
|
805
|
-
get logger():
|
|
820
|
+
get logger(): Logger;
|
|
806
821
|
}
|
|
807
822
|
|
|
808
823
|
declare class Build extends Base {
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as Build, C as Config, R as Release, S as Serve, T as Test, d as defineConfig } from './shared/zotero-plugin-scaffold.
|
|
1
|
+
export { B as Build, C as Config, R as Release, S as Serve, T as Test, d as defineConfig } from './shared/zotero-plugin-scaffold.BfbnPYjV.mjs';
|
|
2
2
|
import 'c12';
|
|
3
3
|
import 'es-toolkit';
|
|
4
4
|
import 'fs-extra/esm';
|
package/dist/shared/{zotero-plugin-scaffold.BglL0tS0.mjs → zotero-plugin-scaffold.BfbnPYjV.mjs}
RENAMED
|
@@ -27,101 +27,170 @@ import http from 'node:http';
|
|
|
27
27
|
import { Xvfb } from 'xvfb-ts';
|
|
28
28
|
|
|
29
29
|
var LOG_LEVEL = /* @__PURE__ */ ((LOG_LEVEL2) => {
|
|
30
|
-
LOG_LEVEL2[LOG_LEVEL2["
|
|
31
|
-
LOG_LEVEL2[LOG_LEVEL2["
|
|
32
|
-
LOG_LEVEL2[LOG_LEVEL2["
|
|
33
|
-
LOG_LEVEL2[LOG_LEVEL2["
|
|
34
|
-
LOG_LEVEL2[LOG_LEVEL2["
|
|
30
|
+
LOG_LEVEL2[LOG_LEVEL2["TRACE"] = 0] = "TRACE";
|
|
31
|
+
LOG_LEVEL2[LOG_LEVEL2["DEBUG"] = 1] = "DEBUG";
|
|
32
|
+
LOG_LEVEL2[LOG_LEVEL2["INFO"] = 2] = "INFO";
|
|
33
|
+
LOG_LEVEL2[LOG_LEVEL2["WARN"] = 3] = "WARN";
|
|
34
|
+
LOG_LEVEL2[LOG_LEVEL2["ERROR"] = 4] = "ERROR";
|
|
35
35
|
return LOG_LEVEL2;
|
|
36
36
|
})(LOG_LEVEL || {});
|
|
37
|
-
|
|
37
|
+
const SYMBOLS = {
|
|
38
|
+
SUCCESS: chalk.green("\u2714"),
|
|
39
|
+
INFO: chalk.blue("\u2139"),
|
|
40
|
+
FAIL: chalk.red("\u2716"),
|
|
41
|
+
TIP: chalk.blue("\u2192"),
|
|
42
|
+
ERROR: chalk.bgRed(" ERROR "),
|
|
43
|
+
WARN: chalk.bgYellow(" WARN "),
|
|
44
|
+
DEBUG: chalk.grey("\u2699"),
|
|
45
|
+
NONE: ""
|
|
46
|
+
};
|
|
47
|
+
const DEFAULT_OPTIONS = {
|
|
48
|
+
SPACE: 0,
|
|
49
|
+
LEVEL: 2 /* INFO */,
|
|
50
|
+
SYMBOL: "",
|
|
51
|
+
NEW_LINE: false
|
|
52
|
+
};
|
|
53
|
+
const LOG_METHODS_CONFIG = {
|
|
54
|
+
error: {
|
|
55
|
+
level: 4 /* ERROR */,
|
|
56
|
+
symbol: SYMBOLS.ERROR,
|
|
57
|
+
wrapNewLine: true
|
|
58
|
+
},
|
|
59
|
+
warn: {
|
|
60
|
+
level: 3 /* WARN */,
|
|
61
|
+
symbol: SYMBOLS.WARN,
|
|
62
|
+
wrapNewLine: true
|
|
63
|
+
},
|
|
64
|
+
tip: {
|
|
65
|
+
level: 2 /* INFO */,
|
|
66
|
+
symbol: SYMBOLS.TIP
|
|
67
|
+
},
|
|
68
|
+
info: {
|
|
69
|
+
level: 2 /* INFO */,
|
|
70
|
+
symbol: SYMBOLS.INFO
|
|
71
|
+
},
|
|
72
|
+
debug: {
|
|
73
|
+
level: 1 /* DEBUG */,
|
|
74
|
+
symbol: SYMBOLS.DEBUG
|
|
75
|
+
},
|
|
76
|
+
success: {
|
|
77
|
+
level: 2 /* INFO */,
|
|
78
|
+
symbol: SYMBOLS.SUCCESS
|
|
79
|
+
},
|
|
80
|
+
ready: {
|
|
81
|
+
level: 2 /* INFO */,
|
|
82
|
+
symbol: SYMBOLS.SUCCESS,
|
|
83
|
+
wrapNewLine: true
|
|
84
|
+
},
|
|
85
|
+
fail: {
|
|
86
|
+
level: 4 /* ERROR */,
|
|
87
|
+
symbol: SYMBOLS.FAIL
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
class Logger {
|
|
38
91
|
static instance;
|
|
39
|
-
|
|
92
|
+
currentLogLevel;
|
|
40
93
|
constructor(level) {
|
|
94
|
+
this.currentLogLevel = this.determineLogLevel(level);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Determine the appropriate log level
|
|
98
|
+
*/
|
|
99
|
+
determineLogLevel(level) {
|
|
41
100
|
if (isDebug)
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
else if (level)
|
|
46
|
-
this.logLevel = level;
|
|
47
|
-
else
|
|
48
|
-
this.logLevel = 2 /* info */;
|
|
101
|
+
return 0 /* TRACE */;
|
|
102
|
+
const envLevel = process.env.ZOTERO_PLUGIN_LOG_LEVEL;
|
|
103
|
+
return envLevel ? LOG_LEVEL[envLevel] : level ?? 2 /* INFO */;
|
|
49
104
|
}
|
|
50
105
|
static getInstance() {
|
|
51
|
-
if (!
|
|
52
|
-
|
|
106
|
+
if (!Logger.instance) {
|
|
107
|
+
Logger.instance = new Logger();
|
|
53
108
|
}
|
|
54
|
-
return
|
|
109
|
+
return Logger.instance;
|
|
55
110
|
}
|
|
56
111
|
setLogLevel(level) {
|
|
57
|
-
this.
|
|
112
|
+
this.currentLogLevel = LOG_LEVEL[level];
|
|
58
113
|
}
|
|
59
114
|
get level() {
|
|
60
|
-
return this.
|
|
61
|
-
}
|
|
62
|
-
formatArgs(arg) {
|
|
63
|
-
if (typeof arg === "string")
|
|
64
|
-
return arg;
|
|
65
|
-
if (arg instanceof Error) {
|
|
66
|
-
return `${chalk.red(arg.name)}: ${chalk.red(arg.message)}
|
|
67
|
-
${arg.stack}`;
|
|
68
|
-
}
|
|
69
|
-
if (typeof arg === "object" && arg !== null && isPlainObject(arg)) {
|
|
70
|
-
return JSON.stringify(arg, null, 2);
|
|
71
|
-
}
|
|
72
|
-
return arg;
|
|
115
|
+
return this.currentLogLevel;
|
|
73
116
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Generic log formatting logic
|
|
119
|
+
*/
|
|
120
|
+
formatContent(content) {
|
|
121
|
+
if (typeof content === "string")
|
|
122
|
+
return content;
|
|
123
|
+
if (content instanceof Error)
|
|
124
|
+
return this.formatError(content);
|
|
125
|
+
if (isPlainObject(content))
|
|
126
|
+
return JSON.stringify(content, null, 2);
|
|
127
|
+
return String(content);
|
|
128
|
+
}
|
|
129
|
+
formatError(error) {
|
|
130
|
+
return `${chalk.red(error.name)}: ${chalk.red(error.message)}
|
|
131
|
+
${error.stack}`;
|
|
79
132
|
}
|
|
80
|
-
|
|
81
|
-
|
|
133
|
+
/**
|
|
134
|
+
* Core logging method
|
|
135
|
+
*/
|
|
136
|
+
logInternal(content, config, options = {}) {
|
|
137
|
+
if (this.currentLogLevel > config.level)
|
|
138
|
+
return;
|
|
139
|
+
const { space = DEFAULT_OPTIONS.SPACE, newLine = DEFAULT_OPTIONS.NEW_LINE } = options;
|
|
140
|
+
const formattedContent = this.formatContent(content);
|
|
141
|
+
const output = [
|
|
142
|
+
" ".repeat(space),
|
|
143
|
+
config.symbol,
|
|
144
|
+
formattedContent
|
|
145
|
+
].join(" ");
|
|
146
|
+
if (config.wrapNewLine)
|
|
147
|
+
this.newLine();
|
|
148
|
+
console.log(output);
|
|
149
|
+
if (newLine || config.wrapNewLine)
|
|
150
|
+
this.newLine();
|
|
82
151
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
this.newLine();
|
|
152
|
+
// Public API methods
|
|
153
|
+
error(content, options) {
|
|
154
|
+
this.logInternal(content, LOG_METHODS_CONFIG.error, options);
|
|
87
155
|
}
|
|
88
|
-
warn(
|
|
89
|
-
this.
|
|
90
|
-
this.logArgs(3 /* warn */, chalk.bgYellow(" WARN "), ...args);
|
|
91
|
-
this.newLine();
|
|
156
|
+
warn(content, options) {
|
|
157
|
+
this.logInternal(content, LOG_METHODS_CONFIG.warn, options);
|
|
92
158
|
}
|
|
93
|
-
tip(
|
|
94
|
-
this.
|
|
159
|
+
tip(content, options) {
|
|
160
|
+
this.logInternal(content, LOG_METHODS_CONFIG.tip, options);
|
|
95
161
|
}
|
|
96
|
-
info(
|
|
97
|
-
this.
|
|
162
|
+
info(content, options) {
|
|
163
|
+
this.logInternal(content, LOG_METHODS_CONFIG.info, options);
|
|
98
164
|
}
|
|
99
|
-
debug(
|
|
100
|
-
this.
|
|
165
|
+
debug(content, options) {
|
|
166
|
+
this.logInternal(content, LOG_METHODS_CONFIG.debug, options);
|
|
101
167
|
}
|
|
102
|
-
|
|
103
|
-
this.
|
|
104
|
-
this.logArgs(2 /* info */, chalk.green("\u2714", ...args));
|
|
105
|
-
this.newLine();
|
|
168
|
+
success(content, options) {
|
|
169
|
+
this.logInternal(content, LOG_METHODS_CONFIG.success, options);
|
|
106
170
|
}
|
|
107
|
-
|
|
108
|
-
this.
|
|
171
|
+
fail(content, options) {
|
|
172
|
+
this.logInternal(content, LOG_METHODS_CONFIG.fail, options);
|
|
109
173
|
}
|
|
110
|
-
|
|
111
|
-
this.
|
|
174
|
+
ready(content) {
|
|
175
|
+
this.logInternal(chalk.green(content), LOG_METHODS_CONFIG.success);
|
|
112
176
|
}
|
|
113
177
|
clear() {
|
|
114
|
-
const
|
|
115
|
-
const blank = repeatCount > 0 ? "\n".repeat(repeatCount) : "";
|
|
178
|
+
const blank = process.stdout.rows > 2 ? "\n".repeat(process.stdout.rows - 2) : "";
|
|
116
179
|
console.log(blank);
|
|
117
180
|
readline.cursorTo(process.stdout, 0, 0);
|
|
118
181
|
readline.clearScreenDown(process.stdout);
|
|
119
182
|
}
|
|
120
183
|
newLine() {
|
|
121
|
-
console.log(
|
|
184
|
+
console.log();
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Direct passthrough to console.log
|
|
188
|
+
*/
|
|
189
|
+
log(content) {
|
|
190
|
+
console.log(content);
|
|
122
191
|
}
|
|
123
192
|
}
|
|
124
|
-
const logger =
|
|
193
|
+
const logger = Logger.getInstance();
|
|
125
194
|
|
|
126
195
|
function defineConfig(userConfig) {
|
|
127
196
|
return userConfig;
|
|
@@ -268,7 +337,7 @@ const defaultConfig = {
|
|
|
268
337
|
watch: false,
|
|
269
338
|
hooks: {}
|
|
270
339
|
},
|
|
271
|
-
logLevel: "
|
|
340
|
+
logLevel: "INFO"
|
|
272
341
|
};
|
|
273
342
|
const getDefaultConfig = () => defaultConfig;
|
|
274
343
|
|
|
@@ -298,69 +367,74 @@ class PrefsManager {
|
|
|
298
367
|
/**
|
|
299
368
|
* Parse Method 3 - Using AST
|
|
300
369
|
*/
|
|
301
|
-
parse(
|
|
302
|
-
const
|
|
303
|
-
const ast = parseSync(
|
|
370
|
+
parse(content) {
|
|
371
|
+
const _map = {};
|
|
372
|
+
const ast = parseSync(content, { syntax: "ecmascript" });
|
|
304
373
|
for (const node of ast.body) {
|
|
305
374
|
if (node.type !== "ExpressionStatement" || node.expression.type !== "CallExpression" || node.expression.callee.type !== "Identifier" || node.expression.callee.value !== this.namespace || node.expression.arguments.length !== 2) {
|
|
306
375
|
throw new Error("Invalid prefs.js file.");
|
|
307
376
|
}
|
|
308
|
-
|
|
377
|
+
const [arg1, arg2] = node.expression.arguments;
|
|
378
|
+
if (arg1.expression.type !== "StringLiteral") {
|
|
309
379
|
throw new Error("Invalid prefs.js file - unsupported key type.");
|
|
310
380
|
}
|
|
311
|
-
const key =
|
|
381
|
+
const key = arg1.expression.value.trim();
|
|
312
382
|
let value;
|
|
313
|
-
switch (
|
|
383
|
+
switch (arg2.expression.type) {
|
|
314
384
|
// https://babeljs.io/docs/babel-parser#output
|
|
315
385
|
case "StringLiteral":
|
|
316
386
|
case "NumericLiteral":
|
|
317
387
|
case "BooleanLiteral":
|
|
318
|
-
value =
|
|
388
|
+
value = arg2.expression.value;
|
|
319
389
|
break;
|
|
320
390
|
// https://github.com/estree/estree/blob/master/es5.md#unaryexpression
|
|
321
391
|
// https://github.com/northword/zotero-plugin-scaffold/issues/98
|
|
322
392
|
case "UnaryExpression":
|
|
323
|
-
if (
|
|
393
|
+
if (arg2.expression.argument.type !== "NumericLiteral")
|
|
324
394
|
throw new Error("Invalid prefs.js file - unsupported value type.");
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
value = node.expression.arguments[1].expression.argument.value;
|
|
395
|
+
if (arg2.expression.operator === "-")
|
|
396
|
+
value = -arg2.expression.argument.value;
|
|
397
|
+
else if (arg2.expression.operator === "+")
|
|
398
|
+
value = arg2.expression.argument.value;
|
|
330
399
|
else
|
|
331
400
|
throw new Error("Invalid prefs.js file - unsupported value type.");
|
|
332
401
|
break;
|
|
333
402
|
default:
|
|
334
403
|
throw new Error("Invalid prefs.js file - unsupported value type.");
|
|
335
404
|
}
|
|
336
|
-
|
|
405
|
+
_map[key] = value;
|
|
337
406
|
}
|
|
338
|
-
return
|
|
407
|
+
return _map;
|
|
339
408
|
}
|
|
340
409
|
/**
|
|
341
410
|
* Parse Method 1 - Using RegExp
|
|
342
411
|
* @deprecated
|
|
343
412
|
*/
|
|
344
|
-
parseByRegExp(
|
|
345
|
-
const
|
|
413
|
+
parseByRegExp(content) {
|
|
414
|
+
const _map = {};
|
|
346
415
|
const prefPattern = /^(pref|user_pref)\s*\(\s*["']([^"']+)["']\s*,\s*(.+)\s*,?\s*\)\s*;?$/gm;
|
|
347
|
-
const matches =
|
|
416
|
+
const matches = content.matchAll(prefPattern);
|
|
348
417
|
for (const match of matches) {
|
|
349
418
|
const key = match[2].trim();
|
|
350
419
|
const value = match[3].trim();
|
|
351
|
-
|
|
420
|
+
_map[key] = this.cleanValue(value);
|
|
352
421
|
}
|
|
353
|
-
return
|
|
422
|
+
return _map;
|
|
354
423
|
}
|
|
355
424
|
/**
|
|
356
425
|
* Parse Method 2 - Using eval
|
|
357
426
|
* @deprecated
|
|
358
427
|
*/
|
|
359
|
-
parseByEval(content) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
428
|
+
// private parseByEval(content: string) {
|
|
429
|
+
// const _map: Prefs = {};
|
|
430
|
+
// // eslint-disable-next-line unused-imports/no-unused-vars
|
|
431
|
+
// const pref = (key: any, value: any) => {
|
|
432
|
+
// _map[key.trim()] = this.cleanValue(value.trim());
|
|
433
|
+
// };
|
|
434
|
+
// // eslint-disable-next-line no-eval
|
|
435
|
+
// eval(content);
|
|
436
|
+
// return _map;
|
|
437
|
+
// }
|
|
364
438
|
cleanValue(value) {
|
|
365
439
|
if (value === "true")
|
|
366
440
|
return true;
|
|
@@ -380,13 +454,13 @@ class PrefsManager {
|
|
|
380
454
|
}).join("\n");
|
|
381
455
|
}
|
|
382
456
|
async read(path) {
|
|
383
|
-
const
|
|
384
|
-
const map = this.parse(
|
|
457
|
+
const content = await readFile(path, "utf-8");
|
|
458
|
+
const map = this.parse(content);
|
|
385
459
|
this.setPrefs(map);
|
|
386
460
|
}
|
|
387
461
|
async write(path) {
|
|
388
|
-
const
|
|
389
|
-
await outputFile(path,
|
|
462
|
+
const content = this.render();
|
|
463
|
+
await outputFile(path, content, "utf-8");
|
|
390
464
|
logger.debug("The prefs.js has been modified.");
|
|
391
465
|
}
|
|
392
466
|
setPref(key, value) {
|
|
@@ -413,18 +487,18 @@ class PrefsManager {
|
|
|
413
487
|
}
|
|
414
488
|
getPrefsWithPrefix(prefix) {
|
|
415
489
|
const _prefs = {};
|
|
416
|
-
for (const
|
|
417
|
-
if (
|
|
418
|
-
_prefs[
|
|
490
|
+
for (const pref in this.prefs) {
|
|
491
|
+
if (pref.startsWith(prefix))
|
|
492
|
+
_prefs[pref] = this.prefs[pref];
|
|
419
493
|
else
|
|
420
|
-
_prefs[`${prefix}.${
|
|
494
|
+
_prefs[`${prefix}.${pref}`] = this.prefs[pref];
|
|
421
495
|
}
|
|
422
496
|
return _prefs;
|
|
423
497
|
}
|
|
424
498
|
getPrefsWithoutPrefix(prefix) {
|
|
425
499
|
const _prefs = {};
|
|
426
|
-
for (const
|
|
427
|
-
_prefs[
|
|
500
|
+
for (const pref in this.prefs) {
|
|
501
|
+
_prefs[pref.replace(`${prefix}.`, "")] = this.prefs[pref];
|
|
428
502
|
}
|
|
429
503
|
return _prefs;
|
|
430
504
|
}
|
|
@@ -523,7 +597,7 @@ class Build extends Base {
|
|
|
523
597
|
define[key]
|
|
524
598
|
])
|
|
525
599
|
);
|
|
526
|
-
this.logger.debug(
|
|
600
|
+
this.logger.debug(`replace map: ${replaceMap}`);
|
|
527
601
|
await replaceInFile({
|
|
528
602
|
files: newPaths,
|
|
529
603
|
from: Array.from(replaceMap.keys()),
|
|
@@ -555,7 +629,7 @@ class Build extends Base {
|
|
|
555
629
|
}
|
|
556
630
|
};
|
|
557
631
|
const data = toMerged(userData, template);
|
|
558
|
-
this.logger.debug(
|
|
632
|
+
this.logger.debug(`manifest: ${JSON.stringify(data, null, 2)}`);
|
|
559
633
|
outputJSON(`${dist}/addon/manifest.json`, data, { spaces: 2 });
|
|
560
634
|
}
|
|
561
635
|
async prepareLocaleFiles() {
|
|
@@ -565,7 +639,7 @@ class Build extends Base {
|
|
|
565
639
|
const HTML_DATAI10NID_PATTERN = new RegExp(`(data-l10n-id)="((?!${namespace})\\S*)"`, "g");
|
|
566
640
|
const localePaths = await glob(`${dist}/addon/locale/*`, { onlyDirectories: true });
|
|
567
641
|
const localeNames = localePaths.map((locale) => basename(locale));
|
|
568
|
-
this.logger.debug(
|
|
642
|
+
this.logger.debug(`Locale names:", ${localeNames}`);
|
|
569
643
|
const allMessages = /* @__PURE__ */ new Set();
|
|
570
644
|
const messagesByLocale = /* @__PURE__ */ new Map();
|
|
571
645
|
for (const localeName of localeNames) {
|
|
@@ -750,7 +824,7 @@ class Bump extends Base {
|
|
|
750
824
|
this.ctx.version = result.newVersion;
|
|
751
825
|
this.ctx.release.bumpp.tag = result.tag || this.ctx.release.bumpp.tag.toString().replace("%s", result.newVersion);
|
|
752
826
|
this.ctx.release.bumpp.commit = result.commit || this.ctx.release.bumpp.commit.toString().replace("%s", result.newVersion);
|
|
753
|
-
this.logger.debug(
|
|
827
|
+
this.logger.debug(`The release context after bump: ", ${this.ctx.release}`);
|
|
754
828
|
}
|
|
755
829
|
/**
|
|
756
830
|
* bumpp 显示进度的回调
|
|
@@ -863,7 +937,8 @@ class GitHub extends ReleaseBase {
|
|
|
863
937
|
});
|
|
864
938
|
}
|
|
865
939
|
async createRelease(options) {
|
|
866
|
-
this.logger.debug("Creating release..."
|
|
940
|
+
this.logger.debug("Creating release...");
|
|
941
|
+
this.logger.debug(options);
|
|
867
942
|
return await this.client.rest.repos.createRelease(options).catch((e) => {
|
|
868
943
|
this.logger.error(e);
|
|
869
944
|
throw new Error("Create release failed.");
|
|
@@ -989,7 +1064,7 @@ class Release extends Base {
|
|
|
989
1064
|
this.logger.warn(`The current release needs to run the build after bumping the version number, please configure the build script in 'config.release.bumpp.execute'${isBumpNeeded ? "" : " or run build before run release"}.`);
|
|
990
1065
|
this.ctx.release.bumpp.execute ||= "npm run build";
|
|
991
1066
|
}
|
|
992
|
-
this.logger.debug(
|
|
1067
|
+
this.logger.debug(`Release config: ", ${this.ctx.release}`);
|
|
993
1068
|
await this.ctx.hooks.callHook("release:init", this.ctx);
|
|
994
1069
|
await new Bump(this.ctx).run();
|
|
995
1070
|
await this.ctx.hooks.callHook("release:push", this.ctx);
|
|
@@ -1432,7 +1507,7 @@ class RemoteFirefox {
|
|
|
1432
1507
|
});
|
|
1433
1508
|
return response;
|
|
1434
1509
|
} catch (err) {
|
|
1435
|
-
logger.debug(`Client responded to '${request}' request with error
|
|
1510
|
+
logger.debug(`Client responded to '${request}' request with error: ${err}`);
|
|
1436
1511
|
const message = requestErrorToMessage(err);
|
|
1437
1512
|
throw new Error(`Remote Firefox: addonRequest() error: ${message}`);
|
|
1438
1513
|
}
|
|
@@ -1449,7 +1524,7 @@ class RemoteFirefox {
|
|
|
1449
1524
|
}
|
|
1450
1525
|
return response.addonsActor;
|
|
1451
1526
|
} catch (err) {
|
|
1452
|
-
logger.debug(
|
|
1527
|
+
logger.debug(`Falling back to listTabs because getRoot failed", ${err}`);
|
|
1453
1528
|
}
|
|
1454
1529
|
try {
|
|
1455
1530
|
const response = await this.client.request("listTabs");
|
|
@@ -1465,7 +1540,7 @@ class RemoteFirefox {
|
|
|
1465
1540
|
}
|
|
1466
1541
|
return response.addonsActor;
|
|
1467
1542
|
} catch (err) {
|
|
1468
|
-
logger.debug(
|
|
1543
|
+
logger.debug(`listTabs error: ${err}`);
|
|
1469
1544
|
const message = requestErrorToMessage(err);
|
|
1470
1545
|
throw new Error(`Remote Firefox: listTabs() error: ${message}`);
|
|
1471
1546
|
}
|
|
@@ -1641,7 +1716,7 @@ class ZoteroRunner {
|
|
|
1641
1716
|
}
|
|
1642
1717
|
const remotePort = await findFreeTcpPort();
|
|
1643
1718
|
args.push("-start-debugger-server", String(remotePort));
|
|
1644
|
-
logger.debug(
|
|
1719
|
+
logger.debug(`Zotero start args: ${args}`);
|
|
1645
1720
|
const env = {
|
|
1646
1721
|
...process.env,
|
|
1647
1722
|
XPCOM_DEBUG_BREAK: "stack",
|
|
@@ -1650,7 +1725,7 @@ class ZoteroRunner {
|
|
|
1650
1725
|
if (!await pathExists(this.options.binary.path))
|
|
1651
1726
|
throw new Error("The Zotero binary not found.");
|
|
1652
1727
|
this.zotero = spawn(this.options.binary.path, args, { env });
|
|
1653
|
-
logger.debug(
|
|
1728
|
+
logger.debug(`Zotero started, pid: ${this.zotero.pid}`);
|
|
1654
1729
|
this.zotero.stdout?.on("data", (_data) => {
|
|
1655
1730
|
});
|
|
1656
1731
|
logger.debug("Connecting to the remote Firefox debugger...");
|
|
@@ -1866,7 +1941,8 @@ class Serve extends Base {
|
|
|
1866
1941
|
this.logger.info(`${path} changed`);
|
|
1867
1942
|
await onChangeDebounced(path);
|
|
1868
1943
|
}).on("error", (err) => {
|
|
1869
|
-
this.logger.
|
|
1944
|
+
this.logger.fail("Server start failed!");
|
|
1945
|
+
this.logger.error(err);
|
|
1870
1946
|
});
|
|
1871
1947
|
}
|
|
1872
1948
|
async onChange(path) {
|
|
@@ -1924,13 +2000,13 @@ function isPackageInstalled(packageName) {
|
|
|
1924
2000
|
}
|
|
1925
2001
|
}
|
|
1926
2002
|
function installPackage(packageName) {
|
|
1927
|
-
const debug = isDebug || logger.level <= LOG_LEVEL.
|
|
2003
|
+
const debug = isDebug || logger.level <= LOG_LEVEL.DEBUG;
|
|
1928
2004
|
try {
|
|
1929
2005
|
logger.debug(`Installing ${packageName}...`);
|
|
1930
2006
|
execSync(`sudo apt update && sudo apt install -y ${packageName}`, { stdio: debug ? "inherit" : "pipe" });
|
|
1931
2007
|
logger.debug(`${packageName} installed successfully.`);
|
|
1932
2008
|
} catch (error) {
|
|
1933
|
-
logger.fail(`Failed to install ${packageName}
|
|
2009
|
+
logger.fail(`Failed to install ${packageName}. ${error}`);
|
|
1934
2010
|
throw error;
|
|
1935
2011
|
}
|
|
1936
2012
|
}
|
|
@@ -2382,7 +2458,7 @@ class Test extends Base {
|
|
|
2382
2458
|
res.writeHead(200, { "Content-Type": "application/json" });
|
|
2383
2459
|
res.end(JSON.stringify({ message: "Results received successfully" }));
|
|
2384
2460
|
} catch (error) {
|
|
2385
|
-
this.logger.error(
|
|
2461
|
+
this.logger.error(`Error parsing JSON:, ${error}`);
|
|
2386
2462
|
res.writeHead(400, { "Content-Type": "application/json" });
|
|
2387
2463
|
res.end(JSON.stringify({ error: "Invalid JSON" }));
|
|
2388
2464
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zotero-plugin-scaffold",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.6",
|
|
5
5
|
"description": "A scaffold for Zotero plugin development.",
|
|
6
6
|
"author": "northword",
|
|
7
7
|
"license": "AGPL-3.0-or-later",
|
|
@@ -63,8 +63,7 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@
|
|
67
|
-
"@swc/core": "^1.10.12",
|
|
66
|
+
"@swc/core": "^1.10.14",
|
|
68
67
|
"adm-zip": "^0.5.16",
|
|
69
68
|
"bumpp": "^10.0.1",
|
|
70
69
|
"c12": "^2.0.1",
|
|
@@ -82,6 +81,7 @@
|
|
|
82
81
|
"xvfb-ts": "^1.1.0"
|
|
83
82
|
},
|
|
84
83
|
"devDependencies": {
|
|
84
|
+
"@commander-js/extra-typings": "^13.1.0",
|
|
85
85
|
"@types/adm-zip": "^0.5.7",
|
|
86
86
|
"@types/fs-extra": "^11.0.4"
|
|
87
87
|
},
|