koguma 0.5.0-rc.4 → 0.6.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.
- package/cli/index.ts +54 -2
- package/package.json +1 -1
- package/src/admin/_bundle.ts +1 -1
- package/src/api/router.integration.test.ts +50 -1
- package/src/api/router.ts +30 -1
- package/src/config/field.ts +80 -1
- package/src/config/meta.ts +79 -2
- package/src/db/queries.ts +11 -5
- package/src/db/schema.ts +8 -1
- package/src/media/index.ts +174 -27
package/cli/index.ts
CHANGED
|
@@ -14,8 +14,9 @@
|
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
import { execSync } from 'child_process';
|
|
17
|
-
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|
17
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'fs';
|
|
18
18
|
import { resolve, dirname, basename } from 'path';
|
|
19
|
+
import { generateSchema } from '../src/db/schema.ts';
|
|
19
20
|
|
|
20
21
|
// ── Helpers ─────────────────────────────────────────────────────────
|
|
21
22
|
|
|
@@ -937,6 +938,53 @@ async function cmdMigrate() {
|
|
|
937
938
|
}
|
|
938
939
|
}
|
|
939
940
|
|
|
941
|
+
// ── Schema ──────────────────────────────────────────────────────────
|
|
942
|
+
|
|
943
|
+
async function cmdSchema() {
|
|
944
|
+
header('koguma schema');
|
|
945
|
+
const root = findProjectRoot();
|
|
946
|
+
|
|
947
|
+
const configPath = resolve(root, 'site.config.ts');
|
|
948
|
+
if (!existsSync(configPath)) {
|
|
949
|
+
fail('site.config.ts not found in project root.');
|
|
950
|
+
process.exit(1);
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
log('Reading site.config.ts...');
|
|
954
|
+
const configModule = await import(configPath);
|
|
955
|
+
const config = configModule.default as {
|
|
956
|
+
contentTypes: {
|
|
957
|
+
id: string;
|
|
958
|
+
fieldMeta: Record<string, { fieldType: string; required: boolean }>;
|
|
959
|
+
}[];
|
|
960
|
+
};
|
|
961
|
+
|
|
962
|
+
if (!config.contentTypes?.length) {
|
|
963
|
+
fail('No content types found in site.config.ts');
|
|
964
|
+
process.exit(1);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
const schema = generateSchema(config.contentTypes as any);
|
|
968
|
+
|
|
969
|
+
// Print to stdout
|
|
970
|
+
console.log('');
|
|
971
|
+
console.log(schema.sql);
|
|
972
|
+
console.log('');
|
|
973
|
+
|
|
974
|
+
// Also write to db/schema.sql
|
|
975
|
+
const dbDir = resolve(root, 'db');
|
|
976
|
+
if (!existsSync(dbDir)) mkdirSync(dbDir, { recursive: true });
|
|
977
|
+
const outPath = resolve(dbDir, 'schema.sql');
|
|
978
|
+
writeFileSync(outPath, schema.sql + '\n');
|
|
979
|
+
|
|
980
|
+
ok(
|
|
981
|
+
`Written to ${CYAN}db/schema.sql${RESET} (${schema.tables.length} tables, ${schema.indexes.length} indexes)`
|
|
982
|
+
);
|
|
983
|
+
log(
|
|
984
|
+
`\n ${DIM}Use this as the basis for your seed.sql to avoid schema drift.${RESET}`
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
|
|
940
988
|
// ── Export ───────────────────────────────────────────────────────────
|
|
941
989
|
|
|
942
990
|
async function cmdExport() {
|
|
@@ -1112,7 +1160,7 @@ async function cmdImport() {
|
|
|
1112
1160
|
|
|
1113
1161
|
function cmdHelp() {
|
|
1114
1162
|
console.log(`
|
|
1115
|
-
${BOLD}🐻 Koguma CLI${RESET} ${DIM}v0.
|
|
1163
|
+
${BOLD}🐻 Koguma CLI${RESET} ${DIM}v0.5.0${RESET}
|
|
1116
1164
|
|
|
1117
1165
|
${BOLD}Usage:${RESET} koguma <command>
|
|
1118
1166
|
|
|
@@ -1121,6 +1169,7 @@ ${BOLD}Commands:${RESET}
|
|
|
1121
1169
|
${CYAN}secret${RESET} Set the admin password on Cloudflare
|
|
1122
1170
|
${CYAN}build${RESET} Build the admin dashboard bundle
|
|
1123
1171
|
${CYAN}seed${RESET} Seed the database from db/seed.sql
|
|
1172
|
+
${CYAN}schema${RESET} Generate correct DDL from site.config.ts → db/schema.sql
|
|
1124
1173
|
${CYAN}typegen${RESET} Generate koguma.d.ts typed interfaces
|
|
1125
1174
|
${CYAN}migrate${RESET} Detect schema drift and apply ALTER TABLE changes
|
|
1126
1175
|
${CYAN}export${RESET} Export all content to JSON
|
|
@@ -1163,6 +1212,9 @@ switch (command) {
|
|
|
1163
1212
|
case 'typegen':
|
|
1164
1213
|
await cmdTypegen();
|
|
1165
1214
|
break;
|
|
1215
|
+
case 'schema':
|
|
1216
|
+
await cmdSchema();
|
|
1217
|
+
break;
|
|
1166
1218
|
case 'migrate':
|
|
1167
1219
|
await cmdMigrate();
|
|
1168
1220
|
break;
|