@riavzon/bot-detector-create 1.0.6 → 1.0.9

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/create.js CHANGED
@@ -5,6 +5,10 @@ import fs from "node:fs/promises";
5
5
  import path from "node:path";
6
6
  import { spawn } from "node:child_process";
7
7
  //#region src/default.ts
8
+ const defaultStore = { main: {
9
+ driver: "sqlite",
10
+ name: "./bot_detector.sqlite"
11
+ } };
8
12
  const content = `import { defineConfiguration } from '@riavzon/bot-detector';
9
13
 
10
14
  /**
@@ -290,13 +294,17 @@ const start = defineCommand({
290
294
  "cookie-parser",
291
295
  "better-sqlite3"
292
296
  ]);
293
- consola.start("Installing @riavzon/bot-detector and data sources...");
297
+ consola.start("Installing @riavzon/bot-detector...");
294
298
  await run("npm", ["install", "@riavzon/bot-detector"]);
299
+ consola.start("Fetching data sources...");
300
+ await run("npx", ["@riavzon/bot-detector", "init"]);
295
301
  consola.start("Writing botDetectorConfig.ts...");
296
302
  await fs.writeFile(output, content, "utf-8");
297
303
  consola.success("botDetectorConfig.ts created");
298
304
  consola.start("Creating database tables...");
299
- await run("npx", ["@riavzon/bot-detector", "load-schema"]);
305
+ const { defineConfiguration, createTables, getDb } = await import(path.resolve(process.cwd(), "node_modules/@riavzon/bot-detector/dist/main.mjs"));
306
+ await defineConfiguration({ store: defaultStore });
307
+ await createTables(getDb());
300
308
  consola.success("Setup complete. Import botDetectorConfig.ts at the top of your app entry point and mount the middleware.");
301
309
  consola.log("");
302
310
  consola.log("Keep data sources fresh (run daily or via cron):");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riavzon/bot-detector-create",
3
- "version": "1.0.6",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "author": "Sergio contact@riavzon.com",
6
6
  "license": "Apache-2.0",
package/src/create.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
2
3
 
3
4
  import consola from 'consola';
4
5
  import { defineCommand, runMain } from 'citty';
5
6
  import fs from 'node:fs/promises';
6
7
  import path from 'node:path';
7
8
  import { spawn } from 'node:child_process';
8
- import { content } from './default.js';
9
+ import { content, defaultStore } from './default.js';
9
10
 
10
11
  function run(cmd: string, args: string[]): Promise<void> {
11
12
  return new Promise((resolve, reject) => {
@@ -28,16 +29,24 @@ export const start = defineCommand({
28
29
  consola.start('Installing dependencies...');
29
30
  await run('npm', ['install', 'express', 'cookie-parser', 'better-sqlite3']);
30
31
 
31
- consola.start('Installing @riavzon/bot-detector and data sources...');
32
+ consola.start('Installing @riavzon/bot-detector...');
32
33
  await run('npm', ['install', '@riavzon/bot-detector']);
33
34
 
35
+ consola.start('Fetching data sources...');
36
+ await run('npx', ['@riavzon/bot-detector', 'init']);
34
37
 
35
38
  consola.start('Writing botDetectorConfig.ts...');
36
39
  await fs.writeFile(output, content, 'utf-8');
37
40
  consola.success('botDetectorConfig.ts created');
38
41
 
39
42
  consola.start('Creating database tables...');
40
- await run('npx', ['@riavzon/bot-detector', 'load-schema']);
43
+ const pkgMain = path.resolve(process.cwd(), 'node_modules/@riavzon/bot-detector/dist/main.mjs');
44
+ const { defineConfiguration, createTables, getDb } = await import(pkgMain);
45
+
46
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
47
+ await defineConfiguration({ store: defaultStore });
48
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call
49
+ await createTables(getDb());
41
50
 
42
51
  consola.success('Setup complete. Import botDetectorConfig.ts at the top of your app entry point and mount the middleware.');
43
52
  consola.log('');
package/src/default.ts CHANGED
@@ -1,3 +1,5 @@
1
+ export const defaultStore = { main: { driver: 'sqlite' as const, name: './bot_detector.sqlite' } };
2
+
1
3
  export const content = `import { defineConfiguration } from '@riavzon/bot-detector';
2
4
 
3
5
  /**