panini icon indicating copy to clipboard operation
panini copied to clipboard

No way to refresh panini cache [v2.0]

Open XAMelleOH opened this issue 7 years ago • 11 comments

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.

XAMelleOH avatar Oct 11 '17 11:10 XAMelleOH

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.

gakimball avatar Oct 11 '17 17:10 gakimball

@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 :(

XAMelleOH avatar Oct 12 '17 09:10 XAMelleOH

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: https://github.com/zurb/panini/issues/45#issuecomment-313451499

XAMelleOH avatar Oct 12 '17 09:10 XAMelleOH

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

gakimball avatar Oct 12 '17 18:10 gakimball

Yes, I'm.

XAMelleOH avatar Oct 12 '17 18:10 XAMelleOH

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

gakimball avatar Oct 12 '17 18:10 gakimball

Any progress? Translations data is never updated...

illycz avatar Dec 02 '17 14:12 illycz

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

@gakimball thanks for all your work!

benland avatar Jan 16 '18 12:01 benland

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.

kuzvac avatar Feb 13 '18 21:02 kuzvac

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!

gakimball avatar Feb 13 '18 22:02 gakimball

None of the given solutions (https://github.com/zurb/panini/issues/143#issuecomment-335877866 or https://github.com/zurb/panini/issues/45#issuecomment-313451499) 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.

marvinhuebner avatar Apr 18 '18 21:04 marvinhuebner