zotero-plugin-scaffold 0.2.3 → 0.2.4
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
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.D7j478bu.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.4";
|
|
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.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.D7j478bu.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.D7j478bu.mjs}
RENAMED
|
@@ -298,69 +298,74 @@ class PrefsManager {
|
|
|
298
298
|
/**
|
|
299
299
|
* Parse Method 3 - Using AST
|
|
300
300
|
*/
|
|
301
|
-
parse(
|
|
302
|
-
const
|
|
303
|
-
const ast = parseSync(
|
|
301
|
+
parse(content) {
|
|
302
|
+
const _map = {};
|
|
303
|
+
const ast = parseSync(content, { syntax: "ecmascript" });
|
|
304
304
|
for (const node of ast.body) {
|
|
305
305
|
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
306
|
throw new Error("Invalid prefs.js file.");
|
|
307
307
|
}
|
|
308
|
-
|
|
308
|
+
const [arg1, arg2] = node.expression.arguments;
|
|
309
|
+
if (arg1.expression.type !== "StringLiteral") {
|
|
309
310
|
throw new Error("Invalid prefs.js file - unsupported key type.");
|
|
310
311
|
}
|
|
311
|
-
const key =
|
|
312
|
+
const key = arg1.expression.value.trim();
|
|
312
313
|
let value;
|
|
313
|
-
switch (
|
|
314
|
+
switch (arg2.expression.type) {
|
|
314
315
|
// https://babeljs.io/docs/babel-parser#output
|
|
315
316
|
case "StringLiteral":
|
|
316
317
|
case "NumericLiteral":
|
|
317
318
|
case "BooleanLiteral":
|
|
318
|
-
value =
|
|
319
|
+
value = arg2.expression.value;
|
|
319
320
|
break;
|
|
320
321
|
// https://github.com/estree/estree/blob/master/es5.md#unaryexpression
|
|
321
322
|
// https://github.com/northword/zotero-plugin-scaffold/issues/98
|
|
322
323
|
case "UnaryExpression":
|
|
323
|
-
if (
|
|
324
|
+
if (arg2.expression.argument.type !== "NumericLiteral")
|
|
324
325
|
throw new Error("Invalid prefs.js file - unsupported value type.");
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
value = node.expression.arguments[1].expression.argument.value;
|
|
326
|
+
if (arg2.expression.operator === "-")
|
|
327
|
+
value = -arg2.expression.argument.value;
|
|
328
|
+
else if (arg2.expression.operator === "+")
|
|
329
|
+
value = arg2.expression.argument.value;
|
|
330
330
|
else
|
|
331
331
|
throw new Error("Invalid prefs.js file - unsupported value type.");
|
|
332
332
|
break;
|
|
333
333
|
default:
|
|
334
334
|
throw new Error("Invalid prefs.js file - unsupported value type.");
|
|
335
335
|
}
|
|
336
|
-
|
|
336
|
+
_map[key] = value;
|
|
337
337
|
}
|
|
338
|
-
return
|
|
338
|
+
return _map;
|
|
339
339
|
}
|
|
340
340
|
/**
|
|
341
341
|
* Parse Method 1 - Using RegExp
|
|
342
342
|
* @deprecated
|
|
343
343
|
*/
|
|
344
|
-
parseByRegExp(
|
|
345
|
-
const
|
|
344
|
+
parseByRegExp(content) {
|
|
345
|
+
const _map = {};
|
|
346
346
|
const prefPattern = /^(pref|user_pref)\s*\(\s*["']([^"']+)["']\s*,\s*(.+)\s*,?\s*\)\s*;?$/gm;
|
|
347
|
-
const matches =
|
|
347
|
+
const matches = content.matchAll(prefPattern);
|
|
348
348
|
for (const match of matches) {
|
|
349
349
|
const key = match[2].trim();
|
|
350
350
|
const value = match[3].trim();
|
|
351
|
-
|
|
351
|
+
_map[key] = this.cleanValue(value);
|
|
352
352
|
}
|
|
353
|
-
return
|
|
353
|
+
return _map;
|
|
354
354
|
}
|
|
355
355
|
/**
|
|
356
356
|
* Parse Method 2 - Using eval
|
|
357
357
|
* @deprecated
|
|
358
358
|
*/
|
|
359
|
-
parseByEval(content) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
359
|
+
// private parseByEval(content: string) {
|
|
360
|
+
// const _map: Prefs = {};
|
|
361
|
+
// // eslint-disable-next-line unused-imports/no-unused-vars
|
|
362
|
+
// const pref = (key: any, value: any) => {
|
|
363
|
+
// _map[key.trim()] = this.cleanValue(value.trim());
|
|
364
|
+
// };
|
|
365
|
+
// // eslint-disable-next-line no-eval
|
|
366
|
+
// eval(content);
|
|
367
|
+
// return _map;
|
|
368
|
+
// }
|
|
364
369
|
cleanValue(value) {
|
|
365
370
|
if (value === "true")
|
|
366
371
|
return true;
|
|
@@ -380,13 +385,13 @@ class PrefsManager {
|
|
|
380
385
|
}).join("\n");
|
|
381
386
|
}
|
|
382
387
|
async read(path) {
|
|
383
|
-
const
|
|
384
|
-
const map = this.parse(
|
|
388
|
+
const content = await readFile(path, "utf-8");
|
|
389
|
+
const map = this.parse(content);
|
|
385
390
|
this.setPrefs(map);
|
|
386
391
|
}
|
|
387
392
|
async write(path) {
|
|
388
|
-
const
|
|
389
|
-
await outputFile(path,
|
|
393
|
+
const content = this.render();
|
|
394
|
+
await outputFile(path, content, "utf-8");
|
|
390
395
|
logger.debug("The prefs.js has been modified.");
|
|
391
396
|
}
|
|
392
397
|
setPref(key, value) {
|
|
@@ -413,18 +418,18 @@ class PrefsManager {
|
|
|
413
418
|
}
|
|
414
419
|
getPrefsWithPrefix(prefix) {
|
|
415
420
|
const _prefs = {};
|
|
416
|
-
for (const
|
|
417
|
-
if (
|
|
418
|
-
_prefs[
|
|
421
|
+
for (const pref in this.prefs) {
|
|
422
|
+
if (pref.startsWith(prefix))
|
|
423
|
+
_prefs[pref] = this.prefs[pref];
|
|
419
424
|
else
|
|
420
|
-
_prefs[`${prefix}.${
|
|
425
|
+
_prefs[`${prefix}.${pref}`] = this.prefs[pref];
|
|
421
426
|
}
|
|
422
427
|
return _prefs;
|
|
423
428
|
}
|
|
424
429
|
getPrefsWithoutPrefix(prefix) {
|
|
425
430
|
const _prefs = {};
|
|
426
|
-
for (const
|
|
427
|
-
_prefs[
|
|
431
|
+
for (const pref in this.prefs) {
|
|
432
|
+
_prefs[pref.replace(`${prefix}.`, "")] = this.prefs[pref];
|
|
428
433
|
}
|
|
429
434
|
return _prefs;
|
|
430
435
|
}
|
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.4",
|
|
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
|
},
|