@igniter-js/cli 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/dist/index.mjs +57 -51
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -148,7 +148,7 @@ function registerHandlebarsHelpers() {
|
|
|
148
148
|
});
|
|
149
149
|
handlebars.registerHelper("filterPlugins", function(plugins = []) {
|
|
150
150
|
if (!Array.isArray(plugins)) return [];
|
|
151
|
-
return plugins.filter((
|
|
151
|
+
return plugins.filter((p13) => p13 !== "next-cookies");
|
|
152
152
|
});
|
|
153
153
|
handlebars.registerHelper(
|
|
154
154
|
"generatePluginImports",
|
|
@@ -162,7 +162,7 @@ function registerHandlebarsHelpers() {
|
|
|
162
162
|
if (str === "open-api") return "openAPI";
|
|
163
163
|
return str.replace(/-([a-z])/g, (g) => g[1].toUpperCase());
|
|
164
164
|
};
|
|
165
|
-
const regularPlugins = plugins.filter((
|
|
165
|
+
const regularPlugins = plugins.filter((p13) => p13 !== "next-cookies").map(camelCase);
|
|
166
166
|
const hasNextCookies = plugins.includes("next-cookies");
|
|
167
167
|
const importStatements = [];
|
|
168
168
|
if (regularPlugins.length > 0) {
|
|
@@ -3144,6 +3144,7 @@ import { build } from "esbuild";
|
|
|
3144
3144
|
import zodToJsonSchema from "zod-to-json-schema";
|
|
3145
3145
|
import { createRequire } from "module";
|
|
3146
3146
|
import nodeExternals from "esbuild-node-externals";
|
|
3147
|
+
import * as p8 from "@clack/prompts";
|
|
3147
3148
|
var RouterLoadError = class extends Error {
|
|
3148
3149
|
constructor(message, originalError) {
|
|
3149
3150
|
super(message);
|
|
@@ -3190,7 +3191,7 @@ var RouterInstrospector = class _RouterInstrospector {
|
|
|
3190
3191
|
});
|
|
3191
3192
|
const [outputFile] = result.outputFiles;
|
|
3192
3193
|
if (!outputFile) {
|
|
3193
|
-
throw new
|
|
3194
|
+
throw new RouterLoadError("esbuild did not produce any output.");
|
|
3194
3195
|
}
|
|
3195
3196
|
const compiledCode = outputFile.text;
|
|
3196
3197
|
const routerModule = { exports: {} };
|
|
@@ -3209,7 +3210,7 @@ var RouterInstrospector = class _RouterInstrospector {
|
|
|
3209
3210
|
if (router && typeof router.controllers === "object") {
|
|
3210
3211
|
return router;
|
|
3211
3212
|
}
|
|
3212
|
-
throw new
|
|
3213
|
+
throw new RouterLoadError("Module was compiled and loaded, but no valid Igniter router export was found.");
|
|
3213
3214
|
} catch (error) {
|
|
3214
3215
|
if (error && Array.isArray(error.errors)) {
|
|
3215
3216
|
const buildFailure = error;
|
|
@@ -3218,6 +3219,7 @@ var RouterInstrospector = class _RouterInstrospector {
|
|
|
3218
3219
|
${errorMessages}`;
|
|
3219
3220
|
throw new RouterLoadError(detailedMessage, error);
|
|
3220
3221
|
}
|
|
3222
|
+
p8.log.error(`Error loading router: ${error instanceof Error ? error.message : String(error)}`);
|
|
3221
3223
|
throw new RouterLoadError(`Failed to load router from ${routerPath}`, error);
|
|
3222
3224
|
}
|
|
3223
3225
|
}
|
|
@@ -3235,16 +3237,20 @@ ${errorMessages}`;
|
|
|
3235
3237
|
const typedController = controller;
|
|
3236
3238
|
if (typedController && typedController.actions) {
|
|
3237
3239
|
for (const [actionName, action] of Object.entries(typedController.actions)) {
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3240
|
+
try {
|
|
3241
|
+
const typedAction = action;
|
|
3242
|
+
introspectedActions[actionName] = {
|
|
3243
|
+
name: actionName,
|
|
3244
|
+
path: typedAction.path,
|
|
3245
|
+
method: typedAction.method,
|
|
3246
|
+
description: typedAction.description,
|
|
3247
|
+
bodySchema: typedAction.body ? zodToJsonSchema(typedAction.body, { target: "openApi3" }) : void 0,
|
|
3248
|
+
querySchema: typedAction.query ? zodToJsonSchema(typedAction.query, { target: "openApi3" }) : void 0
|
|
3249
|
+
};
|
|
3250
|
+
totalActions++;
|
|
3251
|
+
} catch (err) {
|
|
3252
|
+
throw err;
|
|
3253
|
+
}
|
|
3248
3254
|
}
|
|
3249
3255
|
}
|
|
3250
3256
|
introspectedControllers[controllerName] = {
|
|
@@ -3267,7 +3273,7 @@ ${errorMessages}`;
|
|
|
3267
3273
|
};
|
|
3268
3274
|
|
|
3269
3275
|
// src/commands/generate/docs/action.ts
|
|
3270
|
-
import * as
|
|
3276
|
+
import * as p9 from "@clack/prompts";
|
|
3271
3277
|
import * as fs5 from "fs";
|
|
3272
3278
|
import * as path19 from "path";
|
|
3273
3279
|
async function generateDocsWatchMode(routerPath, outputDir) {
|
|
@@ -3300,18 +3306,18 @@ async function generateDocsWatchMode(routerPath, outputDir) {
|
|
|
3300
3306
|
}
|
|
3301
3307
|
async function handleGenerateDocsAction(options) {
|
|
3302
3308
|
try {
|
|
3303
|
-
|
|
3304
|
-
const spinner7 =
|
|
3309
|
+
p9.intro("Generate OpenAPI documentation");
|
|
3310
|
+
const spinner7 = p9.spinner();
|
|
3305
3311
|
spinner7.start("Generating OpenAPI documentation...");
|
|
3306
3312
|
const result = await generateDocsWatchMode(options.router, options.output);
|
|
3307
3313
|
spinner7.stop("OpenAPI documentation generated successfully.");
|
|
3308
|
-
|
|
3314
|
+
p9.log.success(
|
|
3309
3315
|
`Docs generated in ${(result.durationMs / 1e3).toFixed(2)}s (${result.sizeKb.toFixed(1)} KB)`
|
|
3310
3316
|
);
|
|
3311
|
-
|
|
3317
|
+
p9.log.info("Test your API on Igniter Studio at: http://localhost:3000/api/v1/docs");
|
|
3312
3318
|
process.exit(0);
|
|
3313
3319
|
} catch (error) {
|
|
3314
|
-
|
|
3320
|
+
p9.log.error(error instanceof Error ? error.message : String(error));
|
|
3315
3321
|
process.exit(1);
|
|
3316
3322
|
}
|
|
3317
3323
|
}
|
|
@@ -3326,7 +3332,7 @@ import { Command as Command4 } from "commander";
|
|
|
3326
3332
|
import * as fs6 from "fs";
|
|
3327
3333
|
import * as path20 from "path";
|
|
3328
3334
|
import * as handlebars5 from "handlebars";
|
|
3329
|
-
import * as
|
|
3335
|
+
import * as p10 from "@clack/prompts";
|
|
3330
3336
|
async function generateSchemaWatchMode(routerPath, outputPath) {
|
|
3331
3337
|
const startTime = Date.now();
|
|
3332
3338
|
const routerInstrospector = RouterInstrospector.create();
|
|
@@ -3350,19 +3356,19 @@ async function generateSchemaWatchMode(routerPath, outputPath) {
|
|
|
3350
3356
|
}
|
|
3351
3357
|
async function handleGenerateSchemaAction({ router: routerPath, output: outputPath }) {
|
|
3352
3358
|
try {
|
|
3353
|
-
|
|
3354
|
-
const spinner7 =
|
|
3359
|
+
p10.intro("Generate Igniter.js Client Schema");
|
|
3360
|
+
const spinner7 = p10.spinner();
|
|
3355
3361
|
spinner7.start("Generating schema...");
|
|
3356
3362
|
const result = await generateSchemaWatchMode(routerPath, outputPath);
|
|
3357
3363
|
spinner7.stop("Schema generated successfully.");
|
|
3358
|
-
|
|
3364
|
+
p10.log.success(
|
|
3359
3365
|
`Schema generated in ${(result.durationMs / 1e3).toFixed(2)}s (${result.controllers} controllers, ${result.actions} actions).`
|
|
3360
3366
|
);
|
|
3361
|
-
|
|
3367
|
+
p10.outro("All done!");
|
|
3362
3368
|
process.exit(0);
|
|
3363
3369
|
} catch (error) {
|
|
3364
3370
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
3365
|
-
|
|
3371
|
+
p10.log.error(`Failed to generate schema: ${errorMessage}`);
|
|
3366
3372
|
process.exit(1);
|
|
3367
3373
|
}
|
|
3368
3374
|
}
|
|
@@ -3375,7 +3381,7 @@ import { Command as Command5 } from "commander";
|
|
|
3375
3381
|
|
|
3376
3382
|
// src/commands/generate/controller/action.ts
|
|
3377
3383
|
import * as path21 from "path";
|
|
3378
|
-
import * as
|
|
3384
|
+
import * as p11 from "@clack/prompts";
|
|
3379
3385
|
|
|
3380
3386
|
// src/utils/try-catch.ts
|
|
3381
3387
|
async function tryCatch(promise) {
|
|
@@ -3389,7 +3395,7 @@ async function tryCatch(promise) {
|
|
|
3389
3395
|
|
|
3390
3396
|
// src/commands/generate/controller/action.ts
|
|
3391
3397
|
async function handleGenerateControllerAction(name, options) {
|
|
3392
|
-
|
|
3398
|
+
p11.intro("Generate Controller");
|
|
3393
3399
|
let controllerInput = name;
|
|
3394
3400
|
if (!controllerInput) {
|
|
3395
3401
|
controllerInput = await FeaturePrompts.askForEntityName({
|
|
@@ -3406,7 +3412,7 @@ async function handleGenerateControllerAction(name, options) {
|
|
|
3406
3412
|
options.feature
|
|
3407
3413
|
));
|
|
3408
3414
|
if (selectedFeature.error) {
|
|
3409
|
-
|
|
3415
|
+
p11.log.error(`Controller generation failed: ${selectedFeature.error.message}`);
|
|
3410
3416
|
process.exit(1);
|
|
3411
3417
|
}
|
|
3412
3418
|
const featureSlug = Casing.toKebabCase(selectedFeature.data);
|
|
@@ -3418,7 +3424,7 @@ async function handleGenerateControllerAction(name, options) {
|
|
|
3418
3424
|
`${controllerSlug}.controller.ts`
|
|
3419
3425
|
);
|
|
3420
3426
|
if (await FeatureWorkspace.fileExists(controllerPath)) {
|
|
3421
|
-
|
|
3427
|
+
p11.log.error(
|
|
3422
3428
|
`Controller '${controllerSlug}' already exists at ${path21.relative(process.cwd(), controllerPath)}.`
|
|
3423
3429
|
);
|
|
3424
3430
|
process.exit(1);
|
|
@@ -3429,7 +3435,7 @@ async function handleGenerateControllerAction(name, options) {
|
|
|
3429
3435
|
"feature",
|
|
3430
3436
|
"empty.controller.hbs"
|
|
3431
3437
|
);
|
|
3432
|
-
const spinner7 =
|
|
3438
|
+
const spinner7 = p11.spinner();
|
|
3433
3439
|
spinner7.start(
|
|
3434
3440
|
`Creating controller '${controllerSlug}' inside feature '${featureSlug}'...`
|
|
3435
3441
|
);
|
|
@@ -3444,14 +3450,14 @@ async function handleGenerateControllerAction(name, options) {
|
|
|
3444
3450
|
controllerPath
|
|
3445
3451
|
);
|
|
3446
3452
|
spinner7.stop("Controller created successfully!");
|
|
3447
|
-
|
|
3453
|
+
p11.log.success(
|
|
3448
3454
|
`Created controller '${controllerSlug}' in feature '${featureSlug}'.`
|
|
3449
3455
|
);
|
|
3450
|
-
|
|
3456
|
+
p11.outro("Controller generation complete!");
|
|
3451
3457
|
} catch (error) {
|
|
3452
3458
|
spinner7.stop("Failed to create the controller.");
|
|
3453
3459
|
const message = error instanceof Error ? error.message : String(error);
|
|
3454
|
-
|
|
3460
|
+
p11.log.error(`Controller generation failed: ${message}`);
|
|
3455
3461
|
process.exit(1);
|
|
3456
3462
|
}
|
|
3457
3463
|
}
|
|
@@ -3464,10 +3470,10 @@ import { Command as Command6 } from "commander";
|
|
|
3464
3470
|
|
|
3465
3471
|
// src/commands/generate/procedure/action.ts
|
|
3466
3472
|
import * as path22 from "path";
|
|
3467
|
-
import * as
|
|
3473
|
+
import * as p12 from "@clack/prompts";
|
|
3468
3474
|
import { rm as rm2 } from "fs/promises";
|
|
3469
3475
|
async function handleGenerateProcedureAction(name, options) {
|
|
3470
|
-
|
|
3476
|
+
p12.intro("Generate Procedure");
|
|
3471
3477
|
let procedureInput = name;
|
|
3472
3478
|
if (!procedureInput) {
|
|
3473
3479
|
procedureInput = await FeaturePrompts.askForEntityName({
|
|
@@ -3484,7 +3490,7 @@ async function handleGenerateProcedureAction(name, options) {
|
|
|
3484
3490
|
options.feature
|
|
3485
3491
|
));
|
|
3486
3492
|
if (selectedFeature.error) {
|
|
3487
|
-
|
|
3493
|
+
p12.log.error(`Procedure generation failed: ${selectedFeature.error.message}`);
|
|
3488
3494
|
process.exit(1);
|
|
3489
3495
|
}
|
|
3490
3496
|
const featureSlug = Casing.toKebabCase(selectedFeature.data);
|
|
@@ -3496,7 +3502,7 @@ async function handleGenerateProcedureAction(name, options) {
|
|
|
3496
3502
|
`${procedureSlug}.procedure.ts`
|
|
3497
3503
|
);
|
|
3498
3504
|
if (await FeatureWorkspace.fileExists(procedurePath)) {
|
|
3499
|
-
|
|
3505
|
+
p12.log.error(
|
|
3500
3506
|
`Procedure '${procedureSlug}' already exists at ${path22.relative(process.cwd(), procedurePath)}.`
|
|
3501
3507
|
);
|
|
3502
3508
|
process.exit(1);
|
|
@@ -3507,7 +3513,7 @@ async function handleGenerateProcedureAction(name, options) {
|
|
|
3507
3513
|
"feature",
|
|
3508
3514
|
"procedure.hbs"
|
|
3509
3515
|
);
|
|
3510
|
-
const spinner7 =
|
|
3516
|
+
const spinner7 = p12.spinner();
|
|
3511
3517
|
spinner7.start(
|
|
3512
3518
|
`Creating procedure '${procedureSlug}' inside feature '${featureSlug}'...`
|
|
3513
3519
|
);
|
|
@@ -3525,14 +3531,14 @@ async function handleGenerateProcedureAction(name, options) {
|
|
|
3525
3531
|
procedurePath
|
|
3526
3532
|
);
|
|
3527
3533
|
spinner7.stop("Procedure created successfully!");
|
|
3528
|
-
|
|
3534
|
+
p12.log.success(
|
|
3529
3535
|
`Created procedure '${procedureSlug}' in feature '${featureSlug}'.`
|
|
3530
3536
|
);
|
|
3531
|
-
|
|
3537
|
+
p12.outro("Procedure generation complete!");
|
|
3532
3538
|
} catch (error) {
|
|
3533
3539
|
spinner7.stop("Failed to create the procedure.");
|
|
3534
3540
|
const message = error instanceof Error ? error.message : String(error);
|
|
3535
|
-
|
|
3541
|
+
p12.log.error(`Procedure generation failed: ${message}`);
|
|
3536
3542
|
process.exit(1);
|
|
3537
3543
|
}
|
|
3538
3544
|
}
|
|
@@ -3583,14 +3589,14 @@ function DevUI({ igniterLogs, appLogs, onExit }) {
|
|
|
3583
3589
|
};
|
|
3584
3590
|
const renderLogs = (logs, maxLines = 50) => {
|
|
3585
3591
|
const visibleLogs = logs.slice(-maxLines);
|
|
3586
|
-
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, visibleLogs.length === 0 ? /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "No logs yet...") : visibleLogs.map((
|
|
3592
|
+
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, visibleLogs.length === 0 ? /* @__PURE__ */ React.createElement(Text, { dimColor: true }, "No logs yet...") : visibleLogs.map((log11, index) => {
|
|
3587
3593
|
const color2 = {
|
|
3588
3594
|
info: "cyan",
|
|
3589
3595
|
success: "green",
|
|
3590
3596
|
error: "red",
|
|
3591
3597
|
warn: "yellow"
|
|
3592
|
-
}[
|
|
3593
|
-
return /* @__PURE__ */ React.createElement(Text, { key: `${
|
|
3598
|
+
}[log11.type];
|
|
3599
|
+
return /* @__PURE__ */ React.createElement(Text, { key: `${log11.timestamp.getTime()}-${index}`, color: color2 }, formatLogEntry(log11));
|
|
3594
3600
|
}));
|
|
3595
3601
|
};
|
|
3596
3602
|
return /* @__PURE__ */ React.createElement(Box, { flexDirection: "column" }, /* @__PURE__ */ React.createElement(Box, { marginBottom: 1 }, /* @__PURE__ */ React.createElement(Text, { bold: true }, "Igniter.js Development Mode")), /* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, /* @__PURE__ */ React.createElement(
|
|
@@ -3663,8 +3669,8 @@ async function handleDevAction(options) {
|
|
|
3663
3669
|
const igniterLogs = [];
|
|
3664
3670
|
const appLogs = [];
|
|
3665
3671
|
let rerenderFn = null;
|
|
3666
|
-
const addIgniterLog = (
|
|
3667
|
-
igniterLogs.push(
|
|
3672
|
+
const addIgniterLog = (log11) => {
|
|
3673
|
+
igniterLogs.push(log11);
|
|
3668
3674
|
if (igniterLogs.length > 1e3) {
|
|
3669
3675
|
igniterLogs.shift();
|
|
3670
3676
|
}
|
|
@@ -3672,8 +3678,8 @@ async function handleDevAction(options) {
|
|
|
3672
3678
|
rerenderFn();
|
|
3673
3679
|
}
|
|
3674
3680
|
};
|
|
3675
|
-
const addAppLog = (
|
|
3676
|
-
appLogs.push(
|
|
3681
|
+
const addAppLog = (log11) => {
|
|
3682
|
+
appLogs.push(log11);
|
|
3677
3683
|
if (appLogs.length > 1e3) {
|
|
3678
3684
|
appLogs.shift();
|
|
3679
3685
|
}
|
|
@@ -3709,7 +3715,7 @@ async function handleDevAction(options) {
|
|
|
3709
3715
|
// Watch router file directly
|
|
3710
3716
|
featuresDir
|
|
3711
3717
|
// Watch features directory recursively
|
|
3712
|
-
].filter((
|
|
3718
|
+
].filter((p13) => fs7.existsSync(p13));
|
|
3713
3719
|
if (watchPaths.length === 0) {
|
|
3714
3720
|
addIgniterLog({
|
|
3715
3721
|
type: "warn",
|
|
@@ -3720,7 +3726,7 @@ async function handleDevAction(options) {
|
|
|
3720
3726
|
}
|
|
3721
3727
|
addIgniterLog({
|
|
3722
3728
|
type: "info",
|
|
3723
|
-
message: `Watching for changes in: ${watchPaths.map((
|
|
3729
|
+
message: `Watching for changes in: ${watchPaths.map((p13) => path23.relative(process.cwd(), p13)).join(", ")}`,
|
|
3724
3730
|
timestamp: /* @__PURE__ */ new Date()
|
|
3725
3731
|
});
|
|
3726
3732
|
let regenerateTimeout = null;
|