Skip to content

No way to refresh panini cache [v2.0] #143

Open

Description

@XAMelleOH

When I use watch to update files I have the next workaround:

import paniniG  from 'panini/gulp';

const panini = paniniG.create; 
...
panini('src')...

In this case partials updated between watch cycles.
The problem is that locales data is not updated.

If I use regular way without .create then it's vice versa: locales data updated, but partials are not.

Activity

  1. gakimball commented on Oct 11, 2017

    @gakimball
    Contributor

    The .refresh() stuff isn't in there right now. Eventually all that stuff is going to be automatic, so you won't have to call it at all, but it's taking some time to implement properly.

    In the mean time, you can access the underlying Panini instance and call the refresh() method directly, although it's a little janky. Can you let me know if integrating this code into your build process works? Thanks :)

    const panini = require('panini/gulp');
    let paniniInstance;
    
    gulp.task('pages', () => {
      const stream = panini('src')
        .pipe(gulp.dest('dist'));
    
      paniniInstance = stream._panini;
      return stream;
    });
    
    gulp.task('pages:refresh', () => {
      return paniniInstance.refresh();
    });

    Make sure pages:refresh doesn't run on the initial build—it doesn't need to anyway, because the library loads all the layouts, partials, etc. automatically on the first run.

  2. XAMelleOH commented on Oct 12, 2017

    @XAMelleOH
    Author

    @gakimball

    Unfortunately, it gives me TypeError: Cannot read property 'refresh' of undefined

    But I changed it to this and it works (not correct but at least works):

    const stream = panini('src');
      paniniInstance = stream._panini;
    
      return stream
        .pipe(inky())
        .pipe(gulp.dest('dist'));
    

    So, it's fine with partials now, but still not updating translations :(

  3. XAMelleOH commented on Oct 12, 2017

    @XAMelleOH
    Author

    Ok, I've tested it all again: translations data is never updated.

    The only way to get partials updated with watch is using .create, which you've recommended here: #45 (comment)

  4. gakimball commented on Oct 12, 2017

    @gakimball
    Contributor

    In the task where you run paniniInstance.refresh(), are you returning that function? That's necessary because it's an asynchronous function now.

  5. XAMelleOH commented on Oct 12, 2017

    @XAMelleOH
    Author

    Yes, I'm.

  6. gakimball commented on Oct 12, 2017

    @gakimball
    Contributor

    Alright, thanks for your patience in working through this with me :) I should be able to look into this in the next few days.

  7. illycz commented on Dec 2, 2017

    @illycz

    Any progress?
    Translations data is never updated...

  8. benland commented on Jan 16, 2018

    @benland

    If someone found a solution it would be very helpful. @XAMelleOH @illycz .

    @gakimball thanks for all your work!

  9. kuzvac commented on Feb 13, 2018

    @kuzvac
    Contributor

    Yeah, refresh page is hard. @gakimball i try to use watch(), but no success, they can't find this.panini.options.pages and throw error.
    I hardcode 'pages' for this.panini.options.pages, and watch() start working properly, but only inside pages directory.
    Callback for watch() will be awesome, for reloading page.

  10. gakimball commented on Feb 13, 2018

    @gakimball
    Contributor

    I've been working on file watching over the past week and I've made decent progress. I abstracted some of the more complex dependency management stuff into a small module: https://github.com/gakimball/bistro

    Hoping to have something for people to use soon!

  11. marvinhuebner commented on Apr 18, 2018

    @marvinhuebner

    None of the given solutions (#143 (comment) or #45 (comment)) has worked for me.

    For now i use panini programmatically inside gulp with a promise:

    import Panini from 'panini';
    
    function pages() {
        return new Promise(resolve => {
            const p = new Panini('src', 'dist');
    
            p.build().then(() => {
                console.log('Done building');
            });
    
            resolve();
        });
    }
    
    gulp.task('pages', pages);

    But this is only a workaround, because it creates a new Panini instance in every tasks. In my watch tasks i watch for the files and if they change i call the pages tasks again. Partials and layouts will get Updated, but locales still won't be updated.

    I've also tried to use p.watch() to avoid watching the changed files by myself and get rid of a new instance of the pages task, but this gives the following error.

    [22:52:18] TypeError: Path must be a string. Received undefined
        at assertPath (path.js:28:11)
        at Object.join (path.js:1236:7)
        at module.exports.watch (/Users/marvinhuebner/Projekte/ait/staging-pages/node_modules/panini/index.js:57:27)
        at /Users/marvinhuebner/Projekte/ait/staging-pages/gulpfile.babel.js:123:6
        at /Users/marvinhuebner/Projekte/ait/staging-pages/gulpfile.babel.js:68:3
        at Array.map (<anonymous>)
        at pageFolders (/Users/marvinhuebner/Projekte/ait/staging-pages/gulpfile.babel.js:67:15)
        at /Users/marvinhuebner/Projekte/ait/staging-pages/gulpfile.babel.js:115:3
        at new Promise (<anonymous>)
        at pages (/Users/marvinhuebner/Projekte/ait/staging-pages/gulpfile.babel.js:114:9)
    

    @gakimball i've installed the current https://github.com/zurb/panini/tree/v2.0 branch, maybe this info is useful for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions