Skip to content

Commit

Permalink
Merge pull request #103 from long-woo/dev
Browse files Browse the repository at this point in the history
release:2.10.0
  • Loading branch information
long-woo authored Jan 23, 2025
2 parents ccafa6f + 43c4b89 commit 2552163
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ App<IAppOption>({
| filter | f | string[] | | Filter interfaces. Interfaces that meet the filter conditions will be generated. Example: `--filter "/pet*"`, generate an interface for `/pet`, and support multiple `--filter`. For more usage information, please refer to [micromatch](https://github.com/micromatch/micromatch) |
| conjunction | c | string | By | The method's connector, the default value is `By`. |
| actionIndex | | number | -1 | The method name index, the default value is `-1`. |
| shared | | boolean | true | Whether to generate the shared directory. [default: true]. |
| version | v | boolean | | Output version information. |
| help | h | boolean | | Output help information. |

Expand All @@ -152,7 +153,7 @@ Create a `myPlugin.ts` file:
```ts
// 引用模块
// import { start } from 'https://deno.land/x/stc@2.7.1/mod.ts'
import { start } from 'jsr:@lonu/stc@^2.9.0'
import { start } from 'jsr:@lonu/stc@^2.10.0'

// Defining plugins
const myPlugin: IPlugin = {
Expand Down
6 changes: 3 additions & 3 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "@lonu/stc",
"version": "2.9.0",
"version": "2.10.0",
"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://cone.devcn.gfk.com/metadata/api/swagger/v1/swagger.json'",
"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.9.0' > release/version",
"version": "echo '2.10.0' > 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",
Expand Down
6 changes: 5 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ ${getT("$t(cli.option)")}
--tag ${getT("$t(cli.option_tag)")}
-c, --conjunction ${getT("$t(cli.option_conjunction)")}
--actionIndex ${getT("$t(cli.option_actionIndex)")}
--shared ${getT("$t(cli.option_shared)")}
-v, --version ${getT("$t(cli.option_version)")}
${getT("$t(cli.example)")}
Expand All @@ -176,7 +177,7 @@ ${getT("$t(cli.example)")}
export const main = async (): Promise<ISwaggerOptions> => {
// 定义命令行参数和选项的配置
const argsConfig: ParseOptions = {
boolean: ["help", "version"],
boolean: ["help", "version", "shared"],
string: [
"url",
"outDir",
Expand All @@ -201,6 +202,8 @@ export const main = async (): Promise<ISwaggerOptions> => {
lang: "ts",
client: "axios",
conjunction: "By",
actionIndex: "-1",
shared: true,
},
unknown: (arg: string) => {
Logs.error(getT("$t(cli.unknownOption)", { arg }));
Expand Down Expand Up @@ -243,5 +246,6 @@ export const main = async (): Promise<ISwaggerOptions> => {
filter: args.filter,
conjunction: args.conjunction,
actionIndex: args.actionIndex,
shared: args.shared,
};
};
3 changes: 2 additions & 1 deletion src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"option_tag": "Specify tags from the interface url for filenames, the first one of tags is read by default.",
"option_version": "View version information.",
"option_conjunction": "Conjunction of method name. [default: \"By\"].",
"option_actionIndex": "Method name index. [default: -1]."
"option_actionIndex": "Method name index. [default: -1].",
"option_shared": "Whether to generate the shared directory. [default: true]."
},
"plugin": {
"name": "Load plugin {{name}}",
Expand Down
3 changes: 2 additions & 1 deletion src/i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
"option_tag": "从接口 url 中指定标签,用于文件名,默认读取 tags 的第一个。",
"option_version": "显示版本信息。",
"option_conjunction": "方法名的连接词。 [默认: \"By\"]。",
"option_actionIndex": "方法名的索引。 [默认: -1]。"
"option_actionIndex": "方法名的索引。 [默认: -1]。",
"option_shared": "是否生成 shared 目录。 [默认: true]。"
},
"plugin": {
"name": "加载插件 {{name}}",
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": "@lonu/stc",
"version": "2.9.0",
"version": "2.10.0",
"description": "A tool for converting OpenApi/Swagger/Apifox into code.",
"type": "module",
"module": "esm/mod.js",
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/dart/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const DartPlugin: IPlugin = {
};
},
onEnd() {
if (!pluginOptions.shared) return;

createFile(
`${pluginOptions.outDir}/shared/api_client_base.${this.lang}`,
shared.api_client_base,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/javascript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const JavaScriptPlugin: IPlugin = {
};
},
onEnd() {
if (!pluginOptions.shared) return;

// 创建运行时需要的文件
const _baseFile = oxcTransform(shared.apiClientBase);
const _parserFetchRuntime = renderEtaString(
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/swift/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export const SwiftPlugin: IPlugin = {
};
},
onEnd() {
if (!pluginOptions.shared) return;

// Copy template files to output directory
createFile(
`${pluginOptions.outDir}/shared/APIClientBase.${this.lang}`,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/typescript/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const TypeScriptPlugin: IPlugin = {
},

onEnd() {
if (!pluginOptions.shared) return;

// 创建运行时需要的文件
const _fetchRuntimeFileContent = renderEtaString(
shared.fetchRuntime,
Expand Down
8 changes: 6 additions & 2 deletions src/swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,17 @@ export interface ISwaggerOptions {
*/
readonly tag?: number;
/**
* 方法名的连接词,默认值为 By
* 方法名的连接。默认:By
*/
readonly conjunction?: string;
/**
* 方法名的下标,默认值为 -1
* 方法名的下标。默认:-1
*/
readonly actionIndex?: number;
/**
* 是否生成 shared 目录。默认:true
*/
readonly shared?: boolean;
}

export interface IDefinitionNameMapping {
Expand Down
16 changes: 16 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,19 @@ Deno.test("actionIndex", async () => {

assertEquals(0, code);
});

Deno.test("shared", async () => {
const command = new Deno.Command("deno", {
args: [
"run",
"-A",
"src/main.ts",
"--url=./test/demo1.json",
"--shared=false",
],
});

const { code } = await command.output();

assertEquals(0, code);
});

0 comments on commit 2552163

Please sign in to comment.