create-disposabl-app 0.3.1 → 0.3.3
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 +36 -8
- package/dist/templates/default/.github/README.md +99 -57
- package/dist/templates/default/.github/actionlint.yaml +6 -0
- package/dist/templates/default/.github/workflows/pipeline.yml.example +492 -0
- package/dist/templates/default/apps/desktop/README.md +44 -14
- package/dist/templates/default/apps/desktop/build-ci.mjs +56 -0
- package/dist/templates/default/apps/desktop/forge.config.mts +36 -17
- package/dist/templates/default/apps/desktop/package.json +5 -5
- package/dist/templates/default/apps/mobile/README.md +127 -0
- package/dist/templates/default/apps/mobile/app.config.js +78 -0
- package/dist/templates/default/apps/mobile/assets/expo.icon/icon.json +21 -26
- package/dist/templates/default/apps/mobile/eas.json +22 -0
- package/dist/templates/default/apps/mobile/eslint.config.js +3 -3
- package/dist/templates/default/apps/mobile/package.json +5 -3
- package/dist/templates/default/apps/mobile/plugins/with-android-signing.js +29 -0
- package/dist/templates/default/apps/mobile/scripts/android-config.test.mjs +128 -0
- package/dist/templates/default/apps/mobile/tsconfig.json +3 -12
- package/dist/templates/default/apps/web/src/index.css +124 -73
- package/dist/templates/default/apps/web/src/routeTree.gen.ts +0 -9
- package/dist/templates/default/bun.lock +121 -11
- package/dist/templates/default/bunfig.toml +8 -1
- package/dist/templates/default/disposabl.json +9 -4
- package/dist/templates/default/gitignore +2 -0
- package/dist/templates/default/package.json +1 -0
- package/dist/templates/default/packages/backend/convex/todos/internal.ts +3 -3
- package/dist/templates/default/packages/backend/generate.ts +114 -0
- package/dist/templates/default/packages/backend/generated/openapi.json +190 -0
- package/dist/templates/default/packages/backend/generated/platforms.ts +3 -0
- package/dist/templates/default/packages/backend/package.json +4 -3
- package/dist/templates/default/packages/disposabl-kit/client/styles/globals.css +43 -43
- package/dist/templates/default/packages/disposabl-kit/eslint.config.js +2 -2
- package/dist/templates/default/packages/disposabl-kit/package.json +2 -1
- package/dist/templates/default/packages/disposabl-kit/platforms.ts +87 -0
- package/dist/templates/default/packages/disposabl-kit/server/http.ts +37 -7
- package/dist/templates/default/packages/disposabl-kit/server/lib/functions.ts +1 -10
- package/dist/templates/default/packages/disposabl-kit/server/lib/platform-spec.ts +226 -0
- package/dist/templates/default/turbo.json +25 -5
- package/package.json +1 -1
- package/dist/templates/default/.github/workflows/pipeline.yml +0 -141
- package/dist/templates/default/packages/disposabl-kit/server/dev-setup.mjs +0 -39
- package/dist/templates/default/packages/disposabl-kit/server/lib/mcp-tools.ts +0 -47
- package/dist/templates/default/packages/disposabl-kit/server/lib/platforms.ts +0 -20
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import {
|
|
2
|
+
checkValue,
|
|
3
|
+
toJsonSchema,
|
|
4
|
+
tool,
|
|
5
|
+
type McpServer,
|
|
6
|
+
type ToolCtx,
|
|
7
|
+
type ToolDefinition,
|
|
8
|
+
} from "@convex-dev/mcp";
|
|
9
|
+
import { makeFunctionReference as reference } from "convex/server";
|
|
10
|
+
import {
|
|
11
|
+
v,
|
|
12
|
+
ConvexError,
|
|
13
|
+
type GenericValidator,
|
|
14
|
+
type PropertyValidators,
|
|
15
|
+
} from "convex/values";
|
|
16
|
+
|
|
17
|
+
type PlatformFunction = {
|
|
18
|
+
isInternal?: boolean;
|
|
19
|
+
isQuery?: boolean;
|
|
20
|
+
isMutation?: boolean;
|
|
21
|
+
isAction?: boolean;
|
|
22
|
+
platforms?: true;
|
|
23
|
+
args: PropertyValidators;
|
|
24
|
+
returns: GenericValidator;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
type Operation = {
|
|
28
|
+
name: string;
|
|
29
|
+
path: string;
|
|
30
|
+
type: "query" | "mutation" | "action";
|
|
31
|
+
args: ReturnType<typeof toJsonSchema>;
|
|
32
|
+
returns: ReturnType<typeof toJsonSchema>;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/** One opt-in produces the shared JSON contract and both transport adapters. */
|
|
36
|
+
export function createPlatforms(
|
|
37
|
+
modules: Record<string, Record<string, unknown>>,
|
|
38
|
+
) {
|
|
39
|
+
const spec: Operation[] = [];
|
|
40
|
+
const tools: Record<string, ToolDefinition> = Object.create(null);
|
|
41
|
+
const routes = new Map<string, ToolDefinition>();
|
|
42
|
+
for (const [path, exports] of Object.entries(modules)) {
|
|
43
|
+
for (const [exportName, value] of Object.entries(exports)) {
|
|
44
|
+
const fn = value as Partial<PlatformFunction> | null;
|
|
45
|
+
if (!fn?.isInternal || fn.platforms !== true) continue;
|
|
46
|
+
const id = `${path}:${exportName}`;
|
|
47
|
+
const name = id.replace(/[^A-Za-z0-9_.-]/g, "_");
|
|
48
|
+
const route = `/api/${id.replace(/\/internal:/, "/").replace(":", "/")}`;
|
|
49
|
+
if (Object.hasOwn(tools, name))
|
|
50
|
+
throw new Error(`Duplicate platform tool name: ${name}`);
|
|
51
|
+
if (routes.has(route)) throw new Error(`Duplicate API path: ${route}`);
|
|
52
|
+
if (
|
|
53
|
+
!fn.args ||
|
|
54
|
+
!fn.returns ||
|
|
55
|
+
!(fn.isQuery || fn.isMutation || fn.isAction)
|
|
56
|
+
)
|
|
57
|
+
throw new Error(`${id}: expected function kind, args and returns`);
|
|
58
|
+
const { userId, ...args } = fn.args;
|
|
59
|
+
const type = fn.isQuery ? "query" : fn.isMutation ? "mutation" : "action";
|
|
60
|
+
spec.push({
|
|
61
|
+
name: id,
|
|
62
|
+
path: route,
|
|
63
|
+
type,
|
|
64
|
+
args: toJsonSchema(v.object(args)),
|
|
65
|
+
returns: toJsonSchema(fn.returns),
|
|
66
|
+
});
|
|
67
|
+
tools[name] = tool({
|
|
68
|
+
description: `Call ${id}.`,
|
|
69
|
+
...(fn.isQuery ? { annotations: { readOnlyHint: true } } : {}),
|
|
70
|
+
args,
|
|
71
|
+
returns: fn.returns,
|
|
72
|
+
handler: async (ctx, input, user) => {
|
|
73
|
+
const params = {
|
|
74
|
+
...input,
|
|
75
|
+
...(userId ? { userId: user.userId } : {}),
|
|
76
|
+
};
|
|
77
|
+
if (type === "query")
|
|
78
|
+
return ctx.runQuery(reference<"query">(id), params);
|
|
79
|
+
if (type === "mutation")
|
|
80
|
+
return ctx.runMutation(reference<"mutation">(id), params);
|
|
81
|
+
return ctx.runAction(reference<"action">(id), params);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
routes.set(route, tools[name]);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
spec,
|
|
89
|
+
tools,
|
|
90
|
+
async handleApi(
|
|
91
|
+
ctx: ToolCtx,
|
|
92
|
+
request: Request,
|
|
93
|
+
authenticate: McpServer["authenticate"],
|
|
94
|
+
) {
|
|
95
|
+
const url = new URL(request.url);
|
|
96
|
+
const definition = routes.get(url.pathname);
|
|
97
|
+
if (!definition)
|
|
98
|
+
return Response.json({ error: "not_found" }, { status: 404 });
|
|
99
|
+
const method =
|
|
100
|
+
spec.find((operation) => operation.path === url.pathname)?.type ===
|
|
101
|
+
"query"
|
|
102
|
+
? "GET"
|
|
103
|
+
: "POST";
|
|
104
|
+
if (request.method !== method)
|
|
105
|
+
return Response.json(
|
|
106
|
+
{ error: "method_not_allowed" },
|
|
107
|
+
{ status: 405, headers: { Allow: method } },
|
|
108
|
+
);
|
|
109
|
+
try {
|
|
110
|
+
const user = await authenticate(ctx, request);
|
|
111
|
+
if (!user)
|
|
112
|
+
return Response.json({ error: "unauthenticated" }, { status: 401 });
|
|
113
|
+
if (definition.scope && !user.scopes.includes(definition.scope))
|
|
114
|
+
return Response.json({ error: "forbidden" }, { status: 403 });
|
|
115
|
+
const raw =
|
|
116
|
+
request.method === "GET"
|
|
117
|
+
? Object.fromEntries(
|
|
118
|
+
[...url.searchParams].map(([key, value]) => {
|
|
119
|
+
if (url.searchParams.getAll(key).length !== 1)
|
|
120
|
+
throw new SyntaxError("Duplicate argument");
|
|
121
|
+
return [key, JSON.parse(value)];
|
|
122
|
+
}),
|
|
123
|
+
)
|
|
124
|
+
: await request.json();
|
|
125
|
+
const input = checkValue(v.object(definition.args ?? {}), raw);
|
|
126
|
+
if (!input.ok)
|
|
127
|
+
return Response.json({ error: input.error }, { status: 400 });
|
|
128
|
+
const result = await definition.handler(
|
|
129
|
+
ctx,
|
|
130
|
+
input.value as Record<string, unknown>,
|
|
131
|
+
user,
|
|
132
|
+
);
|
|
133
|
+
return new Response(
|
|
134
|
+
JSON.stringify(result ?? null, (_, value) =>
|
|
135
|
+
typeof value === "bigint"
|
|
136
|
+
? value.toString()
|
|
137
|
+
: value instanceof ArrayBuffer
|
|
138
|
+
? btoa(
|
|
139
|
+
Array.from(new Uint8Array(value), (byte) =>
|
|
140
|
+
String.fromCharCode(byte),
|
|
141
|
+
).join(""),
|
|
142
|
+
)
|
|
143
|
+
: value,
|
|
144
|
+
),
|
|
145
|
+
{ headers: { "Content-Type": "application/json" } },
|
|
146
|
+
);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (error instanceof SyntaxError || error instanceof ConvexError)
|
|
149
|
+
return Response.json({ error: "invalid_request" }, { status: 400 });
|
|
150
|
+
console.error(error);
|
|
151
|
+
return Response.json({ error: "internal_error" }, { status: 500 });
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The same validator schemas describe the HTTP transport and generated clients. */
|
|
158
|
+
export function createOpenApi(spec: Operation[], version = "0.1.0") {
|
|
159
|
+
const ids = new Set<string>();
|
|
160
|
+
return {
|
|
161
|
+
openapi: "3.1.0",
|
|
162
|
+
info: { title: "Application API", version },
|
|
163
|
+
security: [{ bearerAuth: [] }],
|
|
164
|
+
components: {
|
|
165
|
+
securitySchemes: { bearerAuth: { type: "http", scheme: "bearer" } },
|
|
166
|
+
},
|
|
167
|
+
paths: Object.fromEntries(
|
|
168
|
+
spec.map((operation) => {
|
|
169
|
+
const parts = operation.path.slice(5).split("/");
|
|
170
|
+
const operationId = parts
|
|
171
|
+
.map((part, i) =>
|
|
172
|
+
i ? part.charAt(0).toUpperCase() + part.slice(1) : part,
|
|
173
|
+
)
|
|
174
|
+
.join("");
|
|
175
|
+
if (ids.has(operationId))
|
|
176
|
+
throw new Error(`Duplicate operation ID: ${operationId}`);
|
|
177
|
+
ids.add(operationId);
|
|
178
|
+
const query = operation.type === "query";
|
|
179
|
+
const args = operation.args as {
|
|
180
|
+
properties?: Record<string, unknown>;
|
|
181
|
+
required?: string[];
|
|
182
|
+
};
|
|
183
|
+
return [
|
|
184
|
+
operation.path,
|
|
185
|
+
{
|
|
186
|
+
[query ? "get" : "post"]: {
|
|
187
|
+
operationId,
|
|
188
|
+
"x-convex-function": operation.name,
|
|
189
|
+
...(query
|
|
190
|
+
? {
|
|
191
|
+
parameters: Object.entries(args.properties ?? {}).map(
|
|
192
|
+
([name, schema]) => ({
|
|
193
|
+
name,
|
|
194
|
+
in: "query",
|
|
195
|
+
required: args.required?.includes(name) ?? false,
|
|
196
|
+
content: { "application/json": { schema } },
|
|
197
|
+
}),
|
|
198
|
+
),
|
|
199
|
+
}
|
|
200
|
+
: {
|
|
201
|
+
requestBody: {
|
|
202
|
+
required: true,
|
|
203
|
+
content: {
|
|
204
|
+
"application/json": { schema: operation.args },
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
}),
|
|
208
|
+
responses: {
|
|
209
|
+
"200": {
|
|
210
|
+
description: "Success",
|
|
211
|
+
content: {
|
|
212
|
+
"application/json": { schema: operation.returns },
|
|
213
|
+
},
|
|
214
|
+
},
|
|
215
|
+
"400": { description: "Invalid arguments" },
|
|
216
|
+
"401": { description: "Authentication required" },
|
|
217
|
+
"403": { description: "Insufficient scope" },
|
|
218
|
+
"500": { description: "Internal error" },
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
];
|
|
223
|
+
}),
|
|
224
|
+
),
|
|
225
|
+
};
|
|
226
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://turbo.build/schema.json",
|
|
3
3
|
"ui": "tui",
|
|
4
|
+
"globalEnv": ["BUN_VERSION", "NODE_VERSION"],
|
|
4
5
|
"tasks": {
|
|
5
6
|
"build": {
|
|
6
7
|
"dependsOn": ["^build"],
|
|
@@ -23,16 +24,35 @@
|
|
|
23
24
|
"inputs": ["$TURBO_DEFAULT$", "!src/routeTree.gen.ts"],
|
|
24
25
|
"outputs": ["src/routeTree.gen.ts"]
|
|
25
26
|
},
|
|
26
|
-
"@disposabl/
|
|
27
|
-
"
|
|
28
|
-
"
|
|
27
|
+
"@disposabl/disposabl-kit#build": {
|
|
28
|
+
"dependsOn": ["^build"],
|
|
29
|
+
"inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/packages/backend/convex/**"]
|
|
30
|
+
},
|
|
31
|
+
"@disposabl/disposabl-kit#lint": {
|
|
32
|
+
"dependsOn": ["^lint"],
|
|
33
|
+
"inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/packages/backend/convex/**"]
|
|
34
|
+
},
|
|
35
|
+
"@disposabl/disposabl-kit#typecheck": {
|
|
36
|
+
"dependsOn": ["^typecheck"],
|
|
37
|
+
"inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/packages/backend/convex/**"]
|
|
38
|
+
},
|
|
39
|
+
"create-disposabl-app#build": {
|
|
40
|
+
"cache": false
|
|
29
41
|
},
|
|
30
42
|
"dev": {
|
|
31
|
-
"dependsOn": ["@disposabl/backend#dev:setup"],
|
|
32
43
|
"cache": false,
|
|
33
44
|
"persistent": true,
|
|
34
45
|
"passThroughEnv": ["VITE_*"]
|
|
46
|
+
},
|
|
47
|
+
"@disposabl/backend#dev": {
|
|
48
|
+
"cache": false,
|
|
49
|
+
"persistent": true,
|
|
50
|
+
"with": ["@disposabl/backend#generate:watch"]
|
|
51
|
+
},
|
|
52
|
+
"generate:watch": {
|
|
53
|
+
"cache": false,
|
|
54
|
+
"persistent": true
|
|
35
55
|
}
|
|
36
56
|
},
|
|
37
|
-
"globalDependencies": ["disposabl.json"
|
|
57
|
+
"globalDependencies": ["disposabl.json"]
|
|
38
58
|
}
|
package/package.json
CHANGED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
name: CI and deploy
|
|
2
|
-
|
|
3
|
-
on:
|
|
4
|
-
pull_request:
|
|
5
|
-
branches: [main]
|
|
6
|
-
types: [opened, synchronize, reopened]
|
|
7
|
-
push:
|
|
8
|
-
branches: [main]
|
|
9
|
-
workflow_dispatch:
|
|
10
|
-
inputs:
|
|
11
|
-
runner:
|
|
12
|
-
description: Machine to compare
|
|
13
|
-
type: choice
|
|
14
|
-
options: [ubuntu-latest, boat-small, boat]
|
|
15
|
-
default: boat
|
|
16
|
-
preview:
|
|
17
|
-
description: Deploy an isolated Convex preview, including the web build
|
|
18
|
-
type: boolean
|
|
19
|
-
default: false
|
|
20
|
-
cache_scope:
|
|
21
|
-
description: Use a new value for a cold run; reuse it for warm runs
|
|
22
|
-
type: string
|
|
23
|
-
default: benchmark-v1
|
|
24
|
-
|
|
25
|
-
permissions:
|
|
26
|
-
contents: read
|
|
27
|
-
|
|
28
|
-
concurrency:
|
|
29
|
-
group: ${{ github.workflow }}-${{ github.event_name == 'workflow_dispatch' && 'manual' || github.head_ref || github.ref_name }}-${{ inputs.runner || 'default' }}
|
|
30
|
-
cancel-in-progress: false
|
|
31
|
-
|
|
32
|
-
jobs:
|
|
33
|
-
pipeline:
|
|
34
|
-
if: github.event.deleted != true
|
|
35
|
-
# Install the Boat CI GitHub App first. Fork PRs use GitHub-hosted runners.
|
|
36
|
-
# DISPOSABL_CI_RUNNER can select boat-small or ubuntu-latest for normal runs.
|
|
37
|
-
runs-on: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository && 'ubuntu-latest' || inputs.runner || vars.DISPOSABL_CI_RUNNER || 'boat' }}
|
|
38
|
-
env:
|
|
39
|
-
CI_RUNNER: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository && 'ubuntu-latest' || inputs.runner || vars.DISPOSABL_CI_RUNNER || 'boat' }}
|
|
40
|
-
timeout-minutes: 30
|
|
41
|
-
steps:
|
|
42
|
-
- name: Check out repository
|
|
43
|
-
uses: actions/checkout@v6
|
|
44
|
-
with:
|
|
45
|
-
persist-credentials: false
|
|
46
|
-
|
|
47
|
-
- name: Record machine
|
|
48
|
-
run: |
|
|
49
|
-
printf 'CPUs: %s\n' "$(nproc)"
|
|
50
|
-
lscpu
|
|
51
|
-
free -h
|
|
52
|
-
cat /etc/os-release
|
|
53
|
-
|
|
54
|
-
- name: Install Node.js
|
|
55
|
-
uses: actions/setup-node@v6
|
|
56
|
-
with:
|
|
57
|
-
node-version: "24"
|
|
58
|
-
package-manager-cache: false
|
|
59
|
-
|
|
60
|
-
- name: Install Bun
|
|
61
|
-
uses: oven-sh/setup-bun@v2
|
|
62
|
-
with:
|
|
63
|
-
bun-version: "1.4.4"
|
|
64
|
-
|
|
65
|
-
- name: Cache Turbo tasks
|
|
66
|
-
uses: actions/cache@v4
|
|
67
|
-
with:
|
|
68
|
-
path: .turbo/cache
|
|
69
|
-
key: turbo-${{ inputs.cache_scope || 'ci' }}-${{ env.CI_RUNNER }}-${{ runner.os }}-${{ runner.arch }}-node24-bun1.4.4-${{ github.sha }}
|
|
70
|
-
restore-keys: |
|
|
71
|
-
turbo-${{ inputs.cache_scope || 'ci' }}-${{ env.CI_RUNNER }}-${{ runner.os }}-${{ runner.arch }}-node24-bun1.4.4-
|
|
72
|
-
|
|
73
|
-
- name: Install dependencies
|
|
74
|
-
run: bun install --frozen-lockfile
|
|
75
|
-
|
|
76
|
-
- name: Typecheck
|
|
77
|
-
run: bun run typecheck
|
|
78
|
-
|
|
79
|
-
- name: Lint
|
|
80
|
-
run: bun run lint
|
|
81
|
-
|
|
82
|
-
- name: Check formatting
|
|
83
|
-
run: bun fmt --check
|
|
84
|
-
|
|
85
|
-
- name: Test
|
|
86
|
-
# The starter currently has no tests. Run any tests added later.
|
|
87
|
-
run: bun test --pass-with-no-tests
|
|
88
|
-
|
|
89
|
-
- name: Build
|
|
90
|
-
# Trusted branches build once below, with their actual deployment URLs.
|
|
91
|
-
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository) || (github.event_name == 'workflow_dispatch' && !inputs.preview)
|
|
92
|
-
env:
|
|
93
|
-
VITE_CONVEX_URL: https://ci.invalid
|
|
94
|
-
VITE_CONVEX_SITE_URL: https://ci.invalid
|
|
95
|
-
run: bun run build
|
|
96
|
-
|
|
97
|
-
- name: Deploy production
|
|
98
|
-
id: production
|
|
99
|
-
if: github.event_name == 'push'
|
|
100
|
-
working-directory: packages/backend
|
|
101
|
-
env:
|
|
102
|
-
CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY }}
|
|
103
|
-
run: |
|
|
104
|
-
bun x --no-install convex deploy --yes \
|
|
105
|
-
--cmd-url-env-var-name VITE_CONVEX_URL \
|
|
106
|
-
--cmd '
|
|
107
|
-
bun x --no-install --package @convex-dev/auth auth --keys-only --prod &&
|
|
108
|
-
build_started=$(date +%s) &&
|
|
109
|
-
VITE_CONVEX_SITE_URL="$CONVEX_SITE_URL" bun run --cwd ../.. build &&
|
|
110
|
-
echo "Web build seconds: $(($(date +%s) - build_started))" &&
|
|
111
|
-
echo "url=$CONVEX_SITE_URL" >> "$GITHUB_OUTPUT"
|
|
112
|
-
'
|
|
113
|
-
bun x --no-install static-hosting upload --prod --no-spa --dist ../../apps/web/dist/client
|
|
114
|
-
|
|
115
|
-
- name: Deploy preview
|
|
116
|
-
id: preview
|
|
117
|
-
if: (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) || (github.event_name == 'workflow_dispatch' && inputs.preview)
|
|
118
|
-
working-directory: packages/backend
|
|
119
|
-
env:
|
|
120
|
-
CONVEX_DEPLOY_KEY: ${{ secrets.CONVEX_DEPLOY_KEY_PREVIEW }}
|
|
121
|
-
# Each benchmark runner gets its own preview to avoid concurrent writes.
|
|
122
|
-
PREVIEW_NAME: ${{ github.head_ref || format('ci-benchmark-{0}', inputs.runner) }}
|
|
123
|
-
run: |
|
|
124
|
-
bun x --no-install convex deploy --yes --preview-name "$PREVIEW_NAME" \
|
|
125
|
-
--cmd-url-env-var-name VITE_CONVEX_URL \
|
|
126
|
-
--cmd '
|
|
127
|
-
bun x --no-install --package @convex-dev/auth auth --keys-only --preview-name "$PREVIEW_NAME" &&
|
|
128
|
-
build_started=$(date +%s) &&
|
|
129
|
-
VITE_CONVEX_SITE_URL="$CONVEX_SITE_URL" bun run --cwd ../.. build &&
|
|
130
|
-
echo "Web build seconds: $(($(date +%s) - build_started))" &&
|
|
131
|
-
echo "url=$CONVEX_SITE_URL" >> "$GITHUB_OUTPUT"
|
|
132
|
-
'
|
|
133
|
-
bun x --no-install static-hosting upload --preview-name "$PREVIEW_NAME" --no-spa --dist ../../apps/web/dist/client
|
|
134
|
-
|
|
135
|
-
- name: Show deployment URL
|
|
136
|
-
if: steps.production.outcome == 'success' || steps.preview.outcome == 'success'
|
|
137
|
-
env:
|
|
138
|
-
DEPLOYMENT_URL: ${{ steps.production.outputs.url || steps.preview.outputs.url }}
|
|
139
|
-
run: |
|
|
140
|
-
printf 'Deployed app: %s\n' "$DEPLOYMENT_URL"
|
|
141
|
-
printf '### Deployment\n\n[Open app](%s)\n' "$DEPLOYMENT_URL" >> "$GITHUB_STEP_SUMMARY"
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { $ } from "bun";
|
|
2
|
-
import { dirname, resolve } from "node:path";
|
|
3
|
-
import { parseEnv } from "node:util";
|
|
4
|
-
|
|
5
|
-
const root = resolve(import.meta.dir, "../../..");
|
|
6
|
-
const backend = `${root}/packages/backend`;
|
|
7
|
-
const read = async (path) => (await Bun.file(path).exists()) ? parseEnv(await Bun.file(path).text()) : {};
|
|
8
|
-
const save = async (path, values) => {
|
|
9
|
-
const previous = await read(path);
|
|
10
|
-
if (Object.entries(values).every(([key, value]) => previous[key] === value)) return;
|
|
11
|
-
process.umask(0o077);
|
|
12
|
-
await Bun.write(path, Object.entries({ ...previous, ...values }).filter(([, value]) => value !== undefined).map(([key, value]) => `${key}=${JSON.stringify(value)}\n`).join(""));
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
$.cwd(root);
|
|
16
|
-
if ((await $`git rev-parse --git-dir`.quiet().nothrow()).exitCode !== 0) await $`git init --initial-branch=main`.quiet();
|
|
17
|
-
const branch = (await $`git branch --show-current`.text()).trim();
|
|
18
|
-
if (!branch) throw new Error("Create a named Git branch before running dev.");
|
|
19
|
-
const original = dirname((await $`git rev-parse --path-format=absolute --git-common-dir`.text()).trim());
|
|
20
|
-
const key = process.env.CONVEX_DEPLOY_KEY ?? (await read(`${root}/.env.local`)).CONVEX_DEPLOY_KEY ?? (await read(`${original}/.env.local`)).CONVEX_DEPLOY_KEY;
|
|
21
|
-
const match = key?.match(/^preview:([\w-]+):([\w-]+)\|[A-Za-z0-9_+/=-]+$/);
|
|
22
|
-
if (!match) throw new Error("Set CONVEX_DEPLOY_KEY to the project preview key in root .env.local.");
|
|
23
|
-
let saved = await read(`${backend}/.env.local`);
|
|
24
|
-
if (saved.DISPOSABL_PREVIEW_BRANCH !== branch || saved.CONVEX_SELF_HOSTED_ADMIN_KEY !== key || !saved.CONVEX_SELF_HOSTED_URL) {
|
|
25
|
-
// Convex CLI's create-or-reuse API. Explicit URL/key config lets native `convex dev` use the preview.
|
|
26
|
-
const response = await fetch("https://api.convex.dev/api/claim_preview_deployment", {
|
|
27
|
-
method: "POST", redirect: "error", headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
|
|
28
|
-
body: JSON.stringify({ projectSelection: { kind: "teamAndProjectSlugs", teamSlug: match[1], projectSlug: match[2] }, identifier: branch, reuse: true }),
|
|
29
|
-
});
|
|
30
|
-
if (!response.ok) throw new Error(`Preview setup failed (${response.status}).`);
|
|
31
|
-
const { instanceUrl, adminKey } = await response.json();
|
|
32
|
-
if (!/^https:\/\/[a-z0-9-]+\.convex\.cloud$/.test(instanceUrl) || !adminKey) throw new Error("Invalid preview credentials returned by Convex.");
|
|
33
|
-
await $`bun --no-env-file node_modules/@convex-dev/auth/dist/cli/init.js --keys-only --preview-name ${branch}`.cwd(backend).env({ ...process.env, CONVEX_DEPLOY_KEY: key });
|
|
34
|
-
saved = { DISPOSABL_PREVIEW_BRANCH: branch, CONVEX_SELF_HOSTED_URL: instanceUrl, CONVEX_SELF_HOSTED_ADMIN_KEY: adminKey };
|
|
35
|
-
await save(`${backend}/.env.local`, { ...saved, CONVEX_DEPLOY_KEY: undefined, CONVEX_DEPLOYMENT_TOKEN: undefined, CONVEX_DEPLOYMENT: undefined });
|
|
36
|
-
}
|
|
37
|
-
for await (const manifest of new Bun.Glob("apps/*/package.json").scan({ cwd: root, absolute: true }))
|
|
38
|
-
await save(`${dirname(manifest)}/.env.local`, { VITE_CONVEX_URL: saved.CONVEX_SELF_HOSTED_URL, VITE_CONVEX_SITE_URL: saved.CONVEX_SELF_HOSTED_URL.replace(/\.cloud$/, ".site") });
|
|
39
|
-
console.log(`Using preview ${branch}.`);
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { tool, type ToolDefinition } from "@convex-dev/mcp";
|
|
2
|
-
import { makeFunctionReference as reference } from "convex/server";
|
|
3
|
-
import type { GenericValidator, PropertyValidators } from "convex/values";
|
|
4
|
-
|
|
5
|
-
type PlatformFunction = {
|
|
6
|
-
isInternal?: boolean;
|
|
7
|
-
isQuery?: boolean;
|
|
8
|
-
isMutation?: boolean;
|
|
9
|
-
mcp?: boolean;
|
|
10
|
-
args: PropertyValidators;
|
|
11
|
-
returns: GenericValidator;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/** Adapt opted-in internal functions without duplicating their validators. */
|
|
15
|
-
export function createMcpTools(
|
|
16
|
-
modules: Record<string, Record<string, unknown>>,
|
|
17
|
-
) {
|
|
18
|
-
const tools: Record<string, ToolDefinition> = Object.create(null);
|
|
19
|
-
for (const [path, exports] of Object.entries(modules)) {
|
|
20
|
-
for (const [exportName, value] of Object.entries(exports)) {
|
|
21
|
-
const fn = value as PlatformFunction | null;
|
|
22
|
-
if (!fn?.isInternal || !fn.mcp) continue;
|
|
23
|
-
const id = `${path}:${exportName}`;
|
|
24
|
-
const name = id.replace(/[^A-Za-z0-9_.-]/g, "_");
|
|
25
|
-
if (Object.hasOwn(tools, name))
|
|
26
|
-
throw new Error(`Duplicate MCP tool name: ${name}`);
|
|
27
|
-
const { userId, ...args } = fn.args;
|
|
28
|
-
tools[name] = tool({
|
|
29
|
-
description: `Call ${id}.`,
|
|
30
|
-
...(fn.isQuery ? { annotations: { readOnlyHint: true } } : {}),
|
|
31
|
-
args,
|
|
32
|
-
returns: fn.returns,
|
|
33
|
-
handler: async (ctx, input, user) => {
|
|
34
|
-
const params = {
|
|
35
|
-
...input,
|
|
36
|
-
...(userId ? { userId: user.userId } : {}),
|
|
37
|
-
};
|
|
38
|
-
if (fn.isQuery) return ctx.runQuery(reference<"query">(id), params);
|
|
39
|
-
if (fn.isMutation)
|
|
40
|
-
return ctx.runMutation(reference<"mutation">(id), params);
|
|
41
|
-
return ctx.runAction(reference<"action">(id), params);
|
|
42
|
-
},
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return tools;
|
|
47
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import config from "../../../../disposabl.json";
|
|
2
|
-
|
|
3
|
-
export type Platforms = boolean | { api?: boolean; mcp?: boolean };
|
|
4
|
-
|
|
5
|
-
/** The generated app config is the source of truth for enabled transports. */
|
|
6
|
-
export function getPlatforms() {
|
|
7
|
-
const enabled = new Set(config.platforms);
|
|
8
|
-
return {
|
|
9
|
-
isApiEnabled:
|
|
10
|
-
enabled.has("api") ||
|
|
11
|
-
enabled.has("cli") ||
|
|
12
|
-
enabled.has("python-sdk") ||
|
|
13
|
-
enabled.has("typescript-sdk"),
|
|
14
|
-
isCliEnabled: enabled.has("cli"),
|
|
15
|
-
isMcpEnabled: enabled.has("mcp"),
|
|
16
|
-
isSdkEnabled: enabled.has("python-sdk") || enabled.has("typescript-sdk"),
|
|
17
|
-
isOpenaiPluginEnabled: enabled.has("openai-plugin"),
|
|
18
|
-
isClaudePluginEnabled: enabled.has("claude-code-plugin"),
|
|
19
|
-
};
|
|
20
|
-
}
|