Skip to content

Commit

Permalink
Merge pull request #96 from long-woo/dev
Browse files Browse the repository at this point in the history
release: v2.7.3
  • Loading branch information
long-woo authored Dec 13, 2024
2 parents 002a7ce + dd760a2 commit 57f705a
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ Create a `myPlugin.ts` file:

```ts
// 引用模块
// import { start } from 'https://deno.land/x/[email protected].2/mod.ts'
import { start } from 'jsr:@loongwoo/stc@^2.7.2'
// import { start } from 'https://deno.land/x/[email protected].3/mod.ts'
import { start } from 'jsr:@loongwoo/stc@^2.7.3'

// Defining plugins
const myPlugin: IPlugin = {
Expand Down
Binary file added cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion cover.svg

This file was deleted.

8 changes: 4 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
Binary file added resources/icon.ico
Binary file not shown.
21 changes: 11 additions & 10 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string[]>((prev, current) => {
const _n = current.replace(regReplace, "")
const _namePath =
_name.match(regExp)?.reduce<string[]>((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}`;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/npm/pkg.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/typescript/template/enum.eta
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/plugins/typescript/template/index.ts
Original file line number Diff line number Diff line change
@@ -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"}
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"}

0 comments on commit 57f705a

Please sign in to comment.