@nilejs/cli 0.0.4 → 0.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nilejs/cli",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "CLI for scaffolding and generating Nile backend projects",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,10 +10,6 @@
10
10
  "dist",
11
11
  "template"
12
12
  ],
13
- "scripts": {
14
- "build": "bun run scripts/build.ts",
15
- "dev": "bun run src/index.ts"
16
- },
17
13
  "dependencies": {
18
14
  "commander": "^13.1.0",
19
15
  "json-schema-to-zod": "^2.7.0",
@@ -22,5 +18,9 @@
22
18
  "devDependencies": {
23
19
  "@types/node": "^22.8.1",
24
20
  "typescript": "^5"
21
+ },
22
+ "scripts": {
23
+ "build": "bun run scripts/build.ts",
24
+ "dev": "bun run src/index.ts"
25
25
  }
26
- }
26
+ }
@@ -1 +1 @@
1
- MODE=dev
1
+ # Add your environment variables here
@@ -4,12 +4,12 @@ import { safeTry } from "slang-ts";
4
4
  import { db } from "@/db/client";
5
5
  import { services } from "@/services/services.config";
6
6
 
7
- const logger = createLogger("{{projectName}}", { chunking: "monthly" });
7
+ const logger = createLogger("{{projectName}}", {
8
+ mode: "dev",
9
+ chunking: "monthly",
10
+ });
8
11
 
9
- /**
10
- * Push schema to PGLite on boot.
11
- * Creates the tasks table if it doesn't exist.
12
- */
12
+ /** Push schema to PGLite on boot */
13
13
  const pushSchema = async () => {
14
14
  const result = await safeTry(() =>
15
15
  db.execute(sql`
@@ -39,29 +39,32 @@ const server = createNileServer({
39
39
  port: 8000,
40
40
  allowedOrigins: ["http://localhost:8000"],
41
41
  enableStatus: true,
42
+ discovery: { enabled: true },
42
43
  },
43
44
  onBoot: {
44
- fn: async () => {
45
+ fn: async (ctx) => {
45
46
  await pushSchema();
46
- logger.info({
47
+ ctx.resources?.logger?.info({
47
48
  atFunction: "onBoot",
48
- message: "{{projectName}} booted — PGLite schema ready",
49
+ message: "{{projectName}} booted - PGLite schema ready",
49
50
  });
50
51
  },
51
52
  },
52
53
  });
53
54
 
55
+ // Register custom middleware (runs before all service requests)
56
+ server.rest?.addMiddleware("/api", async (c, next) => {
57
+ const start = performance.now();
58
+ await next();
59
+ const ms = (performance.now() - start).toFixed(1);
60
+ logger.info({
61
+ atFunction: "requestLog",
62
+ message: `${c.req.method} ${c.req.path} - ${ms}ms`,
63
+ });
64
+ });
65
+
54
66
  if (server.rest) {
55
67
  const port = server.config.rest?.port ?? 8000;
56
- const { fetch } = server.rest.app;
57
-
58
- Bun.serve({ port, fetch });
59
-
60
- console.log(`\n{{projectName}} listening on http://localhost:${port}`);
61
- console.log("\nTry it:");
62
- console.log(` curl -X POST http://localhost:${port}/api/services \\`);
63
- console.log(` -H "Content-Type: application/json" \\`);
64
- console.log(
65
- ` -d '{"intent":"explore","service":"*","action":"*","payload":{}}'`
66
- );
68
+ Bun.serve({ port, fetch: server.rest.app.fetch });
69
+ console.log(`\n{{projectName}} listening on http://localhost:${port}\n`);
67
70
  }