Skip to content
This repository was archived by the owner on Feb 1, 2024. It is now read-only.

Commit a6ffc8c

Browse files
authored
Test SQL database runs on all 3 platforms and on centralized exchanges, closes #317 (#320)
* 1 - allow server command for UI to support compilation for non-native platform (bind file dependent) astilectron-bundler will not generate bind files for GOARM versions and not adding arm64 because of duplication of server_amd64.go file for now * 2 - separate bundler.json and bundler_all.json files based on different platforms for local and deploy modes * 3 - run server command by default when running Kelp root command if UI capabiity is enabled * 4 - script to autogenerate bundler.json file for native platform and for all platforms for maximum code reuse * 5 - remove windows.syso file after building UI for windows * 6 - change ccxt panic to a log line * 7 - remove windows.syso file for all builds if it exists
1 parent 2cb5732 commit a6ffc8c

8 files changed

Lines changed: 110 additions & 19 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ bin/
1010
gui/filesystem_vfsdata.go
1111
kelp.prefs
1212
bind_*.go
13+
bundler.json

bundler.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

cmd/root.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ var env string
2020

2121
const envRelease = "release"
2222
const envDev = "dev"
23-
2423
const rootShort = "Kelp is a free and open-source trading bot for the Stellar universal marketplace."
2524
const rootLong = `Kelp is a free and open-source trading bot for the Stellar universal marketplace (https://stellar.org).
2625
@@ -44,7 +43,15 @@ var RootCmd = &cobra.Command{
4443
` + version + `
4544
`
4645
fmt.Println(intro)
47-
serverCmd.Run(ccmd, args)
46+
47+
if hasUICapability {
48+
serverCmd.Run(ccmd, args)
49+
} else {
50+
e := ccmd.Help()
51+
if e != nil {
52+
panic(e)
53+
}
54+
}
4855
},
4956
}
5057

cmd/server.go renamed to cmd/server_amd64.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ const kelpPrefsDirectory = ".kelp"
3232
const kelpAssetsPath = "/assets"
3333
const trayIconName = "kelp-icon@1-8x.png"
3434

35-
var serverCmd = &cobra.Command{
36-
Use: "server",
37-
Short: "Serves the Kelp GUI",
38-
}
39-
4035
type serverInputs struct {
4136
port *uint16
4237
dev *bool
@@ -47,6 +42,8 @@ type serverInputs struct {
4742
}
4843

4944
func init() {
45+
hasUICapability = true
46+
5047
options := serverInputs{}
5148
options.port = serverCmd.Flags().Uint16P("port", "p", 8000, "port on which to serve")
5249
options.dev = serverCmd.Flags().Bool("dev", false, "run in dev mode for hot-reloading of JS code")

cmd/server_noop.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cmd
2+
3+
import (
4+
"log"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
var hasUICapability = false
10+
11+
var serverCmd = &cobra.Command{
12+
Use: "server",
13+
Short: "Serves the Kelp GUI",
14+
Run: func(ccmd *cobra.Command, args []string) {
15+
log.Printf("Kelp GUI Server unsupported in this version: %s [%s]\n", version, gitHash)
16+
},
17+
}

scripts/build.sh

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ check_build_result $?
162162
echo "... finished embedding contents of gui/web/build into a .go file (env=$ENV)"
163163
echo ""
164164

165-
echo -n "generating the bind file in /cmd to create missing files ... "
165+
echo -n "generating the bundler.json file in / to create missing files for current platform ... "
166+
go run ./scripts/gen_bundler_json/gen_bundler_json.go > $KELP/bundler.json
167+
check_build_result $?
168+
echo "done"
169+
echo -n "generating the bind file in /cmd to create missing files for current platform ... "
166170
astilectron-bundler bd -c $KELP/bundler.json
167171
check_build_result $?
168172
echo "done"
@@ -194,6 +198,15 @@ then
194198
exit 0
195199
fi
196200
# else, we are in deploy mode
201+
202+
echo -n "generating the bundler.json file in / to create missing files for all remaining platforms ... "
203+
go run ./scripts/gen_bundler_json/gen_bundler_json.go -a > $KELP/bundler.json
204+
check_build_result $?
205+
echo "done"
206+
echo -n "generating the bind file in /cmd to create missing files for all remaining platforms ... "
207+
astilectron-bundler bd -c $KELP/bundler.json
208+
check_build_result $?
209+
echo "done"
197210
echo ""
198211

199212
ARCHIVE_DIR=build/$DATE
@@ -299,6 +312,15 @@ do
299312
echo -n "cleaning up UI: $ARCHIVE_DIR_SOURCE_UI ... "
300313
rm -rf $ARCHIVE_DIR_SOURCE_UI
301314
echo "successful"
315+
316+
if [[ -f "$KELP/windows.syso" ]]
317+
then
318+
echo -n "removing windows.syso file ... "
319+
rm $KELP/windows.syso
320+
check_build_result $?
321+
echo "successful"
322+
fi
323+
302324
echo ""
303325
done
304326

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"flag"
6+
"fmt"
7+
)
8+
9+
var bundler = `{
10+
"app_name": "Kelp",
11+
"icon_path_darwin": "resources/kelp-icon@2x.icns",
12+
"icon_path_linux": "resources/kelp-icon@2x.png",
13+
"icon_path_windows": "resources/kelp-icon@2x.ico",
14+
"bind": {
15+
"output_path": "./cmd",
16+
"package": "cmd"
17+
}
18+
}`
19+
20+
var environments = `{
21+
"environments": [
22+
{"os": "darwin", "arch": "amd64"},
23+
{"os": "linux", "arch": "amd64"},
24+
{"os": "windows", "arch": "amd64"}
25+
]
26+
}`
27+
28+
func main() {
29+
buildAllP := flag.Bool("a", false, "whether to build for all platforms (default builds only for native platform)")
30+
flag.Parse()
31+
buildAll := *buildAllP
32+
33+
var bundlerJSON map[string]interface{}
34+
e := json.Unmarshal([]byte(bundler), &bundlerJSON)
35+
if e != nil {
36+
panic(e)
37+
}
38+
39+
if buildAll {
40+
var environmentsJSON map[string]interface{}
41+
e := json.Unmarshal([]byte(environments), &environmentsJSON)
42+
if e != nil {
43+
panic(e)
44+
}
45+
46+
for k, v := range environmentsJSON {
47+
bundlerJSON[k] = v
48+
}
49+
}
50+
51+
jsonBytes, e := json.MarshalIndent(bundlerJSON, "", " ")
52+
if e != nil {
53+
panic(e)
54+
}
55+
jsonString := string(jsonBytes)
56+
fmt.Println(jsonString)
57+
}

support/sdk/ccxt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func loadExchangeList() {
109109
if eMsg1 && eMsg2 && eMsg3 {
110110
log.Printf("ccxt-rest is not running at %s so we cannot include those exchanges: %s", ccxtBaseURL, e.Error())
111111
} else {
112-
panic(fmt.Errorf("error getting list of supported exchanges by CCXT: %s", e))
112+
log.Printf("error getting list of supported exchanges at URL %s by CCXT so we cannot include those exchanges: %s", ccxtBaseURL, e)
113113
}
114114
}
115115
exchangeList = &output

0 commit comments

Comments
 (0)