Giter Club home page Giter Club logo

gosu's Introduction

gosu

gosu is a build tool for Go in the spirit of Rake, Gulp, Projmate ... gosu supports watching, globbing, tasks and importing other projects.

Asset.pipeline is in the works. Much simpler than Gulp or Grunt.

Install

go get github.com/mgutz/gosu

Example

gosu does not have its own executable. Instead, use gosu to build your project build tool.

import (
    gosu"github.com/mgutz/gosu"
)

func Project(p *gosu.Project) {
    p.Task("default", "Runs all tasks" string[]{"stylesheets", "app"})

    p.Task("stylesheets", gosu.Files{"public/css/**/*.less"}, func(c *gosu.Context) {
        if c.FileEvent != nil {
            // c.FileEvent contains change event from watch
        }
        for _, f := range c.Task.WatchFiles {
            // f.FileInfo and f.Path
        }
    })

    p.Task("app", "(Re)runs the app", gosu.Files{"**/*.go"}, func() {
        // use any restart package here
    })
}

func main() {
    gosu.Run(Project)
}

To run default task: go run main.go

To run a single task: go run main.go stylesheets

To run and watch a task: go run main.go --watch stylesheets

Build your utility:

go build -o gosu main.go    # name it whatever you want
gosu --watch stylesheets         # profit

Syntax

All file patterns MUST start with a directory:

  • OK "./test.go"
  • Bad "test.go"

Adding tasks

Project.Task has variable arguments of type interface{} for usability.

Tasks MUST define Handler, ContextHandler or have Dependencies

To add a default task, which runs when a task on command-line is not provided

p.Task("default", string[]{"clean", "stylesheets", "views"})

To add a task with description and Handler

p.Task("name", "description", func() {
    // work here
})

To add a task with description and ContextHandler

p.Task("name", "description", func(c *gosu.Context) {
    // use context to get info about c.FileEvent or c.Task
})

To add a task with Dependencies

p.Task("name", string[]{"dep1", "dep2"})

To support watching, add glob patterns

p.Task("views", gosu.Files{"./views/**/*.go.html"}, func() {
    // compile templates
})

Glob Patterns

/**/   - match zero or more directories
{a,b}  - match a or b, no spaces
*      - match any non-separator char
?      - match a single non-separator char
**/    - match any directory, start of pattern only
/**    - match any this directory, end of pattern only
!      - removes files from resultset, start of pattern only

Import another project

import (
    "github.com/acme/project"
)

func Project(p *Project) {
    // Use  it within this project and assign namespace "ns"
    p.Use("ns", project.Project)

    // Add as dependency, note the namespace
    p.Task("default", []string{"ns:sprite"})
}

FAQ

If you are receiving wierd events, please read fsnotify

LICENSE

The MIT License

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.