create-backon 0.9.0 → 0.10.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/README.md +39 -0
- package/dist/cli.js +435 -0
- package/package.json +1 -1
- package/src/cli.ts +368 -1
- package/src/colors.ts +10 -0
- package/src/db-status.ts +117 -0
- package/src/remove-method.ts +100 -0
- package/src/route-methods.ts +24 -0
- package/src/templates/base.ts +6 -0
package/README.md
CHANGED
|
@@ -180,6 +180,45 @@ comes from hand-editing `index.ts`, deleting a route folder without using
|
|
|
180
180
|
`doctor` only reports issues — it doesn't fix them — and exits non-zero if
|
|
181
181
|
it finds any, so it's usable in a pre-commit hook or CI step.
|
|
182
182
|
|
|
183
|
+
## Project overview
|
|
184
|
+
|
|
185
|
+
```
|
|
186
|
+
bun run project
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
or `bunx create-backon project`. Read-only, one shot — not a loop, nothing
|
|
190
|
+
here writes to disk. Prints three things: the database driver actually wired
|
|
191
|
+
up in `src/config/db.<ext>` and whether it has what it needs (a config
|
|
192
|
+
check, not a live connection attempt — for Neon/Postgres that means
|
|
193
|
+
`DATABASE_URL` is set in `.env`; SQLite is always "ready" since it falls
|
|
194
|
+
back to `./dev.db`; "none" means no database is configured, which is also
|
|
195
|
+
"ready"), the same per-endpoint, per-method dashboard `list-routes` shows,
|
|
196
|
+
and a one-line doctor summary. Point of this command is answering "what's
|
|
197
|
+
actually going on in this project" in one glance, without needing to
|
|
198
|
+
remember which of `list-routes`/`doctor`/checking `.env` by hand to run.
|
|
199
|
+
|
|
200
|
+
## Managing endpoints and methods interactively
|
|
201
|
+
|
|
202
|
+
```
|
|
203
|
+
bun run server-config
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
or `bunx create-backon server-config`. The interactive alternative to
|
|
207
|
+
running `add-route`/`add-method`/`remove-route` individually — opens with
|
|
208
|
+
the same endpoint dashboard `project` shows, then a menu: add a new
|
|
209
|
+
endpoint, remove one, add a method, remove a method, or modify a method
|
|
210
|
+
(change its path, name, or body/query validation in place — the one thing
|
|
211
|
+
none of the standalone commands offer, since it's a checked
|
|
212
|
+
remove-then-re-add rather than a new codegen path). Loops back to the menu
|
|
213
|
+
after each action, re-reading the endpoint list fresh every time, until
|
|
214
|
+
told to stop. `project` and `server-config` are deliberately two separate
|
|
215
|
+
commands rather than one combined dashboard — "show me what's here" and
|
|
216
|
+
"let me start changing things" are different intents, and an overview that
|
|
217
|
+
can also accidentally edit something isn't actually a safe overview.
|
|
218
|
+
`add-route`/`add-method`/`remove-route`/`list-routes`/`doctor` all keep
|
|
219
|
+
working exactly as documented above; `server-config` is a wrapper around
|
|
220
|
+
the same underlying logic, not a replacement for them.
|
|
221
|
+
|
|
183
222
|
## Generating API docs
|
|
184
223
|
|
|
185
224
|
Every generated project includes a `docs` script:
|
package/dist/cli.js
CHANGED
|
@@ -552,6 +552,12 @@ function renderPackageJson(projectName, framework, language, db) {
|
|
|
552
552
|
"remove-route": "bunx create-backon remove-route",
|
|
553
553
|
"list-routes": "bunx create-backon list-routes",
|
|
554
554
|
doctor: "bunx create-backon doctor",
|
|
555
|
+
// project: read-only overview (db status, endpoints, methods, doctor
|
|
556
|
+
// summary). server-config: the interactive manager for actually
|
|
557
|
+
// changing endpoints/methods — add/remove/modify, without needing to
|
|
558
|
+
// remember which of the individual subcommands above does what.
|
|
559
|
+
project: "bunx create-backon project",
|
|
560
|
+
"server-config": "bunx create-backon server-config",
|
|
555
561
|
docs: `bun run scripts/generate-docs.${ext}`
|
|
556
562
|
};
|
|
557
563
|
if (language === "typescript") {
|
|
@@ -933,6 +939,12 @@ function colorVerb(verb) {
|
|
|
933
939
|
function dim(text3) {
|
|
934
940
|
return `\x1B[2m${text3}${RESET}`;
|
|
935
941
|
}
|
|
942
|
+
function ok(text3) {
|
|
943
|
+
return `\x1B[32m${text3}${RESET}`;
|
|
944
|
+
}
|
|
945
|
+
function warn(text3) {
|
|
946
|
+
return `\x1B[33m${text3}${RESET}`;
|
|
947
|
+
}
|
|
936
948
|
|
|
937
949
|
// src/route-methods.ts
|
|
938
950
|
var METHOD_MOUNT_PATTERN = /\.(get|post|put|patch|delete)\(\s*"([^"]*)"\s*,\s*controller\.(\w+)\s*\)/g;
|
|
@@ -946,6 +958,15 @@ function parseRouteMethods(routesFileContents) {
|
|
|
946
958
|
}
|
|
947
959
|
return methods;
|
|
948
960
|
}
|
|
961
|
+
async function detectMethodValidation(route, name, cwd = process.cwd()) {
|
|
962
|
+
const { root, ext } = await detectProject(cwd);
|
|
963
|
+
const controllerPath = join7(root, "src/endpoints", route, `${route}.controller.${ext}`);
|
|
964
|
+
const contents = await readFile3(controllerPath, "utf-8");
|
|
965
|
+
return {
|
|
966
|
+
needsBody: contents.includes(`export const ${name}BodySchema`),
|
|
967
|
+
needsQuery: contents.includes(`export const ${name}QuerySchema`)
|
|
968
|
+
};
|
|
969
|
+
}
|
|
949
970
|
async function listEndpointsWithMethods(cwd = process.cwd()) {
|
|
950
971
|
const { root, ext } = await detectProject(cwd);
|
|
951
972
|
const { contents } = await readEndpointsIndex(root, ext);
|
|
@@ -1035,12 +1056,134 @@ async function addMethod(route, spec, cwd = process.cwd()) {
|
|
|
1035
1056
|
return { route, root, filesWritten: [controllerPath, routesPath, servicesPath] };
|
|
1036
1057
|
}
|
|
1037
1058
|
|
|
1059
|
+
// src/remove-method.ts
|
|
1060
|
+
import { readFile as readFile5, writeFile as writeFile5 } from "node:fs/promises";
|
|
1061
|
+
import { join as join9 } from "node:path";
|
|
1062
|
+
function removeBlock(content, matches) {
|
|
1063
|
+
const blocks = content.split(/\n\n+/);
|
|
1064
|
+
const index = blocks.findIndex(matches);
|
|
1065
|
+
if (index === -1) return content;
|
|
1066
|
+
blocks.splice(index, 1);
|
|
1067
|
+
const joined = blocks.filter((b) => b.length > 0).join("\n\n");
|
|
1068
|
+
return joined ? `${joined}
|
|
1069
|
+
` : "";
|
|
1070
|
+
}
|
|
1071
|
+
async function removeMethod(route, verb, path, cwd = process.cwd()) {
|
|
1072
|
+
const { root, framework, language, ext } = await detectProject(cwd);
|
|
1073
|
+
const { contents: indexContents } = await readEndpointsIndex(root, ext);
|
|
1074
|
+
const mounted = parseMountedRoutes(indexContents);
|
|
1075
|
+
if (!mounted.includes(route)) {
|
|
1076
|
+
throw new Error(`"${route}" isn't mounted in src/endpoints/index.${ext}.`);
|
|
1077
|
+
}
|
|
1078
|
+
const routeDir = join9(root, "src/endpoints", route);
|
|
1079
|
+
const controllerPath = join9(routeDir, `${route}.controller.${ext}`);
|
|
1080
|
+
const routesPath = join9(routeDir, `${route}.routes.${ext}`);
|
|
1081
|
+
const servicesPath = join9(routeDir, `${route}.services.${ext}`);
|
|
1082
|
+
const [controllerContents, routesContents, servicesContents] = await Promise.all([
|
|
1083
|
+
readFile5(controllerPath, "utf-8"),
|
|
1084
|
+
readFile5(routesPath, "utf-8"),
|
|
1085
|
+
readFile5(servicesPath, "utf-8")
|
|
1086
|
+
]);
|
|
1087
|
+
const existing = parseRouteMethods(routesContents);
|
|
1088
|
+
const match = existing.find((m) => m.verb === verb && m.path === path);
|
|
1089
|
+
if (!match) {
|
|
1090
|
+
throw new Error(`${verb.toUpperCase()} ${path} isn't mounted in ${routesPath}.`);
|
|
1091
|
+
}
|
|
1092
|
+
const { name } = match;
|
|
1093
|
+
if (existing.length === 1) {
|
|
1094
|
+
await Promise.all([
|
|
1095
|
+
writeFile5(controllerPath, renderBlankController()),
|
|
1096
|
+
writeFile5(routesPath, renderBlankRoutes(route, framework, language)),
|
|
1097
|
+
writeFile5(servicesPath, renderBlankServices())
|
|
1098
|
+
]);
|
|
1099
|
+
return { route, root, removed: match };
|
|
1100
|
+
}
|
|
1101
|
+
const expectedMountLine = routeMountLine(route, { verb, path, name, needsBody: false, needsQuery: false });
|
|
1102
|
+
const newController = removeBlock(controllerContents, (block) => block.includes(`export const ${name} = defineRoute(`));
|
|
1103
|
+
const newRoutes = removeBlock(routesContents, (block) => block.trim() === expectedMountLine);
|
|
1104
|
+
const newServices = removeBlock(servicesContents, (block) => block.includes(`export async function ${name}(`));
|
|
1105
|
+
await Promise.all([
|
|
1106
|
+
writeFile5(controllerPath, newController),
|
|
1107
|
+
writeFile5(routesPath, newRoutes),
|
|
1108
|
+
writeFile5(servicesPath, newServices)
|
|
1109
|
+
]);
|
|
1110
|
+
return { route, root, removed: match };
|
|
1111
|
+
}
|
|
1112
|
+
|
|
1113
|
+
// src/db-status.ts
|
|
1114
|
+
import { readFile as readFile6 } from "node:fs/promises";
|
|
1115
|
+
import { join as join10 } from "node:path";
|
|
1116
|
+
var DRIVER_SIGNATURES = [
|
|
1117
|
+
["drizzle-orm/neon-http", "neon"],
|
|
1118
|
+
["drizzle-orm/node-postgres", "postgres"],
|
|
1119
|
+
["drizzle-orm/bun-sqlite", "sqlite"]
|
|
1120
|
+
];
|
|
1121
|
+
function detectDriver(dbFileContents) {
|
|
1122
|
+
for (const [signature, driver] of DRIVER_SIGNATURES) {
|
|
1123
|
+
if (dbFileContents.includes(signature)) return driver;
|
|
1124
|
+
}
|
|
1125
|
+
if (dbFileContents.includes("No database configured yet")) return "none";
|
|
1126
|
+
return "custom";
|
|
1127
|
+
}
|
|
1128
|
+
function parseEnvValue(envContents, key) {
|
|
1129
|
+
const match = envContents.match(new RegExp(`^${key}=(.*)$`, "m"));
|
|
1130
|
+
const value = match?.[1]?.trim();
|
|
1131
|
+
return value ? value : void 0;
|
|
1132
|
+
}
|
|
1133
|
+
async function detectDbStatus(cwd = process.cwd()) {
|
|
1134
|
+
const { root, ext } = await detectProject(cwd);
|
|
1135
|
+
let dbFileContents;
|
|
1136
|
+
try {
|
|
1137
|
+
dbFileContents = await readFile6(join10(root, "src/config", `db.${ext}`), "utf-8");
|
|
1138
|
+
} catch {
|
|
1139
|
+
dbFileContents = void 0;
|
|
1140
|
+
}
|
|
1141
|
+
const driver = dbFileContents === void 0 ? "missing" : detectDriver(dbFileContents);
|
|
1142
|
+
let envContents = "";
|
|
1143
|
+
let envFileExists = true;
|
|
1144
|
+
try {
|
|
1145
|
+
envContents = await readFile6(join10(root, ".env"), "utf-8");
|
|
1146
|
+
} catch {
|
|
1147
|
+
envFileExists = false;
|
|
1148
|
+
}
|
|
1149
|
+
const databaseUrl = parseEnvValue(envContents, "DATABASE_URL");
|
|
1150
|
+
if (driver === "missing") {
|
|
1151
|
+
return { driver, envFileExists, ready: "unknown", summary: warn("src/config/db file not found.") };
|
|
1152
|
+
}
|
|
1153
|
+
if (driver === "custom") {
|
|
1154
|
+
return {
|
|
1155
|
+
driver,
|
|
1156
|
+
envFileExists,
|
|
1157
|
+
ready: "unknown",
|
|
1158
|
+
summary: `${dim("custom")} \u2014 src/config/db has been hand-edited, can't tell you its status here.`
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
if (driver === "none") {
|
|
1162
|
+
return { driver, envFileExists, ready: true, summary: dim("none \u2014 no database configured.") };
|
|
1163
|
+
}
|
|
1164
|
+
if (driver === "sqlite") {
|
|
1165
|
+
const path = databaseUrl ?? "./dev.db";
|
|
1166
|
+
return { driver, envFileExists, ready: true, summary: `${ok("sqlite")} \u2014 using ${path}.` };
|
|
1167
|
+
}
|
|
1168
|
+
if (databaseUrl) {
|
|
1169
|
+
return { driver, envFileExists, ready: true, summary: `${ok(driver)} \u2014 DATABASE_URL is set in .env.` };
|
|
1170
|
+
}
|
|
1171
|
+
return {
|
|
1172
|
+
driver,
|
|
1173
|
+
envFileExists,
|
|
1174
|
+
ready: false,
|
|
1175
|
+
summary: `${warn(driver)} \u2014 DATABASE_URL missing from .env${envFileExists ? "" : " (no .env file)"}; src/config/db.ts will throw at startup until it's set.`
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1038
1179
|
// src/cli.ts
|
|
1039
1180
|
var ADD_ROUTE_SUBCOMMANDS = /* @__PURE__ */ new Set(["add-route", "route"]);
|
|
1040
1181
|
var REMOVE_ROUTE_SUBCOMMANDS = /* @__PURE__ */ new Set(["remove-route", "rm-route"]);
|
|
1041
1182
|
var LIST_ROUTES_SUBCOMMANDS = /* @__PURE__ */ new Set(["list-routes", "routes"]);
|
|
1042
1183
|
var DOCTOR_SUBCOMMANDS = /* @__PURE__ */ new Set(["doctor"]);
|
|
1043
1184
|
var ADD_METHOD_SUBCOMMANDS = /* @__PURE__ */ new Set(["add-method", "method"]);
|
|
1185
|
+
var PROJECT_SUBCOMMANDS = /* @__PURE__ */ new Set(["project"]);
|
|
1186
|
+
var SERVER_CONFIG_SUBCOMMANDS = /* @__PURE__ */ new Set(["server-config"]);
|
|
1044
1187
|
async function promptForRouteName(introText) {
|
|
1045
1188
|
p2.intro(introText);
|
|
1046
1189
|
const answer = await p2.text({
|
|
@@ -1099,6 +1242,21 @@ async function runDoctorCommand() {
|
|
|
1099
1242
|
${issues.map((issue) => ` - ${issue.detail}`).join("\n")}`);
|
|
1100
1243
|
process.exitCode = 1;
|
|
1101
1244
|
}
|
|
1245
|
+
async function runProjectOverview() {
|
|
1246
|
+
p2.intro("create-backon project");
|
|
1247
|
+
const { root } = await detectProject();
|
|
1248
|
+
const dbStatus = await detectDbStatus();
|
|
1249
|
+
const summaries = await listEndpointsWithMethods();
|
|
1250
|
+
const { issues } = await runDoctor();
|
|
1251
|
+
p2.note(dbStatus.summary, "Database");
|
|
1252
|
+
p2.note(formatEndpointsDashboard(summaries), `Endpoints in ${root}`);
|
|
1253
|
+
if (issues.length > 0) {
|
|
1254
|
+
p2.log.warn(`${issues.length} issue(s) between src/endpoints/ and index \u2014 run \`bun run doctor\` for details.`);
|
|
1255
|
+
} else {
|
|
1256
|
+
p2.log.success("No drift between src/endpoints/ and index.");
|
|
1257
|
+
}
|
|
1258
|
+
p2.outro("Manage endpoints and methods with `bun run server-config`.");
|
|
1259
|
+
}
|
|
1102
1260
|
function suggestMethodName(verb, path) {
|
|
1103
1261
|
const params = paramNamesFromPath(path);
|
|
1104
1262
|
if (verb === "get" && params.length === 0) return "list";
|
|
@@ -1201,6 +1359,275 @@ async function runAddMethod() {
|
|
|
1201
1359
|
}
|
|
1202
1360
|
p2.outro("Done.");
|
|
1203
1361
|
}
|
|
1362
|
+
async function serverConfigAddEndpoint() {
|
|
1363
|
+
const name = await p2.text({
|
|
1364
|
+
message: "New endpoint name",
|
|
1365
|
+
placeholder: "e.g. users",
|
|
1366
|
+
validate: (value) => !value ? "Required." : void 0
|
|
1367
|
+
});
|
|
1368
|
+
if (p2.isCancel(name)) {
|
|
1369
|
+
p2.cancel("Cancelled.");
|
|
1370
|
+
return;
|
|
1371
|
+
}
|
|
1372
|
+
const { route, filesWritten } = await addRoute(name);
|
|
1373
|
+
p2.log.success(`Added src/endpoints/${route} (${filesWritten.length} files, no methods yet).`);
|
|
1374
|
+
}
|
|
1375
|
+
async function serverConfigRemoveEndpoint(summaries) {
|
|
1376
|
+
if (summaries.length === 0) {
|
|
1377
|
+
p2.log.info("No endpoints yet.");
|
|
1378
|
+
return;
|
|
1379
|
+
}
|
|
1380
|
+
const route = await p2.select({
|
|
1381
|
+
message: "Remove which endpoint?",
|
|
1382
|
+
options: summaries.map((s) => ({ value: s.route, label: s.route }))
|
|
1383
|
+
});
|
|
1384
|
+
if (p2.isCancel(route)) {
|
|
1385
|
+
p2.cancel("Cancelled.");
|
|
1386
|
+
return;
|
|
1387
|
+
}
|
|
1388
|
+
const confirmed = await p2.confirm({
|
|
1389
|
+
message: `Remove src/endpoints/${route} and unmount it? This deletes the folder.`,
|
|
1390
|
+
initialValue: false
|
|
1391
|
+
});
|
|
1392
|
+
if (p2.isCancel(confirmed) || !confirmed) {
|
|
1393
|
+
p2.cancel("Cancelled.");
|
|
1394
|
+
return;
|
|
1395
|
+
}
|
|
1396
|
+
const { removedDir } = await removeRoute(route);
|
|
1397
|
+
p2.log.success(`Removed ${removedDir}.`);
|
|
1398
|
+
}
|
|
1399
|
+
async function serverConfigAddMethod(summaries) {
|
|
1400
|
+
const routeChoice = await p2.select({
|
|
1401
|
+
message: "Add a method to which endpoint?",
|
|
1402
|
+
options: [
|
|
1403
|
+
...summaries.map((s) => ({ value: s.route, label: s.route })),
|
|
1404
|
+
{ value: "__new__", label: "+ New blank endpoint" }
|
|
1405
|
+
]
|
|
1406
|
+
});
|
|
1407
|
+
if (p2.isCancel(routeChoice)) {
|
|
1408
|
+
p2.cancel("Cancelled.");
|
|
1409
|
+
return;
|
|
1410
|
+
}
|
|
1411
|
+
let route = routeChoice;
|
|
1412
|
+
let existingMethods = summaries.find((s) => s.route === route)?.methods ?? [];
|
|
1413
|
+
if (route === "__new__") {
|
|
1414
|
+
const name2 = await p2.text({
|
|
1415
|
+
message: "New endpoint name",
|
|
1416
|
+
placeholder: "e.g. users",
|
|
1417
|
+
validate: (value) => !value ? "Required." : void 0
|
|
1418
|
+
});
|
|
1419
|
+
if (p2.isCancel(name2)) {
|
|
1420
|
+
p2.cancel("Cancelled.");
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
const added = await addRoute(name2);
|
|
1424
|
+
route = added.route;
|
|
1425
|
+
existingMethods = [];
|
|
1426
|
+
p2.log.success(`Added blank endpoint src/endpoints/${route}`);
|
|
1427
|
+
}
|
|
1428
|
+
const verb = await p2.select({
|
|
1429
|
+
message: "HTTP method",
|
|
1430
|
+
options: HTTP_VERBS.map((v) => ({ value: v, label: v.toUpperCase() }))
|
|
1431
|
+
});
|
|
1432
|
+
if (p2.isCancel(verb)) {
|
|
1433
|
+
p2.cancel("Cancelled.");
|
|
1434
|
+
return;
|
|
1435
|
+
}
|
|
1436
|
+
const defaultPath = verb === "get" || verb === "post" ? "/" : "/:id";
|
|
1437
|
+
const path = await p2.text({
|
|
1438
|
+
message: "Path (relative to this endpoint's mount)",
|
|
1439
|
+
placeholder: defaultPath,
|
|
1440
|
+
initialValue: defaultPath,
|
|
1441
|
+
validate: (value) => !value.startsWith("/") ? 'Must start with "/".' : void 0
|
|
1442
|
+
});
|
|
1443
|
+
if (p2.isCancel(path)) {
|
|
1444
|
+
p2.cancel("Cancelled.");
|
|
1445
|
+
return;
|
|
1446
|
+
}
|
|
1447
|
+
const defaultName = suggestMethodName(verb, path);
|
|
1448
|
+
const name = await p2.text({
|
|
1449
|
+
message: "Name (controller export + service function)",
|
|
1450
|
+
placeholder: defaultName,
|
|
1451
|
+
initialValue: defaultName,
|
|
1452
|
+
validate: (value) => {
|
|
1453
|
+
if (!IDENTIFIER_PATTERN.test(value)) return "Must be a valid identifier.";
|
|
1454
|
+
if (existingMethods.some((m) => m.name === value)) return `"${value}" is already used in this endpoint.`;
|
|
1455
|
+
return void 0;
|
|
1456
|
+
}
|
|
1457
|
+
});
|
|
1458
|
+
if (p2.isCancel(name)) {
|
|
1459
|
+
p2.cancel("Cancelled.");
|
|
1460
|
+
return;
|
|
1461
|
+
}
|
|
1462
|
+
let needsBody = false;
|
|
1463
|
+
if (verb === "post" || verb === "put" || verb === "patch") {
|
|
1464
|
+
const answer = await p2.confirm({ message: "Validate a request body?", initialValue: true });
|
|
1465
|
+
if (p2.isCancel(answer)) {
|
|
1466
|
+
p2.cancel("Cancelled.");
|
|
1467
|
+
return;
|
|
1468
|
+
}
|
|
1469
|
+
needsBody = answer;
|
|
1470
|
+
}
|
|
1471
|
+
const needsQuery = await p2.confirm({ message: "Validate query params?", initialValue: false });
|
|
1472
|
+
if (p2.isCancel(needsQuery)) {
|
|
1473
|
+
p2.cancel("Cancelled.");
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
const spec = { verb, path, name, needsBody, needsQuery };
|
|
1477
|
+
const { filesWritten } = await addMethod(route, spec);
|
|
1478
|
+
p2.log.success(`Added ${verb.toUpperCase()} ${path} \u2192 ${name} in src/endpoints/${route} (${filesWritten.length} files)`);
|
|
1479
|
+
}
|
|
1480
|
+
async function selectEndpointWithMethods(summaries, message) {
|
|
1481
|
+
const withMethods = summaries.filter((s) => s.methods.length > 0);
|
|
1482
|
+
if (withMethods.length === 0) {
|
|
1483
|
+
p2.log.info("No methods yet \u2014 add one first.");
|
|
1484
|
+
return null;
|
|
1485
|
+
}
|
|
1486
|
+
const route = await p2.select({
|
|
1487
|
+
message,
|
|
1488
|
+
options: withMethods.map((s) => ({ value: s.route, label: s.route }))
|
|
1489
|
+
});
|
|
1490
|
+
if (p2.isCancel(route)) {
|
|
1491
|
+
p2.cancel("Cancelled.");
|
|
1492
|
+
return null;
|
|
1493
|
+
}
|
|
1494
|
+
return withMethods.find((s) => s.route === route) ?? null;
|
|
1495
|
+
}
|
|
1496
|
+
async function selectMethod(endpoint, message) {
|
|
1497
|
+
const choice = await p2.select({
|
|
1498
|
+
message,
|
|
1499
|
+
options: endpoint.methods.map((m) => ({
|
|
1500
|
+
value: `${m.verb}:${m.path}`,
|
|
1501
|
+
label: `${m.verb.toUpperCase()} ${m.path} \u2192 ${m.name}`
|
|
1502
|
+
}))
|
|
1503
|
+
});
|
|
1504
|
+
if (p2.isCancel(choice)) {
|
|
1505
|
+
p2.cancel("Cancelled.");
|
|
1506
|
+
return null;
|
|
1507
|
+
}
|
|
1508
|
+
const [verb, path] = choice.split(/:(.*)/s);
|
|
1509
|
+
return endpoint.methods.find((m) => m.verb === verb && m.path === path) ?? null;
|
|
1510
|
+
}
|
|
1511
|
+
async function serverConfigRemoveMethod(summaries) {
|
|
1512
|
+
const endpoint = await selectEndpointWithMethods(summaries, "Remove a method from which endpoint?");
|
|
1513
|
+
if (!endpoint) return;
|
|
1514
|
+
const method = await selectMethod(endpoint, "Remove which method?");
|
|
1515
|
+
if (!method) return;
|
|
1516
|
+
const confirmed = await p2.confirm({
|
|
1517
|
+
message: `Remove ${method.verb.toUpperCase()} ${method.path} (${method.name}) from ${endpoint.route}?`,
|
|
1518
|
+
initialValue: false
|
|
1519
|
+
});
|
|
1520
|
+
if (p2.isCancel(confirmed) || !confirmed) {
|
|
1521
|
+
p2.cancel("Cancelled.");
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
const { removed } = await removeMethod(endpoint.route, method.verb, method.path);
|
|
1525
|
+
p2.log.success(`Removed ${removed.verb.toUpperCase()} ${removed.path} (${removed.name}) from src/endpoints/${endpoint.route}.`);
|
|
1526
|
+
}
|
|
1527
|
+
async function serverConfigModifyMethod(summaries) {
|
|
1528
|
+
const endpoint = await selectEndpointWithMethods(summaries, "Modify a method on which endpoint?");
|
|
1529
|
+
if (!endpoint) return;
|
|
1530
|
+
const old = await selectMethod(endpoint, "Modify which method?");
|
|
1531
|
+
if (!old) return;
|
|
1532
|
+
const { needsBody: oldNeedsBody, needsQuery: oldNeedsQuery } = await detectMethodValidation(endpoint.route, old.name);
|
|
1533
|
+
const others = endpoint.methods.filter((m) => m !== old);
|
|
1534
|
+
const verb = await p2.select({
|
|
1535
|
+
message: "HTTP method",
|
|
1536
|
+
initialValue: old.verb,
|
|
1537
|
+
options: HTTP_VERBS.map((v) => ({ value: v, label: v.toUpperCase() }))
|
|
1538
|
+
});
|
|
1539
|
+
if (p2.isCancel(verb)) {
|
|
1540
|
+
p2.cancel("Cancelled.");
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
const path = await p2.text({
|
|
1544
|
+
message: "Path (relative to this endpoint's mount)",
|
|
1545
|
+
initialValue: old.path,
|
|
1546
|
+
validate: (value) => !value.startsWith("/") ? 'Must start with "/".' : void 0
|
|
1547
|
+
});
|
|
1548
|
+
if (p2.isCancel(path)) {
|
|
1549
|
+
p2.cancel("Cancelled.");
|
|
1550
|
+
return;
|
|
1551
|
+
}
|
|
1552
|
+
const name = await p2.text({
|
|
1553
|
+
message: "Name (controller export + service function)",
|
|
1554
|
+
initialValue: old.name,
|
|
1555
|
+
validate: (value) => {
|
|
1556
|
+
if (!IDENTIFIER_PATTERN.test(value)) return "Must be a valid identifier.";
|
|
1557
|
+
if (others.some((m) => m.name === value)) return `"${value}" is already used in this endpoint.`;
|
|
1558
|
+
return void 0;
|
|
1559
|
+
}
|
|
1560
|
+
});
|
|
1561
|
+
if (p2.isCancel(name)) {
|
|
1562
|
+
p2.cancel("Cancelled.");
|
|
1563
|
+
return;
|
|
1564
|
+
}
|
|
1565
|
+
if (others.some((m) => m.verb === verb && m.path === path)) {
|
|
1566
|
+
p2.log.error(`${verb.toUpperCase()} ${path} is already used by another method on this endpoint.`);
|
|
1567
|
+
return;
|
|
1568
|
+
}
|
|
1569
|
+
let needsBody = false;
|
|
1570
|
+
if (verb === "post" || verb === "put" || verb === "patch") {
|
|
1571
|
+
const answer = await p2.confirm({ message: "Validate a request body?", initialValue: oldNeedsBody });
|
|
1572
|
+
if (p2.isCancel(answer)) {
|
|
1573
|
+
p2.cancel("Cancelled.");
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
needsBody = answer;
|
|
1577
|
+
}
|
|
1578
|
+
const needsQuery = await p2.confirm({ message: "Validate query params?", initialValue: oldNeedsQuery });
|
|
1579
|
+
if (p2.isCancel(needsQuery)) {
|
|
1580
|
+
p2.cancel("Cancelled.");
|
|
1581
|
+
return;
|
|
1582
|
+
}
|
|
1583
|
+
await removeMethod(endpoint.route, old.verb, old.path);
|
|
1584
|
+
const { filesWritten } = await addMethod(endpoint.route, { verb, path, name, needsBody, needsQuery });
|
|
1585
|
+
p2.log.success(
|
|
1586
|
+
`Updated src/endpoints/${endpoint.route}: ${old.verb.toUpperCase()} ${old.path} \u2192 ${verb.toUpperCase()} ${path} (${name}), ${filesWritten.length} files touched.`
|
|
1587
|
+
);
|
|
1588
|
+
}
|
|
1589
|
+
async function runServerConfig() {
|
|
1590
|
+
p2.intro("create-backon server-config");
|
|
1591
|
+
while (true) {
|
|
1592
|
+
const { root } = await detectProject();
|
|
1593
|
+
const summaries = await listEndpointsWithMethods();
|
|
1594
|
+
p2.note(formatEndpointsDashboard(summaries), `Endpoints in ${root}`);
|
|
1595
|
+
const action = await p2.select({
|
|
1596
|
+
message: "What do you want to do?",
|
|
1597
|
+
options: [
|
|
1598
|
+
{ value: "add-endpoint", label: "Add a new endpoint" },
|
|
1599
|
+
{ value: "remove-endpoint", label: "Remove an endpoint" },
|
|
1600
|
+
{ value: "add-method", label: "Add a method" },
|
|
1601
|
+
{ value: "remove-method", label: "Remove a method" },
|
|
1602
|
+
{ value: "modify-method", label: "Modify a method" },
|
|
1603
|
+
{ value: "exit", label: "Exit" }
|
|
1604
|
+
]
|
|
1605
|
+
});
|
|
1606
|
+
if (p2.isCancel(action) || action === "exit") break;
|
|
1607
|
+
try {
|
|
1608
|
+
switch (action) {
|
|
1609
|
+
case "add-endpoint":
|
|
1610
|
+
await serverConfigAddEndpoint();
|
|
1611
|
+
break;
|
|
1612
|
+
case "remove-endpoint":
|
|
1613
|
+
await serverConfigRemoveEndpoint(summaries);
|
|
1614
|
+
break;
|
|
1615
|
+
case "add-method":
|
|
1616
|
+
await serverConfigAddMethod(summaries);
|
|
1617
|
+
break;
|
|
1618
|
+
case "remove-method":
|
|
1619
|
+
await serverConfigRemoveMethod(summaries);
|
|
1620
|
+
break;
|
|
1621
|
+
case "modify-method":
|
|
1622
|
+
await serverConfigModifyMethod(summaries);
|
|
1623
|
+
break;
|
|
1624
|
+
}
|
|
1625
|
+
} catch (err) {
|
|
1626
|
+
p2.log.error(err instanceof Error ? err.message : String(err));
|
|
1627
|
+
}
|
|
1628
|
+
}
|
|
1629
|
+
p2.outro("Done.");
|
|
1630
|
+
}
|
|
1204
1631
|
async function runScaffold() {
|
|
1205
1632
|
const answers = await runPrompts();
|
|
1206
1633
|
const { root, filesWritten } = await generateProject(answers);
|
|
@@ -1232,6 +1659,14 @@ async function main() {
|
|
|
1232
1659
|
await runAddMethod();
|
|
1233
1660
|
return;
|
|
1234
1661
|
}
|
|
1662
|
+
if (subcommand && PROJECT_SUBCOMMANDS.has(subcommand)) {
|
|
1663
|
+
await runProjectOverview();
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
if (subcommand && SERVER_CONFIG_SUBCOMMANDS.has(subcommand)) {
|
|
1667
|
+
await runServerConfig();
|
|
1668
|
+
return;
|
|
1669
|
+
}
|
|
1235
1670
|
await runScaffold();
|
|
1236
1671
|
}
|
|
1237
1672
|
main().catch((err) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-backon",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Scaffolds a new backend project on backon — like `bun create vite@latest`, but for a consistent controller/routes/services backend layout. Runs via bunx/bun create or npx/npm create.",
|
|
6
6
|
"license": "MIT",
|
package/src/cli.ts
CHANGED
|
@@ -15,7 +15,16 @@ import { removeRoute } from "./remove-route";
|
|
|
15
15
|
import { listRoutes } from "./list-routes";
|
|
16
16
|
import { runDoctor } from "./doctor";
|
|
17
17
|
import { addMethod } from "./add-method";
|
|
18
|
-
import {
|
|
18
|
+
import { removeMethod } from "./remove-method";
|
|
19
|
+
import { detectDbStatus } from "./db-status";
|
|
20
|
+
import { detectProject } from "./detect";
|
|
21
|
+
import {
|
|
22
|
+
detectMethodValidation,
|
|
23
|
+
formatEndpointsDashboard,
|
|
24
|
+
listEndpointsWithMethods,
|
|
25
|
+
type EndpointMethod,
|
|
26
|
+
type EndpointSummary,
|
|
27
|
+
} from "./route-methods";
|
|
19
28
|
import { HTTP_VERBS, paramNamesFromPath, pascalCase, type HttpVerb, type MethodSpec } from "./templates/route";
|
|
20
29
|
|
|
21
30
|
const ADD_ROUTE_SUBCOMMANDS = new Set(["add-route", "route"]);
|
|
@@ -23,6 +32,17 @@ const REMOVE_ROUTE_SUBCOMMANDS = new Set(["remove-route", "rm-route"]);
|
|
|
23
32
|
const LIST_ROUTES_SUBCOMMANDS = new Set(["list-routes", "routes"]);
|
|
24
33
|
const DOCTOR_SUBCOMMANDS = new Set(["doctor"]);
|
|
25
34
|
const ADD_METHOD_SUBCOMMANDS = new Set(["add-method", "method"]);
|
|
35
|
+
// project: a read-only overview (db status, endpoints, methods, doctor
|
|
36
|
+
// summary) — nothing here writes to disk. server-config: the interactive
|
|
37
|
+
// wrapper around add-route/remove-route/add-method/remove-method (plus
|
|
38
|
+
// modify, which neither standalone command offers) for managing endpoints
|
|
39
|
+
// without remembering individual subcommand names. Deliberately two
|
|
40
|
+
// separate commands rather than one combined dashboard — "just show me
|
|
41
|
+
// what's here" and "let me start changing things" are different intents,
|
|
42
|
+
// and collapsing them risks an accidental edit from someone who only
|
|
43
|
+
// wanted to look.
|
|
44
|
+
const PROJECT_SUBCOMMANDS = new Set(["project"]);
|
|
45
|
+
const SERVER_CONFIG_SUBCOMMANDS = new Set(["server-config"]);
|
|
26
46
|
|
|
27
47
|
async function promptForRouteName(introText: string): Promise<string> {
|
|
28
48
|
p.intro(introText);
|
|
@@ -91,6 +111,31 @@ async function runDoctorCommand(): Promise<void> {
|
|
|
91
111
|
process.exitCode = 1;
|
|
92
112
|
}
|
|
93
113
|
|
|
114
|
+
/**
|
|
115
|
+
* Read-only: db status, every endpoint and its methods, and a doctor
|
|
116
|
+
* summary, in one shot. No prompts, no writes — `bun run server-config` is
|
|
117
|
+
* where anything actually changes.
|
|
118
|
+
*/
|
|
119
|
+
async function runProjectOverview(): Promise<void> {
|
|
120
|
+
p.intro("create-backon project");
|
|
121
|
+
|
|
122
|
+
const { root } = await detectProject();
|
|
123
|
+
const dbStatus = await detectDbStatus();
|
|
124
|
+
const summaries = await listEndpointsWithMethods();
|
|
125
|
+
const { issues } = await runDoctor();
|
|
126
|
+
|
|
127
|
+
p.note(dbStatus.summary, "Database");
|
|
128
|
+
p.note(formatEndpointsDashboard(summaries), `Endpoints in ${root}`);
|
|
129
|
+
|
|
130
|
+
if (issues.length > 0) {
|
|
131
|
+
p.log.warn(`${issues.length} issue(s) between src/endpoints/ and index — run \`bun run doctor\` for details.`);
|
|
132
|
+
} else {
|
|
133
|
+
p.log.success("No drift between src/endpoints/ and index.");
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
p.outro("Manage endpoints and methods with `bun run server-config`.");
|
|
137
|
+
}
|
|
138
|
+
|
|
94
139
|
function suggestMethodName(verb: HttpVerb, path: string): string {
|
|
95
140
|
const params = paramNamesFromPath(path);
|
|
96
141
|
if (verb === "get" && params.length === 0) return "list";
|
|
@@ -215,6 +260,320 @@ async function runAddMethod(): Promise<void> {
|
|
|
215
260
|
p.outro("Done.");
|
|
216
261
|
}
|
|
217
262
|
|
|
263
|
+
// ---------------------------------------------------------------------------
|
|
264
|
+
// server-config: the interactive endpoint/method manager. Each of these is
|
|
265
|
+
// a single, self-contained step (no intro/outro of its own, no "add
|
|
266
|
+
// another?" loop of its own) — runServerConfig()'s own while loop is what
|
|
267
|
+
// repeats, and it re-reads the endpoint list fresh every iteration so any
|
|
268
|
+
// step's changes are immediately visible to the next one.
|
|
269
|
+
// ---------------------------------------------------------------------------
|
|
270
|
+
|
|
271
|
+
async function serverConfigAddEndpoint(): Promise<void> {
|
|
272
|
+
const name = await p.text({
|
|
273
|
+
message: "New endpoint name",
|
|
274
|
+
placeholder: "e.g. users",
|
|
275
|
+
validate: (value) => (!value ? "Required." : undefined),
|
|
276
|
+
});
|
|
277
|
+
if (p.isCancel(name)) {
|
|
278
|
+
p.cancel("Cancelled.");
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
const { route, filesWritten } = await addRoute(name);
|
|
282
|
+
p.log.success(`Added src/endpoints/${route} (${filesWritten.length} files, no methods yet).`);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
async function serverConfigRemoveEndpoint(summaries: EndpointSummary[]): Promise<void> {
|
|
286
|
+
if (summaries.length === 0) {
|
|
287
|
+
p.log.info("No endpoints yet.");
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const route = await p.select({
|
|
291
|
+
message: "Remove which endpoint?",
|
|
292
|
+
options: summaries.map((s) => ({ value: s.route, label: s.route })),
|
|
293
|
+
});
|
|
294
|
+
if (p.isCancel(route)) {
|
|
295
|
+
p.cancel("Cancelled.");
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const confirmed = await p.confirm({
|
|
299
|
+
message: `Remove src/endpoints/${route} and unmount it? This deletes the folder.`,
|
|
300
|
+
initialValue: false,
|
|
301
|
+
});
|
|
302
|
+
if (p.isCancel(confirmed) || !confirmed) {
|
|
303
|
+
p.cancel("Cancelled.");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
const { removedDir } = await removeRoute(route);
|
|
307
|
+
p.log.success(`Removed ${removedDir}.`);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
async function serverConfigAddMethod(summaries: EndpointSummary[]): Promise<void> {
|
|
311
|
+
const routeChoice = await p.select({
|
|
312
|
+
message: "Add a method to which endpoint?",
|
|
313
|
+
options: [
|
|
314
|
+
...summaries.map((s) => ({ value: s.route, label: s.route })),
|
|
315
|
+
{ value: "__new__", label: "+ New blank endpoint" },
|
|
316
|
+
],
|
|
317
|
+
});
|
|
318
|
+
if (p.isCancel(routeChoice)) {
|
|
319
|
+
p.cancel("Cancelled.");
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let route = routeChoice;
|
|
324
|
+
let existingMethods = summaries.find((s) => s.route === route)?.methods ?? [];
|
|
325
|
+
if (route === "__new__") {
|
|
326
|
+
const name = await p.text({
|
|
327
|
+
message: "New endpoint name",
|
|
328
|
+
placeholder: "e.g. users",
|
|
329
|
+
validate: (value) => (!value ? "Required." : undefined),
|
|
330
|
+
});
|
|
331
|
+
if (p.isCancel(name)) {
|
|
332
|
+
p.cancel("Cancelled.");
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
const added = await addRoute(name);
|
|
336
|
+
route = added.route;
|
|
337
|
+
existingMethods = [];
|
|
338
|
+
p.log.success(`Added blank endpoint src/endpoints/${route}`);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const verb = await p.select({
|
|
342
|
+
message: "HTTP method",
|
|
343
|
+
options: HTTP_VERBS.map((v) => ({ value: v, label: v.toUpperCase() })),
|
|
344
|
+
});
|
|
345
|
+
if (p.isCancel(verb)) {
|
|
346
|
+
p.cancel("Cancelled.");
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
const defaultPath = verb === "get" || verb === "post" ? "/" : "/:id";
|
|
351
|
+
const path = await p.text({
|
|
352
|
+
message: "Path (relative to this endpoint's mount)",
|
|
353
|
+
placeholder: defaultPath,
|
|
354
|
+
initialValue: defaultPath,
|
|
355
|
+
validate: (value) => (!value.startsWith("/") ? 'Must start with "/".' : undefined),
|
|
356
|
+
});
|
|
357
|
+
if (p.isCancel(path)) {
|
|
358
|
+
p.cancel("Cancelled.");
|
|
359
|
+
return;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
const defaultName = suggestMethodName(verb, path);
|
|
363
|
+
const name = await p.text({
|
|
364
|
+
message: "Name (controller export + service function)",
|
|
365
|
+
placeholder: defaultName,
|
|
366
|
+
initialValue: defaultName,
|
|
367
|
+
validate: (value) => {
|
|
368
|
+
if (!IDENTIFIER_PATTERN.test(value)) return "Must be a valid identifier.";
|
|
369
|
+
if (existingMethods.some((m) => m.name === value)) return `"${value}" is already used in this endpoint.`;
|
|
370
|
+
return undefined;
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
if (p.isCancel(name)) {
|
|
374
|
+
p.cancel("Cancelled.");
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
let needsBody = false;
|
|
379
|
+
if (verb === "post" || verb === "put" || verb === "patch") {
|
|
380
|
+
const answer = await p.confirm({ message: "Validate a request body?", initialValue: true });
|
|
381
|
+
if (p.isCancel(answer)) {
|
|
382
|
+
p.cancel("Cancelled.");
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
needsBody = answer;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const needsQuery = await p.confirm({ message: "Validate query params?", initialValue: false });
|
|
389
|
+
if (p.isCancel(needsQuery)) {
|
|
390
|
+
p.cancel("Cancelled.");
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const spec: MethodSpec = { verb, path, name, needsBody, needsQuery };
|
|
395
|
+
const { filesWritten } = await addMethod(route, spec);
|
|
396
|
+
p.log.success(`Added ${verb.toUpperCase()} ${path} → ${name} in src/endpoints/${route} (${filesWritten.length} files)`);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** Endpoints with at least one method — remove/modify both operate on an existing method, so an endpoint with none isn't a valid choice for either. */
|
|
400
|
+
async function selectEndpointWithMethods(summaries: EndpointSummary[], message: string): Promise<EndpointSummary | null> {
|
|
401
|
+
const withMethods = summaries.filter((s) => s.methods.length > 0);
|
|
402
|
+
if (withMethods.length === 0) {
|
|
403
|
+
p.log.info("No methods yet — add one first.");
|
|
404
|
+
return null;
|
|
405
|
+
}
|
|
406
|
+
const route = await p.select({
|
|
407
|
+
message,
|
|
408
|
+
options: withMethods.map((s) => ({ value: s.route, label: s.route })),
|
|
409
|
+
});
|
|
410
|
+
if (p.isCancel(route)) {
|
|
411
|
+
p.cancel("Cancelled.");
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
return withMethods.find((s) => s.route === route) ?? null;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
async function selectMethod(endpoint: EndpointSummary, message: string): Promise<EndpointMethod | null> {
|
|
418
|
+
const choice = await p.select({
|
|
419
|
+
message,
|
|
420
|
+
options: endpoint.methods.map((m) => ({
|
|
421
|
+
value: `${m.verb}:${m.path}`,
|
|
422
|
+
label: `${m.verb.toUpperCase()} ${m.path} → ${m.name}`,
|
|
423
|
+
})),
|
|
424
|
+
});
|
|
425
|
+
if (p.isCancel(choice)) {
|
|
426
|
+
p.cancel("Cancelled.");
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
// Split on the FIRST colon only — a path itself can contain no colons
|
|
430
|
+
// outside of :param segments, but this keeps the parse correct even if
|
|
431
|
+
// that ever changes, since verb never contains one.
|
|
432
|
+
const [verb, path] = choice.split(/:(.*)/s) as [HttpVerb, string];
|
|
433
|
+
return endpoint.methods.find((m) => m.verb === verb && m.path === path) ?? null;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
async function serverConfigRemoveMethod(summaries: EndpointSummary[]): Promise<void> {
|
|
437
|
+
const endpoint = await selectEndpointWithMethods(summaries, "Remove a method from which endpoint?");
|
|
438
|
+
if (!endpoint) return;
|
|
439
|
+
const method = await selectMethod(endpoint, "Remove which method?");
|
|
440
|
+
if (!method) return;
|
|
441
|
+
|
|
442
|
+
const confirmed = await p.confirm({
|
|
443
|
+
message: `Remove ${method.verb.toUpperCase()} ${method.path} (${method.name}) from ${endpoint.route}?`,
|
|
444
|
+
initialValue: false,
|
|
445
|
+
});
|
|
446
|
+
if (p.isCancel(confirmed) || !confirmed) {
|
|
447
|
+
p.cancel("Cancelled.");
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const { removed } = await removeMethod(endpoint.route, method.verb, method.path);
|
|
452
|
+
p.log.success(`Removed ${removed.verb.toUpperCase()} ${removed.path} (${removed.name}) from src/endpoints/${endpoint.route}.`);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/** Edits a method's verb/path/name/validation in place: a checked removeMethod() + addMethod() pair, not a separate codegen path. */
|
|
456
|
+
async function serverConfigModifyMethod(summaries: EndpointSummary[]): Promise<void> {
|
|
457
|
+
const endpoint = await selectEndpointWithMethods(summaries, "Modify a method on which endpoint?");
|
|
458
|
+
if (!endpoint) return;
|
|
459
|
+
const old = await selectMethod(endpoint, "Modify which method?");
|
|
460
|
+
if (!old) return;
|
|
461
|
+
|
|
462
|
+
const { needsBody: oldNeedsBody, needsQuery: oldNeedsQuery } = await detectMethodValidation(endpoint.route, old.name);
|
|
463
|
+
const others = endpoint.methods.filter((m) => m !== old);
|
|
464
|
+
|
|
465
|
+
const verb = await p.select({
|
|
466
|
+
message: "HTTP method",
|
|
467
|
+
initialValue: old.verb,
|
|
468
|
+
options: HTTP_VERBS.map((v) => ({ value: v, label: v.toUpperCase() })),
|
|
469
|
+
});
|
|
470
|
+
if (p.isCancel(verb)) {
|
|
471
|
+
p.cancel("Cancelled.");
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
const path = await p.text({
|
|
476
|
+
message: "Path (relative to this endpoint's mount)",
|
|
477
|
+
initialValue: old.path,
|
|
478
|
+
validate: (value) => (!value.startsWith("/") ? 'Must start with "/".' : undefined),
|
|
479
|
+
});
|
|
480
|
+
if (p.isCancel(path)) {
|
|
481
|
+
p.cancel("Cancelled.");
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const name = await p.text({
|
|
486
|
+
message: "Name (controller export + service function)",
|
|
487
|
+
initialValue: old.name,
|
|
488
|
+
validate: (value) => {
|
|
489
|
+
if (!IDENTIFIER_PATTERN.test(value)) return "Must be a valid identifier.";
|
|
490
|
+
if (others.some((m) => m.name === value)) return `"${value}" is already used in this endpoint.`;
|
|
491
|
+
return undefined;
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
if (p.isCancel(name)) {
|
|
495
|
+
p.cancel("Cancelled.");
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// Checked before anything on disk changes — removeMethod() below is only
|
|
500
|
+
// safe to run once we know addMethod() won't then fail on a collision.
|
|
501
|
+
if (others.some((m) => m.verb === verb && m.path === path)) {
|
|
502
|
+
p.log.error(`${verb.toUpperCase()} ${path} is already used by another method on this endpoint.`);
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
let needsBody = false;
|
|
507
|
+
if (verb === "post" || verb === "put" || verb === "patch") {
|
|
508
|
+
const answer = await p.confirm({ message: "Validate a request body?", initialValue: oldNeedsBody });
|
|
509
|
+
if (p.isCancel(answer)) {
|
|
510
|
+
p.cancel("Cancelled.");
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
needsBody = answer;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
const needsQuery = await p.confirm({ message: "Validate query params?", initialValue: oldNeedsQuery });
|
|
517
|
+
if (p.isCancel(needsQuery)) {
|
|
518
|
+
p.cancel("Cancelled.");
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
await removeMethod(endpoint.route, old.verb, old.path);
|
|
523
|
+
const { filesWritten } = await addMethod(endpoint.route, { verb, path, name, needsBody, needsQuery });
|
|
524
|
+
p.log.success(
|
|
525
|
+
`Updated src/endpoints/${endpoint.route}: ${old.verb.toUpperCase()} ${old.path} → ${verb.toUpperCase()} ${path} (${name}), ${filesWritten.length} files touched.`
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
async function runServerConfig(): Promise<void> {
|
|
530
|
+
p.intro("create-backon server-config");
|
|
531
|
+
|
|
532
|
+
// eslint-disable-next-line no-constant-condition
|
|
533
|
+
while (true) {
|
|
534
|
+
const { root } = await detectProject();
|
|
535
|
+
const summaries = await listEndpointsWithMethods();
|
|
536
|
+
p.note(formatEndpointsDashboard(summaries), `Endpoints in ${root}`);
|
|
537
|
+
|
|
538
|
+
const action = await p.select({
|
|
539
|
+
message: "What do you want to do?",
|
|
540
|
+
options: [
|
|
541
|
+
{ value: "add-endpoint", label: "Add a new endpoint" },
|
|
542
|
+
{ value: "remove-endpoint", label: "Remove an endpoint" },
|
|
543
|
+
{ value: "add-method", label: "Add a method" },
|
|
544
|
+
{ value: "remove-method", label: "Remove a method" },
|
|
545
|
+
{ value: "modify-method", label: "Modify a method" },
|
|
546
|
+
{ value: "exit", label: "Exit" },
|
|
547
|
+
],
|
|
548
|
+
});
|
|
549
|
+
if (p.isCancel(action) || action === "exit") break;
|
|
550
|
+
|
|
551
|
+
try {
|
|
552
|
+
switch (action) {
|
|
553
|
+
case "add-endpoint":
|
|
554
|
+
await serverConfigAddEndpoint();
|
|
555
|
+
break;
|
|
556
|
+
case "remove-endpoint":
|
|
557
|
+
await serverConfigRemoveEndpoint(summaries);
|
|
558
|
+
break;
|
|
559
|
+
case "add-method":
|
|
560
|
+
await serverConfigAddMethod(summaries);
|
|
561
|
+
break;
|
|
562
|
+
case "remove-method":
|
|
563
|
+
await serverConfigRemoveMethod(summaries);
|
|
564
|
+
break;
|
|
565
|
+
case "modify-method":
|
|
566
|
+
await serverConfigModifyMethod(summaries);
|
|
567
|
+
break;
|
|
568
|
+
}
|
|
569
|
+
} catch (err) {
|
|
570
|
+
p.log.error(err instanceof Error ? err.message : String(err));
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
p.outro("Done.");
|
|
575
|
+
}
|
|
576
|
+
|
|
218
577
|
async function runScaffold(): Promise<void> {
|
|
219
578
|
const answers = await runPrompts();
|
|
220
579
|
const { root, filesWritten } = await generateProject(answers);
|
|
@@ -248,6 +607,14 @@ async function main() {
|
|
|
248
607
|
await runAddMethod();
|
|
249
608
|
return;
|
|
250
609
|
}
|
|
610
|
+
if (subcommand && PROJECT_SUBCOMMANDS.has(subcommand)) {
|
|
611
|
+
await runProjectOverview();
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
if (subcommand && SERVER_CONFIG_SUBCOMMANDS.has(subcommand)) {
|
|
615
|
+
await runServerConfig();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
251
618
|
|
|
252
619
|
await runScaffold();
|
|
253
620
|
}
|
package/src/colors.ts
CHANGED
|
@@ -23,3 +23,13 @@ export function colorVerb(verb: HttpVerb): string {
|
|
|
23
23
|
export function dim(text: string): string {
|
|
24
24
|
return `\x1b[2m${text}${RESET}`;
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
/** Green — a status line that's actually fine (a DB driver with everything it needs, a clean doctor run). */
|
|
28
|
+
export function ok(text: string): string {
|
|
29
|
+
return `\x1b[32m${text}${RESET}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Amber — a status line that needs attention, but isn't a hard failure. */
|
|
33
|
+
export function warn(text: string): string {
|
|
34
|
+
return `\x1b[33m${text}${RESET}`;
|
|
35
|
+
}
|
package/src/db-status.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { dim, ok, warn } from "./colors";
|
|
4
|
+
import { detectProject } from "./detect";
|
|
5
|
+
import type { DbChoice } from "./prompts";
|
|
6
|
+
|
|
7
|
+
export interface DbStatus {
|
|
8
|
+
/**
|
|
9
|
+
* Which driver's actually wired up in src/config/db.<ext> — read from the
|
|
10
|
+
* file's own imports rather than remembered from scaffold time, since
|
|
11
|
+
* there's nowhere the original `bun create backon` db choice is
|
|
12
|
+
* persisted. "custom" means the file doesn't match any of the four
|
|
13
|
+
* generated shapes (hand-edited past recognition); "missing" means
|
|
14
|
+
* src/config/db.<ext> doesn't exist at all.
|
|
15
|
+
*/
|
|
16
|
+
driver: DbChoice | "custom" | "missing";
|
|
17
|
+
/** Whether .env exists in the project root at all. */
|
|
18
|
+
envFileExists: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Whether this driver has what it needs to run right now, best guess.
|
|
21
|
+
* "none" and "sqlite" (DATABASE_URL optional there — defaults to
|
|
22
|
+
* ./dev.db) are always ready; "neon"/"postgres" need a non-empty
|
|
23
|
+
* DATABASE_URL in .env; "custom"/"missing" can't be assessed at all.
|
|
24
|
+
*/
|
|
25
|
+
ready: boolean | "unknown";
|
|
26
|
+
/** One-line, human-readable, pre-colored summary — this is what actually gets rendered. */
|
|
27
|
+
summary: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Matches exactly the driver-identifying import each db.ts template in
|
|
31
|
+
// templates/db.ts actually has — read off the file's real imports rather
|
|
32
|
+
// than anything remembered from scaffold time, since the original choice
|
|
33
|
+
// isn't persisted anywhere.
|
|
34
|
+
const DRIVER_SIGNATURES: Array<[string, DbChoice]> = [
|
|
35
|
+
["drizzle-orm/neon-http", "neon"],
|
|
36
|
+
["drizzle-orm/node-postgres", "postgres"],
|
|
37
|
+
["drizzle-orm/bun-sqlite", "sqlite"],
|
|
38
|
+
];
|
|
39
|
+
|
|
40
|
+
function detectDriver(dbFileContents: string): DbChoice | "custom" {
|
|
41
|
+
for (const [signature, driver] of DRIVER_SIGNATURES) {
|
|
42
|
+
if (dbFileContents.includes(signature)) return driver;
|
|
43
|
+
}
|
|
44
|
+
if (dbFileContents.includes("No database configured yet")) return "none";
|
|
45
|
+
return "custom";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function parseEnvValue(envContents: string, key: string): string | undefined {
|
|
49
|
+
const match = envContents.match(new RegExp(`^${key}=(.*)$`, "m"));
|
|
50
|
+
const value = match?.[1]?.trim();
|
|
51
|
+
return value ? value : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Config-check only, on purpose — no network call or file-existence probe
|
|
56
|
+
* against the actual database is attempted. Reports the driver wired up in
|
|
57
|
+
* src/config/db.<ext> and whether the env var it needs is set in .env.
|
|
58
|
+
* Fast, and behaves the same for every provider; a live connectivity test
|
|
59
|
+
* would need separate driver-specific logic (TCP for Postgres, HTTPS for
|
|
60
|
+
* Neon, a file stat for SQLite) for comparatively little extra signal, and
|
|
61
|
+
* would turn every `bun run project` into a network call.
|
|
62
|
+
*/
|
|
63
|
+
export async function detectDbStatus(cwd: string = process.cwd()): Promise<DbStatus> {
|
|
64
|
+
const { root, ext } = await detectProject(cwd);
|
|
65
|
+
|
|
66
|
+
let dbFileContents: string | undefined;
|
|
67
|
+
try {
|
|
68
|
+
dbFileContents = await readFile(join(root, "src/config", `db.${ext}`), "utf-8");
|
|
69
|
+
} catch {
|
|
70
|
+
dbFileContents = undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const driver = dbFileContents === undefined ? "missing" : detectDriver(dbFileContents);
|
|
74
|
+
|
|
75
|
+
let envContents = "";
|
|
76
|
+
let envFileExists = true;
|
|
77
|
+
try {
|
|
78
|
+
envContents = await readFile(join(root, ".env"), "utf-8");
|
|
79
|
+
} catch {
|
|
80
|
+
envFileExists = false;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const databaseUrl = parseEnvValue(envContents, "DATABASE_URL");
|
|
84
|
+
|
|
85
|
+
if (driver === "missing") {
|
|
86
|
+
return { driver, envFileExists, ready: "unknown", summary: warn("src/config/db file not found.") };
|
|
87
|
+
}
|
|
88
|
+
if (driver === "custom") {
|
|
89
|
+
return {
|
|
90
|
+
driver,
|
|
91
|
+
envFileExists,
|
|
92
|
+
ready: "unknown",
|
|
93
|
+
summary: `${dim("custom")} — src/config/db has been hand-edited, can't tell you its status here.`,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (driver === "none") {
|
|
97
|
+
return { driver, envFileExists, ready: true, summary: dim("none — no database configured.") };
|
|
98
|
+
}
|
|
99
|
+
if (driver === "sqlite") {
|
|
100
|
+
const path = databaseUrl ?? "./dev.db";
|
|
101
|
+
return { driver, envFileExists, ready: true, summary: `${ok("sqlite")} — using ${path}.` };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// neon / postgres both hard-require DATABASE_URL — db.ts itself throws at
|
|
105
|
+
// import time without one, so "missing-env" here means the app won't boot.
|
|
106
|
+
if (databaseUrl) {
|
|
107
|
+
return { driver, envFileExists, ready: true, summary: `${ok(driver)} — DATABASE_URL is set in .env.` };
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
driver,
|
|
111
|
+
envFileExists,
|
|
112
|
+
ready: false,
|
|
113
|
+
summary: `${warn(driver)} — DATABASE_URL missing from .env${
|
|
114
|
+
envFileExists ? "" : " (no .env file)"
|
|
115
|
+
}; src/config/db.ts will throw at startup until it's set.`,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { detectProject } from "./detect";
|
|
4
|
+
import { parseMountedRoutes, readEndpointsIndex } from "./endpoints-index";
|
|
5
|
+
import { parseRouteMethods } from "./route-methods";
|
|
6
|
+
import { renderBlankController, renderBlankRoutes, renderBlankServices, routeMountLine, type HttpVerb } from "./templates/route";
|
|
7
|
+
|
|
8
|
+
export interface RemoveMethodResult {
|
|
9
|
+
route: string;
|
|
10
|
+
root: string;
|
|
11
|
+
removed: { verb: HttpVerb; path: string; name: string };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* addMethod() appends each method as its own \n\n-delimited block (see
|
|
16
|
+
* appendBlock() in add-method.ts) — imports/the Router()-or-Hono()
|
|
17
|
+
* declaration are their own leading block, then one block per method, in
|
|
18
|
+
* insertion order, nothing else in between. That's what makes this safe:
|
|
19
|
+
* find the one block matching the predicate and drop it, leaving every
|
|
20
|
+
* other block (including the leading one) untouched.
|
|
21
|
+
*/
|
|
22
|
+
function removeBlock(content: string, matches: (block: string) => boolean): string {
|
|
23
|
+
const blocks = content.split(/\n\n+/);
|
|
24
|
+
const index = blocks.findIndex(matches);
|
|
25
|
+
if (index === -1) return content;
|
|
26
|
+
blocks.splice(index, 1);
|
|
27
|
+
const joined = blocks.filter((b) => b.length > 0).join("\n\n");
|
|
28
|
+
return joined ? `${joined}\n` : "";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The undo for addMethod(): strips one method's mount line from
|
|
33
|
+
* *.routes.<ext>, its defineRoute() export (plus any params/body/query
|
|
34
|
+
* schema consts) from *.controller.<ext>, and its matching function from
|
|
35
|
+
* *.services.<ext>. Identified by verb+path, the same pair addMethod()
|
|
36
|
+
* itself refuses to let collide — not by name alone, since two different
|
|
37
|
+
* verb/path pairs could theoretically end up with the same name checked
|
|
38
|
+
* against different endpoints (name uniqueness is only enforced per
|
|
39
|
+
* endpoint, not globally).
|
|
40
|
+
*
|
|
41
|
+
* Removing the last method on an endpoint resets all three files back to
|
|
42
|
+
* their blank, freshly-scaffolded shape (renderBlank*()) rather than
|
|
43
|
+
* leaving behind an import block with nothing left to import for — the
|
|
44
|
+
* same state addRoute() itself would have written.
|
|
45
|
+
*/
|
|
46
|
+
export async function removeMethod(
|
|
47
|
+
route: string,
|
|
48
|
+
verb: HttpVerb,
|
|
49
|
+
path: string,
|
|
50
|
+
cwd: string = process.cwd()
|
|
51
|
+
): Promise<RemoveMethodResult> {
|
|
52
|
+
const { root, framework, language, ext } = await detectProject(cwd);
|
|
53
|
+
|
|
54
|
+
const { contents: indexContents } = await readEndpointsIndex(root, ext);
|
|
55
|
+
const mounted = parseMountedRoutes(indexContents);
|
|
56
|
+
if (!mounted.includes(route)) {
|
|
57
|
+
throw new Error(`"${route}" isn't mounted in src/endpoints/index.${ext}.`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const routeDir = join(root, "src/endpoints", route);
|
|
61
|
+
const controllerPath = join(routeDir, `${route}.controller.${ext}`);
|
|
62
|
+
const routesPath = join(routeDir, `${route}.routes.${ext}`);
|
|
63
|
+
const servicesPath = join(routeDir, `${route}.services.${ext}`);
|
|
64
|
+
|
|
65
|
+
const [controllerContents, routesContents, servicesContents] = await Promise.all([
|
|
66
|
+
readFile(controllerPath, "utf-8"),
|
|
67
|
+
readFile(routesPath, "utf-8"),
|
|
68
|
+
readFile(servicesPath, "utf-8"),
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
const existing = parseRouteMethods(routesContents);
|
|
72
|
+
const match = existing.find((m) => m.verb === verb && m.path === path);
|
|
73
|
+
if (!match) {
|
|
74
|
+
throw new Error(`${verb.toUpperCase()} ${path} isn't mounted in ${routesPath}.`);
|
|
75
|
+
}
|
|
76
|
+
const { name } = match;
|
|
77
|
+
|
|
78
|
+
if (existing.length === 1) {
|
|
79
|
+
await Promise.all([
|
|
80
|
+
writeFile(controllerPath, renderBlankController()),
|
|
81
|
+
writeFile(routesPath, renderBlankRoutes(route, framework, language)),
|
|
82
|
+
writeFile(servicesPath, renderBlankServices()),
|
|
83
|
+
]);
|
|
84
|
+
return { route, root, removed: match };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const expectedMountLine = routeMountLine(route, { verb, path, name, needsBody: false, needsQuery: false });
|
|
88
|
+
|
|
89
|
+
const newController = removeBlock(controllerContents, (block) => block.includes(`export const ${name} = defineRoute(`));
|
|
90
|
+
const newRoutes = removeBlock(routesContents, (block) => block.trim() === expectedMountLine);
|
|
91
|
+
const newServices = removeBlock(servicesContents, (block) => block.includes(`export async function ${name}(`));
|
|
92
|
+
|
|
93
|
+
await Promise.all([
|
|
94
|
+
writeFile(controllerPath, newController),
|
|
95
|
+
writeFile(routesPath, newRoutes),
|
|
96
|
+
writeFile(servicesPath, newServices),
|
|
97
|
+
]);
|
|
98
|
+
|
|
99
|
+
return { route, root, removed: match };
|
|
100
|
+
}
|
package/src/route-methods.ts
CHANGED
|
@@ -35,6 +35,30 @@ export function parseRouteMethods(routesFileContents: string): EndpointMethod[]
|
|
|
35
35
|
return methods;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Whether a given method actually declared a body/query schema — read off
|
|
40
|
+
* whether *.controller.<ext> exports `<name>BodySchema`/`<name>QuerySchema`,
|
|
41
|
+
* since addMethod() only ever emits those consts when the method's own
|
|
42
|
+
* needsBody/needsQuery was true (see renderControllerMethod in
|
|
43
|
+
* templates/route.ts). Nothing else remembers those two booleans after the
|
|
44
|
+
* fact — this is how the "modify a method" flow prefills its confirm
|
|
45
|
+
* prompts with what the method already has, instead of defaulting both back
|
|
46
|
+
* to false every time.
|
|
47
|
+
*/
|
|
48
|
+
export async function detectMethodValidation(
|
|
49
|
+
route: string,
|
|
50
|
+
name: string,
|
|
51
|
+
cwd: string = process.cwd()
|
|
52
|
+
): Promise<{ needsBody: boolean; needsQuery: boolean }> {
|
|
53
|
+
const { root, ext } = await detectProject(cwd);
|
|
54
|
+
const controllerPath = join(root, "src/endpoints", route, `${route}.controller.${ext}`);
|
|
55
|
+
const contents = await readFile(controllerPath, "utf-8");
|
|
56
|
+
return {
|
|
57
|
+
needsBody: contents.includes(`export const ${name}BodySchema`),
|
|
58
|
+
needsQuery: contents.includes(`export const ${name}QuerySchema`),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
38
62
|
/**
|
|
39
63
|
* Every endpoint currently mounted in src/endpoints/index.<ext>, with the
|
|
40
64
|
* HTTP methods each one's own *.routes.<ext> file actually wires up right
|
package/src/templates/base.ts
CHANGED
|
@@ -327,6 +327,12 @@ export function renderPackageJson(
|
|
|
327
327
|
"remove-route": "bunx create-backon remove-route",
|
|
328
328
|
"list-routes": "bunx create-backon list-routes",
|
|
329
329
|
doctor: "bunx create-backon doctor",
|
|
330
|
+
// project: read-only overview (db status, endpoints, methods, doctor
|
|
331
|
+
// summary). server-config: the interactive manager for actually
|
|
332
|
+
// changing endpoints/methods — add/remove/modify, without needing to
|
|
333
|
+
// remember which of the individual subcommands above does what.
|
|
334
|
+
project: "bunx create-backon project",
|
|
335
|
+
"server-config": "bunx create-backon server-config",
|
|
330
336
|
docs: `bun run scripts/generate-docs.${ext}`,
|
|
331
337
|
};
|
|
332
338
|
if (language === "typescript") {
|