koguma 0.4.1 → 0.4.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/cli/index.ts CHANGED
@@ -393,7 +393,7 @@ async function cmdInit() {
393
393
  } else {
394
394
  log(`Creating D1 database: ${CYAN}${dbName}${RESET}`);
395
395
  try {
396
- const output = runCapture(`npx wrangler d1 create ${dbName}`, root);
396
+ const output = runCapture(`bunx wrangler d1 create ${dbName}`, root);
397
397
  const idMatch = output.match(/database_id\s*=\s*"([^"]+)"/);
398
398
  if (idMatch?.[1]) {
399
399
  toml = toml.replace(
@@ -409,7 +409,7 @@ async function cmdInit() {
409
409
  }
410
410
  } catch {
411
411
  fail(
412
- "Failed to create D1 database. Make sure you're logged into Cloudflare: npx wrangler login"
412
+ "Failed to create D1 database. Make sure you're logged into Cloudflare: bunx wrangler login"
413
413
  );
414
414
  }
415
415
  }
@@ -420,11 +420,11 @@ async function cmdInit() {
420
420
 
421
421
  log(`Checking R2 bucket: ${CYAN}${bucketName}${RESET}`);
422
422
  try {
423
- const buckets = runCapture('npx wrangler r2 bucket list', root);
423
+ const buckets = runCapture('bunx wrangler r2 bucket list', root);
424
424
  if (buckets.includes(bucketName)) {
425
425
  ok(`R2 bucket already exists: ${DIM}${bucketName}${RESET}`);
426
426
  } else {
427
- runCapture(`npx wrangler r2 bucket create ${bucketName}`, root);
427
+ runCapture(`bunx wrangler r2 bucket create ${bucketName}`, root);
428
428
  ok(`Created R2 bucket: ${DIM}${bucketName}${RESET}`);
429
429
  }
430
430
  } catch {
@@ -489,7 +489,7 @@ async function cmdSeed() {
489
489
  log(
490
490
  `Seeding ${isRemote ? 'REMOTE' : 'local'} database: ${CYAN}${dbName}${RESET}`
491
491
  );
492
- run(`npx wrangler d1 execute ${dbName} ${target} --file=${seedSql}`, {
492
+ run(`bunx wrangler d1 execute ${dbName} ${target} --file=${seedSql}`, {
493
493
  cwd: root
494
494
  });
495
495
 
@@ -509,7 +509,7 @@ async function cmdDeploy() {
509
509
 
510
510
  // Deploy
511
511
  log('\nDeploying to Cloudflare...');
512
- run('npx wrangler deploy', { cwd: root });
512
+ run('bunx wrangler deploy', { cwd: root });
513
513
 
514
514
  ok('Deployed! 🎉');
515
515
  }
@@ -518,7 +518,7 @@ async function cmdSecret() {
518
518
  header('koguma secret');
519
519
  const root = findProjectRoot();
520
520
  log('Setting KOGUMA_SECRET (your admin password)...');
521
- run('npx wrangler secret put KOGUMA_SECRET', { cwd: root });
521
+ run('bunx wrangler secret put KOGUMA_SECRET', { cwd: root });
522
522
  ok('Secret set!');
523
523
  }
524
524
 
@@ -650,7 +650,7 @@ async function cmdMigrateMedia() {
650
650
  const target = isRemote ? '--remote' : '--local';
651
651
 
652
652
  log(`\nUpdating ${isRemote ? 'remote' : 'local'} database URLs...`);
653
- run(`npx wrangler d1 execute ${dbName} ${target} --file=${sqlPath}`, {
653
+ run(`bunx wrangler d1 execute ${dbName} ${target} --file=${sqlPath}`, {
654
654
  cwd: root
655
655
  });
656
656
 
@@ -847,7 +847,7 @@ async function cmdMigrate() {
847
847
  for (const ct of config.contentTypes) {
848
848
  try {
849
849
  const output = runCapture(
850
- `npx wrangler d1 execute ${dbName} ${target} --command "SELECT name, type FROM pragma_table_info('${ct.id}')" --json`,
850
+ `bunx wrangler d1 execute ${dbName} ${target} --command "SELECT name, type FROM pragma_table_info('${ct.id}')" --json`,
851
851
  root
852
852
  );
853
853
  const parsed = JSON.parse(output);
@@ -863,8 +863,49 @@ async function cmdMigrate() {
863
863
  const { detectDrift } = await import('../src/db/migrate.ts');
864
864
  const result = detectDrift(config.contentTypes as any, existingColumns);
865
865
 
866
+ // Also ensure _assets table exists
867
+ try {
868
+ const output = runCapture(
869
+ `bunx wrangler d1 execute ${dbName} ${target} --command "SELECT name FROM pragma_table_info('_assets')" --json`,
870
+ root
871
+ );
872
+ const parsed = JSON.parse(output);
873
+ const results = parsed?.[0]?.results ?? [];
874
+ if (results.length === 0) {
875
+ result.sql.unshift(
876
+ `CREATE TABLE IF NOT EXISTS _assets (\n` +
877
+ ` id TEXT PRIMARY KEY,\n` +
878
+ ` title TEXT NOT NULL DEFAULT '',\n` +
879
+ ` description TEXT DEFAULT '',\n` +
880
+ ` url TEXT NOT NULL,\n` +
881
+ ` content_type TEXT DEFAULT '',\n` +
882
+ ` width INTEGER,\n` +
883
+ ` height INTEGER,\n` +
884
+ ` file_size INTEGER,\n` +
885
+ ` created_at TEXT DEFAULT (datetime('now')),\n` +
886
+ ` updated_at TEXT DEFAULT (datetime('now'))\n` +
887
+ `);`
888
+ );
889
+ }
890
+ } catch {
891
+ result.sql.unshift(
892
+ `CREATE TABLE IF NOT EXISTS _assets (\n` +
893
+ ` id TEXT PRIMARY KEY,\n` +
894
+ ` title TEXT NOT NULL DEFAULT '',\n` +
895
+ ` description TEXT DEFAULT '',\n` +
896
+ ` url TEXT NOT NULL,\n` +
897
+ ` content_type TEXT DEFAULT '',\n` +
898
+ ` width INTEGER,\n` +
899
+ ` height INTEGER,\n` +
900
+ ` file_size INTEGER,\n` +
901
+ ` created_at TEXT DEFAULT (datetime('now')),\n` +
902
+ ` updated_at TEXT DEFAULT (datetime('now'))\n` +
903
+ `);`
904
+ );
905
+ }
906
+
866
907
  // Display results
867
- if (result.drift.length === 0 && result.warnings.length === 0) {
908
+ if (result.sql.length === 0 && result.warnings.length === 0) {
868
909
  ok('Schema is up to date — no changes needed!');
869
910
  return;
870
911
  }
@@ -888,7 +929,7 @@ async function cmdMigrate() {
888
929
  log(`\nWritten to ${CYAN}db/migration.sql${RESET}`);
889
930
 
890
931
  log(`\nApplying migration to ${isRemote ? 'REMOTE' : 'local'} database...`);
891
- run(`npx wrangler d1 execute ${dbName} ${target} --file=${sqlFile}`, {
932
+ run(`bunx wrangler d1 execute ${dbName} ${target} --file=${sqlFile}`, {
892
933
  cwd: root
893
934
  });
894
935
 
@@ -931,7 +972,7 @@ async function cmdExport() {
931
972
  // Export main table
932
973
  try {
933
974
  const output = runCapture(
934
- `npx wrangler d1 execute ${dbName} ${target} --command "SELECT * FROM ${ct.id}" --json`,
975
+ `bunx wrangler d1 execute ${dbName} ${target} --command "SELECT * FROM ${ct.id}" --json`,
935
976
  root
936
977
  );
937
978
  const parsed = JSON.parse(output);
@@ -944,7 +985,7 @@ async function cmdExport() {
944
985
  const joinTable = `${ct.id}__${fieldId}`;
945
986
  try {
946
987
  const jtOutput = runCapture(
947
- `npx wrangler d1 execute ${dbName} ${target} --command "SELECT * FROM ${joinTable}" --json`,
988
+ `bunx wrangler d1 execute ${dbName} ${target} --command "SELECT * FROM ${joinTable}" --json`,
948
989
  root
949
990
  );
950
991
  const jtParsed = JSON.parse(jtOutput);
@@ -1039,7 +1080,7 @@ async function cmdImport() {
1039
1080
 
1040
1081
  const sql = `INSERT OR REPLACE INTO ${typeId} (${cols.join(', ')}) VALUES (${vals.join(', ')})`;
1041
1082
  run(
1042
- `npx wrangler d1 execute ${dbName} ${target} --command "${sql.replace(/"/g, '\\"')}"`,
1083
+ `bunx wrangler d1 execute ${dbName} ${target} --command "${sql.replace(/"/g, '\\"')}"`,
1043
1084
  { cwd: root, silent: true }
1044
1085
  );
1045
1086
  totalEntries++;
@@ -1057,7 +1098,7 @@ async function cmdImport() {
1057
1098
 
1058
1099
  const sql = `INSERT OR REPLACE INTO ${jtName} (${cols.join(', ')}) VALUES (${vals.join(', ')})`;
1059
1100
  run(
1060
- `npx wrangler d1 execute ${dbName} ${target} --command "${sql.replace(/"/g, '\\"')}"`,
1101
+ `bunx wrangler d1 execute ${dbName} ${target} --command "${sql.replace(/"/g, '\\"')}"`,
1061
1102
  { cwd: root, silent: true }
1062
1103
  );
1063
1104
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koguma",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "🐻 A little CMS with big heart — schema-driven, runs on Cloudflare's free tier",
5
5
  "type": "module",
6
6
  "license": "MIT",