milkio 0.0.32 → 0.0.34
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/index.ts +1 -1
- package/package.json +1 -1
- package/templates/api.ts +0 -45
- package/utils/create-template.ts +0 -42
package/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from "./utils/create-ulid"
|
|
|
7
7
|
export * from "./utils/env-to-string"
|
|
8
8
|
export * from "./utils/env-to-number"
|
|
9
9
|
export * from "./utils/env-to-boolean"
|
|
10
|
-
export * from "./utils/create-template"
|
|
10
|
+
// export * from "./utils/create-template"
|
|
11
11
|
export * from "./utils/header-to-plain-object"
|
|
12
12
|
|
|
13
13
|
// defines
|
package/package.json
CHANGED
package/templates/api.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { createTemplate } from "../utils/create-template"
|
|
2
|
-
import { join } from "path"
|
|
3
|
-
|
|
4
|
-
await createTemplate(async (tools) => {
|
|
5
|
-
return {
|
|
6
|
-
path: join(tools.directory, `${tools.hyphen(tools.name)}.ts`),
|
|
7
|
-
content: `
|
|
8
|
-
import { defineApi, defineApiTest } from "milkio"
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* ${tools.name}
|
|
12
|
-
*/
|
|
13
|
-
export const api = defineApi({
|
|
14
|
-
meta: {
|
|
15
|
-
// your meta..
|
|
16
|
-
},
|
|
17
|
-
async action(
|
|
18
|
-
params: {
|
|
19
|
-
// your params..
|
|
20
|
-
},
|
|
21
|
-
context
|
|
22
|
-
) {
|
|
23
|
-
const message = \`hello world!\`
|
|
24
|
-
|
|
25
|
-
// your code..
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
say: message
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
export const test = defineApiTest(api, [
|
|
34
|
-
{
|
|
35
|
-
name: "Basic",
|
|
36
|
-
handler: async (test) => {
|
|
37
|
-
const result = await test.execute(await test.randParams())
|
|
38
|
-
|
|
39
|
-
if (!result.success) return test.reject(\`The result was not success\`)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
])
|
|
43
|
-
`.trim()
|
|
44
|
-
}
|
|
45
|
-
})
|
package/utils/create-template.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { argv } from "node:process"
|
|
2
|
-
import { camel, hump, hyphen } from "@poech/camel-hump-under"
|
|
3
|
-
|
|
4
|
-
export type CreateTemplateTools = {
|
|
5
|
-
name: string;
|
|
6
|
-
directory: string;
|
|
7
|
-
src: () => string;
|
|
8
|
-
camel: (str: string) => string;
|
|
9
|
-
hump: (str: string) => string;
|
|
10
|
-
hyphen: (str: string) => string;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export type CreateTemplateFn = (tools: CreateTemplateTools) =>
|
|
14
|
-
| {
|
|
15
|
-
path: string;
|
|
16
|
-
content: string;
|
|
17
|
-
}
|
|
18
|
-
| Promise<{
|
|
19
|
-
path: string;
|
|
20
|
-
content: string;
|
|
21
|
-
}>;
|
|
22
|
-
|
|
23
|
-
export async function createTemplate(fn: CreateTemplateFn) {
|
|
24
|
-
const tools = {
|
|
25
|
-
name: argv[2],
|
|
26
|
-
directory: argv[3],
|
|
27
|
-
src: () => {
|
|
28
|
-
const patharr = argv[3].split("/")
|
|
29
|
-
const i = patharr.length - patharr.findIndex((str: string) => str.startsWith("src")) - 1
|
|
30
|
-
let path = ''
|
|
31
|
-
for (let j = 0; j < i; j++) {
|
|
32
|
-
path += "../"
|
|
33
|
-
}
|
|
34
|
-
return path
|
|
35
|
-
},
|
|
36
|
-
camel: (str: string) => camel(str).replaceAll("-", "").replaceAll("_", ""),
|
|
37
|
-
hump: (str: string) => hump(str).replaceAll("-", "").replaceAll("_", ""),
|
|
38
|
-
hyphen: (str: string) => hyphen(str).replaceAll("_", "")
|
|
39
|
-
}
|
|
40
|
-
const file = await fn(tools)
|
|
41
|
-
await Bun.write(file.path, file.content)
|
|
42
|
-
}
|