@saltify/milky-generator 0.1.1 → 0.2.1
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/README.md +54 -0
- package/dist/cli.mjs +41 -13
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# @saltify/milky-generator
|
|
2
|
+
|
|
3
|
+
Milky 代码生成 CLI,用于基于 Milky IR 生成不同目标格式的规范文件。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @saltify/milky-generator
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
安装后可直接使用命令:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
milkygen
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 命令
|
|
18
|
+
|
|
19
|
+
### 查看可用 generator
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
milkygen list
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
### 生成内容
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
milkygen generate <generator> [--output <file>] [--version <version>]
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
示例:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
milkygen generate openapi
|
|
35
|
+
milkygen generate json-schema -o ./dist/schema.json
|
|
36
|
+
milkygen generate typescript/zod -version latest --output ./generated/schema.ts
|
|
37
|
+
milkygen generate rust/serde --version 1.2.1
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
参数说明:
|
|
41
|
+
|
|
42
|
+
- `--output`, `-o`: 输出文件路径;若未提供,输出到标准输出。
|
|
43
|
+
- `--version`, `-v`: 指定使用的 Milky IR 版本,支持以下值:
|
|
44
|
+
- `latest`: 默认值,使用 npm `latest` 标签对应版本的协议定义。
|
|
45
|
+
- 具体版本号: **只能使用 `1.2.1` 及以上版本**,因为协议定义在 `1.2.1` 版本中才正式发布。
|
|
46
|
+
- `local`: 使用当前包依赖中的本地协议定义。不建议使用,因为可能与发布版本不一致。
|
|
47
|
+
|
|
48
|
+
### 查看 CLI 版本
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
milkygen version
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
注意这里的 version 是指 milkygen CLI 的版本,而不是 Milky IR 协议的版本。Milky IR 协议版本需要通过 `--version` 参数指定,具体说明见上文。
|
package/dist/cli.mjs
CHANGED
|
@@ -58,9 +58,7 @@ function getApiTypeNames(endpoint) {
|
|
|
58
58
|
return {
|
|
59
59
|
pascalEndpoint,
|
|
60
60
|
inputName: `${pascalEndpoint}Input`,
|
|
61
|
-
outputName: `${pascalEndpoint}Output
|
|
62
|
-
requestName: `${pascalEndpoint}Request`,
|
|
63
|
-
responseName: `${pascalEndpoint}Response`
|
|
61
|
+
outputName: `${pascalEndpoint}Output`
|
|
64
62
|
};
|
|
65
63
|
}
|
|
66
64
|
function isSameField(first, second) {
|
|
@@ -885,7 +883,7 @@ const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (i
|
|
|
885
883
|
});
|
|
886
884
|
//#endregion
|
|
887
885
|
//#region ../node_modules/.pnpm/zod@4.3.6/node_modules/zod/v4/core/versions.js
|
|
888
|
-
const version$
|
|
886
|
+
const version$2 = {
|
|
889
887
|
major: 4,
|
|
890
888
|
minor: 3,
|
|
891
889
|
patch: 6
|
|
@@ -897,7 +895,7 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
897
895
|
inst ?? (inst = {});
|
|
898
896
|
inst._zod.def = def;
|
|
899
897
|
inst._zod.bag = inst._zod.bag || {};
|
|
900
|
-
inst._zod.version = version$
|
|
898
|
+
inst._zod.version = version$2;
|
|
901
899
|
const checks = [...inst._zod.def.checks ?? []];
|
|
902
900
|
if (inst._zod.traits.has("$ZodCheck")) checks.unshift(inst);
|
|
903
901
|
for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
|
|
@@ -24919,26 +24917,42 @@ function generateTypeScriptStaticSpec(ir) {
|
|
|
24919
24917
|
const typeNames = getApiTypeNames(api.endpoint);
|
|
24920
24918
|
l(`/** ${api.description} API 请求参数 */`);
|
|
24921
24919
|
if (api.requestFields !== void 0) {
|
|
24922
|
-
l(`export interface ${typeNames.
|
|
24920
|
+
l(`export interface ${typeNames.inputName} {`);
|
|
24923
24921
|
api.requestFields.forEach((field) => {
|
|
24924
24922
|
l(` /** ${field.description} */`);
|
|
24925
24923
|
l(` ${field.name}${field.isOptional ? "?" : ""}: ${getTypeScriptTypeProjection(field)};`);
|
|
24926
24924
|
});
|
|
24927
24925
|
l("}");
|
|
24928
|
-
} else l(`export type ${typeNames.
|
|
24926
|
+
} else l(`export type ${typeNames.inputName} = {};`);
|
|
24929
24927
|
l();
|
|
24930
24928
|
l(`/** ${api.description} API 响应数据 */`);
|
|
24931
24929
|
if (api.responseFields !== void 0) {
|
|
24932
|
-
l(`export interface ${typeNames.
|
|
24930
|
+
l(`export interface ${typeNames.outputName} {`);
|
|
24933
24931
|
api.responseFields.forEach((field) => {
|
|
24934
24932
|
l(` /** ${field.description} */`);
|
|
24935
24933
|
l(` ${field.name}${field.isOptional ? "?" : ""}: ${getTypeScriptTypeProjection(field)};`);
|
|
24936
24934
|
});
|
|
24937
24935
|
l("}");
|
|
24938
|
-
} else l(`export type ${typeNames.
|
|
24936
|
+
} else l(`export type ${typeNames.outputName} = {};`);
|
|
24939
24937
|
l();
|
|
24940
24938
|
});
|
|
24941
24939
|
});
|
|
24940
|
+
l("export interface ApiCategories {");
|
|
24941
|
+
ir.apiCategories.forEach((category) => {
|
|
24942
|
+
l(` /** ${category.name} */`);
|
|
24943
|
+
l(` ${category.key}: {`);
|
|
24944
|
+
category.apis.forEach((api) => {
|
|
24945
|
+
const typeNames = getApiTypeNames(api.endpoint);
|
|
24946
|
+
l(` /** ${api.description} */`);
|
|
24947
|
+
l(` ${api.endpoint}: {`);
|
|
24948
|
+
l(` request: ${typeNames.inputName};`);
|
|
24949
|
+
l(` response: ${typeNames.outputName};`);
|
|
24950
|
+
l(" };");
|
|
24951
|
+
});
|
|
24952
|
+
l(" };");
|
|
24953
|
+
});
|
|
24954
|
+
l("}");
|
|
24955
|
+
l();
|
|
24942
24956
|
return writer.toString();
|
|
24943
24957
|
}
|
|
24944
24958
|
//#endregion
|
|
@@ -25679,12 +25693,12 @@ const apiCategories = [
|
|
|
25679
25693
|
];
|
|
25680
25694
|
//#endregion
|
|
25681
25695
|
//#region ../protocol/package.json
|
|
25682
|
-
var version = "1.2.1
|
|
25696
|
+
var version$1 = "1.2.1";
|
|
25683
25697
|
//#endregion
|
|
25684
25698
|
//#region ../protocol/src/index.ts
|
|
25685
25699
|
const ir = {
|
|
25686
|
-
milkyVersion: version.split(".").slice(0, 2).join("."),
|
|
25687
|
-
milkyPackageVersion: version,
|
|
25700
|
+
milkyVersion: version$1.split(".").slice(0, 2).join("."),
|
|
25701
|
+
milkyPackageVersion: version$1,
|
|
25688
25702
|
commonStructs,
|
|
25689
25703
|
apiCategories
|
|
25690
25704
|
};
|
|
@@ -29284,7 +29298,7 @@ var require_rest = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
29284
29298
|
}
|
|
29285
29299
|
}));
|
|
29286
29300
|
//#endregion
|
|
29287
|
-
//#region
|
|
29301
|
+
//#region package.json
|
|
29288
29302
|
var import_cjs = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
29289
29303
|
/**
|
|
29290
29304
|
* The index module: the entrance to the world of cmd-ts 😎
|
|
@@ -29447,6 +29461,10 @@ var import_cjs = (/* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
29447
29461
|
}
|
|
29448
29462
|
});
|
|
29449
29463
|
})))();
|
|
29464
|
+
var version = "0.2.1";
|
|
29465
|
+
var description = "Milky codegen CLI";
|
|
29466
|
+
//#endregion
|
|
29467
|
+
//#region src/cli.ts
|
|
29450
29468
|
const generators = [
|
|
29451
29469
|
{
|
|
29452
29470
|
canonicalName: "dart/json-serializable",
|
|
@@ -29496,9 +29514,11 @@ function serializeOutput(output) {
|
|
|
29496
29514
|
}
|
|
29497
29515
|
(0, import_cjs.run)((0, import_cjs.subcommands)({
|
|
29498
29516
|
name: "milkygen",
|
|
29517
|
+
description,
|
|
29499
29518
|
cmds: {
|
|
29500
29519
|
generate: (0, import_cjs.command)({
|
|
29501
29520
|
name: "generate",
|
|
29521
|
+
description: "Generate a spec from Milky IR.",
|
|
29502
29522
|
args: {
|
|
29503
29523
|
generator: (0, import_cjs.positional)({
|
|
29504
29524
|
type: import_cjs.string,
|
|
@@ -29551,6 +29571,14 @@ function serializeOutput(output) {
|
|
|
29551
29571
|
console.log(` - ${gen.canonicalName}`);
|
|
29552
29572
|
});
|
|
29553
29573
|
}
|
|
29574
|
+
}),
|
|
29575
|
+
version: (0, import_cjs.command)({
|
|
29576
|
+
name: "version",
|
|
29577
|
+
description: "Print the version of milkygen.",
|
|
29578
|
+
args: {},
|
|
29579
|
+
handler: () => {
|
|
29580
|
+
console.log(version);
|
|
29581
|
+
}
|
|
29554
29582
|
})
|
|
29555
29583
|
}
|
|
29556
29584
|
}), process.argv.slice(2));
|