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

Commit

Permalink
Test SQL database runs on all 3 platforms and on centralized exchanges,
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikhilsaraf authored Dec 18, 2019
1 parent 2cb5732 commit a6ffc8c
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ bin/
gui/filesystem_vfsdata.go
kelp.prefs
bind_*.go
bundler.json
10 changes: 0 additions & 10 deletions bundler.json

This file was deleted.

11 changes: 9 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var env string

const envRelease = "release"
const envDev = "dev"

const rootShort = "Kelp is a free and open-source trading bot for the Stellar universal marketplace."
const rootLong = `Kelp is a free and open-source trading bot for the Stellar universal marketplace (https://stellar.org).
Expand All @@ -44,7 +43,15 @@ var RootCmd = &cobra.Command{
` + version + `
`
fmt.Println(intro)
serverCmd.Run(ccmd, args)

if hasUICapability {
serverCmd.Run(ccmd, args)
} else {
e := ccmd.Help()
if e != nil {
panic(e)
}
}
},
}

Expand Down
7 changes: 2 additions & 5 deletions cmd/server.go → cmd/server_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ const kelpPrefsDirectory = ".kelp"
const kelpAssetsPath = "/assets"
const trayIconName = "[email protected]"

var serverCmd = &cobra.Command{
Use: "server",
Short: "Serves the Kelp GUI",
}

type serverInputs struct {
port *uint16
dev *bool
Expand All @@ -47,6 +42,8 @@ type serverInputs struct {
}

func init() {
hasUICapability = true

options := serverInputs{}
options.port = serverCmd.Flags().Uint16P("port", "p", 8000, "port on which to serve")
options.dev = serverCmd.Flags().Bool("dev", false, "run in dev mode for hot-reloading of JS code")
Expand Down
17 changes: 17 additions & 0 deletions cmd/server_noop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

import (
"log"

"github.com/spf13/cobra"
)

var hasUICapability = false

var serverCmd = &cobra.Command{
Use: "server",
Short: "Serves the Kelp GUI",
Run: func(ccmd *cobra.Command, args []string) {
log.Printf("Kelp GUI Server unsupported in this version: %s [%s]\n", version, gitHash)
},
}
24 changes: 23 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ check_build_result $?
echo "... finished embedding contents of gui/web/build into a .go file (env=$ENV)"
echo ""

echo -n "generating the bind file in /cmd to create missing files ... "
echo -n "generating the bundler.json file in / to create missing files for current platform ... "
go run ./scripts/gen_bundler_json/gen_bundler_json.go > $KELP/bundler.json
check_build_result $?
echo "done"
echo -n "generating the bind file in /cmd to create missing files for current platform ... "
astilectron-bundler bd -c $KELP/bundler.json
check_build_result $?
echo "done"
Expand Down Expand Up @@ -194,6 +198,15 @@ then
exit 0
fi
# else, we are in deploy mode

echo -n "generating the bundler.json file in / to create missing files for all remaining platforms ... "
go run ./scripts/gen_bundler_json/gen_bundler_json.go -a > $KELP/bundler.json
check_build_result $?
echo "done"
echo -n "generating the bind file in /cmd to create missing files for all remaining platforms ... "
astilectron-bundler bd -c $KELP/bundler.json
check_build_result $?
echo "done"
echo ""

ARCHIVE_DIR=build/$DATE
Expand Down Expand Up @@ -299,6 +312,15 @@ do
echo -n "cleaning up UI: $ARCHIVE_DIR_SOURCE_UI ... "
rm -rf $ARCHIVE_DIR_SOURCE_UI
echo "successful"

if [[ -f "$KELP/windows.syso" ]]
then
echo -n "removing windows.syso file ... "
rm $KELP/windows.syso
check_build_result $?
echo "successful"
fi

echo ""
done

Expand Down
57 changes: 57 additions & 0 deletions scripts/gen_bundler_json/gen_bundler_json.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package main

import (
"encoding/json"
"flag"
"fmt"
)

var bundler = `{
"app_name": "Kelp",
"icon_path_darwin": "resources/[email protected]",
"icon_path_linux": "resources/[email protected]",
"icon_path_windows": "resources/[email protected]",
"bind": {
"output_path": "./cmd",
"package": "cmd"
}
}`

var environments = `{
"environments": [
{"os": "darwin", "arch": "amd64"},
{"os": "linux", "arch": "amd64"},
{"os": "windows", "arch": "amd64"}
]
}`

func main() {
buildAllP := flag.Bool("a", false, "whether to build for all platforms (default builds only for native platform)")
flag.Parse()
buildAll := *buildAllP

var bundlerJSON map[string]interface{}
e := json.Unmarshal([]byte(bundler), &bundlerJSON)
if e != nil {
panic(e)
}

if buildAll {
var environmentsJSON map[string]interface{}
e := json.Unmarshal([]byte(environments), &environmentsJSON)
if e != nil {
panic(e)
}

for k, v := range environmentsJSON {
bundlerJSON[k] = v
}
}

jsonBytes, e := json.MarshalIndent(bundlerJSON, "", " ")
if e != nil {
panic(e)
}
jsonString := string(jsonBytes)
fmt.Println(jsonString)
}
2 changes: 1 addition & 1 deletion support/sdk/ccxt.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func loadExchangeList() {
if eMsg1 && eMsg2 && eMsg3 {
log.Printf("ccxt-rest is not running at %s so we cannot include those exchanges: %s", ccxtBaseURL, e.Error())
} else {
panic(fmt.Errorf("error getting list of supported exchanges by CCXT: %s", e))
log.Printf("error getting list of supported exchanges at URL %s by CCXT so we cannot include those exchanges: %s", ccxtBaseURL, e)
}
}
exchangeList = &output
Expand Down

0 comments on commit a6ffc8c

Please sign in to comment.