Skip to content

Commit

Permalink
Add node back to serve cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Jun 30, 2020
1 parent 1a0dc5c commit db68e5d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 10 deletions.
23 changes: 19 additions & 4 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"net/http"
"os"
"os/exec"
"os/signal"
"time"

gocmd "github.com/go-cmd/cmd"
"github.com/gobuffalo/packr/v2"
"github.com/gorilla/mux"
"github.com/radovskyb/watcher"
Expand All @@ -21,8 +23,11 @@ type Env struct {
NodeJS bool `json:"node_js"`
}

func startServe(verbose bool) (*exec.Cmd, *exec.Cmd) {
func startServe(verbose bool) (*exec.Cmd, *exec.Cmd, *gocmd.Cmd) {
appName, _ := getAppAndModule()
cmdNpm := gocmd.NewCmd("npm", "run", "dev")
cmdNpm.Dir = "frontend"
cmdNpm.Start()
fmt.Printf("\n📦 Installing dependencies...\n")
cmdMod := exec.Command("/bin/sh", "-c", "go mod tidy")
if verbose {
Expand Down Expand Up @@ -117,7 +122,7 @@ func startServe(verbose bool) (*exec.Cmd, *exec.Cmd) {
if !verbose {
fmt.Printf("\n🚀 Get started: http://localhost:12345/\n\n")
}
return cmdTendermint, cmdREST
return cmdTendermint, cmdREST, cmdNpm
}

var serveCmd = &cobra.Command{
Expand All @@ -126,16 +131,26 @@ var serveCmd = &cobra.Command{
Args: cobra.ExactArgs(0),
Run: func(cmd *cobra.Command, args []string) {
verbose, _ := cmd.Flags().GetBool("verbose")
cmdt, cmdr := startServe(verbose)
cmdt, cmdr, cmdn := startServe(verbose)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
<-c
cmdn.Stop()
cmdr.Process.Kill()
cmdt.Process.Kill()
os.Exit(0)
}()
w := watcher.New()
w.SetMaxEvents(1)
go func() {
for {
select {
case <-w.Event:
cmdn.Stop()
cmdr.Process.Kill()
cmdt.Process.Kill()
cmdt, cmdr = startServe(verbose)
cmdt, cmdr, cmdn = startServe(verbose)
case err := <-w.Error:
log.Fatalln(err)
case <-w.Closed:
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/tendermint/starport
go 1.14

require (
github.com/go-cmd/cmd v1.2.0
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/genny v0.6.0
github.com/gobuffalo/packr/v2 v2.8.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,15 @@ github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/go-cmd/cmd v1.2.0 h1:Aohz0ZG0nQbvT4z55Mh+fdegX48GSAXL3cSsbYxRfvI=
github.com/go-cmd/cmd v1.2.0/go.mod h1:XgKkd0L6sv9WcYV0FS8RfG1RJCSTVHTsLeAD2pTgHt0=
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.5 h1:AKODKU3pDH1RzZzm6YZu77YWtEAq6uh1rLIAQlay2qc=
github.com/go-test/deep v1.0.5/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
github.com/gobuffalo/envy v1.7.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
github.com/gobuffalo/envy v1.8.1/go.mod h1:FurDp9+EDPE4aIUS3ZLyD+7/9fpx7YRt/ukY6jIHf0w=
Expand Down
4 changes: 0 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,3 @@ starport type post title body
This command generates a type `Post` with two fields: `title` and `body`.

To add a post run `blogcli tx blog create-post "My title" "This is a blog" --from=me`.

## Front-end application

By default the generator creates a front-end application in `frontend` directory. If you have Node.js installed, run `cd frontend && npm run dev` to launch the app. With this app you can generate accounts, request tokens from a faucet, list and create objects generated with `starport type`.
4 changes: 2 additions & 2 deletions ui/src/views/Start.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div class="card__desc__h1">User interface</div>
<div class="card__desc__p">
<span v-if="running.frontend">The front-end of your app. A Vue application is running on port <span class="card__desc__tag">8080</span></span>
<span v-else>To start the app, run: <code>cd frontend && npm run dev</code></span>
<span v-else>Loading...</code></span>
</div>
</div>
</a>
Expand All @@ -35,7 +35,7 @@
<div class="card__desc">
<div class="card__desc__h1">User interface</div>
<div class="card__desc__p">
<span>Can't find npm. Please, make sure Node.js is installed.</span>
<span>Can't start UI, because Node.js is not found.</span>
</div>
</div>
</a>
Expand Down

0 comments on commit db68e5d

Please sign in to comment.