github.com/mkasner/goat@v0.0.0-20190419083224-77b17249a8e3/README.md (about)

     1  # Goat - File watcher
     2  
     3  ## Abstract
     4  
     5  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.
     6  
     7  ## Use cases
     8  
     9  You can use Goat to:
    10  
    11  * Restart a Golang web server process when one of the Golang source files is updated.
    12  * Compile Stylus, Sass/SCSS and LESS source files when one of these files is updated.
    13  * Concatenate and compress JS and CSS source files when one of these files is updated.
    14  
    15  ## Installation
    16  
    17  ### From source codes
    18  
    19  ```sh
    20  $ go get github.com/yosssi/goat/...
    21  ```
    22  
    23  ### By deploying a binary file
    24  
    25  * [Linux(64bit)](https://s3-ap-northeast-1.amazonaws.com/yosssi/goat/linux_amd64/goat)
    26  * [Linux(32bit)](https://s3-ap-northeast-1.amazonaws.com/yosssi/goat/linux_386/goat)
    27  * [Mac OS X(64bit)](https://s3-ap-northeast-1.amazonaws.com/yosssi/goat/darwin_amd64/goat)
    28  * [Mac OS X(32bit)](https://s3-ap-northeast-1.amazonaws.com/yosssi/goat/darwin_386/goat)
    29  * [Windows(64bit)](https://s3-ap-northeast-1.amazonaws.com/yosssi/goat/windows_amd64/goat.exe)
    30  * [Windows(32bit)](https://s3-ap-northeast-1.amazonaws.com/yosssi/goat/windows_386/goat.exe)
    31  
    32  ## Configuration file
    33  
    34  To run goat, you have to create a configuration file named `goat.json` or `goat.yml` in your project root directory.
    35  
    36  The JSON file looks like the following:
    37  
    38  ```json
    39  {
    40    "init_tasks": [
    41      {
    42        "command": "make stop"
    43      },
    44      {
    45        "command": "make run",
    46        "nowait": true
    47      }
    48    ],
    49    "watchers": [
    50      {
    51        "extension": "go",
    52        "tasks": [
    53          {
    54            "command": "make stop"
    55          },
    56          {
    57            "command": "make run",
    58            "nowait": true
    59          }
    60        ]
    61      },
    62      {
    63        "extension": "styl",
    64        "tasks": [
    65          {
    66            "command": "make stylus"
    67          }
    68        ]
    69      },
    70      {
    71        "extension": "css",
    72        "excludes": ["all.css", "all.min.css"],
    73        "tasks": [
    74          {
    75            "command": "make catcss"
    76          },
    77          {
    78            "command": "make uglifycss"
    79          }
    80        ]
    81      },
    82      {
    83        "extension": "js",
    84        "directory": "test",
    85        "excludes": ["all.js", "all.min.js"],
    86        "tasks": [
    87          {
    88            "command": "make catjs"
    89          },
    90          {
    91            "command": "make uglifyjs"
    92          }
    93        ]
    94      }
    95    ]
    96  }
    97  ```
    98  
    99  
   100  The equivalent YAML file looks like the following:
   101  ```yaml
   102  init_tasks:
   103   - command: "make stop"
   104   - command: "make run"
   105     nowait: true
   106  
   107  
   108  watchers:
   109   - extension: go
   110     tasks:
   111     - command: "make stop"
   112     - command: "make run"
   113       nowait: true
   114  
   115   - extension: styl
   116     tasks:
   117     - command: "make stylus"
   118  
   119   - extension: css
   120     excludes:
   121     - "all.css"
   122     - "all.min.css"
   123    tasks:
   124     - command: "make catcss"
   125     - command: "make uglifycss"
   126  
   127   - extension: js
   128     directory: test
   129     excludes:
   130     - "all.js"
   131     - "all.min.js"
   132    tasks:
   133     - command: "make catjs"
   134     - command: "make uglifyjs"
   135  ```
   136  
   137  * `init_tasks` defines an array of initial tasks. This definition is optional. Each task definition has the following properties:
   138    * `command` (required)
   139    * `nowait` (optional)
   140  * `command` defines a command which is executed when one of the target files is created, updated or removed.
   141  * `nowait` defines whether Goat waits the completion of the command or not.
   142  * `watchers` defines an array of file watchers. Each watcher definition has the following properties:
   143    * `extension` (required)
   144    * `tasks` (required)
   145    * `excludes` (optional)
   146    * `directory` (optional)
   147  * `extension` defines target file's extension. Goat watches all files which have this extension in and under your project root directory.
   148  * `tasks` defines an array of tasks.
   149  * `excludes` defines an array of file names which is out of watching range.
   150  * `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.
   151  
   152  ## Execution
   153  
   154  On the your project root directory which has `goat.json` or `goat.yml` file, execute the following command:
   155  
   156  ```sh
   157  $ goat
   158  2014/03/06 01:22:04 [Watcher for go files under project root] Watching...
   159  2014/03/06 01:22:04 [Watcher for js files under test] Watching...
   160  2014/03/06 01:22:04 [Watcher for css files under project root] Watching...
   161  2014/03/06 01:22:04 [Watcher for styl files under project root] Watching...
   162  ```
   163  
   164  Goat launches watcher processes defined on `goat.json` or `goat.yml` file.
   165  
   166  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:
   167  
   168  ```sh
   169  $ goat -i 1000
   170  ```