Skip to content

Commit 7cf0007

Browse files
authored
Merge pull request #114 from long-woo/dev
- 插件示例完善,增加 ga4 - 单个 API 支持 errorIgnore 配置
2 parents 7056b74 + 4d4ac86 commit 7cf0007

File tree

23 files changed

+170
-41
lines changed

23 files changed

+170
-41
lines changed

.vscode/settings.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
"[javascript]": {
1313
"editor.defaultFormatter": "denoland.vscode-deno"
1414
},
15-
"[typescript]": {
16-
"editor.defaultFormatter": "denoland.vscode-deno"
17-
},
1815
"[json]": {
1916
"editor.defaultFormatter": "denoland.vscode-deno"
2017
},

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ Create a `myPlugin.ts` file:
153153

154154
```ts
155155
// 引用模块
156-
// import { start } from 'https://deno.land/x/stc@2.13.1/mod.ts'
157-
import { start } from 'jsr:@lonu/stc@^2.13.1'
156+
// import { start } from 'https://deno.land/x/stc@2.14.0/mod.ts'
157+
import { start } from 'jsr:@lonu/stc@^2.14.0'
158158

159159
// Defining plugins
160160
const myPlugin: IPlugin = {

deno.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"name": "@lonu/stc",
3-
"version": "2.13.1",
3+
"version": "2.14.0",
44
"exports": "./mod.ts",
55
"tasks": {
66
"pack": "deno run -A src/pack.ts",
77
"dev": "deno task pack && deno run -A --watch=src src/main.ts --url='https://petstore3.swagger.io/api/v3/openapi.json'",
88
"serve": "deno run -A --watch=src src/service.ts",
9-
"version": "echo '2.13.1' > release/version",
9+
"version": "echo '2.14.0' > release/version",
1010
"build:npm": "deno run -A src/npm/build.ts",
1111
"build:mac": "deno compile -A --target x86_64-apple-darwin --output release/stc src/main.ts",
1212
"build:mac-m": "deno compile -A --target aarch64-apple-darwin --output release/stc-m src/main.ts",
@@ -61,6 +61,11 @@
6161
"@std/datetime": "jsr:@std/datetime@^0.225.1",
6262
"@std/fmt": "jsr:@std/fmt@^1.0.1",
6363
"@std/fs": "jsr:@std/fs@^1.0.2",
64-
"diff": "npm:diff@^7.0.0"
64+
"diff": "npm:diff@^7.0.0",
65+
"analytics": "npm:analytics@0.8.16",
66+
"@analytics/google-analytics": "npm:@analytics/google-analytics@1.1.0",
67+
"micromatch": "npm:micromatch@4.0.8",
68+
"i18next":"npm:i18next@^23.14.0",
69+
"oxc-transform": "npm:oxc-transform@^0.63.0"
6570
}
6671
}

examples/my-plugin/index.mjs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { start } from "@lonu/stc";
22

3+
// 导入解析 eta 文件
4+
import { buildEta } from "@lonu/stc/plugin/common";
5+
36
// 导入解析方法
47
// import { parserDefinition } from "@lonu/stc/plugin/definition";
58
// import { parserActions } from '@lonu/stc/plugin/action'
@@ -8,10 +11,33 @@ import { start } from "@lonu/stc";
811
const myPlugin = {
912
name: "stc:myPlugin",
1013
lang: "cs",
11-
setup(context) {
14+
async setup(context) {
15+
// template 的文件是伪代码。
16+
const template = await buildEta("./template");
17+
1218
console.log(context);
19+
1320
// 类型映射
14-
return {};
21+
return {
22+
unknownType: "",
23+
typeMap(func, type) {
24+
const _newType =
25+
type && func(type, undefined, undefined, pluginSetup) ||
26+
pluginSetup.unknownType;
27+
28+
return {
29+
string: "string",
30+
integer: "int",
31+
boolean: "boolean",
32+
array: `List<${_newType}>`,
33+
object: "object",
34+
file: "File",
35+
null: "null",
36+
bool: "boolean",
37+
};
38+
},
39+
template,
40+
};
1541
},
1642
};
1743

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// using ...
2+
3+
<% if (it.imports.length) { %>
4+
import '<%= it.importPath %><%= it.typeFileName %>.dart';
5+
<% } %>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/// <%= it.description %>
2+
<% if (it.deprecated) { %>
3+
@available(*, deprecated, message: "This API is deprecated")
4+
<% } %>
5+
public func <%= it.name %>(
6+
<% it.parameters.forEach(function(param, index) { %>
7+
<%= param.name %>: <%= param.type %><% if (param.optional) { %>?<% } %><% if (index < it.parameters.length - 1) { %>,<% } %>
8+
<% }) %>
9+
) async throws -> <%= it.responseType %> {
10+
<% if (it.pathParams && it.pathParams.length > 0) { %>
11+
let pathParams: [String: String] = [
12+
<% it.pathParams.forEach(function(param, index) { %>
13+
"<%= param.name %>": String(<%= param.value %>)<% if (index < it.pathParams.length - 1) { %>,<% } %>
14+
<% }) %>
15+
]
16+
let parsedUrl = "<%= it.url %>".parsePathParams(pathParams)
17+
<% } %>
18+
19+
<% if (it.requestBody) { %>
20+
let params: [String: Any] = <%= it.requestBody %>
21+
<% } %>
22+
23+
let config = APIClientConfig(
24+
url: <% if (it.pathParams && it.pathParams.length > 0) { %>parsedUrl<% } else { %>"<%= it.url %>"<% } %>,
25+
method: "<%= it.method %>"<% if (it.requestBody) { %>,
26+
params: params<% } %>
27+
)
28+
29+
return try await APIClient.shared.request(config, type: <%= it.responseType %>.self)
30+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/// <%= it.description %>
2+
public struct <%= it.name %>: Codable {
3+
<% it.properties.forEach(function(item) { %>
4+
/// <%= item.description %>
5+
public let <%= item.name %>: <%= item.type %><% if (item.optional) { %>?<% } %>
6+
<% }) %>
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// MARK: - End of Models
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class <%= it.defName %> {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/// <%= it.description %>
2+
enum <%= it.name %> {
3+
<%= it.data.map(it.convertValue).join(",\n\t")%>
4+
}

0 commit comments

Comments
 (0)