(tsTypeMap map[reflect.Type]string)
| 127 | } |
| 128 | |
| 129 | func generateWshClientApiFile(tsTypeMap map[reflect.Type]string) error { |
| 130 | fileName := "frontend/app/store/wshclientapi.ts" |
| 131 | var buf bytes.Buffer |
| 132 | declMap := wshrpc.GenerateWshCommandDeclMap() |
| 133 | fmt.Fprintf(os.Stderr, "generating wshclientapi file to %s\n", fileName) |
| 134 | fmt.Fprintf(&buf, "// Copyright 2026, Command Line Inc.\n") |
| 135 | fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n") |
| 136 | fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n") |
| 137 | fmt.Fprintf(&buf, "import { WshClient } from \"./wshclient\";\n\n") |
| 138 | fmt.Fprintf(&buf, "export interface MockRpcClient {\n") |
| 139 | fmt.Fprintf(&buf, " mockWshRpcCall(client: WshClient, command: string, data: any, opts?: RpcOpts): Promise<any>;\n") |
| 140 | fmt.Fprintf(&buf, " mockWshRpcStream(client: WshClient, command: string, data: any, opts?: RpcOpts): AsyncGenerator<any, void, boolean>;\n") |
| 141 | fmt.Fprintf(&buf, "}\n\n") |
| 142 | orderedKeys := utilfn.GetOrderedMapKeys(declMap) |
| 143 | fmt.Fprintf(&buf, "// WshServerCommandToDeclMap\n") |
| 144 | fmt.Fprintf(&buf, "export class RpcApiType {\n") |
| 145 | fmt.Fprintf(&buf, " mockClient: MockRpcClient = null;\n\n") |
| 146 | fmt.Fprintf(&buf, " setMockRpcClient(client: MockRpcClient): void {\n") |
| 147 | fmt.Fprintf(&buf, " this.mockClient = client;\n") |
| 148 | fmt.Fprintf(&buf, " }\n\n") |
| 149 | for _, methodDecl := range orderedKeys { |
| 150 | methodDecl := declMap[methodDecl] |
| 151 | methodStr := tsgen.GenerateWshClientApiMethod(methodDecl, tsTypeMap) |
| 152 | fmt.Fprint(&buf, methodStr) |
| 153 | fmt.Fprintf(&buf, "\n") |
| 154 | } |
| 155 | fmt.Fprintf(&buf, "}\n\n") |
| 156 | fmt.Fprintf(&buf, "export const RpcApi = new RpcApiType();\n") |
| 157 | written, err := utilfn.WriteFileIfDifferent(fileName, buf.Bytes()) |
| 158 | if !written { |
| 159 | fmt.Fprintf(os.Stderr, "no changes to %s\n", fileName) |
| 160 | } |
| 161 | return err |
| 162 | } |
| 163 | |
| 164 | func main() { |
| 165 | err := service.ValidateServiceMap() |
no test coverage detected