@kotori-bot/loader 1.6.0 → 1.6.2

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.
@@ -1,5 +1,5 @@
1
1
  import { Context, LocaleType, ModuleConfig, Symbols } from '@kotori-bot/core';
2
- import { BUILD_MODE, DEV_MODE, DEV_SOURCE_MODE } from '../constants';
2
+ import { BUILD_MODE, DEV_MODE } from '../constants';
3
3
  import '../types/internal';
4
4
  import './loader';
5
5
  interface BaseDir {
@@ -10,7 +10,7 @@ interface BaseDir {
10
10
  config: string;
11
11
  }
12
12
  interface Options {
13
- mode: typeof BUILD_MODE | typeof DEV_MODE | typeof DEV_SOURCE_MODE;
13
+ mode: typeof BUILD_MODE | typeof DEV_MODE;
14
14
  }
15
15
  interface RunnerConfig {
16
16
  baseDir: BaseDir;
@@ -47,7 +47,6 @@ export declare class Runner {
47
47
  readonly options: Options;
48
48
  private readonly ctx;
49
49
  private readonly isDev;
50
- private readonly isSourceDev;
51
50
  readonly [Symbols.modules]: Map<string, [ModuleMeta, ModuleConfig]>;
52
51
  constructor(ctx: Context, config: RunnerConfig);
53
52
  private getDirFiles;
@@ -1,12 +1,12 @@
1
1
 
2
2
  /**
3
3
  * @Package @kotori-bot/loader
4
- * @Version 1.6.0-beta.1
4
+ * @Version 1.6.2
5
5
  * @Author Hotaru <biyuehuya@gmail.com>
6
6
  * @Copyright 2024 Hotaru. All rights reserved.
7
7
  * @License GPL-3.0
8
8
  * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/6 21:03:54
9
+ * @Date 2024/6/7 11:53:11
10
10
  */
11
11
 
12
12
  "use strict";
@@ -37,8 +37,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  mod
38
38
  ));
39
39
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
40
-
41
- // src/class/runner.ts
42
40
  var runner_exports = {};
43
41
  __export(runner_exports, {
44
42
  Runner: () => Runner,
@@ -46,118 +44,35 @@ __export(runner_exports, {
46
44
  localeTypeSchema: () => localeTypeSchema
47
45
  });
48
46
  module.exports = __toCommonJS(runner_exports);
49
- var import_node_fs2 = __toESM(require("fs"));
50
- var import_node_path3 = __toESM(require("path"));
51
- var import_core4 = require("@kotori-bot/core");
52
- var import_logger3 = require("@kotori-bot/logger");
53
-
54
- // src/constants.ts
55
- var DEV_FILE = ".ts";
56
- var BUILD_FILE = ".js";
57
- var DEV_CODE_DIRS = "./src/";
58
- var DEV_IMPORT = `${DEV_CODE_DIRS}index.ts`;
59
- var DEV_MODE = "dev";
60
- var DEV_SOURCE_MODE = "dev-source";
61
- var CORE_MODULES = [
62
- "@kotori-bot/kotori-plugin-core",
63
- "@kotori-bot/kotori-plugin-i18n-command",
64
- "@kotori-bot/kotori-plugin-filter"
65
- // '@kotori-bot/kotori-plugin-webui'
66
- ];
67
-
68
- // src/utils/logger.ts
69
- var import_logger = require("@kotori-bot/logger");
70
- var KotoriLogger = class extends import_logger.Logger {
71
- constructor(optionsSelf, ctx) {
72
- super(optionsSelf);
73
- this.optionsSelf = optionsSelf;
74
- this.ctx = ctx;
75
- }
76
- setLabel() {
77
- const origin = Object.create(this.optionsSelf.label);
78
- const label = this.ctx.identity ? [this.ctx.identity, ...this.optionsSelf.label] : this.optionsSelf.label;
79
- this[/* @__PURE__ */ (() => "options")()].label = label;
80
- return () => {
81
- this[/* @__PURE__ */ (() => "options")()].label = origin;
82
- };
83
- }
84
- fatal(...args) {
85
- const dispose = this.setLabel();
86
- super.fatal(...args);
87
- dispose();
88
- }
89
- error(...args) {
90
- const dispose = this.setLabel();
91
- super.error(...args);
92
- dispose();
93
- }
94
- warn(...args) {
95
- const dispose = this.setLabel();
96
- super.warn(...args);
97
- dispose();
98
- }
99
- info(...args) {
100
- const dispose = this.setLabel();
101
- super.info(...args);
102
- dispose();
103
- }
104
- record(...args) {
105
- const dispose = this.setLabel();
106
- super.record(...args);
107
- dispose();
108
- }
109
- debug(...args) {
110
- const dispose = this.setLabel();
111
- super.debug(...args);
112
- dispose();
113
- }
114
- trace(...args) {
115
- const dispose = this.setLabel();
116
- super.trace(...args);
117
- dispose();
118
- }
119
- };
120
- var logger_default = KotoriLogger;
121
-
122
- // src/class/loader.ts
123
- var import_core3 = require("@kotori-bot/core");
124
- var import_node_path2 = __toESM(require("path"));
125
- var import_node_fs = __toESM(require("fs"));
126
- var import_logger2 = __toESM(require("@kotori-bot/logger"));
127
-
128
- // src/service/server.ts
47
+ var import_node_fs = __toESM(require("node:fs"));
48
+ var import_node_path = __toESM(require("node:path"));
129
49
  var import_core = require("@kotori-bot/core");
130
- var import_node_http = require("http");
131
- var import_path_to_regexp = require("path-to-regexp");
132
- var import_express = __toESM(require("express"));
133
- var import_ws = __toESM(require("ws"));
134
-
135
- // src/service/file.ts
136
- var import_core2 = require("@kotori-bot/core");
137
- var import_node_path = require("path");
138
-
139
- // src/class/runner.ts
140
- var localeTypeSchema = import_core4.Tsu.Union([
141
- import_core4.Tsu.Union([import_core4.Tsu.Literal("en_US"), import_core4.Tsu.Literal("ja_JP")]),
142
- import_core4.Tsu.Union([import_core4.Tsu.Literal("zh_TW"), import_core4.Tsu.Any()])
50
+ var import_logger = require("@kotori-bot/logger");
51
+ var import_constants = require("../constants");
52
+ var import_internal = require("../types/internal");
53
+ var import_logger2 = __toESM(require("../utils/logger"));
54
+ var import_loader = require("./loader");
55
+ const localeTypeSchema = import_core.Tsu.Union([
56
+ import_core.Tsu.Union([import_core.Tsu.Literal("en_US"), import_core.Tsu.Literal("ja_JP")]),
57
+ import_core.Tsu.Union([import_core.Tsu.Literal("zh_TW"), import_core.Tsu.Any()])
143
58
  ]);
144
- var modulePackageSchema = import_core4.Tsu.Object({
145
- name: import_core4.Tsu.String().regexp(/kotori-plugin-[a-z]([a-z,0-9]{2,13})\b/),
146
- version: import_core4.Tsu.String(),
147
- description: import_core4.Tsu.String(),
148
- main: import_core4.Tsu.String(),
149
- license: import_core4.Tsu.Literal("GPL-3.0"),
150
- keywords: import_core4.Tsu.Custom(
59
+ const modulePackageSchema = import_core.Tsu.Object({
60
+ name: import_core.Tsu.String().regexp(/kotori-plugin-[a-z]([a-z,0-9]{2,13})\b/),
61
+ version: import_core.Tsu.String(),
62
+ description: import_core.Tsu.String(),
63
+ main: import_core.Tsu.String(),
64
+ license: import_core.Tsu.Literal("GPL-3.0"),
65
+ keywords: import_core.Tsu.Custom(
151
66
  (val) => Array.isArray(val) && val.includes("kotori") && val.includes("chatbot") && val.includes("kotori-plugin")
152
67
  ),
153
- author: import_core4.Tsu.Union([import_core4.Tsu.String(), import_core4.Tsu.Array(import_core4.Tsu.String())]),
154
- peerDependencies: import_core4.Tsu.Object({
155
- "kotori-bot": import_core4.Tsu.String()
68
+ author: import_core.Tsu.Union([import_core.Tsu.String(), import_core.Tsu.Array(import_core.Tsu.String())]),
69
+ peerDependencies: import_core.Tsu.Object({
70
+ "kotori-bot": import_core.Tsu.String()
156
71
  }),
157
- kotori: import_core4.Tsu.Object({
158
- enforce: import_core4.Tsu.Union([import_core4.Tsu.Literal("pre"), import_core4.Tsu.Literal("post")]).optional(),
159
- meta: import_core4.Tsu.Object({
160
- language: import_core4.Tsu.Array(localeTypeSchema).default([])
72
+ kotori: import_core.Tsu.Object({
73
+ enforce: import_core.Tsu.Union([import_core.Tsu.Literal("pre"), import_core.Tsu.Literal("post")]).optional(),
74
+ meta: import_core.Tsu.Object({
75
+ language: import_core.Tsu.Array(localeTypeSchema).default([])
161
76
  }).default({ language: [] })
162
77
  }).default({
163
78
  enforce: void 0,
@@ -165,99 +80,97 @@ var modulePackageSchema = import_core4.Tsu.Object({
165
80
  })
166
81
  });
167
82
  function moduleLoadOrder(pkg) {
168
- if (CORE_MODULES.includes(pkg.name)) return 1;
169
- if (pkg.name.includes(import_core4.DATABASE_PREFIX)) return 2;
170
- if (pkg.name.includes(import_core4.ADAPTER_PREFIX)) return 3;
83
+ if (import_constants.CORE_MODULES.includes(pkg.name)) return 1;
84
+ if (pkg.name.includes(import_core.DATABASE_PREFIX)) return 2;
85
+ if (pkg.name.includes(import_core.ADAPTER_PREFIX)) return 3;
171
86
  if (pkg.kotori.enforce === "pre") return 4;
172
87
  if (!pkg.kotori.enforce) return 5;
173
88
  return 6;
174
89
  }
175
- var Runner = class {
90
+ class Runner {
176
91
  baseDir;
177
92
  options;
178
93
  ctx;
179
94
  isDev;
180
- isSourceDev;
181
- [import_core4.Symbols.modules] = /* @__PURE__ */ new Map();
95
+ [import_core.Symbols.modules] = /* @__PURE__ */ new Map();
182
96
  constructor(ctx, config) {
183
97
  this.ctx = ctx;
184
98
  this.baseDir = config.baseDir;
185
99
  this.options = config.options;
186
- this.isDev = this.options.mode.startsWith(DEV_MODE);
187
- this.isSourceDev = this.options.mode === DEV_SOURCE_MODE;
100
+ this.isDev = this.options.mode === import_constants.DEV_MODE;
188
101
  const loggerOptions = {
189
102
  level: this.ctx.config.global.level ?? config.level,
190
103
  label: [],
191
104
  transports: [
192
- new import_logger3.ConsoleTransport({
105
+ new import_logger.ConsoleTransport({
193
106
  template: "<blue>%time%</blue> %level% (<bold>%pid%</bold>) %labels%: %msg%",
194
107
  time: "M/D H:m:s"
195
108
  }),
196
- new import_logger3.FileTransport({ dir: this.baseDir.logs, filter: (data) => data.level >= import_logger3.LoggerLevel.WARN })
109
+ new import_logger.FileTransport({ dir: this.baseDir.logs, filter: (data) => data.level >= import_logger.LoggerLevel.WARN })
197
110
  ]
198
111
  };
199
- ctx.provide("logger", new logger_default(loggerOptions, this.ctx));
112
+ ctx.provide("logger", new import_logger2.default(loggerOptions, this.ctx));
200
113
  ctx.inject("logger");
201
114
  }
202
115
  getDirFiles(rootDir) {
203
- const files = import_node_fs2.default.readdirSync(rootDir);
116
+ const files = import_node_fs.default.readdirSync(rootDir);
204
117
  const list = [];
205
118
  files.forEach((fileName) => {
206
- const file = import_node_path3.default.join(rootDir, fileName);
207
- if (import_node_fs2.default.statSync(file).isDirectory()) {
119
+ const file = import_node_path.default.join(rootDir, fileName);
120
+ if (import_node_fs.default.statSync(file).isDirectory()) {
208
121
  list.push(...this.getDirFiles(file));
209
122
  }
210
- if (import_node_path3.default.parse(file).ext !== (this.isSourceDev ? DEV_FILE : BUILD_FILE)) return;
211
- list.push(import_node_path3.default.resolve(file));
123
+ if (import_node_path.default.parse(file).ext !== (this.isDev ? import_constants.DEV_FILE : import_constants.BUILD_FILE)) return;
124
+ list.push(import_node_path.default.resolve(file));
212
125
  });
213
126
  return list;
214
127
  }
215
128
  getModuleRootDir() {
216
129
  const moduleRootDir = [];
217
130
  [
218
- ...this.ctx.config.global.dirs.map((dir) => import_node_path3.default.resolve(this.ctx.baseDir.root, dir)),
131
+ ...this.ctx.config.global.dirs.map((dir) => import_node_path.default.resolve(this.ctx.baseDir.root, dir)),
219
132
  this.ctx.baseDir.modules
220
133
  ].forEach((dir) => {
221
- if (import_node_fs2.default.existsSync(dir) && import_node_fs2.default.statSync(dir).isDirectory()) moduleRootDir.push(dir);
134
+ if (import_node_fs.default.existsSync(dir) && import_node_fs.default.statSync(dir).isDirectory()) moduleRootDir.push(dir);
222
135
  });
223
136
  return moduleRootDir;
224
137
  }
225
138
  async checkModuleFiles(rootDir, filename) {
226
- const dir = import_node_path3.default.join(rootDir, filename);
227
- if (!import_node_fs2.default.statSync(dir).isDirectory()) return;
228
- if (rootDir !== this.ctx.baseDir.modules && !filename.startsWith(import_core4.PLUGIN_PREFIX)) return;
229
- const packagePath = import_node_path3.default.join(dir, "package.json");
139
+ const dir = import_node_path.default.join(rootDir, filename);
140
+ if (!import_node_fs.default.statSync(dir).isDirectory()) return;
141
+ if (rootDir !== this.ctx.baseDir.modules && !filename.startsWith(import_core.PLUGIN_PREFIX)) return;
142
+ const packagePath = import_node_path.default.join(dir, "package.json");
230
143
  let pkg;
231
- if (!import_node_fs2.default.existsSync(packagePath)) return;
144
+ if (!import_node_fs.default.existsSync(packagePath)) return;
232
145
  try {
233
- pkg = JSON.parse(import_node_fs2.default.readFileSync(packagePath).toString());
146
+ pkg = JSON.parse(import_node_fs.default.readFileSync(packagePath).toString());
234
147
  } catch {
235
- throw new import_core4.DevError(this.ctx.format("error.dev.package.illegal", [packagePath]));
148
+ throw new import_core.DevError(this.ctx.format("error.dev.package.illegal", [packagePath]));
236
149
  }
237
150
  const result = modulePackageSchema.parseSafe(pkg);
238
151
  if (!result.value) {
239
152
  if (rootDir !== this.ctx.baseDir.modules) return;
240
- throw new import_core4.DevError(this.ctx.format("error.dev.package.missing", [packagePath, result.error.message]));
153
+ throw new import_core.DevError(this.ctx.format("error.dev.package.missing", [packagePath, result.error.message]));
241
154
  }
242
155
  pkg = result.data;
243
- const devMode = this.isSourceDev && (0, import_node_fs2.existsSync)(import_node_path3.default.resolve(dir, DEV_IMPORT));
244
- const main = import_node_path3.default.resolve(dir, devMode ? DEV_IMPORT : pkg.main);
245
- if (!import_node_fs2.default.existsSync(main)) throw new import_core4.DevError(this.ctx.format("error.dev.main_file", [main]));
246
- const dirs = import_node_path3.default.join(dir, devMode ? DEV_CODE_DIRS : import_node_path3.default.dirname(pkg.main));
247
- const files = import_node_fs2.default.statSync(dirs).isDirectory() ? this.getDirFiles(dirs) : [];
248
- this[import_core4.Symbols.modules].set(pkg.name, [
156
+ const devMode = this.isDev && (0, import_node_fs.existsSync)(import_node_path.default.resolve(dir, import_constants.DEV_IMPORT));
157
+ const main = import_node_path.default.resolve(dir, devMode ? import_constants.DEV_IMPORT : pkg.main);
158
+ if (!import_node_fs.default.existsSync(main)) throw new import_core.DevError(this.ctx.format("error.dev.main_file", [main]));
159
+ const dirs = import_node_path.default.join(dir, devMode ? import_constants.DEV_CODE_DIRS : import_node_path.default.dirname(pkg.main));
160
+ const files = import_node_fs.default.statSync(dirs).isDirectory() ? this.getDirFiles(dirs) : [];
161
+ this[import_core.Symbols.modules].set(pkg.name, [
249
162
  { pkg, files, main },
250
- this.ctx.config.plugin[(0, import_core4.stringRightSplit)(pkg.name, import_core4.PLUGIN_PREFIX)] || {}
163
+ this.ctx.config.plugin[(0, import_core.stringRightSplit)(pkg.name, import_core.PLUGIN_PREFIX)] || {}
251
164
  ]);
252
165
  }
253
166
  getModuleList(rootDir) {
254
167
  this.ctx.logger.trace("load dirs:", rootDir);
255
- import_node_fs2.default.readdirSync(rootDir).forEach(async (filename) => {
168
+ import_node_fs.default.readdirSync(rootDir).forEach(async (filename) => {
256
169
  await this.checkModuleFiles(rootDir, filename);
257
170
  });
258
171
  }
259
172
  loadLang(lang) {
260
- if (lang) this.ctx.i18n.use((0, import_node_path3.resolve)(...Array.isArray(lang) ? lang : [lang]));
173
+ if (lang) this.ctx.i18n.use((0, import_node_path.resolve)(...Array.isArray(lang) ? lang : [lang]));
261
174
  }
262
175
  loadEx(instance, origin) {
263
176
  this.ctx.logger.trace("module:", instance, origin);
@@ -265,32 +178,32 @@ var Runner = class {
265
178
  const parsed = (schema) => {
266
179
  const result = schema.parseSafe(config);
267
180
  if (!result.value)
268
- throw new import_core4.ModuleError(this.ctx.format("error.module.config", [pkg.name, result.error.message]));
181
+ throw new import_core.ModuleError(this.ctx.format("error.module.config", [pkg.name, result.error.message]));
269
182
  return result.data;
270
183
  };
271
184
  const { main, pkg } = instance;
272
185
  let obj = require(main);
273
186
  let config = origin;
274
- const adapterName = pkg.name.split(import_core4.ADAPTER_PREFIX)[1];
187
+ const adapterName = pkg.name.split(import_core.ADAPTER_PREFIX)[1];
275
188
  if (this.ctx.get("decorators")?.registers.includes(pkg.name)) {
276
189
  this.ctx.emit("ready_module_decorators", pkg.name);
277
190
  return;
278
191
  }
279
- if (import_core4.Adapter.isPrototypeOf.call(import_core4.Adapter, obj.default) && adapterName && (!obj.config || obj.config instanceof import_core4.Parser)) {
280
- this.ctx[import_core4.Symbols.adapter].set(adapterName, [obj.default, obj.config]);
192
+ if (import_core.Adapter.isPrototypeOf.call(import_core.Adapter, obj.default) && adapterName && (!obj.config || obj.config instanceof import_core.Parser)) {
193
+ this.ctx[import_core.Symbols.adapter].set(adapterName, [obj.default, obj.config]);
281
194
  obj = {};
282
- } else if (import_core4.Service.isPrototypeOf.call(import_core4.Service, obj.default)) {
195
+ } else if (import_core.Service.isPrototypeOf.call(import_core.Service, obj.default)) {
283
196
  obj = {};
284
- } else if (obj.config instanceof import_core4.Parser) {
197
+ } else if (obj.config instanceof import_core.Parser) {
285
198
  config = parsed(obj.config);
286
199
  }
287
200
  if (obj.lang) this.loadLang(obj.lang);
288
201
  if (obj.default) {
289
202
  if (obj.default.lang) this.loadLang(obj.default.lang);
290
- if (obj.default.config instanceof import_core4.Parser) config = parsed(obj.default.config);
203
+ if (obj.default.config instanceof import_core.Parser) config = parsed(obj.default.config);
291
204
  } else if (obj.Main) {
292
205
  if (obj.Main.lang) this.loadLang(obj.Main.lang);
293
- if (obj.Main.config instanceof import_core4.Parser) config = parsed(obj.Main.config);
206
+ if (obj.Main.config instanceof import_core.Parser) config = parsed(obj.Main.config);
294
207
  }
295
208
  this.ctx.load({ name: pkg.name, ...obj, config });
296
209
  }
@@ -301,14 +214,14 @@ var Runner = class {
301
214
  loadAll() {
302
215
  this.getModuleRootDir().forEach((dir) => this.getModuleList(dir));
303
216
  const modules = [];
304
- this[import_core4.Symbols.modules].forEach((val) => modules.push(val));
217
+ this[import_core.Symbols.modules].forEach((val) => modules.push(val));
305
218
  modules.sort(([{ pkg: pkg1 }], [{ pkg: pkg2 }]) => moduleLoadOrder(pkg1) - moduleLoadOrder(pkg2)).forEach((el) => this.loadEx(...el));
306
219
  if (this.isDev) this.watcher();
307
220
  }
308
221
  watcher() {
309
- this[import_core4.Symbols.modules].forEach(
222
+ this[import_core.Symbols.modules].forEach(
310
223
  (data) => data[0].files.forEach(
311
- (file) => import_node_fs2.default.watchFile(file, async () => {
224
+ (file) => import_node_fs.default.watchFile(file, async () => {
312
225
  this.ctx.logger.debug(this.ctx.format("loader.debug.reload", [data[0].pkg.name]));
313
226
  this.unloadEx(data[0]);
314
227
  this.loadEx(...data);
@@ -316,7 +229,7 @@ var Runner = class {
316
229
  )
317
230
  );
318
231
  }
319
- };
232
+ }
320
233
  var runner_default = Runner;
321
234
  // Annotate the CommonJS export names for ESM import in node:
322
235
  0 && (module.exports = {
@@ -9,5 +9,4 @@ export declare const SUPPORTS_VERSION: RegExp;
9
9
  export declare const SUPPORTS_HALF_VERSION: RegExp;
10
10
  export declare const BUILD_MODE: "build";
11
11
  export declare const DEV_MODE: "dev";
12
- export declare const DEV_SOURCE_MODE: "dev-source";
13
12
  export declare const CORE_MODULES: string[];
package/lib/constants.js CHANGED
@@ -1,12 +1,12 @@
1
1
 
2
2
  /**
3
3
  * @Package @kotori-bot/loader
4
- * @Version 1.6.0-beta.1
4
+ * @Version 1.6.2
5
5
  * @Author Hotaru <biyuehuya@gmail.com>
6
6
  * @Copyright 2024 Hotaru. All rights reserved.
7
7
  * @License GPL-3.0
8
8
  * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/6 21:03:54
9
+ * @Date 2024/6/7 11:53:11
10
10
  */
11
11
 
12
12
  "use strict";
@@ -27,8 +27,6 @@ var __copyProps = (to, from, except, desc) => {
27
27
  return to;
28
28
  };
29
29
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/constants.ts
32
30
  var constants_exports = {};
33
31
  __export(constants_exports, {
34
32
  BUILD_CONFIG_NAME: () => BUILD_CONFIG_NAME,
@@ -41,26 +39,23 @@ __export(constants_exports, {
41
39
  DEV_FILE: () => DEV_FILE,
42
40
  DEV_IMPORT: () => DEV_IMPORT,
43
41
  DEV_MODE: () => DEV_MODE,
44
- DEV_SOURCE_MODE: () => DEV_SOURCE_MODE,
45
42
  SUPPORTS_HALF_VERSION: () => SUPPORTS_HALF_VERSION,
46
43
  SUPPORTS_VERSION: () => SUPPORTS_VERSION
47
44
  });
48
45
  module.exports = __toCommonJS(constants_exports);
49
- var DEV_FILE = ".ts";
50
- var BUILD_FILE = ".js";
51
- var DEV_CODE_DIRS = "./src/";
52
- var DEV_IMPORT = `${DEV_CODE_DIRS}index.ts`;
53
- var CONFIG_EXT = [".toml", ".yml", ".yaml", ".json"];
54
- var BUILD_CONFIG_NAME = "kotori";
55
- var DEV_CONFIG_NAME = "kotori.dev";
56
- var SUPPORTS_VERSION = /(1\.1\.0)|(1\.2\.0)|(1\.3\.(.*))|(1\.4\.(.*))/;
57
- var SUPPORTS_HALF_VERSION = /(x\.x\.(.*?))/;
58
- var BUILD_MODE = "build";
59
- var DEV_MODE = "dev";
60
- var DEV_SOURCE_MODE = "dev-source";
61
- var CORE_MODULES = [
46
+ const DEV_FILE = ".ts";
47
+ const BUILD_FILE = ".js";
48
+ const DEV_CODE_DIRS = "./src/";
49
+ const DEV_IMPORT = `${DEV_CODE_DIRS}index.ts`;
50
+ const CONFIG_EXT = [".toml", ".yml", ".yaml", ".json"];
51
+ const BUILD_CONFIG_NAME = "kotori";
52
+ const DEV_CONFIG_NAME = "kotori.dev";
53
+ const SUPPORTS_VERSION = /(1\.1\.0)|(1\.2\.0)|(1\.3\.(.*))|(1\.4\.(.*))/;
54
+ const SUPPORTS_HALF_VERSION = /(x\.x\.(.*?))/;
55
+ const BUILD_MODE = "build";
56
+ const DEV_MODE = "dev";
57
+ const CORE_MODULES = [
62
58
  "@kotori-bot/kotori-plugin-core",
63
- "@kotori-bot/kotori-plugin-i18n-command",
64
59
  "@kotori-bot/kotori-plugin-filter"
65
60
  // '@kotori-bot/kotori-plugin-webui'
66
61
  ];
@@ -76,7 +71,6 @@ var CORE_MODULES = [
76
71
  DEV_FILE,
77
72
  DEV_IMPORT,
78
73
  DEV_MODE,
79
- DEV_SOURCE_MODE,
80
74
  SUPPORTS_HALF_VERSION,
81
75
  SUPPORTS_VERSION
82
76
  });
@@ -1,18 +1,20 @@
1
1
 
2
2
  /**
3
3
  * @Package @kotori-bot/loader
4
- * @Version 1.6.0-beta.1
4
+ * @Version 1.6.2
5
5
  * @Author Hotaru <biyuehuya@gmail.com>
6
6
  * @Copyright 2024 Hotaru. All rights reserved.
7
7
  * @License GPL-3.0
8
8
  * @Link https://github.com/kotorijs/kotori
9
- * @Date 2024/6/6 21:03:54
9
+ * @Date 2024/6/7 11:53:11
10
10
  */
11
11
 
12
12
  "use strict";
13
+ var __create = Object.create;
13
14
  var __defProp = Object.defineProperty;
14
15
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
15
16
  var __getOwnPropNames = Object.getOwnPropertyNames;
17
+ var __getProtoOf = Object.getPrototypeOf;
16
18
  var __hasOwnProp = Object.prototype.hasOwnProperty;
17
19
  var __export = (target, all) => {
18
20
  for (var name in all)
@@ -26,140 +28,42 @@ var __copyProps = (to, from, except, desc) => {
26
28
  }
27
29
  return to;
28
30
  };
31
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
32
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
33
+ // If the importer is in node compatibility mode or this is not an ESM
34
+ // file that has been converted to a CommonJS file using a Babel-
35
+ // compatible transform (i.e. "__esModule" has not been set), then set
36
+ // "default" to the CommonJS "module.exports" for node compatibility.
37
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
+ mod
39
+ ));
29
40
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/decorators/index.ts
32
41
  var decorators_exports = {};
33
42
  __export(decorators_exports, {
34
- KotoriPlugin: () => KotoriPlugin,
35
43
  default: () => decorators_default,
36
44
  plugins: () => plugins
37
45
  });
38
46
  module.exports = __toCommonJS(decorators_exports);
39
- var import_node_fs = require("fs");
40
- var import_node_path2 = require("path");
41
- var import_core2 = require("@kotori-bot/core");
42
-
43
- // src/decorators/utils.ts
44
- var import_node_path = require("path");
47
+ var import_node_fs = require("node:fs");
48
+ var import_node_path = require("node:path");
45
49
  var import_core = require("@kotori-bot/core");
46
- var Decorators = class {
47
- ctx;
48
- isCreated = false;
49
- object;
50
- /* eslint-disable @typescript-eslint/no-explicit-any */
51
- register(callback) {
52
- return (...args) => this.ctx.root.once("ready_module_decorators", (pkgName) => {
53
- if (pkgName === this.ctx.identity) {
54
- callback(...args);
55
- return;
56
- }
57
- this.register(callback);
58
- });
59
- }
60
- /* eslint-enable @typescript-eslint/no-explicit-any */
61
- constructor(ctx) {
62
- this.ctx = ctx;
63
- if (!this.ctx.root.get("decorators")) this.ctx.root.provide("decorators", { registers: [] });
64
- if (this.ctx.identity) this.ctx.root.get("decorators").registers.push(this.ctx.identity);
65
- }
66
- import = (Target) => {
67
- this.register(() => {
68
- if (!this.isCreated) this.schema(Target, void 0);
69
- })();
70
- };
71
- lang = (target, property) => {
72
- this.register(() => {
73
- const lang = target[property];
74
- this.ctx.parent.i18n.use((0, import_node_path.resolve)(...Array.isArray(lang) ? lang : [lang]));
75
- })();
76
- };
77
- inject = (target, property) => {
78
- this.register(() => {
79
- const inject = target[property];
80
- inject.forEach(
81
- (identity) => this.ctx[import_core.Tokens.container].forEach((service, name) => {
82
- if (!(service instanceof import_core.Service) || service.identity !== identity) return;
83
- this.ctx.inject(name);
84
- })
85
- );
86
- })();
87
- };
88
- schema = (Target, property) => {
89
- this.register(() => {
90
- let config = (this.ctx[import_core.Symbols.modules].get(this.ctx.identity) ?? [])[1];
91
- if (Target[property]) {
92
- const result = Target[property].parseSafe(config);
93
- if (!result.value)
94
- throw new import_core.ModuleError(`Config format of module ${this.ctx.identity} is error: ${result.error.message}`);
95
- config = result.data;
96
- }
97
- if (this.isCreated) return;
98
- this.isCreated = true;
99
- this.object = new Target(this.ctx, config);
100
- this.ctx.root.emit("ready_module", { instance: { name: this.ctx.identity, config } });
101
- })();
102
- };
103
- on(meta) {
104
- return this.register(
105
- (target, property) => this.ctx.on(meta.type, (...args) => target[property].bind(this.object)(...args))
106
- );
107
- }
108
- once(meta) {
109
- return this.register(
110
- (target, property) => this.ctx.once(meta.type, (...args) => target[property].bind(this.object)(...args))
111
- );
112
- }
113
- midware(meta) {
114
- return this.register(
115
- (target, property) => this.ctx.midware((next, session) => target[property].bind(this.object)(next, session), meta?.priority)
116
- );
117
- }
118
- command(meta) {
119
- return this.register((target, property) => {
120
- const command = this.ctx.command(meta.template, meta).action((data, session) => target[property].bind(this.object)(data, session));
121
- meta.options?.forEach(([name, template]) => command.option(name, template));
122
- });
123
- }
124
- regexp(meta) {
125
- return this.register(
126
- (target, property) => this.ctx.regexp(meta.match, (match, session) => target[property].bind(this.object)(match, session))
127
- );
128
- }
129
- task(meta) {
130
- return this.register(
131
- (target, property) => this.ctx.task(meta, (ctx) => target[property].bind(this.object)(ctx))
132
- );
133
- }
134
- };
135
- var utils_default = Decorators;
136
-
137
- // src/decorators/plugin.ts
138
- var KotoriPlugin = class {
139
- ctx;
140
- config;
141
- constructor(ctx, config) {
142
- this.ctx = ctx;
143
- this.config = config;
144
- }
145
- };
146
-
147
- // src/decorators/index.ts
50
+ var import_utils = __toESM(require("./utils"));
51
+ __reExport(decorators_exports, require("./plugin"), module.exports);
148
52
  function plugins(plugin) {
149
53
  let pkgName;
150
54
  if (!Array.isArray(plugin) && typeof plugin === "object") {
151
55
  pkgName = plugin.name;
152
56
  } else {
153
57
  pkgName = JSON.parse(
154
- (0, import_node_fs.readFileSync)((0, import_node_path2.resolve)(...Array.isArray(plugin) ? plugin : [plugin], "package.json")).toString()
58
+ (0, import_node_fs.readFileSync)((0, import_node_path.resolve)(...Array.isArray(plugin) ? plugin : [plugin], "package.json")).toString()
155
59
  ).name;
156
60
  }
157
- const ctx = import_core2.Container.getInstance().extends(void 0, pkgName);
158
- return new utils_default(ctx);
61
+ const ctx = import_core.Container.getInstance().extends(void 0, pkgName);
62
+ return new import_utils.default(ctx);
159
63
  }
160
64
  var decorators_default = plugins;
161
65
  // Annotate the CommonJS export names for ESM import in node:
162
66
  0 && (module.exports = {
163
- KotoriPlugin,
164
- plugins
67
+ plugins,
68
+ ...require("./plugin")
165
69
  });