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

Rebuild not starts if changes were done in included template file #13

Closed
frkd-dev opened this issue Nov 29, 2014 · 16 comments · Fixed by #19
Closed

Rebuild not starts if changes were done in included template file #13

frkd-dev opened this issue Nov 29, 2014 · 16 comments · Fixed by #19

Comments

@frkd-dev
Copy link

If template has kind of "include/extends" directive, then watcher detects changes in included/extended file, but it doesn't make a rebuild. Example:

index.jade:

extends _base.jade

block someSpecificContent
    div Some specific content

_base.jade:

doctype html
html
    head
        title Any title
        script(src='http://localhost:35729/livereload.js')
    body
        block someSpecificContent

Run node build.js. Now modify index.jade, plugin detects changes, rebuilds and notifies browser. This is OK.

Then modify _base.jade – plugin detects changes, but no rebuild/notification happens. This is NOT OK.

@blunckr
Copy link

blunckr commented Mar 5, 2015

I have the same problem with scss files that import other files. Changes to the base file trigger a reload, changes to included files are logged, but do not trigger a reload

@chinedufn
Copy link

This is the current expected behavior.

@blunckr The rebuilder function only runs changed source directory files through metalsmith's build change. https://github.com/FWeinb/metalsmith-watch/blob/master/lib/index.js#L29-#L30 . Your main .scss file isn't getting rebuilt with your new partial.

Ideally, metalsmith-watch would let you specify multiple mappings of source glob patterns to rebuild glob patterns, similar to gulp.watch.
For example, whenever "templates/partials/" was changed "src/.md" might be rebuilt.

The simplest fix for now though might be an optional flag to rebuild all files upon any change.

If @FWeinb wants to weigh in here, I wouldn't mind making a PR on the simpler (temporary?) fix.

@MoOx
Copy link
Collaborator

MoOx commented Apr 15, 2015

Interested for that too.
webpack as an API to tell him which files depends on what.
We might want to do the same, or at least offer an option to get full reload, better than nothing.

@MoOx
Copy link
Collaborator

MoOx commented Apr 16, 2015

I got a simple idea to implement: what if we just add an map option to say what will rebuild what ?
Like this

watch({
  rebuildMapping: {
    "src/templates/**/*": "src/*", // editing a templates will trigger rebuild for everything
    "src/css/**/*": "src/css/*" // editing any css will rebuild css entry points
  }
})

@FWeinb what do you think about that ? I am open to make a PR for this.

@FWeinb
Copy link
Owner

FWeinb commented Apr 16, 2015

@MoOx I like that. Would like your PR. I don't have much time to work on this.

@zenorocha
Copy link

+1

@MoOx
Copy link
Collaborator

MoOx commented Apr 30, 2015

@FWeinb I have made an entire rewrite of this plugin you can see here https://github.com/putaindecode/putaindecode.fr/blob/4a99b6194412b5f15ae941780fa3cde9ccc22557/scripts/metalsmith/server/watcher.es ( + decoupled lr https://github.com/putaindecode/putaindecode.fr/blob/4a99b6194412b5f15ae941780fa3cde9ccc22557/scripts/metalsmith/server/livereload.es)
tests: https://github.com/putaindecode/putaindecode.fr/blob/4a99b6194412b5f15ae941780fa3cde9ccc22557/scripts/metalsmith/server/__tests__/watcher.es
It's written in es6/7 using babel cause I can't work in es5 anymore :)

Here is an example of the usage: https://github.com/putaindecode/putaindecode.fr/blob/4a99b6194412b5f15ae941780fa3cde9ccc22557/scripts/build.js#L141-L146

Also I included a fix to metalsmith-collections and a feature to clean js cache (I am using react as a template engine, so when I save the file, I need the node cache to be cleaned).

If I do a PR, this is likely to change a lot of things (the code just won't be the same). I can do that if you want. Or I can just create another metalsmith plugin. You tell me :)

@FWeinb
Copy link
Owner

FWeinb commented Apr 30, 2015

This looks awesome. I don't have much time to maintain this plugin but I can give you commit rights on this repo and add you to the author list on npm so you could publish the updated plugin yourself. Would that be ok with you?

@MoOx
Copy link
Collaborator

MoOx commented Apr 30, 2015

yup.
My npm login is "moox" :)

@FWeinb
Copy link
Owner

FWeinb commented Apr 30, 2015

Awesome. You can push to this repo now. Will add you to npm once I am at home.

@MoOx
Copy link
Collaborator

MoOx commented Apr 30, 2015

Cool, I will push things when I get some times too. Glad to be a collaborator :)

@zenorocha
Copy link

Nice initiative @FWeinb and thanks for maintaining this @MoOx!

@FWeinb
Copy link
Owner

FWeinb commented Apr 30, 2015

@MoOx
You can now publish to npm. But be sure to change the version number of this plugin according to semver.

@MoOx
Copy link
Collaborator

MoOx commented Apr 30, 2015

Don't worry, I am a semver fanboy ;)
I will probably release 1.0 after a last small enhancement to make.

@FWeinb
Copy link
Owner

FWeinb commented Apr 30, 2015

👍

MoOx added a commit that referenced this issue May 4, 2015
- Fixed: metalsmith-collections are now correctly adjusted to avoid
duplicates entries after rebuilds)
- Removed: `pattern` option has been remove. Please use the new `paths`
option
- Added: `paths` option allows you to specify a map to trigger rebuilds
(closes [#4](#4) and
[#13](#13))
- Added: `log` option to be able to control watcher logs
- Added: when a JavaScript file is changed, the corresponding cache in
node/iojs cache is refreshed.
This is particularly handy when working with plain JavaScript template
(eg: react template made with
[metalsmith-react](https://github.com/MoOx/metalsmith-react))

Closes #4
Closes #13
Closes #17
Closes #18
@MoOx MoOx mentioned this issue May 4, 2015
@MoOx
Copy link
Collaborator

MoOx commented May 4, 2015

I opened a PR for this #19
I have 2 tiny things to handle before merging.

MoOx added a commit that referenced this issue May 5, 2015
- Fixed: metalsmith-collections are now correctly adjusted to avoid
duplicates entries after rebuilds)
- Removed: `pattern` option has been remove. Please use the new `paths`
option
- Added: `paths` option allows you to specify a map to trigger rebuilds
(closes [#4](#4) and
[#13](#13))
- Added: `log` option to be able to control watcher logs
- Added: when a JavaScript file is changed, the corresponding cache in
node/iojs cache is refreshed.
This is particularly handy when working with plain JavaScript template
(eg: react template made with
[metalsmith-react](https://github.com/MoOx/metalsmith-react))

Closes #4
Closes #13
Closes #17
Closes #18
MoOx added a commit that referenced this issue May 5, 2015
- Fixed: metalsmith-collections are now correctly adjusted to avoid
duplicates entries after rebuilds)
- Removed: `pattern` option has been remove. Please use the new `paths`
option
- Added: `paths` option allows you to specify a map to trigger rebuilds
(closes [#4](#4) and
[#13](#13))
- Added: `log` option to be able to control watcher logs
- Added: when a JavaScript file is changed, the corresponding cache in
node/iojs cache is refreshed.
This is particularly handy when working with plain JavaScript template
(eg: react template made with
[metalsmith-react](https://github.com/MoOx/metalsmith-react))

Closes #4
Closes #13
Closes #17
Closes #18
@MoOx MoOx closed this as completed in #19 May 8, 2015
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

Successfully merging a pull request may close this issue.

6 participants