mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-22 16:48: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:linux
|
||||||
- build:server:macos
|
- build:server:macos
|
||||||
- build:server:windows
|
- build:server:windows
|
||||||
|
sources:
|
||||||
|
- "cmd/server/*.go"
|
||||||
|
- "pkg/**/*.go"
|
||||||
|
|
||||||
build:server:macos:
|
build:server:macos:
|
||||||
desc: Build the wavesrv component for macOS (Darwin) platforms (generates artifacts for both arm64 and amd64).
|
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
|
- task: build:server:internal
|
||||||
vars:
|
vars:
|
||||||
ARCHS: arm64,amd64
|
ARCHS: arm64,amd64
|
||||||
|
sources:
|
||||||
|
- "cmd/server/*.go"
|
||||||
|
- "pkg/**/*.go"
|
||||||
|
|
||||||
build:server:windows:
|
build:server:windows:
|
||||||
desc: Build the wavesrv component for Windows platforms (only generates artifacts for the current architecture).
|
desc: Build the wavesrv component for Windows platforms (only generates artifacts for the current architecture).
|
||||||
@ -82,6 +88,9 @@ tasks:
|
|||||||
vars:
|
vars:
|
||||||
ARCHS:
|
ARCHS:
|
||||||
sh: echo {{if eq "arm" ARCH}}arm64{{else}}{{ARCH}}{{end}}
|
sh: echo {{if eq "arm" ARCH}}arm64{{else}}{{ARCH}}{{end}}
|
||||||
|
sources:
|
||||||
|
- "cmd/server/*.go"
|
||||||
|
- "pkg/**/*.go"
|
||||||
|
|
||||||
build:server:linux:
|
build:server:linux:
|
||||||
desc: Build the wavesrv component for Linux platforms (only generates artifacts for the current architecture).
|
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}}
|
sh: echo {{if eq "arm" ARCH}}arm64{{else}}{{ARCH}}{{end}}
|
||||||
GO_ENV_VARS:
|
GO_ENV_VARS:
|
||||||
sh: echo "{{if eq "amd64" ARCH}}CC=\"zig cc -target x86_64-linux-gnu.2.28\"{{end}}"
|
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:
|
build:server:internal:
|
||||||
requires:
|
requires:
|
||||||
@ -147,6 +159,11 @@ tasks:
|
|||||||
GOARCH: arm64
|
GOARCH: arm64
|
||||||
deps:
|
deps:
|
||||||
- generate
|
- generate
|
||||||
|
sources:
|
||||||
|
- "cmd/wsh/**/*.go"
|
||||||
|
- "pkg/**/*.go"
|
||||||
|
- go.mod
|
||||||
|
- go.sum
|
||||||
|
|
||||||
dev:installwsh:
|
dev:installwsh:
|
||||||
desc: quick shortcut to rebuild wsh and install for macos arm64
|
desc: quick shortcut to rebuild wsh and install for macos arm64
|
||||||
@ -174,6 +191,8 @@ tasks:
|
|||||||
sources:
|
sources:
|
||||||
- "cmd/wsh/**/*.go"
|
- "cmd/wsh/**/*.go"
|
||||||
- "pkg/**/*.go"
|
- "pkg/**/*.go"
|
||||||
|
- go.mod
|
||||||
|
- go.sum
|
||||||
generates:
|
generates:
|
||||||
- dist/bin/wsh-{{.VERSION}}-{{.GOOS}}.{{.NORMALIZEDARCH}}{{.EXT}}
|
- 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)
|
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:
|
sources:
|
||||||
- "cmd/generatego/*.go"
|
- "cmd/generatego/*.go"
|
||||||
- "cmd/generatets/*.go"
|
- "cmd/generatets/*.go"
|
||||||
- "pkg/service/**/*.go"
|
- "pkg/**/*.go"
|
||||||
- "pkg/waveobj/*.go"
|
sources-excluce:
|
||||||
- "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/wshrpc/wshclient/wshclient.go
|
- pkg/wshrpc/wshclient/wshclient.go
|
||||||
- frontend/app/store/services.ts
|
- pkg/waveobj/metaconsts.go
|
||||||
- frontend/app/store/wshserver.ts
|
- pkg/wconfig/metaconsts.go
|
||||||
|
# remove the "generates" key since they are conditionally generated (otherwise task will re-run every time)
|
||||||
|
|
||||||
version:
|
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.
|
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"
|
"strings"
|
||||||
|
|
||||||
"github.com/wavetermdev/waveterm/pkg/gogen"
|
"github.com/wavetermdev/waveterm/pkg/gogen"
|
||||||
|
"github.com/wavetermdev/waveterm/pkg/tsgen"
|
||||||
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
|
"github.com/wavetermdev/waveterm/pkg/util/utilfn"
|
||||||
"github.com/wavetermdev/waveterm/pkg/waveobj"
|
"github.com/wavetermdev/waveterm/pkg/waveobj"
|
||||||
"github.com/wavetermdev/waveterm/pkg/wconfig"
|
"github.com/wavetermdev/waveterm/pkg/wconfig"
|
||||||
@ -42,7 +43,7 @@ func GenerateWshClient() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
err := os.WriteFile(WshClientFileName, []byte(buf.String()), 0644)
|
err := tsgen.WriteFileIfChanged(WshClientFileName, []byte(buf.String()), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -54,7 +55,7 @@ func GenerateWaveObjMetaConsts() {
|
|||||||
gogen.GenerateBoilerplate(&buf, "waveobj", []string{})
|
gogen.GenerateBoilerplate(&buf, "waveobj", []string{})
|
||||||
gogen.GenerateMetaMapConsts(&buf, "MetaKey_", reflect.TypeOf(waveobj.MetaTSType{}))
|
gogen.GenerateMetaMapConsts(&buf, "MetaKey_", reflect.TypeOf(waveobj.MetaTSType{}))
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
err := os.WriteFile(WaveObjMetaConstsFileName, []byte(buf.String()), 0644)
|
err := tsgen.WriteFileIfChanged(WaveObjMetaConstsFileName, []byte(buf.String()), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -66,7 +67,7 @@ func GenerateSettingsMetaConsts() {
|
|||||||
gogen.GenerateBoilerplate(&buf, "wconfig", []string{})
|
gogen.GenerateBoilerplate(&buf, "wconfig", []string{})
|
||||||
gogen.GenerateMetaMapConsts(&buf, "ConfigKey_", reflect.TypeOf(wconfig.SettingsType{}))
|
gogen.GenerateMetaMapConsts(&buf, "ConfigKey_", reflect.TypeOf(wconfig.SettingsType{}))
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
err := os.WriteFile(SettingsMetaConstsFileName, []byte(buf.String()), 0644)
|
err := tsgen.WriteFileIfChanged(SettingsMetaConstsFileName, []byte(buf.String()), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -17,14 +17,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func generateTypesFile(tsTypesMap map[reflect.Type]string) error {
|
func generateTypesFile(tsTypesMap map[reflect.Type]string) error {
|
||||||
fd, err := os.Create("frontend/types/gotypes.d.ts")
|
var buf strings.Builder
|
||||||
if err != nil {
|
fileName := "frontend/types/gotypes.d.ts"
|
||||||
return err
|
fmt.Fprintf(os.Stderr, "generating types file to %s\n", fileName)
|
||||||
}
|
|
||||||
defer fd.Close()
|
|
||||||
fmt.Fprintf(os.Stderr, "generating types file to %s\n", fd.Name())
|
|
||||||
tsgen.GenerateWaveObjTypes(tsTypesMap)
|
tsgen.GenerateWaveObjTypes(tsTypesMap)
|
||||||
err = tsgen.GenerateServiceTypes(tsTypesMap)
|
err := tsgen.GenerateServiceTypes(tsTypesMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error generating service types: %v\n", err)
|
fmt.Fprintf(os.Stderr, "Error generating service types: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -33,10 +30,10 @@ func generateTypesFile(tsTypesMap map[reflect.Type]string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error generating wsh server types: %w", err)
|
return fmt.Errorf("error generating wsh server types: %w", err)
|
||||||
}
|
}
|
||||||
fmt.Fprintf(fd, "// Copyright 2024, Command Line Inc.\n")
|
fmt.Fprintf(&buf, "// Copyright 2024, Command Line Inc.\n")
|
||||||
fmt.Fprintf(fd, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
||||||
fmt.Fprintf(fd, "// generated by cmd/generate/main-generatets.go\n\n")
|
fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n")
|
||||||
fmt.Fprintf(fd, "declare global {\n\n")
|
fmt.Fprintf(&buf, "declare global {\n\n")
|
||||||
var keys []reflect.Type
|
var keys []reflect.Type
|
||||||
for key := range tsTypesMap {
|
for key := range tsTypesMap {
|
||||||
keys = append(keys, key)
|
keys = append(keys, key)
|
||||||
@ -48,62 +45,68 @@ func generateTypesFile(tsTypesMap map[reflect.Type]string) error {
|
|||||||
})
|
})
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
// don't output generic types
|
// don't output generic types
|
||||||
if strings.Index(key.Name(), "[") != -1 {
|
if strings.Contains(key.Name(), "[") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
tsCode := tsTypesMap[key]
|
tsCode := tsTypesMap[key]
|
||||||
istr := utilfn.IndentString(" ", tsCode)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServicesFile(tsTypesMap map[reflect.Type]string) error {
|
func generateServicesFile(tsTypesMap map[reflect.Type]string) error {
|
||||||
fd, err := os.Create("frontend/app/store/services.ts")
|
var buf strings.Builder
|
||||||
if err != nil {
|
fileName := "frontend/app/store/services.ts"
|
||||||
return err
|
fmt.Fprintf(os.Stderr, "generating services file to %s\n", fileName)
|
||||||
}
|
fmt.Fprintf(&buf, "// Copyright 2024, Command Line Inc.\n")
|
||||||
defer fd.Close()
|
fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
||||||
fmt.Fprintf(os.Stderr, "generating services file to %s\n", fd.Name())
|
fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n")
|
||||||
fmt.Fprintf(fd, "// Copyright 2024, Command Line Inc.\n")
|
fmt.Fprintf(&buf, "import * as WOS from \"./wos\";\n\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")
|
|
||||||
orderedKeys := utilfn.GetOrderedMapKeys(service.ServiceMap)
|
orderedKeys := utilfn.GetOrderedMapKeys(service.ServiceMap)
|
||||||
for _, serviceName := range orderedKeys {
|
for _, serviceName := range orderedKeys {
|
||||||
serviceObj := service.ServiceMap[serviceName]
|
serviceObj := service.ServiceMap[serviceName]
|
||||||
svcStr := tsgen.GenerateServiceClass(serviceName, serviceObj, tsTypesMap)
|
svcStr := tsgen.GenerateServiceClass(serviceName, serviceObj, tsTypesMap)
|
||||||
fmt.Fprint(fd, svcStr)
|
fmt.Fprint(&buf, svcStr)
|
||||||
fmt.Fprint(fd, "\n")
|
fmt.Fprint(&buf, "\n")
|
||||||
|
}
|
||||||
|
err := tsgen.WriteFileIfChanged(fileName, []byte(buf.String()), true)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateWshClientApiFile(tsTypeMap map[reflect.Type]string) error {
|
func generateWshClientApiFile(tsTypeMap map[reflect.Type]string) error {
|
||||||
fd, err := os.Create("frontend/app/store/wshclientapi.ts")
|
var buf strings.Builder
|
||||||
if err != nil {
|
fileName := "frontend/app/store/wshclientapi.ts"
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer fd.Close()
|
|
||||||
declMap := wshrpc.GenerateWshCommandDeclMap()
|
declMap := wshrpc.GenerateWshCommandDeclMap()
|
||||||
fmt.Fprintf(os.Stderr, "generating wshclientapi file to %s\n", fd.Name())
|
fmt.Fprintf(os.Stderr, "generating wshclientapi file to %s\n", fileName)
|
||||||
fmt.Fprintf(fd, "// Copyright 2024, Command Line Inc.\n")
|
fmt.Fprintf(&buf, "// Copyright 2024, Command Line Inc.\n")
|
||||||
fmt.Fprintf(fd, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
fmt.Fprintf(&buf, "// SPDX-License-Identifier: Apache-2.0\n\n")
|
||||||
fmt.Fprintf(fd, "// generated by cmd/generate/main-generatets.go\n\n")
|
fmt.Fprintf(&buf, "// generated by cmd/generate/main-generatets.go\n\n")
|
||||||
fmt.Fprintf(fd, "import { WshClient } from \"./wshclient\";\n\n")
|
fmt.Fprintf(&buf, "import { WshClient } from \"./wshclient\";\n\n")
|
||||||
orderedKeys := utilfn.GetOrderedMapKeys(declMap)
|
orderedKeys := utilfn.GetOrderedMapKeys(declMap)
|
||||||
fmt.Fprintf(fd, "// WshServerCommandToDeclMap\n")
|
fmt.Fprintf(&buf, "// WshServerCommandToDeclMap\n")
|
||||||
fmt.Fprintf(fd, "class RpcApiType {\n")
|
fmt.Fprintf(&buf, "class RpcApiType {\n")
|
||||||
for _, methodDecl := range orderedKeys {
|
for _, methodDecl := range orderedKeys {
|
||||||
methodDecl := declMap[methodDecl]
|
methodDecl := declMap[methodDecl]
|
||||||
methodStr := tsgen.GenerateWshClientApiMethod(methodDecl, tsTypeMap)
|
methodStr := tsgen.GenerateWshClientApiMethod(methodDecl, tsTypeMap)
|
||||||
fmt.Fprint(fd, methodStr)
|
fmt.Fprint(&buf, methodStr)
|
||||||
fmt.Fprintf(fd, "\n")
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -64,6 +65,25 @@ var updatesRtnRType = reflect.TypeOf(waveobj.UpdatesRtnType{})
|
|||||||
var orefRType = reflect.TypeOf((*waveobj.ORef)(nil)).Elem()
|
var orefRType = reflect.TypeOf((*waveobj.ORef)(nil)).Elem()
|
||||||
var wshRpcInterfaceRType = reflect.TypeOf((*wshrpc.WshRpcInterface)(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 {
|
func generateTSMethodTypes(method reflect.Method, tsTypesMap map[reflect.Type]string, skipFirstArg bool) error {
|
||||||
for idx := 0; idx < method.Type.NumIn(); idx++ {
|
for idx := 0; idx < method.Type.NumIn(); idx++ {
|
||||||
if skipFirstArg && idx == 0 {
|
if skipFirstArg && idx == 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user