koishi-plugin-rzgtboeyndxsklmq-commons 1.0.1 → 1.0.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.
package/lib/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { Context, Schema } from 'koishi';
2
- export * from './utils/BeanHelper';
3
- export * from './utils/File';
1
+ import { Context, Schema } from "koishi";
2
+ export * from "./utils/BeanHelper";
3
+ export * from "./utils/File";
4
+ export * from "./utils/Test";
4
5
  export declare const name = "rzgtboeyndxsklmq-commons";
5
6
  export interface Config {
6
7
  }
package/lib/index.js CHANGED
@@ -35,7 +35,9 @@ __export(src_exports, {
35
35
  Config: () => Config,
36
36
  apply: () => apply,
37
37
  name: () => name,
38
- readDirFiles: () => readDirFiles
38
+ readDirFiles: () => readDirFiles,
39
+ test: () => test,
40
+ test2: () => test2
39
41
  });
40
42
  module.exports = __toCommonJS(src_exports);
41
43
  var import_koishi = require("koishi");
@@ -198,24 +200,85 @@ var import_promises = __toESM(require("node:fs/promises"));
198
200
  var import_node_path = __toESM(require("node:path"));
199
201
  async function readDirFiles(dirPath, needDir = false) {
200
202
  const files = await import_promises.default.readdir(dirPath, {
203
+ recursive: true,
201
204
  withFileTypes: true
202
205
  });
203
206
  const paths = [];
204
- files.sort((a, b) => (a.isFile() ? 1 : 0) - (b.isFile() ? 1 : 0));
205
- for (const file of files) {
207
+ files.forEach((file) => {
206
208
  if (file.isDirectory()) {
207
- if (needDir) {
208
- paths.push(import_node_path.default.join(import_node_path.default.resolve(dirPath, file.name), import_node_path.default.sep));
209
+ if (!needDir) {
210
+ return;
209
211
  }
210
- paths.push(...await readDirFiles(import_node_path.default.join(dirPath, file.name)));
212
+ paths.push(import_node_path.default.join(file.parentPath, file.name, import_node_path.default.sep));
211
213
  } else if (file.isFile()) {
212
- paths.push(import_node_path.default.resolve(dirPath, file.name));
214
+ paths.push(import_node_path.default.join(file.parentPath, file.name));
213
215
  }
214
- }
216
+ });
215
217
  return paths;
216
218
  }
217
219
  __name(readDirFiles, "readDirFiles");
218
220
 
221
+ // src/utils/Test.ts
222
+ async function test(name2, count, serial, run) {
223
+ const timeout = setInterval(() => {
224
+ process.stdout.write(".");
225
+ }, 100);
226
+ let timeConsumings = [];
227
+ timeConsumings.length = count;
228
+ const testStartTime = Date.now();
229
+ if (serial) {
230
+ for (let i = 0; i < count; i++) {
231
+ const time = Date.now();
232
+ await run();
233
+ timeConsumings[i] = Date.now() - time;
234
+ }
235
+ } else {
236
+ timeConsumings = [...timeConsumings];
237
+ await Promise.all(
238
+ timeConsumings.map((_, i) => {
239
+ return new Promise((resolve) => {
240
+ setImmediate(async () => {
241
+ const time = Date.now();
242
+ await run();
243
+ timeConsumings[i] = Date.now() - time;
244
+ resolve(0);
245
+ });
246
+ });
247
+ })
248
+ );
249
+ }
250
+ const testTime = Date.now() - testStartTime;
251
+ clearInterval(timeout);
252
+ if (count < 2) {
253
+ console.log(`
254
+ run: ${name2}; total: ${timeConsumings[0]};`);
255
+ return;
256
+ }
257
+ let total = 0;
258
+ let average = 0;
259
+ let highest = 0;
260
+ let lowest = null;
261
+ for (let i = 1; i < timeConsumings.length; i++) {
262
+ const t = timeConsumings[i];
263
+ if (lowest == null || t < lowest) {
264
+ lowest = t;
265
+ }
266
+ highest = Math.max(t, highest);
267
+ total += t;
268
+ }
269
+ average = total / (count - 1);
270
+ console.log(
271
+ `
272
+ run: ${name2}; serial: ${serial}; count: ${count}; testTime: ${testTime}; total: ${total}; first: ${timeConsumings[0]}; average: ${average}; highest: ${highest}; lowest: ${lowest};`
273
+ );
274
+ }
275
+ __name(test, "test");
276
+ async function test2(name2, count, run) {
277
+ await test(name2, count, true, run);
278
+ await test(name2, count, false, run);
279
+ }
280
+ __name(test2, "test2");
281
+
219
282
  // src/index.ts
220
283
  var name = "rzgtboeyndxsklmq-commons";
221
284
  var Config = import_koishi.Schema.object({});
@@ -229,5 +292,7 @@ __name(apply, "apply");
229
292
  Config,
230
293
  apply,
231
294
  name,
232
- readDirFiles
295
+ readDirFiles,
296
+ test,
297
+ test2
233
298
  });
@@ -0,0 +1,2 @@
1
+ export declare function test(name: string, count: number, serial: boolean, run: () => any): Promise<void>;
2
+ export declare function test2(name: string, count: number, run: () => any): Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-rzgtboeyndxsklmq-commons",
3
3
  "description": "",
4
- "version": "1.0.1",
4
+ "version": "1.0.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "scripts": {