zotero-plugin-scaffold 0.3.2 → 0.3.3

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
@@ -1,6 +1,6 @@
1
1
  import process from 'node:process';
2
2
  import { Command } from 'commander';
3
- import { l as logger, E as ExitSignals, C as Config, B as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.BivfUAGX.mjs';
3
+ import { l as logger, E as ExitSignals, C as Config, B as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.7eS2y7c2.mjs';
4
4
  import { readFile } from 'node:fs/promises';
5
5
  import { pathExists } from 'fs-extra';
6
6
  import tinyUpdateNotifier from 'tiny-update-notifier';
@@ -31,7 +31,7 @@ import 'node:http';
31
31
  import 'xvfb-ts';
32
32
 
33
33
  const name = "zotero-plugin-scaffold";
34
- const version = "0.3.2";
34
+ const version = "0.3.3";
35
35
  const pkg = {
36
36
  name: name,
37
37
  version: version};
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.BivfUAGX.mjs';
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.7eS2y7c2.mjs';
2
2
  import 'c12';
3
3
  import 'es-toolkit';
4
4
  import 'fs-extra/esm';
@@ -7,14 +7,14 @@ import readline from 'node:readline';
7
7
  import util from 'node:util';
8
8
  import { isDebug, isCI, isWindows, isMacOS, isLinux } from 'std-env';
9
9
  import { p as parseRepoUrl, d as dateFormat, t as template, b as toArray, a as replaceInFile } from './zotero-plugin-scaffold.v8dJZZ-v.mjs';
10
- import { createReadStream, writeFileSync, existsSync } from 'node:fs';
10
+ import { createReadStream, existsSync } from 'node:fs';
11
11
  import { readFile, writeFile, stat } from 'node:fs/promises';
12
12
  import { basename, dirname, join, resolve, extname } from 'node:path';
13
13
  import AdmZip from 'adm-zip';
14
14
  import { build } from 'esbuild';
15
15
  import { glob, globSync } from 'tinyglobby';
16
16
  import { createHash } from 'node:crypto';
17
- import { parseSync } from '@swc/core';
17
+ import { parseSync, printSync } from '@swc/core';
18
18
  import { execSync, spawn } from 'node:child_process';
19
19
  import { versionBump, ProgressEvent } from 'bumpp';
20
20
  import { Octokit } from 'octokit';
@@ -369,7 +369,6 @@ class PrefsManager {
369
369
  parse(content) {
370
370
  const _map = {};
371
371
  const ast = parseSync(content, { syntax: "ecmascript" });
372
- writeFileSync("ast.json", JSON.stringify(ast, null, 2));
373
372
  for (const node of ast.body) {
374
373
  if (node.type !== "ExpressionStatement" || node.expression.type !== "CallExpression" || node.expression.callee.type !== "Identifier" || node.expression.callee.value !== this.namespace || node.expression.arguments.length !== 2) {
375
374
  throw new Error("Invalid prefs.js file.");
@@ -447,7 +446,79 @@ class PrefsManager {
447
446
  else
448
447
  return value;
449
448
  }
449
+ /**
450
+ * Parse Method 2 - Using swc
451
+ */
450
452
  render() {
453
+ const span = { start: 0, end: 0, ctxt: 0 };
454
+ function getExpression(value) {
455
+ switch (typeof value) {
456
+ case "string":
457
+ return {
458
+ type: "StringLiteral",
459
+ span,
460
+ value
461
+ };
462
+ case "boolean":
463
+ return {
464
+ type: "BooleanLiteral",
465
+ span,
466
+ value
467
+ };
468
+ case "number":
469
+ if (value < 0) {
470
+ return {
471
+ type: "UnaryExpression",
472
+ span,
473
+ operator: "-",
474
+ argument: {
475
+ type: "NumericLiteral",
476
+ value: Math.abs(value)
477
+ }
478
+ };
479
+ }
480
+ return {
481
+ type: "NumericLiteral",
482
+ span,
483
+ value
484
+ };
485
+ default:
486
+ throw new Error(`Unsupported value type: ${typeof value}`);
487
+ }
488
+ }
489
+ const ast = {
490
+ type: "Module",
491
+ span,
492
+ // @ts-expect-error no raw property
493
+ body: Object.entries(this.prefs).map(([key, value]) => ({
494
+ type: "ExpressionStatement",
495
+ span,
496
+ expression: {
497
+ type: "CallExpression",
498
+ span,
499
+ ctxt: 0,
500
+ callee: {
501
+ type: "Identifier",
502
+ span,
503
+ ctxt: 0,
504
+ value: this.namespace,
505
+ optional: false
506
+ },
507
+ arguments: [
508
+ { expression: getExpression(key) },
509
+ { expression: getExpression(value) }
510
+ ]
511
+ }
512
+ }))
513
+ };
514
+ const { code } = printSync(ast);
515
+ return code;
516
+ }
517
+ /**
518
+ * Parse Method 1 - Using string
519
+ * @deprecated
520
+ */
521
+ renderByString() {
451
522
  return Object.entries(this.prefs).map(([key, value]) => {
452
523
  const _v = typeof value === "string" ? `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"` : value;
453
524
  return `${this.namespace}("${key}", ${_v});`;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
3
  "type": "module",
4
- "version": "0.3.2",
4
+ "version": "0.3.3",
5
5
  "description": "A scaffold for Zotero plugin development.",
6
6
  "author": "northword",
7
7
  "license": "AGPL-3.0-or-later",