MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / generateWshClientApiFile

Function generateWshClientApiFile

cmd/generatets/main-generatets.go:129–162  ·  view source on GitHub ↗
(tsTypeMap map[reflect.Type]string)

Source from the content-addressed store, hash-verified

127}
128
129func 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
164func main() {
165 err := service.ValidateServiceMap()

Callers 1

mainFunction · 0.85

Calls 5

GetOrderedMapKeysFunction · 0.92
WriteFileIfDifferentFunction · 0.92
BytesMethod · 0.80

Tested by

no test coverage detected