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

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

Open
XAMelleOH opened this issue Oct 11, 2017 · 11 comments
Open

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

XAMelleOH opened this issue Oct 11, 2017 · 11 comments

Comments

@XAMelleOH
Copy link

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.

@gakimball
Copy link
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.

@XAMelleOH
Copy link
Author

XAMelleOH commented Oct 12, 2017

@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
Copy link
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)

@gakimball
Copy link
Contributor

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

@XAMelleOH
Copy link
Author

Yes, I'm.

@gakimball
Copy link
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.

@illycz
Copy link

illycz commented Dec 2, 2017

Any progress?
Translations data is never updated...

@benland
Copy link

benland commented Jan 16, 2018

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

@gakimball thanks for all your work!

@kuzvac
Copy link
Contributor

kuzvac commented Feb 13, 2018

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.

@gakimball
Copy link
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!

@marvinhuebner
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants