create-m5kdev 0.15.0 → 0.15.1
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 +1 -1
- package/templates/minimal-app/README.md.tpl +2 -1
- package/templates/minimal-app/apps/server/drizzle/generate-schema.ts.tpl +33 -0
- package/templates/minimal-app/apps/server/drizzle/sync.ts.tpl +9 -6
- package/templates/minimal-app/apps/server/drizzle.config.ts.tpl +3 -6
- package/templates/minimal-app/apps/server/package.json.tpl +9 -8
- package/templates/minimal-app/apps/server/src/app.ts.tpl +12 -30
- package/templates/minimal-app/apps/server/src/modules.ts.tpl +36 -0
package/package.json
CHANGED
|
@@ -18,7 +18,8 @@ pnpm --filter ./apps/server seed
|
|
|
18
18
|
pnpm dev
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
The starter uses a local LibSQL file by default and writes local auth emails to `apps/server/.emails`.
|
|
21
|
+
The starter uses a local LibSQL file by default and writes local auth emails to `apps/server/.emails`.
|
|
22
|
+
Before running `drizzle-kit`, the starter generates `apps/server/src/generated/schema.ts` from the registered backend modules.
|
|
22
23
|
|
|
23
24
|
## Demo Credentials
|
|
24
25
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { collectBackendSchema, generateBackendSchemaSource } from "@m5kdev/backend/app";
|
|
4
|
+
import { backendModules } from "../src/modules";
|
|
5
|
+
|
|
6
|
+
export async function generateSchema(): Promise<void> {
|
|
7
|
+
const collected = collectBackendSchema(backendModules, {
|
|
8
|
+
env: process.env,
|
|
9
|
+
});
|
|
10
|
+
const outputDirectory = path.resolve(process.cwd(), "src/generated");
|
|
11
|
+
const outputPath = path.join(outputDirectory, "schema.ts");
|
|
12
|
+
|
|
13
|
+
const source = [
|
|
14
|
+
'import { collectBackendSchema } from "@m5kdev/backend/app";',
|
|
15
|
+
'import { backendModules } from "../modules";',
|
|
16
|
+
"",
|
|
17
|
+
"const collected = collectBackendSchema(backendModules, {",
|
|
18
|
+
" env: process.env,",
|
|
19
|
+
"});",
|
|
20
|
+
"",
|
|
21
|
+
generateBackendSchemaSource({
|
|
22
|
+
schema: collected.schema,
|
|
23
|
+
schemaExpression: "collected.schema",
|
|
24
|
+
}),
|
|
25
|
+
].join("\n");
|
|
26
|
+
|
|
27
|
+
await fs.mkdir(outputDirectory, { recursive: true });
|
|
28
|
+
await fs.writeFile(outputPath, source, "utf8");
|
|
29
|
+
|
|
30
|
+
console.info(`Generated Drizzle schema at ${outputPath}`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
void generateSchema();
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { spawnSync } from "node:child_process";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { generateSchema } from "./generate-schema";
|
|
3
|
+
|
|
4
|
+
export async function syncDatabase(): Promise<void> {
|
|
5
|
+
await generateSchema();
|
|
6
|
+
|
|
7
|
+
const command = process.platform === "win32" ? "drizzle-kit.cmd" : "drizzle-kit";
|
|
8
|
+
const result = spawnSync(command, ["push", "--config", "drizzle.config.ts", "--force"], {
|
|
9
|
+
cwd: process.cwd(),
|
|
7
10
|
env: process.env,
|
|
8
11
|
stdio: "inherit",
|
|
9
12
|
});
|
|
@@ -3,12 +3,9 @@ import { defineConfig } from "drizzle-kit";
|
|
|
3
3
|
|
|
4
4
|
dotenv.config({ path: "../shared/.env" });
|
|
5
5
|
|
|
6
|
-
const url = process.env.TURSO_DATABASE_URL || process.env.DATABASE_URL;
|
|
7
|
-
const authToken = process.env.TURSO_AUTH_TOKEN;
|
|
8
|
-
const schema =
|
|
9
|
-
"./src/modules/**/*.db.ts",
|
|
10
|
-
"./node_modules/@m5kdev/backend/dist/src/modules/auth/*.db.js",
|
|
11
|
-
];
|
|
6
|
+
const url = process.env.TURSO_DATABASE_URL || process.env.DATABASE_URL;
|
|
7
|
+
const authToken = process.env.TURSO_AUTH_TOKEN;
|
|
8
|
+
const schema = "./src/generated/schema.ts";
|
|
12
9
|
|
|
13
10
|
if (!url) {
|
|
14
11
|
throw new Error("DATABASE_URL or TURSO_DATABASE_URL must be set");
|
|
@@ -5,14 +5,15 @@
|
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "tsx watch --env-file=../shared/.env src/index.ts",
|
|
8
|
-
"build": "tsup",
|
|
9
|
-
"start": "node dist/index.js",
|
|
10
|
-
"lint": "biome check .",
|
|
11
|
-
"lint:fix": "biome check . --write",
|
|
12
|
-
"check-types": "tsc --noEmit",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
8
|
+
"build": "tsup",
|
|
9
|
+
"start": "node dist/index.js",
|
|
10
|
+
"lint": "biome check .",
|
|
11
|
+
"lint:fix": "biome check . --write",
|
|
12
|
+
"check-types": "tsc --noEmit",
|
|
13
|
+
"generate:schema": "tsx --env-file=../shared/.env drizzle/generate-schema.ts",
|
|
14
|
+
"sync": "tsx --env-file=../shared/.env drizzle/sync.ts",
|
|
15
|
+
"seed": "tsx --env-file=../shared/.env drizzle/seed.ts"
|
|
16
|
+
},
|
|
16
17
|
"dependencies": {
|
|
17
18
|
"{{PACKAGE_SCOPE}}/email": "workspace:*",
|
|
18
19
|
"{{PACKAGE_SCOPE}}/shared": "workspace:*",
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { createBackendApp, type InferBackendAppRouter } from "@m5kdev/backend/app";
|
|
2
2
|
import { createBetterAuth } from "@m5kdev/backend/modules/auth/auth.lib";
|
|
3
|
-
import { createAuthBackendModule } from "@m5kdev/backend/modules/auth/auth.module";
|
|
4
|
-
import { createEmailBackendModule } from "@m5kdev/backend/modules/email/email.module";
|
|
5
|
-
import { createNotificationBackendModule } from "@m5kdev/backend/modules/notification/notification.module";
|
|
6
|
-
import { createWorkflowBackendModule } from "@m5kdev/backend/modules/workflow/workflow.module";
|
|
7
|
-
import { templates } from "{{PACKAGE_SCOPE}}/email";
|
|
8
3
|
import type { inferRouterInputs, inferRouterOutputs } from "@trpc/server";
|
|
9
4
|
import cors from "cors";
|
|
10
5
|
import express from "express";
|
|
11
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
authBackendModule,
|
|
8
|
+
emailBackendModule,
|
|
9
|
+
notificationBackendModule,
|
|
10
|
+
postsBackendModule,
|
|
11
|
+
workflowBackendModule,
|
|
12
|
+
} from "./modules";
|
|
12
13
|
|
|
13
14
|
const app = express();
|
|
14
15
|
const appUrl = process.env.VITE_APP_URL ?? "http://localhost:5173";
|
|
@@ -80,30 +81,11 @@ export const backendApp = createBackendApp({
|
|
|
80
81
|
},
|
|
81
82
|
},
|
|
82
83
|
})
|
|
83
|
-
.use(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
88
|
-
.use(
|
|
89
|
-
createAuthBackendModule({
|
|
90
|
-
emailModuleId: "email",
|
|
91
|
-
})
|
|
92
|
-
)
|
|
93
|
-
.use(
|
|
94
|
-
createWorkflowBackendModule({
|
|
95
|
-
queues: {
|
|
96
|
-
fast: { concurrency: 5 },
|
|
97
|
-
},
|
|
98
|
-
defaultQueue: "fast",
|
|
99
|
-
defaults: {
|
|
100
|
-
timeout: 60_000,
|
|
101
|
-
jobOptions: { removeOnComplete: { age: 3600 } },
|
|
102
|
-
},
|
|
103
|
-
})
|
|
104
|
-
)
|
|
105
|
-
.use(createNotificationBackendModule())
|
|
106
|
-
.use(postsModule);
|
|
84
|
+
.use(emailBackendModule)
|
|
85
|
+
.use(authBackendModule)
|
|
86
|
+
.use(workflowBackendModule)
|
|
87
|
+
.use(notificationBackendModule)
|
|
88
|
+
.use(postsBackendModule);
|
|
107
89
|
|
|
108
90
|
export const builtBackendApp = backendApp.build();
|
|
109
91
|
export const appRouter = builtBackendApp.trpc.router;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createAuthBackendModule } from "@m5kdev/backend/modules/auth/auth.module";
|
|
2
|
+
import { createEmailBackendModule } from "@m5kdev/backend/modules/email/email.module";
|
|
3
|
+
import { createNotificationBackendModule } from "@m5kdev/backend/modules/notification/notification.module";
|
|
4
|
+
import { createWorkflowBackendModule } from "@m5kdev/backend/modules/workflow/workflow.module";
|
|
5
|
+
import { templates } from "{{PACKAGE_SCOPE}}/email";
|
|
6
|
+
import { postsModule } from "./modules/posts/posts.module";
|
|
7
|
+
|
|
8
|
+
export const emailBackendModule = createEmailBackendModule({
|
|
9
|
+
templates: templates as never,
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
export const authBackendModule = createAuthBackendModule({
|
|
13
|
+
emailModuleId: "email",
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const workflowBackendModule = createWorkflowBackendModule({
|
|
17
|
+
queues: {
|
|
18
|
+
fast: { concurrency: 5 },
|
|
19
|
+
},
|
|
20
|
+
defaultQueue: "fast",
|
|
21
|
+
defaults: {
|
|
22
|
+
timeout: 60_000,
|
|
23
|
+
jobOptions: { removeOnComplete: { age: 3600 } },
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const notificationBackendModule = createNotificationBackendModule();
|
|
28
|
+
export const postsBackendModule = postsModule;
|
|
29
|
+
|
|
30
|
+
export const backendModules = [
|
|
31
|
+
emailBackendModule,
|
|
32
|
+
authBackendModule,
|
|
33
|
+
workflowBackendModule,
|
|
34
|
+
notificationBackendModule,
|
|
35
|
+
postsBackendModule,
|
|
36
|
+
] as const;
|