Giter VIP home page Giter VIP logo

goat's Introduction

Goat - File watcher

Abstract

Goat is a file watcher written in Golang. Goat watches files which have specific extensions and executes specific commands when one of these files is created, updated or removed.

Use cases

You can use Goat to:

  • Restart a Golang web server process when one of the Golang source files is updated.
  • Compile Stylus, Sass/SCSS and LESS source files when one of these files is updated.
  • Concatenate and compress JS and CSS source files when one of these files is updated.

Installation

From source codes

$ go get github.com/yosssi/goat/...

By deploying a binary file

Configuration file

To run goat, you have to create a configuration file named goat.json or goat.yml in your project root directory.

The JSON file looks like the following:

{
  "init_tasks": [
    {
      "command": "make stop"
    },
    {
      "command": "make run",
      "nowait": true
    }
  ],
  "watchers": [
    {
      "extension": "go",
      "tasks": [
        {
          "command": "make stop"
        },
        {
          "command": "make run",
          "nowait": true
        }
      ]
    },
    {
      "extension": "styl",
      "tasks": [
        {
          "command": "make stylus"
        }
      ]
    },
    {
      "extension": "css",
      "excludes": [{"pattern": "all.css", "algorithm": "exact"}, {"pattern": "min.css", "algorithm": "suffix"}],
      "tasks": [
        {
          "command": "make catcss"
        },
        {
          "command": "make uglifycss"
        }
      ]
    },
    {
      "extension": "js",
      "directory": "test",
      "excludes": [{"pattern": "all.js", "algorithm": "exact"}, {"pattern": "min.js", "algorithm": "suffix"}],
      "tasks": [
        {
          "command": "make catjs"
        },
        {
          "command": "make uglifyjs"
        }
      ]
    }
  ]
}

The equivalent YAML file looks like the following:

init_tasks:
 - command: "make stop"
 - command: "make run"
   nowait: true


watchers:
 - extension: go
   tasks:
   - command: "make stop"
   - command: "make run"
     nowait: true

 - extension: styl
   tasks:
   - command: "make stylus"

 - extension: css
   excludes:
   - pattern: "all.css"
     algorithm: "exact"
   - pattern: "min.css"
     algorithm: "suffix"
  tasks:
   - command: "make catcss"
   - command: "make uglifycss"

 - extension: js
   directory: test
   excludes:
   - pattern: "all.js"
     algorithm: "exact"
   - pattern: "min.js"
     algorithm: "suffix"
  tasks:
   - command: "make catjs"
   - command: "make uglifyjs"
  • init_tasks defines an array of initial tasks. This definition is optional. Each task definition has the following properties:
    • command (required)
    • nowait (optional)
  • command defines a command which is executed when one of the target files is created, updated or removed.
  • nowait defines whether Goat waits the completion of the command or not.
  • watchers defines an array of file watchers. Each watcher definition has the following properties:
    • extension (required)
    • tasks (required)
    • excludes (optional)
      • pattern defile filename or filename pattern which matched with the respective algorithm.
      • algorithm (optional, default is exact)
        • exact exclude the file matched exactly
        • regexp exclude the file(s) matched with regexp pattern.
        • suffix exclude the file(s) ends with suffix.
        • prefix exclude the file(s) starts with prefix.
    • directory (optional)
  • extension defines target file's extension. Goat watches all files which have this extension in and under your project root directory.
  • tasks defines an array of tasks.
  • excludes defines an array of file names which is out of watching range.
  • directory defines the subdirectory. Goat watches all files which have the specified extension in and under this subdirectory under your project root directory. Defaults to your project root directory, if not specified.

Execution

On the your project root directory which has goat.json or goat.yml file, execute the following command:

$ goat
2014/03/06 01:22:04 [Watcher for go files under project root] Watching...
2014/03/06 01:22:04 [Watcher for js files under test] Watching...
2014/03/06 01:22:04 [Watcher for css files under project root] Watching...
2014/03/06 01:22:04 [Watcher for styl files under project root] Watching...

Goat launches watcher processes defined on goat.json or goat.yml file.

Default interval time of each watcher's file check loop is 500 ms. You can change this interval time by specifying -i flag. The following example shows a command which sets the interval time to 1000 ms:

$ goat -i 1000

goat's People

Contributors

yosssi avatar majidfn avatar kjmrknsn avatar barryz avatar gmonnerat avatar mkasner avatar

Stargazers

choirudin avatar Michael Scholle avatar Tomartin avatar Daniel avatar jchen-ls avatar Jannis Fink avatar baxiry avatar Amey Narkhede avatar Matthew Olenik avatar Danny Feller avatar ja.nz avatar Josef Pospíšil avatar Yifan Wu avatar Karsten Schmidt avatar Krzysztof Wilczyński avatar Chris McKee avatar Robert Monden avatar Toan Tran avatar Brendan Le Glaunec avatar Kent Gruber avatar YouCanFly avatar Doru Carastan avatar  avatar Robin Michael avatar K.Furukawa avatar MA Jianjun avatar  avatar AEKnow avatar Martín López avatar Xu avatar Paul Williams avatar steve avatar Abbas avatar abdul dakkak avatar Rafael Escobar avatar Andrey Nering avatar Julian Gaal avatar Mustafa Yasin Halici avatar Ali UYGUR avatar Rob Warner avatar Christopher "Chief" Najewicz avatar Bart avatar John Connors avatar Kiswono Prayogo avatar Claus Mandal avatar Corentin GITTON avatar Darren avatar David C. Bishop avatar Ali Hammad avatar Lee Provoost avatar Francois avatar Dave Hulihan avatar kerneltravel avatar Ming Wang avatar Q avatar Nithin Bose avatar Pawel Kasperek avatar Michael S. Manley avatar Geert-Johan Riemer avatar Mark Sta Ana avatar Yaoda Liu avatar Christian Sakshaug avatar  avatar Lubomir Anastasov avatar Xe Iaso avatar George Erickson avatar Dario Castañé avatar Herbert Fischer avatar Pavel Korotkov avatar Maxim Zhukov avatar Tomohiro Taira avatar ruedap avatar Eric Myhre avatar OKAMURA Naoki aka nyarla / kalaclista avatar SHIMIZU Taku avatar Tsuyoshi Higuchi avatar Samora Dake avatar  avatar Matt Carrier avatar George Xie avatar Michael Reynolds avatar Attila Oláh avatar Ben Phegan avatar  avatar Damon Zhao avatar Yoshiki Schmitz avatar Satish Puranam avatar Artem Kovardin avatar Neil Cowburn avatar  avatar

Watchers

James Cloos avatar  avatar James Malley avatar  avatar  avatar

goat's Issues

Exclude folders with wildcards

Being able to exclude entire folders seems very beneficial! This comes in handy when working with package managers like npm or go's vendor directory among others.

Proposed syntax:

watchers:
 - extension: js
   tasks:
    - command: npm build
   directory: js
   excludes:
    - node_modules/*

Or maybe have a new field be a regex, to be used in place of both extension and excludes

watchers:
 - match: /(?!(\/?node_modules).)\/.+\.js$/
   tasks:
    - command: npm build

or alternatively with globs and not_matches

watchers:
 - matches: /**/*.js
   not_matches: */node_modules/*
   tasks:
    - command: npm build

Thoughts on this? I'd gladly create a pull request if desired.

make: *** No rule to make target `stylus'. Stop.

I'm getting the following error when using the JSON from the README:

make: *** No rule to make target `stylus'.  Stop.

stylus is installed and I can run it from the command line. Goat picks up the file changes and attempts to execute the command, but it fails at the error above.

Thanks.

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.