clawnify 0.1.14 → 0.1.16
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/README.md +3 -0
- package/dist/{chunk-6UAOYVZ6.js → chunk-CMM323B2.js} +65 -16
- package/dist/chunk-CMM323B2.js.map +1 -0
- package/dist/{cli-GKDOQZ5A.js → cli-KWGS4LVM.js} +372 -74
- package/dist/cli-KWGS4LVM.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/{mcp-JLE4IWRX.js → mcp-6Q2NXUA4.js} +3 -3
- package/dist/mcp-6Q2NXUA4.js.map +1 -0
- package/package.json +1 -1
- package/dist/chunk-6UAOYVZ6.js.map +0 -1
- package/dist/cli-GKDOQZ5A.js.map +0 -1
- package/dist/mcp-JLE4IWRX.js.map +0 -1
|
@@ -7,13 +7,14 @@ import {
|
|
|
7
7
|
createArchive,
|
|
8
8
|
generatePkce,
|
|
9
9
|
getEmailFromToken,
|
|
10
|
+
listMyOrgs,
|
|
10
11
|
loadAuth,
|
|
11
12
|
pollUntilReady,
|
|
12
13
|
readManifest,
|
|
13
14
|
readProject,
|
|
14
15
|
saveAuth,
|
|
15
16
|
saveProject
|
|
16
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-CMM323B2.js";
|
|
17
18
|
|
|
18
19
|
// src/cli.ts
|
|
19
20
|
import { Command } from "commander";
|
|
@@ -170,6 +171,8 @@ async function loginCommand() {
|
|
|
170
171
|
// src/commands/deploy.ts
|
|
171
172
|
import path from "path";
|
|
172
173
|
import readline2 from "readline";
|
|
174
|
+
var EXIT_USAGE = 64;
|
|
175
|
+
var EXIT_CONFLICT_NEEDS_DECISION = 75;
|
|
173
176
|
function ask(question) {
|
|
174
177
|
const rl = readline2.createInterface({
|
|
175
178
|
input: process.stdin,
|
|
@@ -182,12 +185,12 @@ function ask(question) {
|
|
|
182
185
|
});
|
|
183
186
|
});
|
|
184
187
|
}
|
|
185
|
-
async function uploadDeploy(archive, name, framework) {
|
|
188
|
+
async function uploadDeploy(archive, name, framework, orgId) {
|
|
186
189
|
const formData = new FormData();
|
|
187
190
|
formData.append("source", new Blob([archive]), "source.tar.gz");
|
|
188
191
|
formData.append("name", name);
|
|
189
192
|
formData.append("framework", framework);
|
|
190
|
-
const res = await api.postForm("/v1/apps/deploy", formData);
|
|
193
|
+
const res = await api.postForm("/v1/apps/deploy", formData, { orgId });
|
|
191
194
|
if (res.ok) {
|
|
192
195
|
const data = await res.json();
|
|
193
196
|
return { ok: true, data };
|
|
@@ -199,10 +202,10 @@ async function uploadDeploy(archive, name, framework) {
|
|
|
199
202
|
const err = await res.json().catch(() => ({}));
|
|
200
203
|
return { ok: false, error: err.error || res.statusText };
|
|
201
204
|
}
|
|
202
|
-
async function uploadRedeploy(appId, archive) {
|
|
205
|
+
async function uploadRedeploy(appId, archive, orgId) {
|
|
203
206
|
const formData = new FormData();
|
|
204
207
|
formData.append("source", new Blob([archive]), "source.tar.gz");
|
|
205
|
-
const res = await api.postForm(`/v1/apps/${appId}/redeploy`, formData);
|
|
208
|
+
const res = await api.postForm(`/v1/apps/${appId}/redeploy`, formData, { orgId });
|
|
206
209
|
if (res.ok) {
|
|
207
210
|
const data = await res.json();
|
|
208
211
|
return { ok: true, data };
|
|
@@ -225,15 +228,95 @@ function assertNodeVersion() {
|
|
|
225
228
|
process.exit(1);
|
|
226
229
|
}
|
|
227
230
|
}
|
|
228
|
-
async function
|
|
231
|
+
async function resolveOrgId(options, linkedProject) {
|
|
232
|
+
if (options.org) {
|
|
233
|
+
const orgs = await listMyOrgs();
|
|
234
|
+
const match = orgs.find((o) => o.id === options.org || o.slug === options.org);
|
|
235
|
+
if (!match) {
|
|
236
|
+
console.error(
|
|
237
|
+
`No org matched "${options.org}". Available: ${orgs.map((o) => o.slug).join(", ")}`
|
|
238
|
+
);
|
|
239
|
+
process.exit(EXIT_USAGE);
|
|
240
|
+
}
|
|
241
|
+
if (linkedProject?.app_id && linkedProject.org_id && linkedProject.org_id !== match.id) {
|
|
242
|
+
console.error(
|
|
243
|
+
`This project is linked to a different org (${linkedProject.org_id}).
|
|
244
|
+
--org ${options.org} resolves to ${match.id}.
|
|
245
|
+
Re-link first: clawnify link ${linkedProject.app_id} --org ${options.org}`
|
|
246
|
+
);
|
|
247
|
+
process.exit(1);
|
|
248
|
+
}
|
|
249
|
+
return match.id;
|
|
250
|
+
}
|
|
251
|
+
if (linkedProject?.app_id && linkedProject.org_id) {
|
|
252
|
+
return linkedProject.org_id;
|
|
253
|
+
}
|
|
254
|
+
return void 0;
|
|
255
|
+
}
|
|
256
|
+
async function resolveConflictDecision(options, conflict) {
|
|
257
|
+
if (options.updateExisting) return "update";
|
|
258
|
+
if (options.createNew) return "create";
|
|
259
|
+
if (options.yes) return "update";
|
|
260
|
+
if (!process.stdin.isTTY) {
|
|
261
|
+
console.error(
|
|
262
|
+
`
|
|
263
|
+
Slug '${conflict.slug}' is taken in this organization.
|
|
264
|
+
Pass one of:
|
|
265
|
+
--update-existing overwrite the existing app
|
|
266
|
+
--create-new deploy as '${conflict.suggested_slug}'
|
|
267
|
+
--yes default to update (safest)
|
|
268
|
+
`
|
|
269
|
+
);
|
|
270
|
+
process.exit(EXIT_CONFLICT_NEEDS_DECISION);
|
|
271
|
+
}
|
|
272
|
+
console.log(
|
|
273
|
+
`
|
|
274
|
+
Slug '${conflict.slug}' is taken in this organization (currently held by an app named '${conflict.existing_app_name}').
|
|
275
|
+
`
|
|
276
|
+
);
|
|
277
|
+
console.log(` 1) Update that app \u2014 deploy this source over it`);
|
|
278
|
+
console.log(` 2) Create a new app at slug '${conflict.suggested_slug}'
|
|
279
|
+
`);
|
|
280
|
+
const answer = await ask(" Choose [1/2] (default 1): ");
|
|
281
|
+
if (answer === "" || answer === "1") return "update";
|
|
282
|
+
if (answer === "2") return "create";
|
|
283
|
+
console.error(
|
|
284
|
+
`
|
|
285
|
+
Cancelled. Received '${answer}' \u2014 expected 1 or 2.
|
|
286
|
+
For non-interactive use, pass --update-existing or --create-new.
|
|
287
|
+
`
|
|
288
|
+
);
|
|
289
|
+
return "cancel";
|
|
290
|
+
}
|
|
291
|
+
function summarizeArchive(buf, files, framework, name) {
|
|
292
|
+
const sizeKB = (buf.length / 1024).toFixed(1);
|
|
293
|
+
console.log(`
|
|
294
|
+
Dry run \u2014 would deploy '${name}' (${framework})`);
|
|
295
|
+
console.log(` Archive: ${files.length} files, ${sizeKB}KB gzipped
|
|
296
|
+
`);
|
|
297
|
+
const preview = files.slice(0, 25);
|
|
298
|
+
for (const f of preview) console.log(` ${f}`);
|
|
299
|
+
if (files.length > preview.length) {
|
|
300
|
+
console.log(` ... and ${files.length - preview.length} more`);
|
|
301
|
+
}
|
|
302
|
+
console.log();
|
|
303
|
+
}
|
|
304
|
+
async function deployCommand(dir, options = {}) {
|
|
229
305
|
assertNodeVersion();
|
|
230
306
|
let appId;
|
|
231
307
|
let slug;
|
|
232
308
|
let appToken;
|
|
233
|
-
if (options
|
|
309
|
+
if (options.from) {
|
|
234
310
|
const repo = options.from.replace(/^github:/, "");
|
|
311
|
+
if (options.dryRun) {
|
|
312
|
+
console.log(`
|
|
313
|
+
Dry run \u2014 would deploy from GitHub repo '${repo}' (branch: main)
|
|
314
|
+
`);
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
235
317
|
console.log(`Deploying from ${repo}...`);
|
|
236
|
-
const
|
|
318
|
+
const orgId = options.org ? await resolveOrgId(options, null) : void 0;
|
|
319
|
+
const res = await api.post("/v1/apps/deploy", { repo, branch: "main" }, { orgId });
|
|
237
320
|
if (!res.ok) {
|
|
238
321
|
const err = await res.json().catch(() => ({}));
|
|
239
322
|
console.error(`Deploy failed: ${err.error || res.statusText}`);
|
|
@@ -246,13 +329,25 @@ async function deployCommand(dir, options) {
|
|
|
246
329
|
} else {
|
|
247
330
|
const resolvedDir = dir ? path.resolve(dir) : process.cwd();
|
|
248
331
|
const manifest = readManifest(resolvedDir);
|
|
249
|
-
const baseName = options
|
|
332
|
+
const baseName = options.name || manifest?.name || path.basename(resolvedDir);
|
|
250
333
|
const framework = manifest?.app?.framework || "vite-preact";
|
|
251
334
|
const linkedProject = readProject(resolvedDir);
|
|
252
|
-
const archive = createArchive(resolvedDir);
|
|
335
|
+
const { archive, files } = createArchive(resolvedDir);
|
|
336
|
+
const orgId = await resolveOrgId(options, linkedProject);
|
|
337
|
+
if (options.dryRun) {
|
|
338
|
+
summarizeArchive(archive, files, framework, baseName);
|
|
339
|
+
if (linkedProject?.app_id) {
|
|
340
|
+
console.log(` Would update existing app: ${linkedProject.slug ?? linkedProject.app_id}
|
|
341
|
+
`);
|
|
342
|
+
} else {
|
|
343
|
+
console.log(` Would create new app: ${baseName}
|
|
344
|
+
`);
|
|
345
|
+
}
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
253
348
|
if (linkedProject?.app_id) {
|
|
254
349
|
console.log(`Updating ${baseName} (${linkedProject.slug ?? linkedProject.app_id})...`);
|
|
255
|
-
const result2 = await uploadRedeploy(linkedProject.app_id, archive);
|
|
350
|
+
const result2 = await uploadRedeploy(linkedProject.app_id, archive, orgId);
|
|
256
351
|
if (!result2.ok) {
|
|
257
352
|
console.error(`Deploy failed: ${result2.error}`);
|
|
258
353
|
process.exit(1);
|
|
@@ -260,23 +355,14 @@ async function deployCommand(dir, options) {
|
|
|
260
355
|
appId = result2.data.app_id;
|
|
261
356
|
slug = result2.data.slug;
|
|
262
357
|
appToken = result2.data.app_token;
|
|
263
|
-
saveProject(resolvedDir, { app_id: appId, slug, app_token: appToken });
|
|
358
|
+
saveProject(resolvedDir, { org_id: orgId, app_id: appId, slug, app_token: appToken });
|
|
264
359
|
} else {
|
|
265
360
|
console.log(`Deploying ${baseName}...`);
|
|
266
|
-
let result2 = await uploadDeploy(archive, baseName, framework);
|
|
361
|
+
let result2 = await uploadDeploy(archive, baseName, framework, orgId);
|
|
267
362
|
if (!result2.ok && "conflict" in result2) {
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
An app named '${c.existing_app_name}' (slug: ${c.slug}) already exists in this organization.
|
|
272
|
-
`
|
|
273
|
-
);
|
|
274
|
-
console.log(` 1) Update the existing app`);
|
|
275
|
-
console.log(` 2) Create a new app as '${c.suggested_slug}'
|
|
276
|
-
`);
|
|
277
|
-
const answer = await ask(" Choose [1/2]: ");
|
|
278
|
-
if (answer === "1" || answer === "") {
|
|
279
|
-
const redeployResult = await uploadRedeploy(c.existing_app_id, archive);
|
|
363
|
+
const decision = await resolveConflictDecision(options, result2.conflict);
|
|
364
|
+
if (decision === "update") {
|
|
365
|
+
const redeployResult = await uploadRedeploy(result2.conflict.existing_app_id, archive, orgId);
|
|
280
366
|
if (!redeployResult.ok) {
|
|
281
367
|
console.error(`Deploy failed: ${redeployResult.error}`);
|
|
282
368
|
process.exit(1);
|
|
@@ -284,8 +370,8 @@ async function deployCommand(dir, options) {
|
|
|
284
370
|
appId = redeployResult.data.app_id;
|
|
285
371
|
slug = redeployResult.data.slug;
|
|
286
372
|
appToken = redeployResult.data.app_token;
|
|
287
|
-
} else if (
|
|
288
|
-
result2 = await uploadDeploy(archive,
|
|
373
|
+
} else if (decision === "create") {
|
|
374
|
+
result2 = await uploadDeploy(archive, result2.conflict.suggested_slug, framework, orgId);
|
|
289
375
|
if (!result2.ok) {
|
|
290
376
|
const errMsg = "conflict" in result2 ? "Slug still conflicts" : result2.error;
|
|
291
377
|
console.error(`Deploy failed: ${errMsg}`);
|
|
@@ -295,8 +381,7 @@ async function deployCommand(dir, options) {
|
|
|
295
381
|
slug = result2.data.slug;
|
|
296
382
|
appToken = result2.data.app_token;
|
|
297
383
|
} else {
|
|
298
|
-
|
|
299
|
-
process.exit(1);
|
|
384
|
+
process.exit(EXIT_CONFLICT_NEEDS_DECISION);
|
|
300
385
|
}
|
|
301
386
|
} else if (!result2.ok) {
|
|
302
387
|
console.error(`Deploy failed: ${result2.error}`);
|
|
@@ -306,7 +391,7 @@ async function deployCommand(dir, options) {
|
|
|
306
391
|
slug = result2.data.slug;
|
|
307
392
|
appToken = result2.data.app_token;
|
|
308
393
|
}
|
|
309
|
-
saveProject(resolvedDir, { app_id: appId, slug, app_token: appToken });
|
|
394
|
+
saveProject(resolvedDir, { org_id: orgId, app_id: appId, slug, app_token: appToken });
|
|
310
395
|
}
|
|
311
396
|
}
|
|
312
397
|
const result = await pollUntilReady(appId);
|
|
@@ -331,7 +416,8 @@ async function lsCommand() {
|
|
|
331
416
|
console.error("Failed to list apps.");
|
|
332
417
|
process.exit(1);
|
|
333
418
|
}
|
|
334
|
-
const
|
|
419
|
+
const payload = await res.json();
|
|
420
|
+
const apps = Array.isArray(payload) ? payload : payload.apps;
|
|
335
421
|
if (apps.length === 0) {
|
|
336
422
|
console.log("No apps deployed yet.");
|
|
337
423
|
return;
|
|
@@ -500,7 +586,7 @@ async function initCommand(dir, opts) {
|
|
|
500
586
|
"@types/react": "^19.0.0",
|
|
501
587
|
"@types/react-dom": "^19.0.0",
|
|
502
588
|
"@vitejs/plugin-react": "^4.0.0",
|
|
503
|
-
"clawnify": "^0.1.
|
|
589
|
+
"clawnify": "^0.1.15",
|
|
504
590
|
"tailwindcss": "^4.0.0",
|
|
505
591
|
"vite": "^6.0.0",
|
|
506
592
|
"wrangler": "^4.0.0"
|
|
@@ -515,9 +601,11 @@ async function initCommand(dir, opts) {
|
|
|
515
601
|
deploy: "clawnify deploy"
|
|
516
602
|
},
|
|
517
603
|
dependencies: {
|
|
604
|
+
"@hono/zod-openapi": "^0.19.0",
|
|
518
605
|
hono: "^4.0.0",
|
|
519
606
|
react: "^19.0.0",
|
|
520
|
-
"react-dom": "^19.0.0"
|
|
607
|
+
"react-dom": "^19.0.0",
|
|
608
|
+
zod: "^3.0.0"
|
|
521
609
|
},
|
|
522
610
|
devDependencies: devDeps,
|
|
523
611
|
engines: { node: ">=22" },
|
|
@@ -622,14 +710,14 @@ export async function run(
|
|
|
622
710
|
}
|
|
623
711
|
`);
|
|
624
712
|
if (storage) {
|
|
625
|
-
write(targetDir, "src/server/index.ts", `import {
|
|
713
|
+
write(targetDir, "src/server/index.ts", `import { OpenAPIHono } from "@hono/zod-openapi";
|
|
626
714
|
import { initDB } from "./db";
|
|
627
715
|
import { initUploads } from "./uploads";
|
|
628
716
|
import api from "./routes";
|
|
629
717
|
|
|
630
718
|
type Env = { Bindings: { DB: D1Database; UPLOADS: R2Bucket } };
|
|
631
719
|
|
|
632
|
-
const app = new
|
|
720
|
+
const app = new OpenAPIHono<Env>();
|
|
633
721
|
|
|
634
722
|
app.use("*", async (c, next) => {
|
|
635
723
|
initDB(c.env.DB);
|
|
@@ -639,6 +727,11 @@ app.use("*", async (c, next) => {
|
|
|
639
727
|
|
|
640
728
|
app.route("/", api);
|
|
641
729
|
|
|
730
|
+
app.doc("/api/openapi.json", {
|
|
731
|
+
openapi: "3.0.0",
|
|
732
|
+
info: { title: "${name}", version: "1.0.0" },
|
|
733
|
+
});
|
|
734
|
+
|
|
642
735
|
export default app;
|
|
643
736
|
`);
|
|
644
737
|
write(targetDir, "src/server/uploads.ts", `let _bucket: R2Bucket;
|
|
@@ -683,13 +776,13 @@ export async function readUploadAsBase64DataUrl(
|
|
|
683
776
|
}
|
|
684
777
|
`);
|
|
685
778
|
} else {
|
|
686
|
-
write(targetDir, "src/server/index.ts", `import {
|
|
779
|
+
write(targetDir, "src/server/index.ts", `import { OpenAPIHono } from "@hono/zod-openapi";
|
|
687
780
|
import { initDB } from "./db";
|
|
688
781
|
import api from "./routes";
|
|
689
782
|
|
|
690
783
|
type Env = { Bindings: { DB: D1Database } };
|
|
691
784
|
|
|
692
|
-
const app = new
|
|
785
|
+
const app = new OpenAPIHono<Env>();
|
|
693
786
|
|
|
694
787
|
app.use("*", async (c, next) => {
|
|
695
788
|
initDB(c.env.DB);
|
|
@@ -698,6 +791,11 @@ app.use("*", async (c, next) => {
|
|
|
698
791
|
|
|
699
792
|
app.route("/", api);
|
|
700
793
|
|
|
794
|
+
app.doc("/api/openapi.json", {
|
|
795
|
+
openapi: "3.0.0",
|
|
796
|
+
info: { title: "${name}", version: "1.0.0" },
|
|
797
|
+
});
|
|
798
|
+
|
|
701
799
|
export default app;
|
|
702
800
|
`);
|
|
703
801
|
}
|
|
@@ -736,15 +834,34 @@ function writeBlankTemplate(dir, name) {
|
|
|
736
834
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
737
835
|
);
|
|
738
836
|
`);
|
|
739
|
-
write(dir, "src/server/routes.ts", `import {
|
|
837
|
+
write(dir, "src/server/routes.ts", `import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
740
838
|
import { query } from "./db";
|
|
741
839
|
|
|
742
|
-
const api = new
|
|
840
|
+
const api = new OpenAPIHono();
|
|
743
841
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
842
|
+
const ItemSchema = z.object({
|
|
843
|
+
id: z.number(),
|
|
844
|
+
name: z.string(),
|
|
845
|
+
created_at: z.string(),
|
|
846
|
+
}).openapi("Item");
|
|
847
|
+
|
|
848
|
+
api.openapi(
|
|
849
|
+
createRoute({
|
|
850
|
+
method: "get",
|
|
851
|
+
path: "/api/items",
|
|
852
|
+
summary: "List items",
|
|
853
|
+
responses: {
|
|
854
|
+
200: {
|
|
855
|
+
description: "List of items",
|
|
856
|
+
content: { "application/json": { schema: z.array(ItemSchema) } },
|
|
857
|
+
},
|
|
858
|
+
},
|
|
859
|
+
}),
|
|
860
|
+
async (c) => {
|
|
861
|
+
const items = await query("SELECT * FROM items ORDER BY created_at DESC");
|
|
862
|
+
return c.json(items);
|
|
863
|
+
},
|
|
864
|
+
);
|
|
748
865
|
|
|
749
866
|
export default api;
|
|
750
867
|
`);
|
|
@@ -783,41 +900,107 @@ function writeCrudTemplate(dir, name) {
|
|
|
783
900
|
created_at TEXT NOT NULL DEFAULT (datetime('now'))
|
|
784
901
|
);
|
|
785
902
|
`);
|
|
786
|
-
write(dir, "src/server/routes.ts", `import {
|
|
903
|
+
write(dir, "src/server/routes.ts", `import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
787
904
|
import { query, run } from "./db";
|
|
788
905
|
|
|
789
|
-
const api = new
|
|
906
|
+
const api = new OpenAPIHono();
|
|
790
907
|
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
908
|
+
const ItemSchema = z.object({
|
|
909
|
+
id: z.number(),
|
|
910
|
+
title: z.string(),
|
|
911
|
+
status: z.string(),
|
|
912
|
+
created_at: z.string(),
|
|
913
|
+
}).openapi("Item");
|
|
795
914
|
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
});
|
|
915
|
+
const CreateItemSchema = z.object({ title: z.string().min(1) }).openapi("CreateItem");
|
|
916
|
+
const UpdateItemSchema = z.object({
|
|
917
|
+
title: z.string().min(1).optional(),
|
|
918
|
+
status: z.string().optional(),
|
|
919
|
+
}).openapi("UpdateItem");
|
|
920
|
+
const IdParamSchema = z.object({ id: z.string() });
|
|
921
|
+
const OkSchema = z.object({ ok: z.boolean() }).openapi("Ok");
|
|
802
922
|
|
|
803
|
-
api.
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
})
|
|
923
|
+
api.openapi(
|
|
924
|
+
createRoute({
|
|
925
|
+
method: "get",
|
|
926
|
+
path: "/api/items",
|
|
927
|
+
summary: "List items",
|
|
928
|
+
responses: {
|
|
929
|
+
200: {
|
|
930
|
+
description: "List of items",
|
|
931
|
+
content: { "application/json": { schema: z.array(ItemSchema) } },
|
|
932
|
+
},
|
|
933
|
+
},
|
|
934
|
+
}),
|
|
935
|
+
async (c) => {
|
|
936
|
+
const items = await query("SELECT * FROM items ORDER BY created_at DESC");
|
|
937
|
+
return c.json(items);
|
|
938
|
+
},
|
|
939
|
+
);
|
|
815
940
|
|
|
816
|
-
api.
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
941
|
+
api.openapi(
|
|
942
|
+
createRoute({
|
|
943
|
+
method: "post",
|
|
944
|
+
path: "/api/items",
|
|
945
|
+
summary: "Create item",
|
|
946
|
+
request: { body: { content: { "application/json": { schema: CreateItemSchema } } } },
|
|
947
|
+
responses: {
|
|
948
|
+
201: {
|
|
949
|
+
description: "Created item",
|
|
950
|
+
content: { "application/json": { schema: ItemSchema } },
|
|
951
|
+
},
|
|
952
|
+
},
|
|
953
|
+
}),
|
|
954
|
+
async (c) => {
|
|
955
|
+
const { title } = c.req.valid("json");
|
|
956
|
+
const result = await run("INSERT INTO items (title) VALUES (?)", [title.trim()]);
|
|
957
|
+
return c.json({ id: result.lastInsertRowid, title: title.trim(), status: "active", created_at: new Date().toISOString() }, 201);
|
|
958
|
+
},
|
|
959
|
+
);
|
|
960
|
+
|
|
961
|
+
api.openapi(
|
|
962
|
+
createRoute({
|
|
963
|
+
method: "patch",
|
|
964
|
+
path: "/api/items/:id",
|
|
965
|
+
summary: "Update item",
|
|
966
|
+
request: {
|
|
967
|
+
params: IdParamSchema,
|
|
968
|
+
body: { content: { "application/json": { schema: UpdateItemSchema } } },
|
|
969
|
+
},
|
|
970
|
+
responses: {
|
|
971
|
+
200: { description: "Updated", content: { "application/json": { schema: OkSchema } } },
|
|
972
|
+
},
|
|
973
|
+
}),
|
|
974
|
+
async (c) => {
|
|
975
|
+
const { id } = c.req.valid("param");
|
|
976
|
+
const body = c.req.valid("json");
|
|
977
|
+
const sets: string[] = [];
|
|
978
|
+
const params: unknown[] = [];
|
|
979
|
+
if (body.title !== undefined) { sets.push("title = ?"); params.push(body.title); }
|
|
980
|
+
if (body.status !== undefined) { sets.push("status = ?"); params.push(body.status); }
|
|
981
|
+
if (sets.length === 0) return c.json({ ok: false }, 400);
|
|
982
|
+
params.push(id);
|
|
983
|
+
await run(\`UPDATE items SET \${sets.join(", ")} WHERE id = ?\`, params);
|
|
984
|
+
return c.json({ ok: true });
|
|
985
|
+
},
|
|
986
|
+
);
|
|
987
|
+
|
|
988
|
+
api.openapi(
|
|
989
|
+
createRoute({
|
|
990
|
+
method: "delete",
|
|
991
|
+
path: "/api/items/:id",
|
|
992
|
+
summary: "Delete item",
|
|
993
|
+
request: { params: IdParamSchema },
|
|
994
|
+
responses: {
|
|
995
|
+
200: { description: "Deleted", content: { "application/json": { schema: OkSchema } } },
|
|
996
|
+
},
|
|
997
|
+
}),
|
|
998
|
+
async (c) => {
|
|
999
|
+
const { id } = c.req.valid("param");
|
|
1000
|
+
await run("DELETE FROM items WHERE id = ?", [id]);
|
|
1001
|
+
return c.json({ ok: true });
|
|
1002
|
+
},
|
|
1003
|
+
);
|
|
821
1004
|
|
|
822
1005
|
export default api;
|
|
823
1006
|
`);
|
|
@@ -1084,6 +1267,117 @@ function runQuiet(cwd, cmd, args) {
|
|
|
1084
1267
|
});
|
|
1085
1268
|
}
|
|
1086
1269
|
|
|
1270
|
+
// src/commands/link.ts
|
|
1271
|
+
import path4 from "path";
|
|
1272
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
1273
|
+
async function findByAppId(orgs, appId) {
|
|
1274
|
+
for (const org of orgs) {
|
|
1275
|
+
const res = await api.get(`/v1/apps/${appId}`, { orgId: org.id });
|
|
1276
|
+
if (res.ok) {
|
|
1277
|
+
return { app: await res.json(), org };
|
|
1278
|
+
}
|
|
1279
|
+
if (res.status !== 404) {
|
|
1280
|
+
const err = await res.json().catch(() => ({}));
|
|
1281
|
+
console.error(`Link failed (${org.name}): ${err.error || res.statusText}`);
|
|
1282
|
+
process.exit(1);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return null;
|
|
1286
|
+
}
|
|
1287
|
+
async function findBySlug(orgs, slug) {
|
|
1288
|
+
for (const org of orgs) {
|
|
1289
|
+
const res = await api.get(`/v1/apps`, { orgId: org.id });
|
|
1290
|
+
if (!res.ok) {
|
|
1291
|
+
if (res.status === 404) continue;
|
|
1292
|
+
const err = await res.json().catch(() => ({}));
|
|
1293
|
+
console.error(`Link failed (${org.name}): ${err.error || res.statusText}`);
|
|
1294
|
+
process.exit(1);
|
|
1295
|
+
}
|
|
1296
|
+
const payload = await res.json();
|
|
1297
|
+
const apps = Array.isArray(payload) ? payload : payload.apps;
|
|
1298
|
+
const match = apps.find((a) => a.slug === slug);
|
|
1299
|
+
if (match) {
|
|
1300
|
+
const detailRes = await api.get(`/v1/apps/${match.id}`, { orgId: org.id });
|
|
1301
|
+
if (detailRes.ok) {
|
|
1302
|
+
return { app: await detailRes.json(), org };
|
|
1303
|
+
}
|
|
1304
|
+
return { app: match, org };
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
return null;
|
|
1308
|
+
}
|
|
1309
|
+
async function linkCommand(appIdOrSlug, options) {
|
|
1310
|
+
const dir = options?.dir ? path4.resolve(options.dir) : process.cwd();
|
|
1311
|
+
const orgs = await listMyOrgs();
|
|
1312
|
+
if (orgs.length === 0) {
|
|
1313
|
+
console.error("No organizations found. Run `clawnify login` first.");
|
|
1314
|
+
process.exit(1);
|
|
1315
|
+
}
|
|
1316
|
+
const candidates = options?.org ? orgs.filter((o) => o.id === options.org || o.slug === options.org) : orgs;
|
|
1317
|
+
if (candidates.length === 0) {
|
|
1318
|
+
console.error(
|
|
1319
|
+
`No org matched "${options?.org}". Available: ${orgs.map((o) => o.slug).join(", ")}`
|
|
1320
|
+
);
|
|
1321
|
+
process.exit(1);
|
|
1322
|
+
}
|
|
1323
|
+
const isUuid = UUID_RE.test(appIdOrSlug);
|
|
1324
|
+
const matched = isUuid ? await findByAppId(candidates, appIdOrSlug) : await findBySlug(candidates, appIdOrSlug);
|
|
1325
|
+
if (!matched) {
|
|
1326
|
+
const kind = isUuid ? "id" : "slug";
|
|
1327
|
+
console.error(
|
|
1328
|
+
`App with ${kind} '${appIdOrSlug}' not found in ${candidates.map((o) => o.slug).join(", ")}.`
|
|
1329
|
+
);
|
|
1330
|
+
process.exit(1);
|
|
1331
|
+
}
|
|
1332
|
+
saveProject(dir, {
|
|
1333
|
+
org_id: matched.org.id,
|
|
1334
|
+
app_id: matched.app.id,
|
|
1335
|
+
slug: matched.app.slug,
|
|
1336
|
+
app_token: matched.app.app_token
|
|
1337
|
+
});
|
|
1338
|
+
const rel = path4.relative(process.cwd(), dir) || ".";
|
|
1339
|
+
console.log(` Linked ${matched.app.name} (${matched.app.slug}) in ${matched.org.name}`);
|
|
1340
|
+
console.log(` Wrote ${rel}/.clawnify/project.json`);
|
|
1341
|
+
console.log(` Run \`clawnify deploy\` to push the current source to this app.`);
|
|
1342
|
+
}
|
|
1343
|
+
|
|
1344
|
+
// src/commands/org.ts
|
|
1345
|
+
async function orgListCommand() {
|
|
1346
|
+
const orgs = await listMyOrgs();
|
|
1347
|
+
if (orgs.length === 0) {
|
|
1348
|
+
console.log("No organizations.");
|
|
1349
|
+
return;
|
|
1350
|
+
}
|
|
1351
|
+
const auth = loadAuth();
|
|
1352
|
+
const nameWidth = Math.max(4, ...orgs.map((o) => o.name.length));
|
|
1353
|
+
const slugWidth = Math.max(4, ...orgs.map((o) => o.slug.length));
|
|
1354
|
+
console.log(`${"Name".padEnd(nameWidth)} ${"Slug".padEnd(slugWidth)} Role Active`);
|
|
1355
|
+
console.log(`${"\u2500".repeat(nameWidth)} ${"\u2500".repeat(slugWidth)} \u2500\u2500\u2500\u2500\u2500\u2500\u2500 \u2500\u2500\u2500\u2500\u2500\u2500`);
|
|
1356
|
+
for (const o of orgs) {
|
|
1357
|
+
const active = auth?.org_id === o.id ? " *" : "";
|
|
1358
|
+
console.log(
|
|
1359
|
+
`${o.name.padEnd(nameWidth)} ${o.slug.padEnd(slugWidth)} ${o.role.padEnd(7)}${active}`
|
|
1360
|
+
);
|
|
1361
|
+
}
|
|
1362
|
+
}
|
|
1363
|
+
async function orgUseCommand(slugOrId) {
|
|
1364
|
+
const orgs = await listMyOrgs();
|
|
1365
|
+
const match = orgs.find((o) => o.id === slugOrId || o.slug === slugOrId);
|
|
1366
|
+
if (!match) {
|
|
1367
|
+
console.error(
|
|
1368
|
+
`No org matched "${slugOrId}". Available: ${orgs.map((o) => o.slug).join(", ")}`
|
|
1369
|
+
);
|
|
1370
|
+
process.exit(1);
|
|
1371
|
+
}
|
|
1372
|
+
const auth = loadAuth();
|
|
1373
|
+
if (!auth) {
|
|
1374
|
+
console.error("Not logged in. Run `clawnify login` first.");
|
|
1375
|
+
process.exit(1);
|
|
1376
|
+
}
|
|
1377
|
+
saveAuth({ ...auth, org_id: match.id });
|
|
1378
|
+
console.log(` Active org set to ${match.name} (${match.slug})`);
|
|
1379
|
+
}
|
|
1380
|
+
|
|
1087
1381
|
// src/cli.ts
|
|
1088
1382
|
function runCli() {
|
|
1089
1383
|
const program = new Command();
|
|
@@ -1091,7 +1385,11 @@ function runCli() {
|
|
|
1091
1385
|
program.command("init [dir]").description("Scaffold a new Clawnify app").option("--name <name>", "App name (skips prompt)").option("--template <template>", "Template: blank or crud (skips prompt)").option("--storage", "Enable file uploads (R2)").action(initCommand);
|
|
1092
1386
|
program.command("dev [dir]").description("Start local dev server").option("--port <port>", "API server port (default: 8787)").action(devCommand);
|
|
1093
1387
|
program.command("login").description("Authenticate with Clawnify").action(loginCommand);
|
|
1094
|
-
program.command("deploy [dir]").description("Deploy an app to Clawnify").option("--from <repo>", "Deploy from a GitHub repo (owner/repo)").option("--name <name>", "Override app name").action(deployCommand);
|
|
1388
|
+
program.command("deploy [dir]").description("Deploy an app to Clawnify").option("--from <repo>", "Deploy from a GitHub repo (owner/repo)").option("--name <name>", "Override app name").option("--org <slug-or-id>", "Deploy to a specific org (overrides active org)").option("-y, --yes", "Non-interactive: on slug conflict, update existing app").option("--update-existing", "Non-interactive: on slug conflict, overwrite existing app").option("--create-new", "Non-interactive: on slug conflict, create a new app with the suggested slug").option("--dry-run", "List files that would be uploaded; do not deploy").action(deployCommand);
|
|
1389
|
+
program.command("link <app-id-or-slug>").description("Link the current directory to an existing Clawnify app (accepts id or slug)").option("--dir <dir>", "Directory to link (default: cwd)").option("--org <slug-or-id>", "Restrict the app lookup to a specific org").action(linkCommand);
|
|
1390
|
+
const org = program.command("org").description("Manage organizations");
|
|
1391
|
+
org.command("list").description("List orgs you belong to").action(orgListCommand);
|
|
1392
|
+
org.command("use <slug-or-id>").description("Set the active org for global commands (ls, whoami, etc.)").action(orgUseCommand);
|
|
1095
1393
|
program.command("ls").description("List deployed apps").action(lsCommand);
|
|
1096
1394
|
program.command("logs <app-id>").description("Show build logs for an app").action(logsCommand);
|
|
1097
1395
|
program.command("rm <app-id>").description("Delete an app").action(rmCommand);
|
|
@@ -1102,4 +1400,4 @@ function runCli() {
|
|
|
1102
1400
|
export {
|
|
1103
1401
|
runCli
|
|
1104
1402
|
};
|
|
1105
|
-
//# sourceMappingURL=cli-
|
|
1403
|
+
//# sourceMappingURL=cli-KWGS4LVM.js.map
|