mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
better conditional taskfile running (#864)
still builds the server, but fixes the generate steps and wsh
This commit is contained in:
parent
df57896e2b
commit
68dfc4ab90
37
Taskfile.yml
37
Taskfile.yml
@ -59,6 +59,9 @@ tasks:
|
||||
- build:server:linux
|
||||
- build:server:macos
|
||||
- build:server:windows
|
||||
sources:
|
||||
- "cmd/server/*.go"
|
||||
- "pkg/**/*.go"
|
||||
|
||||
build:server:macos:
|
||||
desc: Build the wavesrv component for macOS (Darwin) platforms (generates artifacts for both arm64 and amd64).
|
||||
@ -70,6 +73,9 @@ tasks:
|
||||
- task: build:server:internal
|
||||
vars:
|
||||
ARCHS: arm64,amd64
|
||||
sources:
|
||||
- "cmd/server/*.go"
|
||||
- "pkg/**/*.go"
|
||||
|
||||
build:server:windows:
|
||||
desc: Build the wavesrv component for Windows platforms (only generates artifacts for the current architecture).
|
||||
@ -82,6 +88,9 @@ tasks:
|
||||
vars:
|
||||
ARCHS:
|
||||
sh: echo {{if eq "arm" ARCH}}arm64{{else}}{{ARCH}}{{end}}
|
||||
sources:
|
||||
- "cmd/server/*.go"
|
||||
- "pkg/**/*.go"
|
||||
|
||||
build:server:linux:
|
||||
desc: Build the wavesrv component for Linux platforms (only generates artifacts for the current architecture).
|
||||
@ -96,6 +105,9 @@ tasks:
|
||||
sh: echo {{if eq "arm" ARCH}}arm64{{else}}{{ARCH}}{{end}}
|
||||
GO_ENV_VARS:
|
||||
sh: echo "{{if eq "amd64" ARCH}}CC=\"zig cc -target x86_64-linux-gnu.2.28\"{{end}}"
|
||||
sources:
|
||||
- "cmd/server/*.go"
|
||||
- "pkg/**/*.go"
|
||||
|
||||
build:server:internal:
|
||||
requires:
|
||||
@ -147,6 +159,11 @@ tasks:
|
||||
GOARCH: arm64
|
||||
deps:
|
||||
- generate
|
||||
sources:
|
||||
- "cmd/wsh/**/*.go"
|
||||
- "pkg/**/*.go"
|
||||
- go.mod
|
||||
- go.sum
|
||||
|
||||
dev:installwsh:
|
||||
desc: quick shortcut to rebuild wsh and install for macos arm64
|
||||
@ -174,6 +191,8 @@ tasks:
|
||||
sources:
|
||||
- "cmd/wsh/**/*.go"
|
||||
- "pkg/**/*.go"
|
||||
- go.mod
|
||||
- go.sum
|
||||
generates:
|
||||
- dist/bin/wsh-{{.VERSION}}-{{.GOOS}}.{{.NORMALIZEDARCH}}{{.EXT}}
|
||||
cmd: (CGO_ENABLED=0 GOOS={{.GOOS}} GOARCH={{.GOARCH}} go build -ldflags="-s -w -X main.BuildTime=$({{.DATE}} +'%Y%m%d%H%M') -X main.WaveVersion={{.VERSION}}" -o dist/bin/wsh-{{.VERSION}}-{{.GOOS}}.{{.NORMALIZEDARCH}}{{.EXT}} cmd/wsh/main-wsh.go)
|
||||
@ -189,20 +208,12 @@ tasks:
|
||||
sources:
|
||||
- "cmd/generatego/*.go"
|
||||
- "cmd/generatets/*.go"
|
||||
- "pkg/service/**/*.go"
|
||||
- "pkg/waveobj/*.go"
|
||||
- "pkg/wconfig/**/*.go"
|
||||
- "pkg/wstore/*.go"
|
||||
- "pkg/wshrpc/**/*.go"
|
||||
- "pkg/tsgen/**/*.go"
|
||||
- "pkg/gogen/**/*.go"
|
||||
- "pkg/wconfig/**/*.go"
|
||||
- "pkg/eventbus/eventbus.go"
|
||||
generates:
|
||||
- frontend/types/gotypes.d.ts
|
||||
- "pkg/**/*.go"
|
||||
sources-excluce:
|
||||
- pkg/wshrpc/wshclient/wshclient.go
|
||||
- frontend/app/store/services.ts
|
||||
- frontend/app/store/wshserver.ts
|
||||
- pkg/waveobj/metaconsts.go
|
||||
- pkg/wconfig/metaconsts.go
|
||||
# remove the "generates" key since they are conditionally generated (otherwise task will re-run every time)
|
||||
|
||||
version:
|
||||
desc: Get the current package version, or bump version if args are present. To pass args to `version.cjs`, add them after `--`. See `version.cjs` for usage definitions for the arguments.
|
||||
|
@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/wavetermdev/waveterm/pkg/gogen"
|
||||
"github.com/wavetermdev/waveterm/pkg/tsgen"
|
||||
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
|
||||
"github.com/wavetermdev/waveterm/pkg/waveobj"
|
||||
"github.com/wavetermdev/waveterm/pkg/wconfig"
|
||||
@ -42,7 +43,7 @@ func GenerateWshClient() {
|
||||
}
|
||||
}
|
||||
buf.WriteString("\n")
|
||||
err := os.WriteFile(WshClientFileName, []byte(buf.String()), 0644)
|
||||
err := tsgen.WriteFileIfChanged(WshClientFileName, []byte(buf.String()), true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -54,7 +55,7 @@ func GenerateWaveObjMetaConsts() {
|
||||
gogen.GenerateBoilerplate(&buf, "waveobj", []string{})
|
||||
gogen.GenerateMetaMapConsts(&buf, "MetaKey_", reflect.TypeOf(waveobj.MetaTSType{}))
|
||||
buf.WriteString("\n")
|
||||
err := os.WriteFile(WaveObjMetaConstsFileName, []byte(buf.String()), 0644)
|
||||
err := tsgen.WriteFileIfChanged(WaveObjMetaConstsFileName, []byte(buf.String()), true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -66,7 +67,7 @@ func GenerateSettingsMetaConsts() {
|
||||
gogen.GenerateBoilerplate(&buf, "wconfig", []string{})
|
||||
gogen.GenerateMetaMapConsts(&buf, "ConfigKey_", reflect.TypeOf(wconfig.SettingsType{}))
|
||||
buf.WriteString("\n")
|
||||
err := os.WriteFile(SettingsMetaConstsFileName, []byte(buf.String()), 0644)
|
||||
err := tsgen.WriteFileIfChanged(SettingsMetaConstsFileName, []byte(buf.String()), true)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -17,14 +17,11 @@ import (
|
||||
)
|
||||
|
||||
func generateTypesFile(tsTypesMap map[reflect.Type]string) error {
|
||||
fd, err := os.Create("frontend/types/gotypes.d.ts")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fd.Close()
|
||||
fmt.Fprintf(os.Stderr, "generating types file to %s\n", fd.Name())
|
||||
var buf strings.Builder
|
||||
fileName := "frontend/types/gotypes.d.ts"
|
||||
fmt.Fprintf(os.Stderr, "generating types file to %s\n", fileName)
|
||||
tsgen.GenerateWaveObjTypes(tsTypesMap)
|
||||
err = tsgen.GenerateServiceTypes(tsTypesMap)
|
||||
err := tsgen.GenerateServiceTypes(tsTypesMap)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error generating service types: %v\n", err)
|
||||
os.Exit(1)
|
||||
@ -33,10 +30,10 @@ func generateTypesFile(tsTypesMap map[reflect.Type]string) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("error generating wsh server types: %w", err)
|
||||
}
|
||||
fmt.Fprintf(fd, "// Copyright 2024, Command Line Inc.\n")
|
||||
fmt.Fprintf(fd, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
||||
fmt.Fprintf(fd, "// generated by cmd/generate/main-generatets.go\n\n")
|
||||
fmt.Fprintf(fd, "declare global {\n\n")
|
||||
fmt.Fprintf(&buf, "// Copyright 2024, Command Line Inc.\n")
|
||||
fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
||||
fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n")
|
||||
fmt.Fprintf(&buf, "declare global {\n\n")
|
||||
var keys []reflect.Type
|
||||
for key := range tsTypesMap {
|
||||
keys = append(keys, key)
|
||||
@ -48,62 +45,68 @@ func generateTypesFile(tsTypesMap map[reflect.Type]string) error {
|
||||
})
|
||||
for _, key := range keys {
|
||||
// don't output generic types
|
||||
if strings.Index(key.Name(), "[") != -1 {
|
||||
if strings.Contains(key.Name(), "[") {
|
||||
continue
|
||||
}
|
||||
tsCode := tsTypesMap[key]
|
||||
istr := utilfn.IndentString(" ", tsCode)
|
||||
fmt.Fprint(fd, istr)
|
||||
fmt.Fprint(&buf, istr)
|
||||
}
|
||||
fmt.Fprintf(&buf, "}\n\n")
|
||||
fmt.Fprintf(&buf, "export {}\n")
|
||||
err = tsgen.WriteFileIfChanged(fileName, []byte(buf.String()), true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(fd, "}\n\n")
|
||||
fmt.Fprintf(fd, "export {}\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateServicesFile(tsTypesMap map[reflect.Type]string) error {
|
||||
fd, err := os.Create("frontend/app/store/services.ts")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fd.Close()
|
||||
fmt.Fprintf(os.Stderr, "generating services file to %s\n", fd.Name())
|
||||
fmt.Fprintf(fd, "// Copyright 2024, Command Line Inc.\n")
|
||||
fmt.Fprintf(fd, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
||||
fmt.Fprintf(fd, "// generated by cmd/generate/main-generatets.go\n\n")
|
||||
fmt.Fprintf(fd, "import * as WOS from \"./wos\";\n\n")
|
||||
var buf strings.Builder
|
||||
fileName := "frontend/app/store/services.ts"
|
||||
fmt.Fprintf(os.Stderr, "generating services file to %s\n", fileName)
|
||||
fmt.Fprintf(&buf, "// Copyright 2024, Command Line Inc.\n")
|
||||
fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
||||
fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n")
|
||||
fmt.Fprintf(&buf, "import * as WOS from \"./wos\";\n\n")
|
||||
orderedKeys := utilfn.GetOrderedMapKeys(service.ServiceMap)
|
||||
for _, serviceName := range orderedKeys {
|
||||
serviceObj := service.ServiceMap[serviceName]
|
||||
svcStr := tsgen.GenerateServiceClass(serviceName, serviceObj, tsTypesMap)
|
||||
fmt.Fprint(fd, svcStr)
|
||||
fmt.Fprint(fd, "\n")
|
||||
fmt.Fprint(&buf, svcStr)
|
||||
fmt.Fprint(&buf, "\n")
|
||||
}
|
||||
err := tsgen.WriteFileIfChanged(fileName, []byte(buf.String()), true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateWshClientApiFile(tsTypeMap map[reflect.Type]string) error {
|
||||
fd, err := os.Create("frontend/app/store/wshclientapi.ts")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fd.Close()
|
||||
var buf strings.Builder
|
||||
fileName := "frontend/app/store/wshclientapi.ts"
|
||||
declMap := wshrpc.GenerateWshCommandDeclMap()
|
||||
fmt.Fprintf(os.Stderr, "generating wshclientapi file to %s\n", fd.Name())
|
||||
fmt.Fprintf(fd, "// Copyright 2024, Command Line Inc.\n")
|
||||
fmt.Fprintf(fd, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
||||
fmt.Fprintf(fd, "// generated by cmd/generate/main-generatets.go\n\n")
|
||||
fmt.Fprintf(fd, "import { WshClient } from \"./wshclient\";\n\n")
|
||||
fmt.Fprintf(os.Stderr, "generating wshclientapi file to %s\n", fileName)
|
||||
fmt.Fprintf(&buf, "// Copyright 2024, Command Line Inc.\n")
|
||||
fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
||||
fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n")
|
||||
fmt.Fprintf(&buf, "import { WshClient } from \"./wshclient\";\n\n")
|
||||
orderedKeys := utilfn.GetOrderedMapKeys(declMap)
|
||||
fmt.Fprintf(fd, "// WshServerCommandToDeclMap\n")
|
||||
fmt.Fprintf(fd, "class RpcApiType {\n")
|
||||
fmt.Fprintf(&buf, "// WshServerCommandToDeclMap\n")
|
||||
fmt.Fprintf(&buf, "class RpcApiType {\n")
|
||||
for _, methodDecl := range orderedKeys {
|
||||
methodDecl := declMap[methodDecl]
|
||||
methodStr := tsgen.GenerateWshClientApiMethod(methodDecl, tsTypeMap)
|
||||
fmt.Fprint(fd, methodStr)
|
||||
fmt.Fprintf(fd, "\n")
|
||||
fmt.Fprint(&buf, methodStr)
|
||||
fmt.Fprintf(&buf, "\n")
|
||||
}
|
||||
fmt.Fprintf(&buf, "}\n\n")
|
||||
fmt.Fprintf(&buf, "export const RpcApi = new RpcApiType();\n")
|
||||
err := tsgen.WriteFileIfChanged(fileName, []byte(buf.String()), true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(fd, "}\n\n")
|
||||
fmt.Fprintf(fd, "export const RpcApi = new RpcApiType();\n")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
@ -64,6 +65,25 @@ var updatesRtnRType = reflect.TypeOf(waveobj.UpdatesRtnType{})
|
||||
var orefRType = reflect.TypeOf((*waveobj.ORef)(nil)).Elem()
|
||||
var wshRpcInterfaceRType = reflect.TypeOf((*wshrpc.WshRpcInterface)(nil)).Elem()
|
||||
|
||||
func checkIfFileUpdated(filename string, newContents []byte) bool {
|
||||
oldContents, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return true
|
||||
}
|
||||
return !bytes.Equal(oldContents, newContents)
|
||||
}
|
||||
|
||||
func WriteFileIfChanged(filename string, newContents []byte, verbose bool) error {
|
||||
shouldWrite := checkIfFileUpdated(filename, newContents)
|
||||
if !shouldWrite {
|
||||
if verbose {
|
||||
fmt.Printf("file %s has not changed (not writing)\n", filename)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return os.WriteFile(filename, []byte(newContents), 0644)
|
||||
}
|
||||
|
||||
func generateTSMethodTypes(method reflect.Method, tsTypesMap map[reflect.Type]string, skipFirstArg bool) error {
|
||||
for idx := 0; idx < method.Type.NumIn(); idx++ {
|
||||
if skipFirstArg && idx == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user