MCPcopy Create free account
hub / github.com/cogentcore/core / TranspileFile

Method TranspileFile

shell/shell.go:320–338  ·  view source on GitHub ↗

TranspileFile transpiles the given input cosh file to the given output Go file, adding package main and func main declarations.

(in string, out string)

Source from the content-addressed store, hash-verified

318// TranspileFile transpiles the given input cosh file to the given output Go file,
319// adding package main and func main declarations.
320func (sh *Shell) TranspileFile(in string, out string) error {
321 err := sh.TranspileCodeFromFile(in)
322 if err != nil {
323 return err
324 }
325 sh.Lines = slices.Insert(sh.Lines, 0, "package main", "", "func main() {", "shell := shell.NewShell()")
326 sh.Lines = append(sh.Lines, "}")
327 src := []byte(sh.Code())
328 // fmt.Println(string(src))
329 res, err := imports.Process(out, src, nil)
330 if err != nil {
331 res = src
332 slog.Error(err.Error())
333 } else {
334 err = sh.DepthError()
335 }
336 werr := os.WriteFile(out, res, 0666)
337 return errors.Join(err, werr)
338}
339
340// AddError adds the given error to the error stack if it is non-nil,
341// and calls the Cancel function if set, to stop execution.

Callers 1

BuildFunction · 0.80

Calls 6

TranspileCodeFromFileMethod · 0.95
CodeMethod · 0.95
DepthErrorMethod · 0.95
JoinFunction · 0.92
ErrorMethod · 0.65
InsertMethod · 0.45

Tested by

no test coverage detected