Skip to content

Commit

Permalink
[add] setup
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Oct 28, 2022
1 parent 39b59f0 commit 93ba063
Show file tree
Hide file tree
Showing 19 changed files with 2,088 additions and 101 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,15 @@ release: clean
echo "BASE=__yao_admin_root" > .tmp/xgen/v1.0/packages/xgen/.env
cd .tmp/xgen/v1.0 && pnpm install && pnpm run build

# Setup UI
cd .tmp/xgen/v1.0/packages/setup && pnpm install && pnpm run build

# Packing
mkdir -p .tmp/data/xgen
cp -r ./ui .tmp/data/ui
cp -r ./yao .tmp/data/yao
cp -r .tmp/xgen/v0.9/dist .tmp/data/xgen/v0.9
cp -r .tmp/xgen/v1.0/packages/xgen/build .tmp/data/xgen/setup
cp -r .tmp/xgen/v1.0/packages/xgen/dist .tmp/data/xgen/v1.0
go-bindata -fs -pkg data -o data/bindata.go -prefix ".tmp/data/" .tmp/data/...
rm -rf .tmp/data
Expand Down
40 changes: 32 additions & 8 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/yaoapp/yao/engine"
"github.com/yaoapp/yao/fs"
"github.com/yaoapp/yao/service"
"github.com/yaoapp/yao/setup"
"github.com/yaoapp/yao/share"
"github.com/yaoapp/yao/studio"
)
Expand All @@ -35,6 +36,19 @@ var startCmd = &cobra.Command{
Long: L("Start Engine"),
Run: func(cmd *cobra.Command, args []string) {

// Setup
if setup.Check() {
go setup.Start()
select {
case <-setup.Done:
setup.Stop()
break
case <-setup.Canceled:
os.Exit(1)
break
}
}

// recive interrupt signal
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)
Expand All @@ -58,10 +72,6 @@ var startCmd = &cobra.Command{
}

host := config.Conf.Host
if host == "0.0.0.0" {
host = "127.0.0.1"
}

dataRoot, _ := fs.Root(config.Conf)

fmt.Println(color.WhiteString("\n---------------------------------"))
Expand All @@ -73,15 +83,29 @@ var startCmd = &cobra.Command{
}

if share.App.XGen == "1.0" {

root, _ := adminRoot()
fmt.Println(color.WhiteString(L(" XGen")), color.GreenString(" 1.0"))
urls := []string{fmt.Sprintf("http://%s:%s", host, port)}
if host == "0.0.0.0" {
urls, _ = setup.URLs(config.Conf)
}

fmt.Println(color.WhiteString(L("XGen")), color.GreenString(" 1.0"))
fmt.Println(color.WhiteString(L("Data")), color.GreenString(" %s", dataRoot))
fmt.Println(color.WhiteString(L("Frontend")), color.GreenString(" http://%s%s/", host, port))
fmt.Println(color.WhiteString(L("Dashboard")), color.GreenString(" http://%s%s%slogin/admin", host, port, root))
fmt.Println(color.WhiteString(L("API")), color.GreenString(" http://%s%s/api", host, port))
for _, url := range urls {
fmt.Println(color.WhiteString(L("Frontend ")), color.GreenString(" %s", url))
fmt.Println(color.WhiteString(L("Dashboard")), color.GreenString(" %s/%s/login/admin", url, strings.Trim(root, "/")))
fmt.Println(color.WhiteString(L("API ")), color.GreenString(" %s/api", url))
}

fmt.Println(color.WhiteString(L("Listening")), color.GreenString(" %s:%d", config.Conf.Host, config.Conf.Port))

} else {

if host == "0.0.0.0" {
host = "127.0.0.1"
}

fmt.Println(color.WhiteString(L("Data")), color.GreenString(" %s", dataRoot))
fmt.Println(color.WhiteString(L("Frontend")), color.GreenString(" http://%s%s/", host, port))
fmt.Println(color.WhiteString(L("Dashboard")), color.GreenString(" http://%s%s/xiang/login/admin", host, port))
Expand Down
12 changes: 7 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ func LoadFrom(envfile string) Config {

file, err := filepath.Abs(envfile)
if err != nil {
log.Warn("Can't load env file. %s", err.Error())
}
err = godotenv.Overload(file)
if err != nil {
log.Warn("Can't load env file. %s", err.Error())
// log.Warn("Can't load env file. %s", err.Error())
return Load()
}

godotenv.Overload(file)
// if err != nil {
// // log.Warn("Can't load env file. %s", err.Error())
// }

return Load()
}

Expand Down
Loading

0 comments on commit 93ba063

Please sign in to comment.