clawnify 0.3.0 → 0.4.0

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.
@@ -785,6 +785,7 @@ async function askProjectType(opts) {
785
785
  console.error(`Unknown --type '${opts.type}' (expected 'app' or 'website').`);
786
786
  process.exit(1);
787
787
  }
788
+ if (opts?.yes) return "app";
788
789
  console.log();
789
790
  console.log(" What are you creating?");
790
791
  console.log(" 1) app \u2014 full-stack project (React + Hono + D1)");
@@ -793,6 +794,13 @@ async function askProjectType(opts) {
793
794
  const choice = await ask2("Type [1]: ") || "1";
794
795
  return choice === "2" ? "website" : "app";
795
796
  }
797
+ function detectPackageManager() {
798
+ const ua = process.env.npm_config_user_agent ?? "";
799
+ if (ua.startsWith("pnpm")) return "pnpm";
800
+ if (ua.startsWith("yarn")) return "yarn";
801
+ if (ua.startsWith("bun")) return "bun";
802
+ return "npm";
803
+ }
796
804
  async function initCommand(dir, opts) {
797
805
  const type = await askProjectType(opts);
798
806
  if (type === "website") {
@@ -801,12 +809,16 @@ async function initCommand(dir, opts) {
801
809
  return initApp(dir, opts);
802
810
  }
803
811
  async function initApp(dir, opts) {
804
- const name = opts?.name || await ask2("App name: ") || "my-app";
812
+ const yes = !!opts?.yes;
813
+ const dirArgName = dir ? path3.basename(path3.resolve(dir)) : void 0;
814
+ const name = opts?.name || (yes ? dirArgName ?? "my-app" : await ask2("App name: ") || "my-app");
805
815
  const slug = slugify(name);
806
816
  const targetDir = dir ? path3.resolve(dir) : path3.resolve(slug);
807
817
  let template;
808
818
  if (opts?.template) {
809
819
  template = opts.template === "crud" ? "crud" : "blank";
820
+ } else if (yes) {
821
+ template = "blank";
810
822
  } else {
811
823
  console.log();
812
824
  console.log(" Templates:");
@@ -822,9 +834,12 @@ async function initApp(dir, opts) {
822
834
  }
823
835
  fs2.mkdirSync(path3.join(targetDir, "src/server"), { recursive: true });
824
836
  fs2.mkdirSync(path3.join(targetDir, "src/client"), { recursive: true });
837
+ fs2.mkdirSync(path3.join(targetDir, "drizzle"), { recursive: true });
825
838
  let storage;
826
839
  if (opts?.storage !== void 0) {
827
840
  storage = opts.storage;
841
+ } else if (yes) {
842
+ storage = false;
828
843
  } else {
829
844
  const storageChoice = await ask2("Enable file uploads? [y/N]: ") || "n";
830
845
  storage = storageChoice.toLowerCase() === "y";
@@ -842,10 +857,11 @@ async function initApp(dir, opts) {
842
857
  "@types/react": "^19.0.0",
843
858
  "@types/react-dom": "^19.0.0",
844
859
  "@vitejs/plugin-react": "^4.0.0",
845
- "clawnify": "^0.1.15",
846
- "tailwindcss": "^4.0.0",
847
- "vite": "^6.0.0",
848
- "wrangler": "^4.0.0"
860
+ clawnify: "^0.3.0",
861
+ "drizzle-kit": "^0.31.0",
862
+ tailwindcss: "^4.0.0",
863
+ vite: "^6.0.0",
864
+ wrangler: "^4.0.0"
849
865
  };
850
866
  write(targetDir, "package.json", JSON.stringify({
851
867
  name: slug,
@@ -854,9 +870,11 @@ async function initApp(dir, opts) {
854
870
  scripts: {
855
871
  dev: "clawnify dev",
856
872
  build: "vite build",
857
- deploy: "clawnify deploy"
873
+ deploy: "clawnify deploy",
874
+ "db:generate": "drizzle-kit generate"
858
875
  },
859
876
  dependencies: {
877
+ "@clawnify/db": "^0.4.0",
860
878
  "@hono/zod-openapi": "^0.19.0",
861
879
  hono: "^4.0.0",
862
880
  react: "^19.0.0",
@@ -929,45 +947,37 @@ data.db-shm
929
947
  `);
930
948
  write(targetDir, "src/server/worker-env.d.ts", `/// <reference types="@cloudflare/workers-types" />
931
949
  `);
932
- write(targetDir, "src/server/db.ts", `let _db: D1Database;
933
-
934
- export function initDB(db: D1Database) {
935
- _db = db;
936
- }
937
-
938
- export async function query<T = Record<string, unknown>>(
939
- sql: string,
940
- params: unknown[] = [],
941
- ): Promise<T[]> {
942
- const stmt = _db.prepare(sql).bind(...params);
943
- const { results } = await stmt.all<T>();
944
- return results ?? [];
945
- }
946
-
947
- export async function get<T = Record<string, unknown>>(
948
- sql: string,
949
- params: unknown[] = [],
950
- ): Promise<T | undefined> {
951
- const stmt = _db.prepare(sql).bind(...params);
952
- const row = await stmt.first<T>();
953
- return row ?? undefined;
954
- }
950
+ write(targetDir, "src/server/schema.ts", `import { sqliteTable, text, integer } from "@clawnify/db";
951
+
952
+ /**
953
+ * Example table. Replace with your own.
954
+ *
955
+ * Multi-tenancy reminder: every user-facing table should carry an
956
+ * \`org_id\` column and every query should filter by the X-Clawnify-Org-Id
957
+ * header. See docs/build-a-clawnify-app.md.
958
+ */
959
+ export const items = sqliteTable("items", {
960
+ id: integer("id").primaryKey({ autoIncrement: true }),
961
+ name: text("name").notNull(),
962
+ createdAt: text("created_at").notNull().$default(() => new Date().toISOString()),
963
+ });
964
+ `);
965
+ write(targetDir, "drizzle.config.ts", `import { defineConfig } from "drizzle-kit";
955
966
 
956
- export async function run(
957
- sql: string,
958
- params: unknown[] = [],
959
- ): Promise<{ changes: number; lastInsertRowid: number }> {
960
- const stmt = _db.prepare(sql).bind(...params);
961
- const result = await stmt.run();
962
- return {
963
- changes: result.meta?.changes ?? 0,
964
- lastInsertRowid: Number(result.meta?.last_row_id ?? 0),
965
- };
966
- }
967
+ export default defineConfig({
968
+ schema: "./src/server/schema.ts",
969
+ out: "./drizzle",
970
+ dialect: "sqlite",
971
+ });
972
+ `);
973
+ write(targetDir, "drizzle/0000_init.sql", `CREATE TABLE \`items\` (
974
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
975
+ \`name\` text NOT NULL,
976
+ \`created_at\` text NOT NULL
977
+ );
967
978
  `);
968
979
  if (storage) {
969
980
  write(targetDir, "src/server/index.ts", `import { OpenAPIHono } from "@hono/zod-openapi";
970
- import { initDB } from "./db";
971
981
  import { initUploads } from "./uploads";
972
982
  import api from "./routes";
973
983
 
@@ -976,7 +986,6 @@ type Env = { Bindings: { DB: D1Database; UPLOADS: R2Bucket } };
976
986
  const app = new OpenAPIHono<Env>();
977
987
 
978
988
  app.use("*", async (c, next) => {
979
- initDB(c.env.DB);
980
989
  initUploads(c.env.UPLOADS);
981
990
  await next();
982
991
  });
@@ -1033,18 +1042,12 @@ export async function readUploadAsBase64DataUrl(
1033
1042
  `);
1034
1043
  } else {
1035
1044
  write(targetDir, "src/server/index.ts", `import { OpenAPIHono } from "@hono/zod-openapi";
1036
- import { initDB } from "./db";
1037
1045
  import api from "./routes";
1038
1046
 
1039
1047
  type Env = { Bindings: { DB: D1Database } };
1040
1048
 
1041
1049
  const app = new OpenAPIHono<Env>();
1042
1050
 
1043
- app.use("*", async (c, next) => {
1044
- initDB(c.env.DB);
1045
- await next();
1046
- });
1047
-
1048
1051
  app.route("/", api);
1049
1052
 
1050
1053
  app.doc("/api/openapi.json", {
@@ -1073,14 +1076,15 @@ createRoot(document.getElementById("app")!).render(
1073
1076
  } else {
1074
1077
  writeBlankTemplate(targetDir, name);
1075
1078
  }
1079
+ const pm = detectPackageManager();
1076
1080
  console.log();
1077
1081
  console.log(` Created ${name} in ${path3.relative(process.cwd(), targetDir)}/`);
1078
1082
  console.log();
1079
1083
  console.log(" Get started:");
1080
1084
  console.log(` cd ${path3.relative(process.cwd(), targetDir)}`);
1081
- console.log(" pnpm install");
1082
- console.log(" pnpm dev # local dev at http://localhost:5173");
1083
- console.log(" pnpm deploy # deploy to production");
1085
+ console.log(` ${pm} install`);
1086
+ console.log(` ${pm} ${pm === "npm" ? "run " : ""}dev # local dev at http://localhost:5173`);
1087
+ console.log(` ${pm} ${pm === "npm" ? "run " : ""}deploy # deploy to production`);
1084
1088
  console.log();
1085
1089
  }
1086
1090
  async function initWebsite(dir, opts) {
@@ -1211,21 +1215,17 @@ import BaseLayout from "../layouts/BaseLayout.astro";
1211
1215
  console.log();
1212
1216
  }
1213
1217
  function writeBlankTemplate(dir, name) {
1214
- write(dir, "schema.sql", `CREATE TABLE IF NOT EXISTS items (
1215
- id INTEGER PRIMARY KEY AUTOINCREMENT,
1216
- name TEXT NOT NULL,
1217
- created_at TEXT NOT NULL DEFAULT (datetime('now'))
1218
- );
1219
- `);
1220
1218
  write(dir, "src/server/routes.ts", `import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
1221
- import { query } from "./db";
1219
+ import { getDB, desc } from "@clawnify/db";
1220
+ import * as schema from "./schema";
1222
1221
 
1223
- const api = new OpenAPIHono();
1222
+ type Env = { Bindings: { DB: D1Database } };
1223
+ const api = new OpenAPIHono<Env>();
1224
1224
 
1225
1225
  const ItemSchema = z.object({
1226
1226
  id: z.number(),
1227
1227
  name: z.string(),
1228
- created_at: z.string(),
1228
+ createdAt: z.string(),
1229
1229
  }).openapi("Item");
1230
1230
 
1231
1231
  api.openapi(
@@ -1241,58 +1241,87 @@ api.openapi(
1241
1241
  },
1242
1242
  }),
1243
1243
  async (c) => {
1244
- const items = await query("SELECT * FROM items ORDER BY created_at DESC");
1244
+ const db = getDB(c.env, { schema });
1245
+ const items = await db
1246
+ .select()
1247
+ .from(schema.items)
1248
+ .orderBy(desc(schema.items.createdAt));
1245
1249
  return c.json(items);
1246
1250
  },
1247
1251
  );
1248
1252
 
1249
1253
  export default api;
1250
1254
  `);
1251
- write(dir, "src/client/app.tsx", `import { useState, useEffect } from "react";
1252
-
1253
- export function App() {
1254
- const [items, setItems] = useState<any[]>([]);
1255
-
1256
- useEffect(() => {
1257
- fetch("/api/items").then((r) => r.json()).then(setItems);
1258
- }, []);
1259
-
1255
+ write(dir, "src/client/app.tsx", `export function App() {
1260
1256
  return (
1261
- <div className="max-w-xl mx-auto mt-10 px-4">
1262
- <h1 className="text-2xl font-semibold mb-4">${name}</h1>
1263
- <ul className="space-y-2">
1264
- {items.map((item: any) => (
1265
- <li key={item.id} className="p-3 rounded-lg border border-gray-200 text-sm">
1266
- {item.name}
1257
+ <main className="min-h-screen flex items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100 px-6">
1258
+ <div className="max-w-xl w-full text-center">
1259
+ <div className="inline-flex items-center gap-2 rounded-full bg-white/80 backdrop-blur px-3 py-1 text-xs font-medium text-slate-600 ring-1 ring-slate-200">
1260
+ <span className="size-1.5 rounded-full bg-emerald-500" />
1261
+ Clawnify \xB7 live
1262
+ </div>
1263
+
1264
+ <h1 className="mt-6 text-4xl font-semibold tracking-tight text-slate-900">
1265
+ Welcome to ${name}
1266
+ </h1>
1267
+ <p className="mt-3 text-base text-slate-600">
1268
+ Edit <code className="rounded bg-slate-200/70 px-1.5 py-0.5 text-sm">src/client/app.tsx</code> to get started.
1269
+ </p>
1270
+
1271
+ <ul className="mt-8 grid gap-3 text-left text-sm text-slate-700">
1272
+ <li className="rounded-lg border border-slate-200 bg-white px-4 py-3">
1273
+ <span className="font-medium text-slate-900">Try the API.</span> Open <code>/api/items</code> \u2014 empty list to start.
1267
1274
  </li>
1268
- ))}
1269
- </ul>
1270
- {items.length === 0 && (
1271
- <p className="text-gray-400 mt-4 text-sm">No items yet.</p>
1272
- )}
1273
- </div>
1275
+ <li className="rounded-lg border border-slate-200 bg-white px-4 py-3">
1276
+ <span className="font-medium text-slate-900">Evolve the schema.</span> Edit <code>src/server/schema.ts</code>, then run <code>pnpm db:generate</code>.
1277
+ </li>
1278
+ <li className="rounded-lg border border-slate-200 bg-white px-4 py-3">
1279
+ <span className="font-medium text-slate-900">Deploy.</span> Run <code>pnpm deploy</code> to push live.
1280
+ </li>
1281
+ </ul>
1282
+
1283
+ <p className="mt-8 text-xs text-slate-500">
1284
+ Read{" "}
1285
+ <a href="https://github.com/clawnify/clawnify/blob/main/docs/build-a-clawnify-app.md" target="_blank" rel="noreferrer" className="underline underline-offset-2">
1286
+ docs/build-a-clawnify-app.md
1287
+ </a>{" "}
1288
+ for the full gold-standard guide.
1289
+ </p>
1290
+ </div>
1291
+ </main>
1274
1292
  );
1275
1293
  }
1276
1294
  `);
1277
1295
  }
1278
1296
  function writeCrudTemplate(dir, name) {
1279
- write(dir, "schema.sql", `CREATE TABLE IF NOT EXISTS items (
1280
- id INTEGER PRIMARY KEY AUTOINCREMENT,
1281
- title TEXT NOT NULL,
1282
- status TEXT NOT NULL DEFAULT 'active',
1283
- created_at TEXT NOT NULL DEFAULT (datetime('now'))
1297
+ write(dir, "src/server/schema.ts", `import { sqliteTable, text, integer } from "@clawnify/db";
1298
+
1299
+ export const items = sqliteTable("items", {
1300
+ id: integer("id").primaryKey({ autoIncrement: true }),
1301
+ title: text("title").notNull(),
1302
+ status: text("status").notNull().default("active"),
1303
+ createdAt: text("created_at").notNull().$default(() => new Date().toISOString()),
1304
+ });
1305
+ `);
1306
+ write(dir, "drizzle/0000_init.sql", `CREATE TABLE \`items\` (
1307
+ \`id\` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
1308
+ \`title\` text NOT NULL,
1309
+ \`status\` text DEFAULT 'active' NOT NULL,
1310
+ \`created_at\` text NOT NULL
1284
1311
  );
1285
1312
  `);
1286
1313
  write(dir, "src/server/routes.ts", `import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
1287
- import { query, run } from "./db";
1314
+ import { getDB, eq, desc } from "@clawnify/db";
1315
+ import * as schema from "./schema";
1288
1316
 
1289
- const api = new OpenAPIHono();
1317
+ type Env = { Bindings: { DB: D1Database } };
1318
+ const api = new OpenAPIHono<Env>();
1290
1319
 
1291
1320
  const ItemSchema = z.object({
1292
1321
  id: z.number(),
1293
1322
  title: z.string(),
1294
1323
  status: z.string(),
1295
- created_at: z.string(),
1324
+ createdAt: z.string(),
1296
1325
  }).openapi("Item");
1297
1326
 
1298
1327
  const CreateItemSchema = z.object({ title: z.string().min(1) }).openapi("CreateItem");
@@ -1316,7 +1345,11 @@ api.openapi(
1316
1345
  },
1317
1346
  }),
1318
1347
  async (c) => {
1319
- const items = await query("SELECT * FROM items ORDER BY created_at DESC");
1348
+ const db = getDB(c.env, { schema });
1349
+ const items = await db
1350
+ .select()
1351
+ .from(schema.items)
1352
+ .orderBy(desc(schema.items.createdAt));
1320
1353
  return c.json(items);
1321
1354
  },
1322
1355
  );
@@ -1336,8 +1369,12 @@ api.openapi(
1336
1369
  }),
1337
1370
  async (c) => {
1338
1371
  const { title } = c.req.valid("json");
1339
- const result = await run("INSERT INTO items (title) VALUES (?)", [title.trim()]);
1340
- return c.json({ id: result.lastInsertRowid, title: title.trim(), status: "active", created_at: new Date().toISOString() }, 201);
1372
+ const db = getDB(c.env, { schema });
1373
+ const [row] = await db
1374
+ .insert(schema.items)
1375
+ .values({ title: title.trim() })
1376
+ .returning();
1377
+ return c.json(row, 201);
1341
1378
  },
1342
1379
  );
1343
1380
 
@@ -1357,13 +1394,12 @@ api.openapi(
1357
1394
  async (c) => {
1358
1395
  const { id } = c.req.valid("param");
1359
1396
  const body = c.req.valid("json");
1360
- const sets: string[] = [];
1361
- const params: unknown[] = [];
1362
- if (body.title !== undefined) { sets.push("title = ?"); params.push(body.title); }
1363
- if (body.status !== undefined) { sets.push("status = ?"); params.push(body.status); }
1364
- if (sets.length === 0) return c.json({ ok: false }, 400);
1365
- params.push(id);
1366
- await run(\`UPDATE items SET \${sets.join(", ")} WHERE id = ?\`, params);
1397
+ const patch: Partial<typeof schema.items.$inferInsert> = {};
1398
+ if (body.title !== undefined) patch.title = body.title;
1399
+ if (body.status !== undefined) patch.status = body.status;
1400
+ if (Object.keys(patch).length === 0) return c.json({ ok: false }, 400);
1401
+ const db = getDB(c.env, { schema });
1402
+ await db.update(schema.items).set(patch).where(eq(schema.items.id, Number(id)));
1367
1403
  return c.json({ ok: true });
1368
1404
  },
1369
1405
  );
@@ -1380,7 +1416,8 @@ api.openapi(
1380
1416
  }),
1381
1417
  async (c) => {
1382
1418
  const { id } = c.req.valid("param");
1383
- await run("DELETE FROM items WHERE id = ?", [id]);
1419
+ const db = getDB(c.env, { schema });
1420
+ await db.delete(schema.items).where(eq(schema.items.id, Number(id)));
1384
1421
  return c.json({ ok: true });
1385
1422
  },
1386
1423
  );
@@ -1393,7 +1430,7 @@ interface Item {
1393
1430
  id: number;
1394
1431
  title: string;
1395
1432
  status: string;
1396
- created_at: string;
1433
+ createdAt: string;
1397
1434
  }
1398
1435
 
1399
1436
  export function App() {
@@ -2006,7 +2043,7 @@ async function sdkInstallCommand() {
2006
2043
  }
2007
2044
 
2008
2045
  // src/lib/skills/content.gen.ts
2009
- var CLI_VERSION = "0.3.0";
2046
+ var CLI_VERSION = "0.4.0";
2010
2047
  var BUNDLED_SKILLS = [
2011
2048
  {
2012
2049
  name: "build-a-clawnify-app",
@@ -2342,7 +2379,7 @@ Valid: ${ALL_AGENTS.join(", ")}`
2342
2379
  function runCli() {
2343
2380
  const program = new Command();
2344
2381
  program.name("clawnify").description("Deploy apps to Clawnify").version("0.1.0");
2345
- program.command("init [dir]").description("Scaffold a new Clawnify project (app or website)").option("--type <type>", "Project type: app or website (skips prompt)").option("--name <name>", "Project name (skips prompt)").option("--template <template>", "App template: blank or crud (apps only)").option("--storage", "Enable file uploads (R2) \u2014 apps only").action(initCommand);
2382
+ program.command("init [dir]").description("Scaffold a new Clawnify project (app or website)").option("--type <type>", "Project type: app or website (skips prompt)").option("--name <name>", "Project name (skips prompt)").option("--template <template>", "App template: blank or crud (apps only)").option("--storage", "Enable file uploads (R2) \u2014 apps only").option("-y, --yes", "Non-interactive: use all defaults (app, blank, no storage)").action(initCommand);
2346
2383
  program.command("dev [dir]").description("Start local dev server").option("--port <port>", "API server port (default: 8787)").action(devCommand);
2347
2384
  program.command("login").description("Authenticate with Clawnify").action(loginCommand);
2348
2385
  program.command("deploy [dir]").description("Deploy an app or website 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").option("--no-sync", "Skip the post-deploy schema.sql sync into the local working directory").action(deployCommand);
@@ -2373,4 +2410,4 @@ function runCli() {
2373
2410
  export {
2374
2411
  runCli
2375
2412
  };
2376
- //# sourceMappingURL=cli-P6F6JKMF.js.map
2413
+ //# sourceMappingURL=cli-5KZ7W67B.js.map