milkio 0.2.8 → 0.2.10
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/package.json +1 -1
- package/scripts/gen-significant.ts +54 -47
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import ejs from "ejs";
|
|
2
2
|
import { join, dirname } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { mkdirSync } from "node:fs";
|
|
4
4
|
import { cwd, exit } from "node:process";
|
|
5
|
-
import { unlink, writeFile } from "node:fs/promises";
|
|
5
|
+
import { unlink, writeFile, readFile, exists } from "node:fs/promises";
|
|
6
6
|
import { camel, hyphen } from "@poech/camel-hump-under";
|
|
7
7
|
import { $, Glob } from "bun";
|
|
8
8
|
import type { MilkioConfig } from "..";
|
|
@@ -14,19 +14,19 @@ export default async () => {
|
|
|
14
14
|
} catch (error) {} // Maybe the file does not exist
|
|
15
15
|
|
|
16
16
|
// Make sure that the existing directories are all present
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
(await exists(join("generated"))) || mkdirSync(join("generated"));
|
|
18
|
+
(await exists(join("generated", "raw"))) || mkdirSync(join("generated", "raw"));
|
|
19
|
+
(await exists(join("generated", "raw", "apps"))) || mkdirSync(join("generated", "raw", "apps"));
|
|
20
20
|
|
|
21
|
-
if (!
|
|
21
|
+
if (!(await exists(join(cwd(), "milkio.toml")))) return;
|
|
22
22
|
const milkioConfig = (await import(join(cwd(), "milkio.toml"))).default as MilkioConfig;
|
|
23
23
|
|
|
24
24
|
for (const key in milkioConfig.exists) {
|
|
25
25
|
const file = milkioConfig.exists[key];
|
|
26
|
-
if (!
|
|
26
|
+
if (!(await exists(join(cwd(), file.path)))) await writeFile(join(cwd(), file.path), file.content ?? "");
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
if (!
|
|
29
|
+
if (!(await exists(join("generated", "README.md")))) {
|
|
30
30
|
await writeFile(join("generated", "README.md"), "⚠️ All files in this directory are generated by milkio. Please do not modify the content, otherwise your modifications will be overwritten in the next generation.");
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -57,43 +57,47 @@ export default async () => {
|
|
|
57
57
|
|
|
58
58
|
console.time(`File Stage`);
|
|
59
59
|
|
|
60
|
+
const results: Array<Promise<void>> = [];
|
|
60
61
|
for (const pathRaw of appFiles) {
|
|
61
62
|
if (!pathRaw.endsWith(".ts")) continue;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
63
|
+
results.push(
|
|
64
|
+
(async () => {
|
|
65
|
+
const path = pathRaw.replaceAll("\\", "/");
|
|
66
|
+
// const module = await import(/* @vite-ignore */ join(cwd(), "src", "apps", path));
|
|
67
|
+
const moduleCode = await readFile(join(cwd(), "src", "apps", pathRaw), "utf-8");
|
|
68
|
+
|
|
69
|
+
if (/\nexport const api( )*\=( )*defineApi\(\{/.test(moduleCode)) {
|
|
70
|
+
// Exclude disallowed characters
|
|
71
|
+
if (path.includes("_")) {
|
|
72
|
+
console.error(`\n\nPath: "${path.slice(0, -3)}"`);
|
|
73
|
+
console.error(`Do not use "_" in the path. If you want to add a separator between words, please use "-".\n`);
|
|
74
|
+
exit(1);
|
|
75
|
+
}
|
|
76
|
+
if (!/^[a-z0-9/$/-]+$/.test(path.slice(0, -3))) {
|
|
77
|
+
console.error(`\n\nPath: "${path.slice(0, -3)}"`);
|
|
78
|
+
console.error(`The path can only contain lowercase letters, numbers, and "-".\n`);
|
|
79
|
+
exit(1);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
templateVars.apiPaths.push(path);
|
|
83
|
+
|
|
84
|
+
if (/\nexport const test( )*=( )*defineApiTest\(api\,/.test(moduleCode)) {
|
|
85
|
+
templateVars.apiTestPaths.push(path);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// typia
|
|
89
|
+
const filePath = join(cwd(), "generated", "raw", "apps", path);
|
|
90
|
+
const dirPath = join(cwd(), "generated", "raw", "apps", path).split("/").slice(0, -1).join("/");
|
|
91
|
+
if (!(await exists(dirPath))) {
|
|
92
|
+
mkdirSync(dirPath, { recursive: true });
|
|
93
|
+
}
|
|
94
|
+
let importPath = "../../../";
|
|
95
|
+
|
|
96
|
+
for (let i = 0; i < path.split("/").length - 1; i++) {
|
|
97
|
+
importPath = `${importPath}../`;
|
|
98
|
+
}
|
|
99
|
+
importPath = `${importPath}src/apps`;
|
|
100
|
+
const template = `
|
|
97
101
|
import typia from "typia";
|
|
98
102
|
import { _validate, type ExecuteResultFail, type ExecuteResultSuccess } from "milkio";
|
|
99
103
|
import { type TSONEncode } from "@southern-aurora/tson";
|
|
@@ -105,12 +109,15 @@ type ResultsT = Awaited<ReturnType<typeof <%= utils.camel(path.replaceAll('/', '
|
|
|
105
109
|
export const validateResults = async (results: any) => { _validate(typia.validate<TSONEncode<ExecuteResultSuccess<ResultsT> | ExecuteResultFail>>(results)); return typia.json.stringify<TSONEncode<ExecuteResultSuccess<ResultsT> | ExecuteResultFail>>(results); };
|
|
106
110
|
export const randParams = async () => typia.random<ParamsT>();
|
|
107
111
|
`.trim();
|
|
108
|
-
|
|
112
|
+
// export const paramsSchema = typia.json.application<[{ data: ParamsT }], "swagger">();
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
if (!(await exists(dirname(filePath)))) mkdirSync(dirname(filePath), { recursive: true });
|
|
115
|
+
await writeFile(filePath, ejs.render(template, { ...templateVars, path }));
|
|
116
|
+
}
|
|
117
|
+
})(),
|
|
118
|
+
);
|
|
113
119
|
}
|
|
120
|
+
await Promise.all(results);
|
|
114
121
|
|
|
115
122
|
await writeFile(
|
|
116
123
|
join(cwd(), "generated", "api-schema.ts"),
|