create-better-t-stack 3.10.0 → 3.11.0-pr749.5d055e3

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.
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Bin stub for create-better-t-stack.
5
+ * Finds and runs the platform-specific compiled binary.
6
+ *
7
+ * The binary is installed as an optional dependency:
8
+ * @better-t-stack/cli-{platform}-{arch}
9
+ *
10
+ * This stub searches node_modules for the matching binary package.
11
+ */
12
+
13
+ import { spawnSync } from "node:child_process";
14
+ import { existsSync, realpathSync } from "node:fs";
15
+ import { dirname, join } from "node:path";
16
+ import { platform as osPlatform, arch as osArch } from "node:os";
17
+ import { fileURLToPath } from "node:url";
18
+
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ const __dirname = dirname(__filename);
21
+
22
+ function run(target) {
23
+ const result = spawnSync(target, process.argv.slice(2), {
24
+ stdio: "inherit",
25
+ });
26
+ if (result.error) {
27
+ console.error(result.error.message);
28
+ process.exit(1);
29
+ }
30
+ const code = typeof result.status === "number" ? result.status : 0;
31
+ process.exit(code);
32
+ }
33
+
34
+ // Allow override via environment variable
35
+ const envPath = process.env.CREATE_BETTER_T_STACK_BIN_PATH;
36
+ if (envPath) {
37
+ run(envPath);
38
+ }
39
+
40
+ const scriptPath = realpathSync(__filename);
41
+ const scriptDir = dirname(scriptPath);
42
+
43
+ const platformMap = {
44
+ darwin: "darwin",
45
+ linux: "linux",
46
+ win32: "windows",
47
+ };
48
+
49
+ const archMap = {
50
+ x64: "x64",
51
+ arm64: "arm64",
52
+ };
53
+
54
+ let platform = platformMap[osPlatform()];
55
+ if (!platform) {
56
+ platform = osPlatform();
57
+ }
58
+
59
+ let arch = archMap[osArch()];
60
+ if (!arch) {
61
+ arch = osArch();
62
+ }
63
+
64
+ // Scoped package name: @better-t-stack/cli-{platform}-{arch}
65
+ const scopedPackage = "@better-t-stack/cli-" + platform + "-" + arch;
66
+ const binary = platform === "windows" ? "create-better-t-stack.exe" : "create-better-t-stack";
67
+
68
+ function findBinary(startDir) {
69
+ let current = startDir;
70
+ for (; ;) {
71
+ const modules = join(current, "node_modules");
72
+ if (existsSync(modules)) {
73
+ // Check for scoped package: node_modules/@better-t-stack/cli-{platform}-{arch}
74
+ const scopedPath = join(modules, "@better-t-stack", "cli-" + platform + "-" + arch);
75
+ const candidate = join(scopedPath, "bin", binary);
76
+ if (existsSync(candidate)) {
77
+ return candidate;
78
+ }
79
+ }
80
+ const parent = dirname(current);
81
+ if (parent === current) {
82
+ return;
83
+ }
84
+ current = parent;
85
+ }
86
+ }
87
+
88
+ const resolved = findBinary(scriptDir);
89
+
90
+ if (!resolved) {
91
+ console.error(
92
+ 'No binary found for your platform (' + platform + '-' + arch + ').\n' +
93
+ 'You can try manually installing the "' + scopedPackage + '" package.',
94
+ );
95
+ process.exit(1);
96
+ }
97
+
98
+ run(resolved);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-better-t-stack",
3
- "version": "3.10.0",
3
+ "version": "3.11.0-pr749.5d055e3",
4
4
  "description": "A modern CLI tool for scaffolding end-to-end type-safe TypeScript projects with best practices and customizable configurations",
5
5
  "keywords": [
6
6
  "better-auth",
@@ -37,59 +37,55 @@
37
37
  "directory": "apps/cli"
38
38
  },
39
39
  "bin": {
40
- "create-better-t-stack": "dist/cli.mjs"
40
+ "create-better-t-stack": "./bin/create-better-t-stack"
41
41
  },
42
42
  "files": [
43
- "dist",
44
- "templates"
43
+ "bin",
44
+ "templates",
45
+ "scripts/postinstall.mjs"
45
46
  ],
46
47
  "type": "module",
47
- "exports": {
48
- ".": {
49
- "types": "./dist/index.d.mts",
50
- "import": "./dist/index.mjs"
51
- },
52
- "./cli": {
53
- "import": "./dist/cli.mjs"
54
- }
55
- },
56
48
  "publishConfig": {
57
49
  "access": "public"
58
50
  },
59
51
  "scripts": {
60
- "build": "tsdown --publint",
61
- "dev": "tsdown --watch",
52
+ "build": "bun run scripts/build.ts",
53
+ "build:local": "bun run scripts/build.ts --single",
54
+ "dev": "bun run src/cli.ts",
62
55
  "check-types": "tsc --noEmit",
63
- "test": "bun run build && bun test",
64
- "test:watch": "bun run build && bun test --watch",
65
- "test:coverage": "bun run build && bun test --coverage",
66
- "test:ci": "bun run build && AGENT=1 bun test --bail=5",
67
- "prepublishOnly": "npm run build"
56
+ "test": "bun test",
57
+ "test:watch": "bun test --watch",
58
+ "test:coverage": "bun test --coverage",
59
+ "test:ci": "AGENT=1 bun test --bail=5",
60
+ "prepublishOnly": "echo 'Build binaries separately before publishing'",
61
+ "postinstall": "node ./scripts/postinstall.mjs || true"
68
62
  },
69
63
  "dependencies": {
70
- "@better-t-stack/types": "^3.10.0",
64
+ "@better-t-stack/types": "3.11.0-pr749.5d055e3",
71
65
  "@clack/prompts": "^1.0.0-alpha.8",
72
- "@orpc/server": "^1.12.2",
66
+ "commander": "^14.0.2",
73
67
  "consola": "^3.4.2",
74
- "execa": "^9.6.1",
75
- "fs-extra": "^11.3.2",
68
+ "fs-extra": "^11.3.3",
76
69
  "gradient-string": "^3.0.0",
77
70
  "handlebars": "^4.7.8",
78
71
  "jsonc-parser": "^3.3.1",
79
- "oxfmt": "^0.19.0",
80
72
  "picocolors": "^1.1.1",
81
73
  "tinyglobby": "^0.2.15",
82
- "trpc-cli": "^0.12.1",
83
74
  "ts-morph": "^27.0.2",
84
75
  "yaml": "^2.8.2",
85
- "zod": "^4.1.13"
76
+ "zod": "^4.2.1"
86
77
  },
87
78
  "devDependencies": {
88
- "@types/bun": "^1.2.17",
79
+ "@types/bun": "^1.3.5",
89
80
  "@types/fs-extra": "^11.0.4",
90
- "@types/node": "^24.10.2",
91
- "publint": "^0.3.16",
92
- "tsdown": "^0.17.2",
81
+ "@types/node": "^25.0.3",
93
82
  "typescript": "^5.9.3"
83
+ },
84
+ "optionalDependencies": {
85
+ "@better-t-stack/cli-darwin-arm64": "3.11.0",
86
+ "@better-t-stack/cli-darwin-x64": "3.11.0",
87
+ "@better-t-stack/cli-linux-arm64": "3.11.0",
88
+ "@better-t-stack/cli-linux-x64": "3.11.0",
89
+ "@better-t-stack/cli-windows-x64": "3.11.0"
94
90
  }
95
91
  }
@@ -0,0 +1,129 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * Postinstall script for create-better-t-stack.
5
+ * Symlinks the platform-specific binary to the bin directory for convenience.
6
+ *
7
+ * This runs after npm install to set up the binary.
8
+ */
9
+
10
+ import fs from "fs";
11
+ import path from "path";
12
+ import os from "os";
13
+ import { fileURLToPath } from "url";
14
+ import { createRequire } from "module";
15
+
16
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
17
+ const require = createRequire(import.meta.url);
18
+
19
+ function detectPlatformAndArch() {
20
+ let platform;
21
+ switch (os.platform()) {
22
+ case "darwin":
23
+ platform = "darwin";
24
+ break;
25
+ case "linux":
26
+ platform = "linux";
27
+ break;
28
+ case "win32":
29
+ platform = "windows";
30
+ break;
31
+ default:
32
+ platform = os.platform();
33
+ break;
34
+ }
35
+
36
+ let arch;
37
+ switch (os.arch()) {
38
+ case "x64":
39
+ arch = "x64";
40
+ break;
41
+ case "arm64":
42
+ arch = "arm64";
43
+ break;
44
+ default:
45
+ arch = os.arch();
46
+ break;
47
+ }
48
+
49
+ return { platform, arch };
50
+ }
51
+
52
+ function findBinary() {
53
+ const { platform, arch } = detectPlatformAndArch();
54
+ // Scoped package: @better-t-stack/cli-{platform}-{arch}
55
+ const packageName = `@better-t-stack/cli-${platform}-${arch}`;
56
+ const binaryName = platform === "windows" ? "create-better-t-stack.exe" : "create-better-t-stack";
57
+
58
+ try {
59
+ // Use require.resolve to find the package
60
+ const packageJsonPath = require.resolve(`${packageName}/package.json`);
61
+ const packageDir = path.dirname(packageJsonPath);
62
+ const binaryPath = path.join(packageDir, "bin", binaryName);
63
+
64
+ if (!fs.existsSync(binaryPath)) {
65
+ throw new Error(`Binary not found at ${binaryPath}`);
66
+ }
67
+
68
+ return { binaryPath, binaryName };
69
+ } catch (error) {
70
+ throw new Error(`Could not find package ${packageName}: ${error.message}`);
71
+ }
72
+ }
73
+
74
+ function prepareBinDirectory(binaryName) {
75
+ const binDir = path.join(__dirname, "..", "bin");
76
+ const targetPath = path.join(binDir, binaryName);
77
+
78
+ // Ensure bin directory exists
79
+ if (!fs.existsSync(binDir)) {
80
+ fs.mkdirSync(binDir, { recursive: true });
81
+ }
82
+
83
+ // Remove existing binary/symlink if it exists
84
+ try {
85
+ if (fs.existsSync(targetPath) || fs.lstatSync(targetPath).isSymbolicLink()) {
86
+ fs.unlinkSync(targetPath);
87
+ }
88
+ } catch {
89
+ // File doesn't exist, that's fine
90
+ }
91
+
92
+ return { binDir, targetPath };
93
+ }
94
+
95
+ function symlinkBinary(sourcePath, binaryName) {
96
+ const { targetPath } = prepareBinDirectory(binaryName);
97
+
98
+ fs.symlinkSync(sourcePath, targetPath);
99
+ console.log(`create-better-t-stack binary symlinked: ${targetPath} -> ${sourcePath}`);
100
+
101
+ // Verify the file exists after operation
102
+ if (!fs.existsSync(targetPath)) {
103
+ throw new Error(`Failed to symlink binary to ${targetPath}`);
104
+ }
105
+ }
106
+
107
+ async function main() {
108
+ try {
109
+ if (os.platform() === "win32") {
110
+ // On Windows, symlinks require admin privileges
111
+ // The bin stub will find the binary directly
112
+ console.log("Windows detected: skipping symlink (bin stub will find binary directly)");
113
+ return;
114
+ }
115
+
116
+ const { binaryPath, binaryName } = findBinary();
117
+ symlinkBinary(binaryPath, binaryName);
118
+ } catch (error) {
119
+ // Don't fail the install if we can't symlink - the bin stub will still work
120
+ console.log(`Note: Could not symlink binary (${error.message}). The CLI will still work.`);
121
+ }
122
+ }
123
+
124
+ try {
125
+ main();
126
+ } catch (error) {
127
+ // Silently continue - postinstall failures shouldn't break the install
128
+ console.log("Postinstall completed with warnings.");
129
+ }
@@ -64,7 +64,7 @@ export { createAuth };
64
64
  export const getCurrentUser = query({
65
65
  args: {},
66
66
  returns: v.any(),
67
- handler: async function (ctx, args) {
67
+ handler: async function (ctx) {
68
68
  return authComponent.getAuthUser(ctx);
69
69
  },
70
70
  });
@@ -0,0 +1,17 @@
1
+ import { defineApp } from "convex/server";
2
+ {{#if (eq auth "better-auth")}}
3
+ import betterAuth from "@convex-dev/better-auth/convex.config";
4
+ {{/if}}
5
+ {{#if (includes examples "ai")}}
6
+ import agent from "@convex-dev/agent/convex.config";
7
+ {{/if}}
8
+
9
+ const app = defineApp();
10
+ {{#if (eq auth "better-auth")}}
11
+ app.use(betterAuth);
12
+ {{/if}}
13
+ {{#if (includes examples "ai")}}
14
+ app.use(agent);
15
+ {{/if}}
16
+
17
+ export default app;
@@ -0,0 +1,9 @@
1
+ import { Agent } from "@convex-dev/agent";
2
+ import { google } from "@ai-sdk/google";
3
+ import { components } from "./_generated/api";
4
+
5
+ export const chatAgent = new Agent(components.agent, {
6
+ name: "Chat Agent",
7
+ languageModel: google("gemini-2.5-flash"),
8
+ instructions: "You are a helpful AI assistant. Be concise and friendly in your responses.",
9
+ });
@@ -0,0 +1,67 @@
1
+ import {
2
+ createThread,
3
+ listUIMessages,
4
+ saveMessage,
5
+ syncStreams,
6
+ vStreamArgs,
7
+ } from "@convex-dev/agent";
8
+ import { paginationOptsValidator } from "convex/server";
9
+ import { v } from "convex/values";
10
+
11
+ import { components, internal } from "./_generated/api";
12
+ import { internalAction, mutation, query } from "./_generated/server";
13
+ import { chatAgent } from "./agent";
14
+
15
+ export const createNewThread = mutation({
16
+ args: {},
17
+ handler: async (ctx) => {
18
+ const threadId = await createThread(ctx, components.agent, {});
19
+ return threadId;
20
+ },
21
+ });
22
+
23
+ export const listMessages = query({
24
+ args: {
25
+ threadId: v.string(),
26
+ paginationOpts: paginationOptsValidator,
27
+ streamArgs: vStreamArgs,
28
+ },
29
+ handler: async (ctx, args) => {
30
+ const paginated = await listUIMessages(ctx, components.agent, args);
31
+ const streams = await syncStreams(ctx, components.agent, args);
32
+ return { ...paginated, streams };
33
+ },
34
+ });
35
+
36
+ export const sendMessage = mutation({
37
+ args: {
38
+ threadId: v.string(),
39
+ prompt: v.string(),
40
+ },
41
+ handler: async (ctx, { threadId, prompt }) => {
42
+ const { messageId } = await saveMessage(ctx, components.agent, {
43
+ threadId,
44
+ prompt,
45
+ });
46
+ await ctx.scheduler.runAfter(0, internal.chat.generateResponseAsync, {
47
+ threadId,
48
+ promptMessageId: messageId,
49
+ });
50
+ return messageId;
51
+ },
52
+ });
53
+
54
+ export const generateResponseAsync = internalAction({
55
+ args: {
56
+ threadId: v.string(),
57
+ promptMessageId: v.string(),
58
+ },
59
+ handler: async (ctx, { threadId, promptMessageId }) => {
60
+ await chatAgent.streamText(
61
+ ctx,
62
+ { threadId },
63
+ { promptMessageId },
64
+ { saveStreamDeltas: true },
65
+ );
66
+ },
67
+ });