zotero-plugin-scaffold 0.2.0-beta.16 → 0.2.0-beta.18

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.
@@ -4,7 +4,7 @@ import process from 'node:process';
4
4
  import { Octokit } from 'octokit';
5
5
  import { globSync, glob } from 'tinyglobby';
6
6
  import { isCI } from 'std-env';
7
- import { B as Base } from '../shared/zotero-plugin-scaffold.BhavR4LH.mjs';
7
+ import { B as Base } from '../shared/zotero-plugin-scaffold.BRIcU6PR.mjs';
8
8
  import 'c12';
9
9
  import 'es-toolkit';
10
10
  import 'fs-extra/esm';
package/dist/cli.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import process from 'node:process';
2
2
  import { Command } from '@commander-js/extra-typings';
3
- import { E as ExitSignals, l as logger, C as Config, a as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.BhavR4LH.mjs';
3
+ import { E as ExitSignals, l as logger, C as Config, a as Build, S as Serve, T as Test, R as Release } from './shared/zotero-plugin-scaffold.BRIcU6PR.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';
@@ -30,7 +30,7 @@ import 'xvfb-ts';
30
30
 
31
31
  const name = "zotero-plugin-scaffold";
32
32
  const type = "module";
33
- const version = "0.2.0-beta.16";
33
+ const version = "0.2.0-beta.18";
34
34
  const packageManager = "pnpm@9.15.2";
35
35
  const description = "A scaffold for Zotero plugin development.";
36
36
  const author = "northword";
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { a as Build, C as Config, R as Release, S as Serve, T as Test, d as defineConfig } from './shared/zotero-plugin-scaffold.BhavR4LH.mjs';
1
+ export { a as Build, C as Config, R as Release, S as Serve, T as Test, d as defineConfig } from './shared/zotero-plugin-scaffold.BRIcU6PR.mjs';
2
2
  import 'c12';
3
3
  import 'es-toolkit';
4
4
  import 'fs-extra/esm';
@@ -1,5 +1,5 @@
1
1
  import { loadConfig as loadConfig$1 } from 'c12';
2
- import { isPlainObject, kebabCase, mapValues, isNotNil, toMerged, escapeRegExp, delay, debounce } from 'es-toolkit';
2
+ import { isPlainObject, kebabCase, mapValues, toMerged, escapeRegExp, delay, debounce } from 'es-toolkit';
3
3
  import { readJsonSync, outputFile, emptyDir, copy, readJSON, outputJSON, move, writeJson, pathExists, ensureDir, remove } from 'fs-extra/esm';
4
4
  import { createHooks } from 'hookable';
5
5
  import process from 'node:process';
@@ -146,7 +146,7 @@ function resolveConfig(config) {
146
146
  config.id ||= config.name;
147
147
  config.namespace ||= config.name;
148
148
  config.xpiName ||= kebabCase(config.name);
149
- config.build.prefs.prefix ||= `extensions.${config.namespace}`;
149
+ config.build.prefs.prefix ||= pkgUser.config.prefsPrefix || `extensions.${config.namespace}`;
150
150
  const isPreRelease = version.includes("-");
151
151
  const templateData = {
152
152
  owner,
@@ -303,32 +303,38 @@ class PrefsManager {
303
303
  this.namespace = namespace;
304
304
  }
305
305
  parse(content) {
306
+ const _map = {};
306
307
  const prefPattern = /^(pref|user_pref)\s*\(\s*["']([^"']+)["']\s*,\s*(.+)\s*\)\s*;$/gm;
307
308
  const matches = content.matchAll(prefPattern);
308
309
  for (const match of matches) {
309
310
  const key = match[2].trim();
310
311
  const value = match[3].trim();
311
- this.prefs[key] = value;
312
+ _map[key] = this.cleanValue(value);
312
313
  }
314
+ return _map;
315
+ }
316
+ cleanValue(value) {
317
+ if (value === "true")
318
+ return true;
319
+ else if (value === "false")
320
+ return false;
321
+ else if (!Number.isNaN(Number(value)))
322
+ return Number(value);
323
+ else if (value.match(/^["'](.*)["']$/))
324
+ return value.replace(/^["'](.*)["']$/, "$1");
325
+ else
326
+ return value;
313
327
  }
314
328
  render() {
315
329
  return Object.entries(this.prefs).map(([key, value]) => {
316
- if (!isNotNil(value))
317
- return "";
318
- let cleanValue = "";
319
- if (typeof value === "boolean") {
320
- cleanValue = `${value}`;
321
- } else if (typeof value === "string") {
322
- cleanValue = value;
323
- } else if (typeof value === "number") {
324
- cleanValue = value.toString();
325
- }
326
- return `${this.namespace}("${key}", ${cleanValue});`;
327
- }).filter((c) => !!c).join("\n");
330
+ const _v = typeof value === "string" ? `"${value}"` : value;
331
+ return `${this.namespace}("${key}", ${_v});`;
332
+ }).join("\n");
328
333
  }
329
334
  async read(path) {
330
335
  const content = await readFile(path, "utf-8");
331
- this.parse(content);
336
+ const map = this.parse(content);
337
+ this.setPrefs(map);
332
338
  }
333
339
  async write(path) {
334
340
  const content = this.render();
@@ -336,6 +342,12 @@ class PrefsManager {
336
342
  logger.debug("The <profile>/prefs.js has been modified.");
337
343
  }
338
344
  setPref(key, value) {
345
+ if (value === null || value === void 0) {
346
+ if (key in this.prefs)
347
+ delete this.prefs[key];
348
+ else
349
+ return;
350
+ }
339
351
  this.prefs[key] = value;
340
352
  }
341
353
  setPrefs(prefs) {
@@ -376,24 +388,20 @@ function renderPluginPrefsDts(prefs, prefix) {
376
388
  /* eslint-disable */
377
389
  // @ts-nocheck
378
390
 
391
+ // prettier-ignore
379
392
  type _PluginPrefsMap = {
380
393
  ${Object.entries(prefs).map(([key, value]) => {
381
394
  return `"${key}": ${typeof value};`;
382
395
  }).join("\n ")}
383
396
  };
384
397
 
398
+ // prettier-ignore
385
399
  type PluginPrefKey<K extends keyof _PluginPrefsMap> = \`${prefix}.\${K}\`;
386
400
 
401
+ // prettier-ignore
387
402
  type PluginPrefsMap = {
388
403
  [K in keyof _PluginPrefsMap as PluginPrefKey<K>]: _PluginPrefsMap[K]
389
404
  };
390
-
391
- declare namespace _ZoteroTypes {
392
- interface Prefs {
393
- get: <K extends keyof PluginPrefsMap>(key: K, global?: boolean) => PluginPrefsMap[K];
394
- set: <K extends keyof PluginPrefsMap>(key: K, value: PluginPrefsMap[K], global?: boolean) => any;
395
- }
396
- }
397
405
  `;
398
406
  return dtsContent;
399
407
  }
@@ -524,12 +532,11 @@ class Build extends Base {
524
532
  let ftlContent = await readFile(ftlPath, "utf-8");
525
533
  const matches = [...ftlContent.matchAll(FTL_MESSAGE_PATTERN)];
526
534
  for (const match of matches) {
527
- const message = match.groups?.message;
535
+ const [matched, message, _pattern] = match;
528
536
  if (message) {
529
- const namespacedMessage = `${namespace}-${message}`;
530
537
  localeMessages.add(message);
531
538
  allMessages.add(message);
532
- ftlContent = ftlContent.replace(message, namespacedMessage);
539
+ ftlContent = ftlContent.replace(new RegExp(`^${escapeRegExp(matched)}`, "gm"), `${namespace}-${matched}`);
533
540
  }
534
541
  }
535
542
  if (build.fluent.prefixFluentMessages)
@@ -598,14 +605,15 @@ class Build extends Base {
598
605
  const matchs = [...content.matchAll(HTML_PREFERENCE_PATTERN)];
599
606
  for (const match of matchs) {
600
607
  const [matched, key] = match;
601
- if (!prefsWithoutPrefix[key] && !prefsWithoutPrefix[key]) {
602
- this.logger.warn(`preference key '${key}' in ${path} not init in prefs.js`);
608
+ if (!(key in prefsWithoutPrefix) && !(key in prefsWithoutPrefix)) {
609
+ this.logger.warn(`preference key '${key}' in ${path.replace(`${dist}/`, "")} not init in prefs.js`);
603
610
  continue;
604
611
  }
605
- if (key.startsWith(prefix))
612
+ if (key.startsWith(prefix)) {
606
613
  continue;
607
- else
614
+ } else {
608
615
  content = content.replace(matched, `preference="${prefix}.${key}"`);
616
+ }
609
617
  }
610
618
  await outputFile(path, content, "utf-8");
611
619
  }));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "zotero-plugin-scaffold",
3
3
  "type": "module",
4
- "version": "0.2.0-beta.16",
4
+ "version": "0.2.0-beta.18",
5
5
  "description": "A scaffold for Zotero plugin development.",
6
6
  "author": "northword",
7
7
  "license": "AGPL-3.0-or-later",