@devbro/pashmak 0.1.27 → 0.1.28
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/app/console/generate/GenerateApiDocsCommand.d.mts +9 -0
- package/dist/app/console/generate/GenerateApiDocsCommand.mjs +117 -0
- package/dist/app/console/generate/GenerateApiDocsCommand.mjs.map +1 -0
- package/dist/app/console/generate/index.d.mts +1 -0
- package/dist/app/console/generate/index.mjs +1 -0
- package/dist/app/console/generate/index.mjs.map +1 -1
- package/dist/app/console/index.d.mts +1 -0
- package/dist/bin/app/console/generate/GenerateApiDocsCommand.cjs +868 -0
- package/dist/bin/app/console/generate/index.cjs +128 -14
- package/dist/bin/app/console/index.cjs +160 -46
- package/dist/bin/index.cjs +170 -49
- package/package.json +1 -1
package/dist/bin/index.cjs
CHANGED
|
@@ -249,46 +249,46 @@ var init_Route = __esm({
|
|
|
249
249
|
static {
|
|
250
250
|
__name(this, "Route");
|
|
251
251
|
}
|
|
252
|
-
constructor(methods,
|
|
252
|
+
constructor(methods, path10, handler) {
|
|
253
253
|
this.methods = methods;
|
|
254
|
-
this.path =
|
|
254
|
+
this.path = path10;
|
|
255
255
|
this.handler = handler;
|
|
256
|
-
this.urlRegex = this.pathToRegex(
|
|
256
|
+
this.urlRegex = this.pathToRegex(path10);
|
|
257
257
|
}
|
|
258
258
|
middlewares = [];
|
|
259
259
|
urlRegex;
|
|
260
|
-
pathToRegex(
|
|
261
|
-
const lex = this.lexUrlPath(
|
|
260
|
+
pathToRegex(path10) {
|
|
261
|
+
const lex = this.lexUrlPath(path10);
|
|
262
262
|
return this.tokensToRegex(lex);
|
|
263
263
|
}
|
|
264
|
-
lexUrlPath(
|
|
264
|
+
lexUrlPath(path10) {
|
|
265
265
|
const tokens = [];
|
|
266
266
|
let i = 0;
|
|
267
|
-
while (i <
|
|
268
|
-
const char =
|
|
267
|
+
while (i < path10.length) {
|
|
268
|
+
const char = path10[i];
|
|
269
269
|
if (char === "/") {
|
|
270
270
|
tokens.push({ type: "SLASH", value: "/" });
|
|
271
271
|
i++;
|
|
272
272
|
} else if (char === ":") {
|
|
273
273
|
let start = i + 1;
|
|
274
|
-
while (start <
|
|
274
|
+
while (start < path10.length && /[a-zA-Z0-9_]/.test(path10[start])) {
|
|
275
275
|
start++;
|
|
276
276
|
}
|
|
277
|
-
tokens.push({ type: "PARAM", value:
|
|
277
|
+
tokens.push({ type: "PARAM", value: path10.slice(i + 1, start) });
|
|
278
278
|
i = start;
|
|
279
279
|
} else if (char === "*") {
|
|
280
280
|
let start = i + 1;
|
|
281
|
-
while (start <
|
|
281
|
+
while (start < path10.length && /[a-zA-Z0-9_\.]/.test(path10[start])) {
|
|
282
282
|
start++;
|
|
283
283
|
}
|
|
284
|
-
tokens.push({ type: "WILDCARD", value:
|
|
284
|
+
tokens.push({ type: "WILDCARD", value: path10.slice(i + 1, start) });
|
|
285
285
|
i = start;
|
|
286
286
|
} else {
|
|
287
287
|
let start = i;
|
|
288
|
-
while (start <
|
|
288
|
+
while (start < path10.length && !["/", ":", "*"].includes(path10[start])) {
|
|
289
289
|
start++;
|
|
290
290
|
}
|
|
291
|
-
tokens.push({ type: "TEXT", value:
|
|
291
|
+
tokens.push({ type: "TEXT", value: path10.slice(i, start) });
|
|
292
292
|
i = start;
|
|
293
293
|
}
|
|
294
294
|
}
|
|
@@ -2499,33 +2499,153 @@ var init_GenerateControllerCommand = __esm({
|
|
|
2499
2499
|
}
|
|
2500
2500
|
});
|
|
2501
2501
|
|
|
2502
|
+
// src/app/console/generate/GenerateApiDocsCommand.mts
|
|
2503
|
+
var import_clipanion9, import_path7, fs6, GenerateApiDocsCommand;
|
|
2504
|
+
var init_GenerateApiDocsCommand = __esm({
|
|
2505
|
+
"src/app/console/generate/GenerateApiDocsCommand.mts"() {
|
|
2506
|
+
"use strict";
|
|
2507
|
+
init_facades();
|
|
2508
|
+
import_clipanion9 = require("clipanion");
|
|
2509
|
+
import_path7 = __toESM(require("path"), 1);
|
|
2510
|
+
fs6 = __toESM(require("fs/promises"), 1);
|
|
2511
|
+
GenerateApiDocsCommand = class extends import_clipanion9.Command {
|
|
2512
|
+
static {
|
|
2513
|
+
__name(this, "GenerateApiDocsCommand");
|
|
2514
|
+
}
|
|
2515
|
+
static paths = [
|
|
2516
|
+
[`make`, `apidocs`],
|
|
2517
|
+
[`generate`, `apidocs`]
|
|
2518
|
+
];
|
|
2519
|
+
async execute() {
|
|
2520
|
+
const rootDir = process.cwd();
|
|
2521
|
+
this.context.stdout.write(`Generating OpenAPI documentation...
|
|
2522
|
+
`);
|
|
2523
|
+
const routes = router().routes;
|
|
2524
|
+
const openApiSpec = {
|
|
2525
|
+
openapi: "3.0.0",
|
|
2526
|
+
info: {
|
|
2527
|
+
title: "API Documentation",
|
|
2528
|
+
version: "1.0.0",
|
|
2529
|
+
description: "Auto-generated API documentation"
|
|
2530
|
+
},
|
|
2531
|
+
servers: [
|
|
2532
|
+
{
|
|
2533
|
+
url: "/",
|
|
2534
|
+
description: "Local server"
|
|
2535
|
+
}
|
|
2536
|
+
],
|
|
2537
|
+
paths: {}
|
|
2538
|
+
};
|
|
2539
|
+
for (const route of routes) {
|
|
2540
|
+
const routePath = route.path;
|
|
2541
|
+
const openApiPath = routePath.replace(/:([a-zA-Z0-9_]+)/g, "{$1}");
|
|
2542
|
+
if (!openApiSpec.paths[openApiPath]) {
|
|
2543
|
+
openApiSpec.paths[openApiPath] = {};
|
|
2544
|
+
}
|
|
2545
|
+
for (const method of route.methods) {
|
|
2546
|
+
const lowerMethod = method.toLowerCase();
|
|
2547
|
+
if (lowerMethod === "head") {
|
|
2548
|
+
continue;
|
|
2549
|
+
}
|
|
2550
|
+
openApiSpec.paths[openApiPath][lowerMethod] = {
|
|
2551
|
+
summary: `${method} ${routePath}`,
|
|
2552
|
+
description: `Endpoint for ${method} ${routePath}`,
|
|
2553
|
+
parameters: this.extractParameters(routePath),
|
|
2554
|
+
responses: {
|
|
2555
|
+
"200": {
|
|
2556
|
+
description: "Successful response",
|
|
2557
|
+
content: {
|
|
2558
|
+
"application/json": {
|
|
2559
|
+
schema: {
|
|
2560
|
+
type: "object"
|
|
2561
|
+
}
|
|
2562
|
+
}
|
|
2563
|
+
}
|
|
2564
|
+
},
|
|
2565
|
+
"500": {
|
|
2566
|
+
description: "Internal server error"
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
};
|
|
2570
|
+
if (["post", "put", "patch"].includes(lowerMethod)) {
|
|
2571
|
+
openApiSpec.paths[openApiPath][lowerMethod].requestBody = {
|
|
2572
|
+
required: true,
|
|
2573
|
+
content: {
|
|
2574
|
+
"application/json": {
|
|
2575
|
+
schema: {
|
|
2576
|
+
type: "object"
|
|
2577
|
+
}
|
|
2578
|
+
}
|
|
2579
|
+
}
|
|
2580
|
+
};
|
|
2581
|
+
}
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
const publicDir = import_path7.default.join(rootDir, "public");
|
|
2585
|
+
await fs6.mkdir(publicDir, { recursive: true });
|
|
2586
|
+
const outputPath = import_path7.default.join(publicDir, "openapi.json");
|
|
2587
|
+
await fs6.writeFile(
|
|
2588
|
+
outputPath,
|
|
2589
|
+
JSON.stringify(openApiSpec, null, 2),
|
|
2590
|
+
"utf-8"
|
|
2591
|
+
);
|
|
2592
|
+
this.context.stdout.write(
|
|
2593
|
+
`OpenAPI documentation generated at: ${outputPath}
|
|
2594
|
+
`
|
|
2595
|
+
);
|
|
2596
|
+
this.context.stdout.write(`Total routes documented: ${routes.length}
|
|
2597
|
+
`);
|
|
2598
|
+
}
|
|
2599
|
+
extractParameters(routePath) {
|
|
2600
|
+
const paramRegex = /:([a-zA-Z0-9_]+)/g;
|
|
2601
|
+
const parameters = [];
|
|
2602
|
+
let match;
|
|
2603
|
+
while ((match = paramRegex.exec(routePath)) !== null) {
|
|
2604
|
+
parameters.push({
|
|
2605
|
+
name: match[1],
|
|
2606
|
+
in: "path",
|
|
2607
|
+
required: true,
|
|
2608
|
+
schema: {
|
|
2609
|
+
type: "string"
|
|
2610
|
+
},
|
|
2611
|
+
description: `Path parameter ${match[1]}`
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
return parameters;
|
|
2615
|
+
}
|
|
2616
|
+
};
|
|
2617
|
+
cli().register(GenerateApiDocsCommand);
|
|
2618
|
+
}
|
|
2619
|
+
});
|
|
2620
|
+
|
|
2502
2621
|
// src/app/console/generate/index.mts
|
|
2503
2622
|
var init_generate = __esm({
|
|
2504
2623
|
"src/app/console/generate/index.mts"() {
|
|
2505
2624
|
"use strict";
|
|
2506
2625
|
init_GenerateControllerCommand();
|
|
2626
|
+
init_GenerateApiDocsCommand();
|
|
2507
2627
|
}
|
|
2508
2628
|
});
|
|
2509
2629
|
|
|
2510
2630
|
// src/app/console/project/CreateProjectCommand.mts
|
|
2511
|
-
var
|
|
2631
|
+
var import_clipanion10, import_change_case_all3, import_path8, fs7, import_url3, import_handlebars3, import_child_process, import_meta3, CreateProjectCommand;
|
|
2512
2632
|
var init_CreateProjectCommand = __esm({
|
|
2513
2633
|
"src/app/console/project/CreateProjectCommand.mts"() {
|
|
2514
2634
|
"use strict";
|
|
2515
|
-
|
|
2635
|
+
import_clipanion10 = require("clipanion");
|
|
2516
2636
|
import_change_case_all3 = require("change-case-all");
|
|
2517
|
-
|
|
2518
|
-
|
|
2637
|
+
import_path8 = __toESM(require("path"), 1);
|
|
2638
|
+
fs7 = __toESM(require("fs/promises"), 1);
|
|
2519
2639
|
import_url3 = require("url");
|
|
2520
2640
|
import_handlebars3 = __toESM(require("handlebars"), 1);
|
|
2521
2641
|
import_child_process = require("child_process");
|
|
2522
2642
|
import_meta3 = {};
|
|
2523
|
-
CreateProjectCommand = class extends
|
|
2643
|
+
CreateProjectCommand = class extends import_clipanion10.Command {
|
|
2524
2644
|
static {
|
|
2525
2645
|
__name(this, "CreateProjectCommand");
|
|
2526
2646
|
}
|
|
2527
2647
|
static paths = [[`create`, `project`]];
|
|
2528
|
-
static usage =
|
|
2648
|
+
static usage = import_clipanion10.Command.Usage({
|
|
2529
2649
|
category: `Project`,
|
|
2530
2650
|
description: `Create a new project`,
|
|
2531
2651
|
details: `
|
|
@@ -2543,13 +2663,13 @@ var init_CreateProjectCommand = __esm({
|
|
|
2543
2663
|
]
|
|
2544
2664
|
]
|
|
2545
2665
|
});
|
|
2546
|
-
projectPath =
|
|
2547
|
-
git =
|
|
2666
|
+
projectPath = import_clipanion10.Option.String("--path", { required: true });
|
|
2667
|
+
git = import_clipanion10.Option.Boolean(`--git`, false, {
|
|
2548
2668
|
description: `Initialize a git repository in the new project`
|
|
2549
2669
|
});
|
|
2550
2670
|
async folderExists(folderPath) {
|
|
2551
2671
|
try {
|
|
2552
|
-
const stats = await
|
|
2672
|
+
const stats = await fs7.stat(folderPath);
|
|
2553
2673
|
return stats.isDirectory();
|
|
2554
2674
|
} catch (error) {
|
|
2555
2675
|
if (error.code === "ENOENT") {
|
|
@@ -2559,28 +2679,28 @@ var init_CreateProjectCommand = __esm({
|
|
|
2559
2679
|
}
|
|
2560
2680
|
}
|
|
2561
2681
|
async execute() {
|
|
2562
|
-
const projectPath =
|
|
2682
|
+
const projectPath = import_path8.default.join(this.projectPath);
|
|
2563
2683
|
try {
|
|
2564
|
-
await
|
|
2684
|
+
await fs7.access(projectPath);
|
|
2565
2685
|
console.error(`Error: Directory ${projectPath} already exists.`);
|
|
2566
2686
|
return 1;
|
|
2567
2687
|
} catch {
|
|
2568
2688
|
}
|
|
2569
|
-
await
|
|
2689
|
+
await fs7.mkdir(projectPath, { recursive: true });
|
|
2570
2690
|
console.log(`Created project directory at: ${projectPath}`);
|
|
2571
|
-
const dirname = typeof __dirname === "undefined" ?
|
|
2572
|
-
let basePath =
|
|
2691
|
+
const dirname = typeof __dirname === "undefined" ? import_path8.default.dirname((0, import_url3.fileURLToPath)(import_meta3.url)) : __dirname;
|
|
2692
|
+
let basePath = import_path8.default.join(dirname, `./base_project`);
|
|
2573
2693
|
if (await this.folderExists(basePath) === false) {
|
|
2574
|
-
basePath =
|
|
2694
|
+
basePath = import_path8.default.join(dirname, `../app/console/project/base_project`);
|
|
2575
2695
|
}
|
|
2576
2696
|
console.log(`Using base project path: ${basePath}`);
|
|
2577
2697
|
const baseProjectPath = basePath;
|
|
2578
2698
|
await this.processTplFolder(baseProjectPath, projectPath, {});
|
|
2579
2699
|
console.log(`Copied base project files to: ${projectPath}`);
|
|
2580
|
-
const packageJsonPath =
|
|
2581
|
-
const packageJson = JSON.parse(await
|
|
2582
|
-
packageJson.name = import_change_case_all3.Case.snake(
|
|
2583
|
-
await
|
|
2700
|
+
const packageJsonPath = import_path8.default.join(projectPath, `package.json`);
|
|
2701
|
+
const packageJson = JSON.parse(await fs7.readFile(packageJsonPath, `utf-8`));
|
|
2702
|
+
packageJson.name = import_change_case_all3.Case.snake(import_path8.default.basename(projectPath));
|
|
2703
|
+
await fs7.writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2));
|
|
2584
2704
|
console.log(`Updated package.json with project name: ${packageJson.name}`);
|
|
2585
2705
|
if (this.git) {
|
|
2586
2706
|
try {
|
|
@@ -2597,12 +2717,12 @@ var init_CreateProjectCommand = __esm({
|
|
|
2597
2717
|
}
|
|
2598
2718
|
}
|
|
2599
2719
|
async processTplFolder(src, dest, data = {}) {
|
|
2600
|
-
const files = await
|
|
2720
|
+
const files = await fs7.readdir(src, { withFileTypes: true });
|
|
2601
2721
|
for (const file of files) {
|
|
2602
|
-
const srcPath =
|
|
2603
|
-
const destPath = file.isFile() && file.name.endsWith(".tpl") ?
|
|
2722
|
+
const srcPath = import_path8.default.join(src, file.name);
|
|
2723
|
+
const destPath = file.isFile() && file.name.endsWith(".tpl") ? import_path8.default.join(dest, file.name.substring(0, file.name.length - 4)) : import_path8.default.join(dest, file.name);
|
|
2604
2724
|
if (file.isDirectory()) {
|
|
2605
|
-
await
|
|
2725
|
+
await fs7.mkdir(destPath, { recursive: true });
|
|
2606
2726
|
await this.processTplFolder(srcPath, destPath, data);
|
|
2607
2727
|
} else if (file.name.endsWith(".tpl")) {
|
|
2608
2728
|
await this.processTplFile(srcPath, destPath, {});
|
|
@@ -2615,30 +2735,30 @@ var init_CreateProjectCommand = __esm({
|
|
|
2615
2735
|
}
|
|
2616
2736
|
async processTplFile(src, dest, data = {}) {
|
|
2617
2737
|
const compiledTemplate = import_handlebars3.default.compile(
|
|
2618
|
-
(await
|
|
2738
|
+
(await fs7.readFile(src)).toString()
|
|
2619
2739
|
);
|
|
2620
2740
|
const template = await compiledTemplate(data);
|
|
2621
|
-
await
|
|
2741
|
+
await fs7.writeFile(dest, template);
|
|
2622
2742
|
}
|
|
2623
2743
|
};
|
|
2624
2744
|
}
|
|
2625
2745
|
});
|
|
2626
2746
|
|
|
2627
2747
|
// src/app/console/queue/GenerateQueueMigrateCommand.mts
|
|
2628
|
-
var
|
|
2748
|
+
var import_clipanion11, import_change_case_all4, import_path9, fs8, import_neko_config7, import_handlebars4, import_url4, import_meta4, GenerateQueueMigrateCommand;
|
|
2629
2749
|
var init_GenerateQueueMigrateCommand = __esm({
|
|
2630
2750
|
"src/app/console/queue/GenerateQueueMigrateCommand.mts"() {
|
|
2631
2751
|
"use strict";
|
|
2632
2752
|
init_facades();
|
|
2633
|
-
|
|
2753
|
+
import_clipanion11 = require("clipanion");
|
|
2634
2754
|
import_change_case_all4 = require("change-case-all");
|
|
2635
|
-
|
|
2636
|
-
|
|
2755
|
+
import_path9 = __toESM(require("path"), 1);
|
|
2756
|
+
fs8 = __toESM(require("fs/promises"), 1);
|
|
2637
2757
|
import_neko_config7 = require("@devbro/neko-config");
|
|
2638
2758
|
import_handlebars4 = __toESM(require("handlebars"), 1);
|
|
2639
2759
|
import_url4 = require("url");
|
|
2640
2760
|
import_meta4 = {};
|
|
2641
|
-
GenerateQueueMigrateCommand = class extends
|
|
2761
|
+
GenerateQueueMigrateCommand = class extends import_clipanion11.Command {
|
|
2642
2762
|
static {
|
|
2643
2763
|
__name(this, "GenerateQueueMigrateCommand");
|
|
2644
2764
|
}
|
|
@@ -2656,20 +2776,20 @@ var init_GenerateQueueMigrateCommand = __esm({
|
|
|
2656
2776
|
const filename = `${year}_${month}_${day}_${secondsOfDay}_${fixed_name}.ts`;
|
|
2657
2777
|
this.context.stdout.write(`creating migration file ${filename}
|
|
2658
2778
|
`);
|
|
2659
|
-
await
|
|
2779
|
+
await fs8.mkdir(import_neko_config7.config.get("migration.path"), { recursive: true });
|
|
2660
2780
|
let dirname = typeof __dirname === "string" ? __dirname : void 0;
|
|
2661
2781
|
if (!dirname) {
|
|
2662
|
-
dirname =
|
|
2782
|
+
dirname = import_path9.default.dirname((0, import_url4.fileURLToPath)(import_meta4.url));
|
|
2663
2783
|
}
|
|
2664
2784
|
const compiledTemplate = import_handlebars4.default.compile(
|
|
2665
|
-
(await
|
|
2785
|
+
(await fs8.readFile(import_path9.default.join(dirname, "./queue_migration.tpl"))).toString()
|
|
2666
2786
|
);
|
|
2667
2787
|
const template = await compiledTemplate({
|
|
2668
2788
|
className: import_change_case_all4.Case.pascal(this.name) + "Migration",
|
|
2669
2789
|
tableName: import_change_case_all4.Case.snake(this.name)
|
|
2670
2790
|
});
|
|
2671
|
-
await
|
|
2672
|
-
|
|
2791
|
+
await fs8.writeFile(
|
|
2792
|
+
import_path9.default.join(import_neko_config7.config.get("migration.path"), filename),
|
|
2673
2793
|
template
|
|
2674
2794
|
);
|
|
2675
2795
|
}
|
|
@@ -2683,6 +2803,7 @@ var console_exports = {};
|
|
|
2683
2803
|
__export(console_exports, {
|
|
2684
2804
|
CreateProjectCommand: () => CreateProjectCommand,
|
|
2685
2805
|
DefaultCommand: () => DefaultCommand,
|
|
2806
|
+
GenerateApiDocsCommand: () => GenerateApiDocsCommand,
|
|
2686
2807
|
GenerateControllerCommand: () => GenerateControllerCommand,
|
|
2687
2808
|
GenerateMigrateCommand: () => GenerateMigrateCommand,
|
|
2688
2809
|
GenerateQueueMigrateCommand: () => GenerateQueueMigrateCommand,
|