@spfn/cli 0.1.0-alpha.1 → 0.1.0-alpha.2
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/dist/index.js +31 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
@@ -256,7 +256,8 @@ import { watchAndGenerate } from '@spfn/core/codegen';
|
|
256
256
|
|
257
257
|
await watchAndGenerate({
|
258
258
|
routesDir: ${options.routes ? `'${options.routes}'` : "undefined"},
|
259
|
-
debug: true
|
259
|
+
debug: true,
|
260
|
+
watch: ${options.watch !== false}
|
260
261
|
});
|
261
262
|
`);
|
262
263
|
const pm = detectPackageManager(cwd);
|
@@ -267,7 +268,7 @@ await watchAndGenerate({
|
|
267
268
|
try {
|
268
269
|
const tsxCmd2 = watchMode2 ? "tsx --watch" : "tsx";
|
269
270
|
const serverCmd2 = pm === "npm" ? `npx ${tsxCmd2} ${serverEntry}` : `${pm} exec ${tsxCmd2} ${serverEntry}`;
|
270
|
-
const watcherCmd2 = pm === "npm" ? `npx
|
271
|
+
const watcherCmd2 = pm === "npm" ? `npx tsx ${watcherEntry}` : `${pm} exec tsx ${watcherEntry}`;
|
271
272
|
await execa2(
|
272
273
|
pm === "npm" ? "npx" : pm,
|
273
274
|
pm === "npm" ? ["concurrently", "--raw", "--kill-others", `"${serverCmd2}"`, `"${watcherCmd2}"`] : ["exec", "concurrently", "--raw", "--kill-others", `"${serverCmd2}"`, `"${watcherCmd2}"`],
|
@@ -290,7 +291,7 @@ await watchAndGenerate({
|
|
290
291
|
const nextCmd = pm === "npm" ? "npm run spfn:next" : `${pm} run spfn:next`;
|
291
292
|
const tsxCmd = watchMode ? "tsx --watch" : "tsx";
|
292
293
|
const serverCmd = pm === "npm" ? `npx ${tsxCmd} ${serverEntry}` : `${pm} exec ${tsxCmd} ${serverEntry}`;
|
293
|
-
const watcherCmd = pm === "npm" ? `npx
|
294
|
+
const watcherCmd = pm === "npm" ? `npx tsx ${watcherEntry}` : `${pm} exec tsx ${watcherEntry}`;
|
294
295
|
logger.info(`Starting SPFN server + Next.js (Turbopack)${watchMode ? " (watch mode)" : ""}...
|
295
296
|
`);
|
296
297
|
try {
|
@@ -354,6 +355,7 @@ import fse2 from "fs-extra";
|
|
354
355
|
import chalk3 from "chalk";
|
355
356
|
import { dirname as dirname2 } from "path";
|
356
357
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
358
|
+
import { scanContracts, generateClient } from "@spfn/core/codegen";
|
357
359
|
var { ensureDirSync: ensureDirSync2, writeFileSync: writeFileSync3 } = fse2;
|
358
360
|
var __dirname2 = dirname2(fileURLToPath2(import.meta.url));
|
359
361
|
function findScriptTemplatesPath() {
|
@@ -538,12 +540,38 @@ var generateCommand = new Command4("generate").alias("g").description("Generate
|
|
538
540
|
process.exit(0);
|
539
541
|
}
|
540
542
|
await executeOperations(operations, options);
|
543
|
+
if (!options.dryRun) {
|
544
|
+
try {
|
545
|
+
const clientSpinner = ora2("Generating type-safe API client...").start();
|
546
|
+
const routesDir = join5(cwd, "src", "server", "routes");
|
547
|
+
const outputPath = join5(cwd, "src", "lib", "api.ts");
|
548
|
+
const contracts = await scanContracts(routesDir);
|
549
|
+
if (contracts.length > 0) {
|
550
|
+
const clientOptions = {
|
551
|
+
routesDir,
|
552
|
+
outputPath,
|
553
|
+
includeTypes: true,
|
554
|
+
includeJsDoc: true
|
555
|
+
};
|
556
|
+
await generateClient(contracts, clientOptions);
|
557
|
+
clientSpinner.succeed(`Generated API client with ${contracts.length} endpoint(s)`);
|
558
|
+
} else {
|
559
|
+
clientSpinner.info("No contracts found - skipping client generation");
|
560
|
+
}
|
561
|
+
} catch (error) {
|
562
|
+
logger.warn("Client generation failed (server code generated successfully)");
|
563
|
+
if (error instanceof Error) {
|
564
|
+
logger.warn(error.message);
|
565
|
+
}
|
566
|
+
}
|
567
|
+
}
|
541
568
|
if (!options.dryRun) {
|
542
569
|
console.log("\n" + chalk3.green.bold("\u2713 CRUD boilerplate generated successfully!\n"));
|
543
570
|
console.log("Generated files:");
|
544
571
|
operations.forEach((op) => {
|
545
572
|
console.log(" \u2022 " + chalk3.cyan(relative(cwd, op.path)));
|
546
573
|
});
|
574
|
+
console.log(" \u2022 " + chalk3.cyan("src/lib/api.ts") + chalk3.gray(" (API client)"));
|
547
575
|
if (!entityExists) {
|
548
576
|
console.log("\n" + chalk3.yellow("\u{1F4DD} Next steps:"));
|
549
577
|
console.log(" 1. " + chalk3.cyan(`Edit entities/${entityName}.ts`) + " - Add your custom fields");
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@spfn/cli",
|
3
|
-
"version": "0.1.0-alpha.
|
3
|
+
"version": "0.1.0-alpha.2",
|
4
4
|
"description": "SPFN CLI - Add SPFN to your Next.js project",
|
5
5
|
"type": "module",
|
6
6
|
"bin": {
|
@@ -48,7 +48,7 @@
|
|
48
48
|
"ora": "^7.0.1",
|
49
49
|
"prompts": "^2.4.2",
|
50
50
|
"tsx": "^4.20.6",
|
51
|
-
"@spfn/core": "0.1.0-alpha.
|
51
|
+
"@spfn/core": "0.1.0-alpha.2"
|
52
52
|
},
|
53
53
|
"devDependencies": {
|
54
54
|
"@types/fs-extra": "^11.0.4",
|