zotero-plugin-scaffold 0.2.2 → 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.V3TH4au2.mjs → zotero-plugin-scaffold.D7j478bu.mjs}
RENAMED
|
@@ -298,49 +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
|
-
|
|
312
|
-
|
|
312
|
+
const key = arg1.expression.value.trim();
|
|
313
|
+
let value;
|
|
314
|
+
switch (arg2.expression.type) {
|
|
315
|
+
// https://babeljs.io/docs/babel-parser#output
|
|
316
|
+
case "StringLiteral":
|
|
317
|
+
case "NumericLiteral":
|
|
318
|
+
case "BooleanLiteral":
|
|
319
|
+
value = arg2.expression.value;
|
|
320
|
+
break;
|
|
321
|
+
// https://github.com/estree/estree/blob/master/es5.md#unaryexpression
|
|
322
|
+
// https://github.com/northword/zotero-plugin-scaffold/issues/98
|
|
323
|
+
case "UnaryExpression":
|
|
324
|
+
if (arg2.expression.argument.type !== "NumericLiteral")
|
|
325
|
+
throw new Error("Invalid prefs.js file - unsupported value type.");
|
|
326
|
+
if (arg2.expression.operator === "-")
|
|
327
|
+
value = -arg2.expression.argument.value;
|
|
328
|
+
else if (arg2.expression.operator === "+")
|
|
329
|
+
value = arg2.expression.argument.value;
|
|
330
|
+
else
|
|
331
|
+
throw new Error("Invalid prefs.js file - unsupported value type.");
|
|
332
|
+
break;
|
|
333
|
+
default:
|
|
334
|
+
throw new Error("Invalid prefs.js file - unsupported value type.");
|
|
313
335
|
}
|
|
314
|
-
|
|
315
|
-
const value = node.expression.arguments[1].expression.value;
|
|
316
|
-
_map2[key] = value;
|
|
336
|
+
_map[key] = value;
|
|
317
337
|
}
|
|
318
|
-
return
|
|
338
|
+
return _map;
|
|
319
339
|
}
|
|
320
340
|
/**
|
|
321
341
|
* Parse Method 1 - Using RegExp
|
|
322
342
|
* @deprecated
|
|
323
343
|
*/
|
|
324
|
-
parseByRegExp(
|
|
325
|
-
const
|
|
344
|
+
parseByRegExp(content) {
|
|
345
|
+
const _map = {};
|
|
326
346
|
const prefPattern = /^(pref|user_pref)\s*\(\s*["']([^"']+)["']\s*,\s*(.+)\s*,?\s*\)\s*;?$/gm;
|
|
327
|
-
const matches =
|
|
347
|
+
const matches = content.matchAll(prefPattern);
|
|
328
348
|
for (const match of matches) {
|
|
329
349
|
const key = match[2].trim();
|
|
330
350
|
const value = match[3].trim();
|
|
331
|
-
|
|
351
|
+
_map[key] = this.cleanValue(value);
|
|
332
352
|
}
|
|
333
|
-
return
|
|
353
|
+
return _map;
|
|
334
354
|
}
|
|
335
355
|
/**
|
|
336
356
|
* Parse Method 2 - Using eval
|
|
337
357
|
* @deprecated
|
|
338
358
|
*/
|
|
339
|
-
parseByEval(content) {
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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
|
+
// }
|
|
344
369
|
cleanValue(value) {
|
|
345
370
|
if (value === "true")
|
|
346
371
|
return true;
|
|
@@ -360,13 +385,13 @@ class PrefsManager {
|
|
|
360
385
|
}).join("\n");
|
|
361
386
|
}
|
|
362
387
|
async read(path) {
|
|
363
|
-
const
|
|
364
|
-
const map = this.parse(
|
|
388
|
+
const content = await readFile(path, "utf-8");
|
|
389
|
+
const map = this.parse(content);
|
|
365
390
|
this.setPrefs(map);
|
|
366
391
|
}
|
|
367
392
|
async write(path) {
|
|
368
|
-
const
|
|
369
|
-
await outputFile(path,
|
|
393
|
+
const content = this.render();
|
|
394
|
+
await outputFile(path, content, "utf-8");
|
|
370
395
|
logger.debug("The prefs.js has been modified.");
|
|
371
396
|
}
|
|
372
397
|
setPref(key, value) {
|
|
@@ -393,18 +418,18 @@ class PrefsManager {
|
|
|
393
418
|
}
|
|
394
419
|
getPrefsWithPrefix(prefix) {
|
|
395
420
|
const _prefs = {};
|
|
396
|
-
for (const
|
|
397
|
-
if (
|
|
398
|
-
_prefs[
|
|
421
|
+
for (const pref in this.prefs) {
|
|
422
|
+
if (pref.startsWith(prefix))
|
|
423
|
+
_prefs[pref] = this.prefs[pref];
|
|
399
424
|
else
|
|
400
|
-
_prefs[`${prefix}.${
|
|
425
|
+
_prefs[`${prefix}.${pref}`] = this.prefs[pref];
|
|
401
426
|
}
|
|
402
427
|
return _prefs;
|
|
403
428
|
}
|
|
404
429
|
getPrefsWithoutPrefix(prefix) {
|
|
405
430
|
const _prefs = {};
|
|
406
|
-
for (const
|
|
407
|
-
_prefs[
|
|
431
|
+
for (const pref in this.prefs) {
|
|
432
|
+
_prefs[pref.replace(`${prefix}.`, "")] = this.prefs[pref];
|
|
408
433
|
}
|
|
409
434
|
return _prefs;
|
|
410
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
|
},
|