code organization
This commit is contained in:
parent
98439141b7
commit
199d5d95a7
@ -1,4 +1,4 @@
|
||||
package realize
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -10,38 +10,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
// App struct contains the informations about realize
|
||||
type Realize struct {
|
||||
Name, Description, Author, Email string
|
||||
Version string
|
||||
Limit uint64
|
||||
Blueprint Blueprint
|
||||
}
|
||||
|
||||
// Projects struct contains a projects list
|
||||
type Blueprint struct {
|
||||
Projects []Project `yaml:"Projects,omitempty"`
|
||||
files map[string]string
|
||||
}
|
||||
|
||||
// Project defines the informations of a single project
|
||||
type Project struct {
|
||||
reload time.Time
|
||||
base string
|
||||
Name string `yaml:"app_name,omitempty"`
|
||||
Path string `yaml:"app_path,omitempty"`
|
||||
Run bool `yaml:"app_run,omitempty"`
|
||||
Bin bool `yaml:"app_bin,omitempty"`
|
||||
Build bool `yaml:"app_build,omitempty"`
|
||||
Fmt bool `yaml:"app_fmt,omitempty"`
|
||||
Test bool `yaml:"app_test,omitempty"`
|
||||
Params []string `yaml:"app_params,omitempty"`
|
||||
Watcher Watcher `yaml:"app_watcher,omitempty"`
|
||||
}
|
||||
|
||||
// Wdir returns the name last element of the working directory path
|
||||
func (r *Realize) Wdir() string {
|
||||
dir, err := os.Getwd()
|
||||
@ -51,8 +21,8 @@ func (r *Realize) Wdir() string {
|
||||
return filepath.Base(dir)
|
||||
}
|
||||
|
||||
// Limit defines the max number of watched files
|
||||
func (r *Realize) limit() {
|
||||
// Flimit defines the max number of watched files
|
||||
func (r *Realize) Increases() {
|
||||
// increases the files limit
|
||||
var rLimit syscall.Rlimit
|
||||
rLimit.Max = r.Limit
|
||||
@ -138,7 +108,7 @@ func (h *Blueprint) Clean() {
|
||||
|
||||
// Read, Check and remove duplicates from the config file
|
||||
func (h *Blueprint) Read() error {
|
||||
content, err := read(h.files["config"])
|
||||
content, err := read(h.Files["config"])
|
||||
if err == nil {
|
||||
err = yaml.Unmarshal(content, h)
|
||||
if err == nil {
|
||||
@ -159,7 +129,7 @@ func (h *Blueprint) Create() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return write(h.files["config"], y)
|
||||
return write(h.Files["config"], y)
|
||||
}
|
||||
|
||||
// Inserts a new project in the list
|
@ -1,4 +1,4 @@
|
||||
package realize
|
||||
package cli
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@ -55,7 +55,7 @@ func (p *Project) GoRun(channel chan bool, runner chan bool, wr *sync.WaitGroup)
|
||||
log.Println(pname(p.Name, 3), ":", BlueS(in.Text()))
|
||||
}
|
||||
if p.Watcher.Output["file"] {
|
||||
path := filepath.Join(p.base, App.Blueprint.files["output"])
|
||||
path := filepath.Join(p.base, App.Blueprint.Files["output"])
|
||||
f := create(path)
|
||||
t := time.Now()
|
||||
if _, err := f.WriteString(t.Format("2006-01-02 15:04:05") + " : " + in.Text() + "\r\n"); err != nil {
|
70
cli/main.go
Normal file
70
cli/main.go
Normal file
@ -0,0 +1,70 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var App Realize
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// Green, Red Bold, Red, Blue, Blue Bold, Yellow, Yellow Bold, Magenta, Magenta Bold colors
|
||||
var Green, Red, RedS, Blue, BlueS, Yellow, YellowS, Magenta, MagentaS = color.New(color.FgGreen, color.Bold).SprintFunc(),
|
||||
color.New(color.FgRed, color.Bold).SprintFunc(),
|
||||
color.New(color.FgRed).SprintFunc(),
|
||||
color.New(color.FgBlue, color.Bold).SprintFunc(),
|
||||
color.New(color.FgBlue).SprintFunc(),
|
||||
color.New(color.FgYellow, color.Bold).SprintFunc(),
|
||||
color.New(color.FgYellow).SprintFunc(),
|
||||
color.New(color.FgMagenta, color.Bold).SprintFunc(),
|
||||
color.New(color.FgMagenta).SprintFunc()
|
||||
|
||||
// Realize struct contains the general app informations
|
||||
type Realize struct {
|
||||
Name, Description, Author, Email string
|
||||
Version string
|
||||
Limit uint64
|
||||
Blueprint Blueprint
|
||||
}
|
||||
|
||||
// Projects struct contains a projects list
|
||||
type Blueprint struct {
|
||||
Projects []Project `yaml:"Projects,omitempty"`
|
||||
Files map[string]string `yaml:"-"`
|
||||
}
|
||||
|
||||
// Project defines the informations of a single project
|
||||
type Project struct {
|
||||
reload time.Time
|
||||
base string
|
||||
Name string `yaml:"app_name,omitempty"`
|
||||
Path string `yaml:"app_path,omitempty"`
|
||||
Run bool `yaml:"app_run,omitempty"`
|
||||
Bin bool `yaml:"app_bin,omitempty"`
|
||||
Build bool `yaml:"app_build,omitempty"`
|
||||
Fmt bool `yaml:"app_fmt,omitempty"`
|
||||
Test bool `yaml:"app_test,omitempty"`
|
||||
Params []string `yaml:"app_params,omitempty"`
|
||||
Watcher Watcher `yaml:"app_watcher,omitempty"`
|
||||
}
|
||||
|
||||
// Watcher struct defines the livereload's logic
|
||||
type Watcher struct {
|
||||
// different before and after on re-run?
|
||||
Before []string `yaml:"before,omitempty"`
|
||||
After []string `yaml:"after,omitempty"`
|
||||
Paths []string `yaml:"paths,omitempty"`
|
||||
Ignore []string `yaml:"ignore_paths,omitempty"`
|
||||
Exts []string `yaml:"exts,omitempty"`
|
||||
Preview bool `yaml:"preview,omitempty"`
|
||||
Output map[string]bool `yaml:"output,omitempty"`
|
||||
}
|
||||
|
||||
// Initialize the application
|
||||
func init() {
|
||||
log.SetFlags(0)
|
||||
log.SetOutput(new(logWriter))
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package realize
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -30,7 +30,7 @@ func read(file string) ([]byte, error) {
|
||||
func write(name string, data []byte) error {
|
||||
err := ioutil.WriteFile(name, data, 0655)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
log.Fatal(Red(err))
|
||||
return err
|
||||
}
|
||||
return nil
|
@ -1,4 +1,4 @@
|
||||
package realize
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
||||
@ -13,18 +13,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// The Watcher struct defines the livereload's logic
|
||||
type Watcher struct {
|
||||
// different before and after on re-run?
|
||||
Before []string `yaml:"before,omitempty"`
|
||||
After []string `yaml:"after,omitempty"`
|
||||
Paths []string `yaml:"paths,omitempty"`
|
||||
Ignore []string `yaml:"ignore_paths,omitempty"`
|
||||
Exts []string `yaml:"exts,omitempty"`
|
||||
Preview bool `yaml:"preview,omitempty"`
|
||||
Output map[string]bool `yaml:"output,omitempty"`
|
||||
}
|
||||
|
||||
// Watching method is the main core. It manages the livereload and the watching
|
||||
func (p *Project) watching() {
|
||||
|
@ -1,14 +1,31 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
r "github.com/tockins/realize/realize"
|
||||
r "github.com/tockins/realize/cli"
|
||||
//_ "github.com/tockins/realize/server"
|
||||
"fmt"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func init() {
|
||||
App := r.Realize{
|
||||
Name: "Realize",
|
||||
Version: "1.0",
|
||||
Description: "A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths",
|
||||
Limit: 10000,
|
||||
Blueprint: r.Blueprint{
|
||||
Files: map[string]string{
|
||||
"config": "r.config.yaml",
|
||||
"output": "r.output.log",
|
||||
},
|
||||
},
|
||||
}
|
||||
App.Increases()
|
||||
r.App = App
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
app := r.App
|
@ -1,55 +0,0 @@
|
||||
package realize
|
||||
|
||||
import (
|
||||
"github.com/fatih/color"
|
||||
"log"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var App Realize
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
||||
// Green color bold
|
||||
var Green = color.New(color.FgGreen, color.Bold).SprintFunc()
|
||||
|
||||
// Red color bold
|
||||
var Red = color.New(color.FgRed, color.Bold).SprintFunc()
|
||||
|
||||
// RedS color used for errors
|
||||
var RedS = color.New(color.FgRed).SprintFunc()
|
||||
|
||||
// Blue color bold used for project output
|
||||
var Blue = color.New(color.FgBlue, color.Bold).SprintFunc()
|
||||
|
||||
// BlueS color
|
||||
var BlueS = color.New(color.FgBlue).SprintFunc()
|
||||
|
||||
// Yellow color bold
|
||||
var Yellow = color.New(color.FgYellow, color.Bold).SprintFunc()
|
||||
|
||||
// YellowS color
|
||||
var YellowS = color.New(color.FgYellow).SprintFunc()
|
||||
|
||||
// MagentaS color
|
||||
var MagentaS = color.New(color.FgMagenta).SprintFunc()
|
||||
|
||||
// Magenta color bold
|
||||
var Magenta = color.New(color.FgMagenta, color.Bold).SprintFunc()
|
||||
|
||||
// Initialize the application
|
||||
func init() {
|
||||
App = Realize{
|
||||
Name: "Realize",
|
||||
Version: "1.0",
|
||||
Description: "A Go build system with file watchers, output streams and live reload. Run, build and watch file changes with custom paths",
|
||||
Limit: 10000,
|
||||
}
|
||||
App.Blueprint.files = map[string]string{
|
||||
"config": "r.config.yaml",
|
||||
"output": "r.output.log",
|
||||
}
|
||||
App.limit()
|
||||
log.SetFlags(0)
|
||||
log.SetOutput(new(logWriter))
|
||||
}
|
Loading…
Reference in New Issue
Block a user