create-disposabl-app 0.4.0 → 0.4.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/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import { fileURLToPath } from "node:url";
8
8
  import { Command, CommanderError } from "commander";
9
9
  import * as p2 from "@clack/prompts";
10
10
  // package.json
11
- var version = "0.4.0";
11
+ var version = "0.4.2";
12
12
 
13
13
  // ../disposabl-kit/platforms.ts
14
14
  var platforms = [
@@ -404,10 +404,11 @@ async function createApp(template, destination, name, config, overwrite = false)
404
404
  var jsonOutput = process.argv.slice(2).includes("--json");
405
405
  var program = new Command("create-disposabl-app").description("Create a Disposabl starter. Web and authentication are always included.").version(version, "-v, --version").argument("[appname]", "App name and new directory").option("--platforms <ids>", "Comma-separated platform IDs; Web is always included").option("--features <ids>", "Comma-separated optional feature IDs, or none; authentication is always included").option("-y, --yes", "Skip prompts; include Web and authentication, with no optional features").option("--skip-install", "Create files without running bun install").option("--list-options", "List every platform and feature, including disabled choices").option("--json", "Skip prompts and emit a JSON result or error; install logs go to stderr").helpOption("-h, --help").addHelpText("after", `
406
406
  Platforms:
407
- web (required), android, ios, windows, linux, macos, mcp,
408
- openai-plugin, claude-code-plugin
407
+ web (required), android, ios, windows, linux, macos, api, mcp,
408
+ cli, typescript-sdk, openai-plugin, claude-code-plugin
409
+ CLI and TypeScript SDK automatically include API.
409
410
  Either plugin automatically includes MCP.
410
- Disabled: api, cli, python-sdk, typescript-sdk
411
+ Disabled: python-sdk
411
412
 
412
413
  Optional features:
413
414
  docs, blog, changelog
@@ -1,10 +1,15 @@
1
1
  import kitRouter from "@disposabl/disposabl-kit/client/vite.config";
2
- import { createPrerenderFilter } from "@disposabl/disposabl-kit/client/lib/prerender";
2
+ import {
3
+ createPrerenderFilter,
4
+ pageRoutes,
5
+ } from "@disposabl/disposabl-kit/client/lib/prerender";
3
6
  import tailwindcss from "@tailwindcss/vite";
4
7
  import { devtools } from "@tanstack/devtools-vite";
5
8
  import { tanstackStart } from "@tanstack/react-start/plugin/vite";
6
9
  import viteReact from "@vitejs/plugin-react";
7
10
  import { defineConfig, loadEnv } from "vite";
11
+ import { readFileSync, writeFileSync } from "node:fs";
12
+ import { execFileSync } from "node:child_process";
8
13
 
9
14
  const config = defineConfig(({ mode }) => {
10
15
  const { VITE_CONVEX_SITE_URL } = loadEnv(mode, process.cwd(), "VITE_");
@@ -36,6 +41,7 @@ const config = defineConfig(({ mode }) => {
36
41
  tailwindcss(),
37
42
  tanstackStart({
38
43
  router: kitRouter,
44
+ spa: { enabled: true, maskPath: "/?shell" },
39
45
  prerender: {
40
46
  enabled: true,
41
47
  autoStaticPathsDiscovery: true,
@@ -49,6 +55,19 @@ const config = defineConfig(({ mode }) => {
49
55
  {
50
56
  name: "site-robots",
51
57
  apply: "build",
58
+ writeBundle() {
59
+ if (this.environment.name !== "client") return;
60
+ const output = "../../packages/backend/generated/pages.json";
61
+ writeFileSync(
62
+ output,
63
+ JSON.stringify(
64
+ pageRoutes(readFileSync("src/routeTree.gen.ts", "utf8")),
65
+ null,
66
+ 2,
67
+ ) + "\n",
68
+ );
69
+ execFileSync("bun", ["fmt", output], { stdio: "pipe" });
70
+ },
52
71
  generateBundle() {
53
72
  if (this.environment.name !== "client") return;
54
73
  this.emitFile({
@@ -9,6 +9,7 @@ import {
9
9
  } from "../disposabl-kit/server/lib/platform-spec";
10
10
 
11
11
  import config from "../../disposabl.json";
12
+ import { pageRoutes } from "../disposabl-kit/client/lib/prerender";
12
13
 
13
14
  const root = fileURLToPath(new URL(".", import.meta.url));
14
15
  const convex = join(root, "convex");
@@ -84,6 +85,19 @@ export async function generate(acceptBreaking = false) {
84
85
  .join("\n") +
85
86
  `\nexport default {${paths.map((path, index) => `${JSON.stringify(path)}: m${index}`).join(",")}};\n`;
86
87
  await mkdir(output, { recursive: true });
88
+ await writeChanged(
89
+ join(output, "pages.json"),
90
+ JSON.stringify(
91
+ pageRoutes(
92
+ await readFile(
93
+ join(root, "../../apps/web/src/routeTree.gen.ts"),
94
+ "utf8",
95
+ ),
96
+ ),
97
+ null,
98
+ 2,
99
+ ) + "\n",
100
+ );
87
101
  await writeChanged(
88
102
  join(output, "openapi.json"),
89
103
  JSON.stringify(next, null, 2) + "\n",
@@ -0,0 +1,34 @@
1
+ [
2
+ {
3
+ "path": "/",
4
+ "authenticated": false
5
+ },
6
+ {
7
+ "path": "/consent",
8
+ "authenticated": false
9
+ },
10
+ {
11
+ "path": "/login",
12
+ "authenticated": false
13
+ },
14
+ {
15
+ "path": "/signup",
16
+ "authenticated": false
17
+ },
18
+ {
19
+ "path": "/dashboard",
20
+ "authenticated": true
21
+ },
22
+ {
23
+ "path": "/dashboard/api-keys",
24
+ "authenticated": true
25
+ },
26
+ {
27
+ "path": "/todos/",
28
+ "authenticated": true
29
+ },
30
+ {
31
+ "path": "/todos/$id",
32
+ "authenticated": true
33
+ }
34
+ ]
@@ -8,8 +8,7 @@ import {
8
8
  import ts from "typescript";
9
9
 
10
10
  /** Read route metadata without executing route components in the Vite config. */
11
- function routeMatcher(source: string) {
12
- const root = createRootRoute();
11
+ export function pageRoutes(source: string) {
13
12
  const paths = new Map<string, boolean>();
14
13
  const file = ts.createSourceFile("routes.ts", source, ts.ScriptTarget.Latest);
15
14
 
@@ -52,6 +51,14 @@ function routeMatcher(source: string) {
52
51
  throw new Error(
53
52
  "No page routes found in the generated TanStack route tree.",
54
53
  );
54
+ return [...paths].map(([path, authenticated]) => ({ path, authenticated }));
55
+ }
56
+
57
+ function routeMatcher(source: string) {
58
+ const root = createRootRoute();
59
+ const paths = new Map(
60
+ pageRoutes(source).map(({ path, authenticated }) => [path, authenticated]),
61
+ );
55
62
 
56
63
  const router = createRouter({
57
64
  routeTree: root.addChildren(
@@ -1,6 +1,5 @@
1
1
  import { getAuthUserId } from "@convex-dev/auth/server";
2
2
  import { McpServer } from "@convex-dev/mcp";
3
- import { registerStaticRoutes } from "@convex-dev/static-hosting";
4
3
  import { httpActionGeneric, httpRouter } from "convex/server";
5
4
  import { components } from "../../backend/convex/_generated/api";
6
5
  import { env } from "../../backend/convex/_generated/server";
@@ -8,12 +7,20 @@ import modules from "../../backend/generated/platforms";
8
7
  import openapi from "../../backend/generated/openapi.json";
9
8
  import config from "../../../disposabl.json";
10
9
  import { validatePlatforms } from "../platforms";
11
- import { createPlatforms } from "./lib/platform-spec";
10
+ import { createOpenApi, createPlatforms } from "./lib/platform-spec";
11
+ import { registerPageRoutes } from "./lib/static";
12
12
 
13
13
  export { tool } from "@convex-dev/mcp";
14
14
  export type { McpServerOptions, McpUser, ToolCtx } from "@convex-dev/mcp";
15
15
 
16
16
  const platforms = createPlatforms(modules);
17
+ if (
18
+ JSON.stringify(createOpenApi(platforms.spec).paths) !==
19
+ JSON.stringify(openapi.paths)
20
+ )
21
+ throw new Error(
22
+ "Generated API contract is stale. Run bun run generate; review incompatible changes before using --accept-breaking.",
23
+ );
17
24
  export const platformSpec = platforms.spec;
18
25
 
19
26
  const enabled = validatePlatforms(config.platforms);
@@ -86,6 +93,6 @@ export default function createHttpRouter() {
86
93
  }),
87
94
  });
88
95
  }
89
- registerStaticRoutes(http, components.staticHosting);
96
+ registerPageRoutes(http);
90
97
  return http;
91
98
  }
@@ -0,0 +1,70 @@
1
+ import { httpActionGeneric, type HttpRouter } from "convex/server";
2
+ import { components } from "../../../backend/convex/_generated/api";
3
+ import pages from "../../../backend/generated/pages.json";
4
+
5
+ const routes = pages.map((page) => ({
6
+ ...page,
7
+ pattern: new RegExp(
8
+ "^" +
9
+ page.path
10
+ .replace(/\/$/, "")
11
+ .split("/")
12
+ .map((part) =>
13
+ part === "$"
14
+ ? ".+"
15
+ : part.startsWith("$")
16
+ ? "[^/]+"
17
+ : part.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"),
18
+ )
19
+ .join("/") +
20
+ "/?$",
21
+ ),
22
+ }));
23
+
24
+ /** Serve prerendered public pages and the app shell only for known protected routes. */
25
+ export function registerPageRoutes(http: HttpRouter) {
26
+ http.route({
27
+ pathPrefix: "/",
28
+ method: "GET",
29
+ handler: httpActionGeneric(async (ctx, request) => {
30
+ let path: string;
31
+ try {
32
+ path = decodeURIComponent(new URL(request.url).pathname);
33
+ } catch {
34
+ return new Response("Bad Request", { status: 400 });
35
+ }
36
+ const page = routes.find(({ pattern }) => pattern.test(path));
37
+ const file =
38
+ page && !path.split("/").at(-1)?.includes(".")
39
+ ? page.authenticated
40
+ ? "/_shell.html"
41
+ : `${path.replace(/\/$/, "")}/index.html`
42
+ : path === "/"
43
+ ? "/index.html"
44
+ : path;
45
+ const asset = await ctx.runQuery(
46
+ components.staticHosting.lib.resolveAssetForHttp,
47
+ { path: file, spaFallback: false },
48
+ );
49
+ if (!asset) return new Response("Not Found", { status: 404 });
50
+ const contentType = asset.contentType;
51
+ const headers = {
52
+ "Content-Type": contentType,
53
+ "Cache-Control": contentType.includes("text/html")
54
+ ? "no-cache"
55
+ : "public, max-age=3600",
56
+ "X-Content-Type-Options": "nosniff",
57
+ ...(page?.authenticated || path === "/_shell.html"
58
+ ? { "X-Robots-Tag": "noindex" }
59
+ : {}),
60
+ };
61
+ if (asset.storageUrl) {
62
+ const response = await fetch(asset.storageUrl);
63
+ return response.ok
64
+ ? new Response(response.body, { headers })
65
+ : new Response("Asset unavailable", { status: 502 });
66
+ }
67
+ return new Response("Asset unavailable", { status: 502 });
68
+ }),
69
+ });
70
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-disposabl-app",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "Create a Disposabl app",
5
5
  "type": "module",
6
6
  "license": "MIT",