-
Notifications
You must be signed in to change notification settings - Fork 231
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,538 additions
and
283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ _testmain.go | |
.idea | ||
.DS_Store | ||
|
||
server/assets | ||
docker | ||
vendor | ||
bin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package app | ||
|
||
import ( | ||
"fmt" | ||
c "github.com/tockins/realize/cli" | ||
s "github.com/tockins/realize/server" | ||
"gopkg.in/urfave/cli.v2" | ||
"log" | ||
"os" | ||
"syscall" | ||
) | ||
|
||
const ( | ||
Name = "Realize" | ||
Version = "1.1" | ||
Description = "A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths" | ||
Limit = 10000 | ||
Config = "r.config.yaml" | ||
Output = "r.output.log" | ||
) | ||
|
||
var r realize | ||
var R Realizer | ||
|
||
// Realizer interface for wrap the cli, app and server functions | ||
type Realizer interface { | ||
Wdir() string | ||
Before() error | ||
Red(string) string | ||
Blue(string) string | ||
BlueS(string) string | ||
Handle(error) error | ||
Serve(*cli.Context) | ||
Fast(*cli.Context) error | ||
Run(p *cli.Context) error | ||
Add(p *cli.Context) error | ||
Remove(p *cli.Context) error | ||
List(p *cli.Context) error | ||
} | ||
|
||
// Realize struct contains the general app informations | ||
type realize struct { | ||
Name, Description, Author, Email string | ||
Version string | ||
Limit uint64 | ||
Blueprint c.Blueprint | ||
Server s.Server | ||
Files map[string]string | ||
Sync chan string | ||
} | ||
|
||
// Application initialization | ||
func init() { | ||
r = realize{ | ||
Name: Name, | ||
Version: Version, | ||
Description: Description, | ||
Limit: Limit, | ||
Files: map[string]string{ | ||
"config": Config, | ||
"output": Output, | ||
}, | ||
Sync: make(chan string), | ||
} | ||
r.Blueprint = c.Blueprint{ | ||
Files: r.Files, | ||
Sync: r.Sync, | ||
} | ||
r.Server = s.Server{ | ||
Blueprint: &r.Blueprint, | ||
Files: r.Files, | ||
Sync: r.Sync, | ||
} | ||
r.Increase() | ||
R = &r | ||
} | ||
|
||
// Flimit defines the max number of watched files | ||
func (r *realize) Increase() { | ||
// increases the files limit | ||
var rLimit syscall.Rlimit | ||
rLimit.Max = r.Limit | ||
rLimit.Cur = r.Limit | ||
err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit) | ||
if err != nil { | ||
fmt.Println(c.Red("Error Setting Rlimit "), err) | ||
} | ||
} | ||
|
||
func (r *realize) Red(s string) string { | ||
return c.Red(s) | ||
} | ||
|
||
func (r *realize) Blue(s string) string { | ||
return c.Blue(s) | ||
} | ||
|
||
func (r *realize) BlueS(s string) string { | ||
return c.BlueS(s) | ||
} | ||
|
||
func (r *realize) Wdir() string { | ||
return c.WorkingDir() | ||
} | ||
|
||
func (r *realize) Serve(p *cli.Context) { | ||
if !p.Bool("no-server") { | ||
r.Server.Start() | ||
} | ||
} | ||
|
||
func (r *realize) Run(p *cli.Context) error { | ||
r.Serve(p) | ||
return r.Blueprint.Run() | ||
} | ||
|
||
func (r *realize) Fast(p *cli.Context) error { | ||
r.Blueprint.Add(p) | ||
r.Serve(p) | ||
return r.Blueprint.Fast(p) | ||
} | ||
|
||
func (r *realize) Add(p *cli.Context) error { | ||
return r.Blueprint.Insert(p) | ||
} | ||
|
||
func (r *realize) Remove(p *cli.Context) error { | ||
return r.Blueprint.Insert(p) | ||
} | ||
|
||
func (r *realize) List(p *cli.Context) error { | ||
return r.Blueprint.List() | ||
} | ||
|
||
func (r *realize) Before() error { | ||
fmt.Println(r.Blue(r.Name) + " - " + r.Blue(r.Version)) | ||
fmt.Println(r.BlueS(r.Description) + "\n") | ||
gopath := os.Getenv("GOPATH") | ||
if gopath == "" { | ||
log.Fatal(r.Red("$GOPATH isn't set up properly")) | ||
} | ||
return nil | ||
} | ||
|
||
func (r *realize) Handle(err error) error { | ||
if err != nil { | ||
fmt.Println(r.Red(err.Error())) | ||
return nil | ||
} | ||
return nil | ||
} |
Oops, something went wrong.