diff --git a/README.md b/README.md
index 65f3820..ff5354d 100644
--- a/README.md
+++ b/README.md
@@ -155,8 +155,8 @@ Create a `myPlugin.ts` file:
```ts
// 引用模块
-// import { start } from 'https://deno.land/x/stc@2.7.2/mod.ts'
-import { start } from 'jsr:@loongwoo/stc@^2.7.2'
+// import { start } from 'https://deno.land/x/stc@2.7.3/mod.ts'
+import { start } from 'jsr:@loongwoo/stc@^2.7.3'
// Defining plugins
const myPlugin: IPlugin = {
diff --git a/cover.png b/cover.png
new file mode 100644
index 0000000..90874c6
Binary files /dev/null and b/cover.png differ
diff --git a/cover.svg b/cover.svg
deleted file mode 100644
index 945e374..0000000
--- a/cover.svg
+++ /dev/null
@@ -1 +0,0 @@
-
\ No newline at end of file
diff --git a/deno.json b/deno.json
index 601985f..5ed8294 100644
--- a/deno.json
+++ b/deno.json
@@ -1,16 +1,16 @@
{
"name": "@loongwoo/stc",
- "version": "2.7.2",
+ "version": "2.7.3",
"exports": "./mod.ts",
"tasks": {
"pack": "deno run -A src/pack.ts",
- "dev": "deno task pack && deno run -A --watch=src src/main.ts --url='https://petstore3.swagger.io/api/v3/openapi.json' --lang=ts",
+ "dev": "deno task pack && deno run -A --watch=src src/main.ts --url='https://petstore3.swagger.io/api/v3/openapi.json'",
"serve": "deno run -A --watch=src src/service.ts",
- "version": "echo '2.7.2' > release/version",
+ "version": "echo '2.7.3' > release/version",
"build:npm": "deno run -A src/npm/build.ts",
"build:mac": "deno compile -A --target x86_64-apple-darwin --output release/stc src/main.ts",
"build:mac-m": "deno compile -A --target aarch64-apple-darwin --output release/stc-m src/main.ts",
- "build:win": "deno compile -A --target x86_64-pc-windows-msvc --icon resources/stc.svg --output release/stc-win src/main.ts",
+ "build:win": "deno compile -A --target x86_64-pc-windows-msvc --icon resources/icon.ico --output release/stc-win src/main.ts",
"build:linux": "deno compile -A --target x86_64-unknown-linux-gnu --output release/stc-linux src/main.ts"
},
"lint": {
diff --git a/resources/icon.ico b/resources/icon.ico
new file mode 100644
index 0000000..e9dc8bb
Binary files /dev/null and b/resources/icon.ico differ
diff --git a/src/core.ts b/src/core.ts
index 6a0ea5d..fdc5964 100644
--- a/src/core.ts
+++ b/src/core.ts
@@ -229,25 +229,26 @@ const getMethodName = (
if (!_name) return _name;
const regExp = /[\\{|:](\w+)[\\}]/g;
- const regReplace = /[\\{|:\\}]/g
+ const regReplace = /[\\{|:\\}]/g;
if (regExp.test(_url)) {
// 取最后一个动态路径
const _lastName = _url.match(regExp)?.pop()?.replace(regReplace, "");
// 若 _name 中存在动态路径,判断是否与 _lastName 重复
if (regExp.test(_name)) {
- const _namePath = _name.match(regExp)?.reduce((prev, current) => {
- const _n = current.replace(regReplace, "")
+ const _namePath =
+ _name.match(regExp)?.reduce((prev, current) => {
+ const _n = current.replace(regReplace, "");
- // 移除与 _lastName 重复的
- if (_n !== _lastName) {
- prev.push(_n)
- }
- return prev
- }, []).join('_') ?? ''
+ // 移除与 _lastName 重复的
+ if (_n !== _lastName) {
+ prev.push(_n);
+ }
+ return prev;
+ }, []).join("_") ?? "";
if (_namePath) {
- _name = `${conjunction}_${_namePath}`
+ _name = `${conjunction}_${_namePath}`;
}
}
diff --git a/src/npm/pkg.json b/src/npm/pkg.json
index 05f9dff..011d53a 100644
--- a/src/npm/pkg.json
+++ b/src/npm/pkg.json
@@ -1,6 +1,6 @@
{
"name": "@loongwoo/stc",
- "version": "2.7.2",
+ "version": "2.7.3",
"description": "A tool for converting OpenApi/Swagger/Apifox into code.",
"type": "module",
"module": "esm/mod.js",
diff --git a/src/plugins/typescript/template/enum.eta b/src/plugins/typescript/template/enum.eta
index cca8aee..94f18a7 100644
--- a/src/plugins/typescript/template/enum.eta
+++ b/src/plugins/typescript/template/enum.eta
@@ -1,4 +1,11 @@
+<%
+ const option = it.data.map(item => {
+ const val = it.convertValue(item)
+
+ return typeof val === 'number' ? val : `'${val}'`
+ })
+%>
// #region <%= it.name %>
-export type <%= it.name %> = '<%~ it.data.map(it.convertValue).join("' | '") %>';
+export type <%= it.name %> = <%~ option.join(" | ") %>;
// #endregion
diff --git a/src/plugins/typescript/template/index.ts b/src/plugins/typescript/template/index.ts
index 8f90423..cce6e81 100644
--- a/src/plugins/typescript/template/index.ts
+++ b/src/plugins/typescript/template/index.ts
@@ -1,2 +1,2 @@
// this file is auto generated.
-export default {"actionImport":"import { fetchRuntime } from '<%= it.importPath %>shared/fetchRuntime'\n<% if (it.imports.length) { %>\nimport type { <%= it.imports.join(', ') %> } from '<%= it.importPath %><%= it.typeFileName %>'\n<% } %>","actionMethod":"<% /* API 方法注释 */ %>\n/**\n<% if (it.summary) { %>\n * <%~ it.summary %>\n<% } %>\n<% if (it.summary !== it.description) { %>\n<% if (it.summary && it.description) { %>\n\n *\n<% } %>\n<% if (it.description) { %>\n * @description <%~ it.description %>\n<% } %>\n<% } %>\n<% if (it.params.length) { %>\n\n *\n<% it.params.forEach(param => { %>\n * @param {<%~ param.type %>} <% if (!param.required) { %>[<% } %><%= param.name %><% if (!param.required) { %>]<% } %> - <%~ param.description || param.type %>\n\n<% }) %>\n<% } %>\n * @returns {Promise<<%~ it.responseType %>>} Promise<<%~ it.responseType %>>\n */\n<% /* API 方法 */ %>\nexport const <%= it.methodName %> = (<% it.params.forEach((param, index) => { %>\n<%= param.name %><% if (!param.required) { %>?<% } %>: <%~ param.type %><% if (index < it.params.length - 1) { %>, <% } %>\n<% }) %>): Promise<<%~ it.responseType %>> => fetchRuntime<<%~ it.responseType %>>('<%= it.url %>', '<%= it.method.toUpperCase() %>'<% if (it.params.length) { %>, {\n<% it.params.forEach((param, index) => { %>\n <%= param.category %><% if (param.category === param.name) { %>\n<% } else { %>: <% if (param.category === 'body') { %><%= param.name %><% } else { %>{\n\t\t<%= param.name %>\n\n\t}<% } %>\n<% } %><% if (index < it.params.length - 1) { %>, <% } %>\n\n<% }) %>\n}<% } %>)\n","definitionBody":"<% if (it.propCommit) { %>\n /**\n * <%~ it.propCommit %>\n\n */\n<% } %>\n <%= it.prop.name %><% if (!it.prop.required) { %>?<% } %>: <%~ it.propType %>;","definitionFooter":"}\n// #endregion\n","definitionHeader":"// #region <%= it.defName %>\n\nexport interface <%= it.defName %> {","enum":"// #region <%= it.name %>\n\nexport type <%= it.name %> = '<%~ it.data.map(it.convertValue).join(\"' | '\") %>';\n// #endregion\n"}
\ No newline at end of file
+export default {"actionImport":"import { fetchRuntime } from '<%= it.importPath %>shared/fetchRuntime'\n<% if (it.imports.length) { %>\nimport type { <%= it.imports.join(', ') %> } from '<%= it.importPath %><%= it.typeFileName %>'\n<% } %>","actionMethod":"<% /* API 方法注释 */ %>\n/**\n<% if (it.summary) { %>\n * <%~ it.summary %>\n<% } %>\n<% if (it.summary !== it.description) { %>\n<% if (it.summary && it.description) { %>\n\n *\n<% } %>\n<% if (it.description) { %>\n * @description <%~ it.description %>\n<% } %>\n<% } %>\n<% if (it.params.length) { %>\n\n *\n<% it.params.forEach(param => { %>\n * @param {<%~ param.type %>} <% if (!param.required) { %>[<% } %><%= param.name %><% if (!param.required) { %>]<% } %> - <%~ param.description || param.type %>\n\n<% }) %>\n<% } %>\n * @returns {Promise<<%~ it.responseType %>>} Promise<<%~ it.responseType %>>\n */\n<% /* API 方法 */ %>\nexport const <%= it.methodName %> = (<% it.params.forEach((param, index) => { %>\n<%= param.name %><% if (!param.required) { %>?<% } %>: <%~ param.type %><% if (index < it.params.length - 1) { %>, <% } %>\n<% }) %>): Promise<<%~ it.responseType %>> => fetchRuntime<<%~ it.responseType %>>('<%= it.url %>', '<%= it.method.toUpperCase() %>'<% if (it.params.length) { %>, {\n<% it.params.forEach((param, index) => { %>\n <%= param.category %><% if (param.category === param.name) { %>\n<% } else { %>: <% if (param.category === 'body') { %><%= param.name %><% } else { %>{\n\t\t<%= param.name %>\n\n\t}<% } %>\n<% } %><% if (index < it.params.length - 1) { %>, <% } %>\n\n<% }) %>\n}<% } %>)\n","definitionBody":"<% if (it.propCommit) { %>\n /**\n * <%~ it.propCommit %>\n\n */\n<% } %>\n <%= it.prop.name %><% if (!it.prop.required) { %>?<% } %>: <%~ it.propType %>;","definitionFooter":"}\n// #endregion\n","definitionHeader":"// #region <%= it.defName %>\n\nexport interface <%= it.defName %> {","enum":"<% \n const option = it.data.map(item => { \n const val = it.convertValue(item)\n\n return typeof val === 'number' ? val : `'${val}'`\n })\n%>\n// #region <%= it.name %>\n\nexport type <%= it.name %> = <%~ option.join(\" | \") %>;\n// #endregion\n"}
\ No newline at end of file