Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Run watch only to a specific directory #3

Open
bserem opened this issue May 24, 2017 · 4 comments
Open

Run watch only to a specific directory #3

bserem opened this issue May 24, 2017 · 4 comments

Comments

@bserem
Copy link

bserem commented May 24, 2017

When watch is running with this config:

function watch {
  declare -A actions=(
    [".*\.js"]="manuel js"
    [".*\.scss$"]="manuel sass"
  )
  manuel_watch .
}

It looks for scss/js files in the current directory and subdirectories (current dir = dir with manuelfile).
Then, I have these two functions:

# JS Concat
function js {
  echo "[$(timestamp)] Cleaning up dist folder."
  rm -rf dist/js/*.js
  touch dist/js/scripts.js

  echo "[$(timestamp)] Concatenating JS."
  for f in source/js/*.js; do
    cat $f >> dist/js/scripts.js
    echo "[$(timestamp)] scripts.js is" `stat --printf="%s" dist/js/scripts.js` "bytes."
  done

}

# Sass Compile
function sass {
  echo "[$(timestamp)] Cleaning up dist folder."
  rm -rf dist/css/*.css
  rm -rf dist/css/*.map

  echo "[$(timestamp)] Compiling SASS."
  for f in source/scss/*.scss; do
    name=$(basename $f)
    name=$(echo $name | cut -f 1 -d '.')
    sassc -t expanded -m -l $f dist/css/$name.css
    sassc -t compressed $f dist/css/$name.min.css
    echo "[$(timestamp)] $name.css is" `stat --printf="%s" dist/css/$name.css` "bytes."
    echo "[$(timestamp)] $name.min.css is" `stat --printf="%s" dist/css/$name.min.css` "bytes."
  done
}

The SASS function works pretty nicely, but with the JS function I have an issue:
When manuel outputs the dist/js/scripts.js file, the watch function triggers itself again, because a JS file has changed. It then goes on an endless loop!

Is it possible to specify which directory watch should check?
I tried changing [".*\.js"]="manuel js" to ["./source/js/*.js"]="manuel js" but it didn't work.

Ideas?
Thanks ;)

ps: I find manuel to be the finest task runner. Bash can be complicated, but the fact that I do not rely on gulp/grunt/npm is very nice. thnx!

@JuneKelly
Copy link
Owner

Ah, this seems to be something of a bug. Basically, the way this plugin handles regex matching is a bit wrong, as it matches on the fully-qualified path to the file instead of matching against the relative path.

In your example, if you change ["./source/js/*.js"]="manuel js" to ["/full/path/to/source/js/*.js"]="manuel js" it should work, but I appreciate that's a dumb solution.

I'll try to re-design this plugin and get a fix out this week. Thanks for reporting the issue, and for the kind words :)

@bserem
Copy link
Author

bserem commented May 30, 2017

Great!

I had a look at the code, after your comment, to see if I could find/fix the issue myself, but it is way beyond my bash skills at the moment!

@bserem
Copy link
Author

bserem commented Jul 20, 2017

Any luck on the issue?

If you could pinpoint me to where this actually happens I could give it a try. I tried to weeks ago, but without luck.

Thanks

@JuneKelly
Copy link
Owner

I haven't had a chance to look very far into this.

The issue seems to be in the way we check for file changes here: https://github.com/ShaneKilkelly/manuel-contrib-watch/blob/master/manuel-contrib-watch.manuel#L43

It's been a while since I last dealt with this stuff, so I'm not totally sure what the right solution would look like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants