satellite/console/.../consoleapi/gen: ensure go generate works
Currently the paths were set relative to the root of the module, however the code did not ensure that we are running relative to the module directory. Also, ensure typescript output corresponds to our styling. Change-Id: I2b3cbd4ea8f2615e35c7b58c6fb8851669c47885
This commit is contained in:
parent
64e5fb7772
commit
1343528a43
@ -105,7 +105,8 @@ func (f *tsGenFile) pf(format string, a ...interface{}) {
|
||||
}
|
||||
|
||||
func (f *tsGenFile) write() error {
|
||||
return os.WriteFile(f.path, []byte(f.result), 0644)
|
||||
content := strings.ReplaceAll(f.result, "\t", " ")
|
||||
return os.WriteFile(f.path, []byte(content), 0644)
|
||||
}
|
||||
|
||||
func (f *tsGenFile) getStructsFromType(t reflect.Type) {
|
||||
|
@ -6,7 +6,8 @@ package main
|
||||
//go:generate go run ./
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"storj.io/common/uuid"
|
||||
@ -146,6 +147,33 @@ func main() {
|
||||
})
|
||||
}
|
||||
|
||||
a.MustWriteGo("satellite/console/consoleweb/consoleapi/api.gen.go")
|
||||
a.MustWriteTS(fmt.Sprintf("web/satellite/src/api/%s.gen.ts", a.Version))
|
||||
modroot := findModuleRootDir()
|
||||
a.MustWriteGo(filepath.Join(modroot, "satellite", "console", "consoleweb", "consoleapi", "api.gen.go"))
|
||||
a.MustWriteTS(filepath.Join(modroot, "web", "satellite", "src", "api", a.Version+".gen.ts"))
|
||||
}
|
||||
|
||||
func findModuleRootDir() string {
|
||||
dir, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic("unable to find current working directory")
|
||||
}
|
||||
start := dir
|
||||
|
||||
for i := 0; i < 100; i++ {
|
||||
if fileExists(filepath.Join(dir, "go.mod")) {
|
||||
return dir
|
||||
}
|
||||
next := filepath.Dir(dir)
|
||||
if next == dir {
|
||||
break
|
||||
}
|
||||
dir = next
|
||||
}
|
||||
|
||||
panic("unable to find go.mod starting from " + start)
|
||||
}
|
||||
|
||||
func fileExists(path string) bool {
|
||||
_, err := os.Stat(path)
|
||||
return err == nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user