@morehao/dsh-github-trending 0.1.4 → 0.3.0

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/lib/index.js CHANGED
@@ -5,22 +5,16 @@ import {
5
5
  Store,
6
6
  createRoutes,
7
7
  createTrendingHistoryTool,
8
- createTrendingRunTool
9
- } from "./chunk-RXYA5WFW.js";
8
+ createTrendingRunTool,
9
+ readPluginInfo
10
+ } from "./chunk-X4PBXIZE.js";
10
11
  import "./chunk-XLIFTAVL.js";
11
12
 
12
13
  // src/index.ts
13
- import { createRequire } from "module";
14
14
  var name = "dsh-github-trending";
15
15
  var inject = ["webServer"];
16
16
  function readVersion() {
17
- try {
18
- const require2 = createRequire(import.meta.url);
19
- const pkg = require2("../package.json");
20
- return typeof pkg.version === "string" ? pkg.version : "0.0.0";
21
- } catch {
22
- return "0.0.0";
23
- }
17
+ return readPluginInfo().version;
24
18
  }
25
19
  var VERSION = readVersion();
26
20
  function apply(ctx, config = {}) {
@@ -31,6 +25,18 @@ function apply(ctx, config = {}) {
31
25
  ctx.logger?.info?.(`[dsh-github-trending] ${event}${suffix}`);
32
26
  };
33
27
  const store = new Store({ env, ...config.stateDir === void 0 ? {} : { dir: config.stateDir } });
28
+ try {
29
+ const migration = store.migrateLegacyState();
30
+ if (migration.stateChanged || migration.historyMarked > 0) {
31
+ log("state.migrated", {
32
+ clearedDigest: migration.clearedDigest,
33
+ clearedPendingPr: migration.clearedPendingPr,
34
+ historyMarked: migration.historyMarked
35
+ });
36
+ }
37
+ } catch (error) {
38
+ ctx.logger?.warn?.(`[dsh-github-trending] \u65E7\u72B6\u6001\u8FC1\u79FB\u5931\u8D25\uFF1A${error instanceof Error ? error.message : String(error)}`);
39
+ }
34
40
  if (config.corePath !== void 0 && config.corePath !== "") {
35
41
  const settings = store.readSettings();
36
42
  if (settings.corePath === "") store.writeSettings({ ...settings, corePath: config.corePath });
@@ -39,6 +45,7 @@ function apply(ctx, config = {}) {
39
45
  store,
40
46
  get,
41
47
  env,
48
+ logger: log,
42
49
  onFinished: (summary) => log("run.finished", { id: summary.id, ok: summary.ok, skipped: summary.skipped, files: summary.files })
43
50
  });
44
51
  const scheduler = new Scheduler({
@@ -51,7 +58,18 @@ function apply(ctx, config = {}) {
51
58
  },
52
59
  onError: (error) => ctx.logger?.warn?.(`[dsh-github-trending] \u5B9A\u65F6\u8FD0\u884C\u5931\u8D25\uFF1A${error instanceof Error ? error.message : String(error)}`)
53
60
  });
54
- const handler = createRoutes({ store, runner, scheduler, get, env, version: VERSION, logger: log });
61
+ const pluginInfo = readPluginInfo();
62
+ const handler = createRoutes({
63
+ store,
64
+ runner,
65
+ scheduler,
66
+ get,
67
+ env,
68
+ version: VERSION,
69
+ pluginName: pluginInfo.name,
70
+ ...pluginInfo.repository === void 0 ? {} : { repository: pluginInfo.repository },
71
+ logger: log
72
+ });
55
73
  const register = () => {
56
74
  const webServer = ctx.webServer ?? get("webServer");
57
75
  if (webServer === void 0 || typeof webServer.register !== "function") {