Skip to content

Commit

Permalink
Big updates to Watchdog. Added support of ignored files. Added auto-c…
Browse files Browse the repository at this point in the history
…ompile of watched files on initialization.
  • Loading branch information
cballou committed Jun 18, 2012
1 parent 4bff3cd commit 61a416d
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 52 deletions.
37 changes: 34 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ Usage
-----

```bash
./watchdog --types styl --watch /var/www/vhosts/clients/ReTargeter/public/css/
./watchdog --types styl,sass,scss,less,jade,haml --watch /var/www/vhosts/clients/ReTargeter/public/css/
./watchdog --types styl --watch /path/to/public/css/
./watchdog --types styl,sass,scss,less,jade,haml --watch /path/to/public/css/
./watchdog --types styl,less --watch /path/to/public/css/ --ignore mixins.less
./watchdog --types less --watch /path/to/public/css/less/ --ignore mixins.less --
./watchdog --config /path/to/config
./watchdog --help
```
Expand All @@ -30,10 +32,39 @@ return array(
'/path/to/public/css',
'/path/to/alternate/css'
),
'minify' => true
'minify' => true,
'ignore' => array()
);
```

Example Config File demonstrating all settings:

```php
<?php
return array(
'types' => array('sass', 'scss', 'less', 'styl', 'jade', 'haml'),
'watch' => array(
// key => val equivalent to input file for compilation => output file (result of compiling)
'/path/to/public/css/dynamic/' => '/path/to/public/css/',
// assume the input path and output path are the same
'/path/to/alternate/css',
// watch a specific file
'/path/to/public/html/view.jade'
),
'minify' => true,
'ignore' => array(
'mixins.less'
)
);
```

Settings
--------

The configuration file is slightly more customizable than specifying arguments via the command line.
For starters, you can specify both the input file/directory and output file/directory of watched files/directories
which comes in handy if you store your files in two separate directories.

Requirements
------------

Expand Down
28 changes: 27 additions & 1 deletion inc/cli
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Options:

-t\t--types <extension>\t\tSpecify the file extensions to watch, separated by commas with no spaces (supports sass, scss, less, styl, haml, jade).
-w\t--watch <directories>\t\tSpecify the directories to watch for file changes, separated by commas with no spaces.
-i\t--ignore <filenames>\t\tSpecify filenames you wish to ignore, separated by commas with no spaces.
-c\t--config <file>\t\t\tSpecify an absolute/relative path to a config file to load options.
-m\t--minify\t\t\tFlag to indicate you wish to minify/compress output.
-h\t--help\t\t\t\tThis help documentation.
Expand Down Expand Up @@ -115,7 +116,14 @@ if (empty($directoryWatch)) {

// console log
echo 'Watching the following directories:' . PHP_EOL;
echo ' ' . implode(PHP_EOL . ' ', $directoryWatch) . PHP_EOL . PHP_EOL;
foreach ($directoryWatch as $in => $out) {
if (is_numeric($in)) {
echo ' ' . $out . PHP_EOL;
} else {
echo ' ' . $in . ' (output to ' . $out . ')' . PHP_EOL;
}
}
echo PHP_EOL;

// determine file extensions to watch for
if (!empty($config['types'])) {
Expand Down Expand Up @@ -163,3 +171,21 @@ if (!empty($config['minify'])) {
} else if (isset($options['minify'])) {
$minified = true;
}

// determine if we're ignoring any files
$ignoredFiles = array();
if (!empty($config['ignore'])) {
$ignoredFiles = (array) $config['ignore'];
} else if (!empty($options['i'])) {
$ignoredFiles = $options['i'];
} else if (!empty($options['ignore'])) {
$ignoredFiles = $options['ignore'];
}

if (!is_array($ignoredFiles)) {
$ignoredFiles = explode(',', $ignoredFiles);
}

if (!empty($ignoredFiles)) {
echo 'Ignoring files: ' . implode(', ', $ignoredFiles) . PHP_EOL . PHP_EOL;
}
Loading

0 comments on commit 61a416d

Please sign in to comment.