Code Monkey home page Code Monkey logo

Comments (6)

deanebarker avatar deanebarker commented on August 21, 2024 1

@timtribers

Hope that helps someone.

You're damn right it did. If you were standing here, I'd kiss you.

This is also relevant:

gruntjs/grunt#1531 (comment)

You cannot use this.async() this if you use the fancy "fat arrow" syntax:

grunt.registerTask('build', 'Make the EPUB', () => { ... }

You have to do the old school syntax:

grunt.registerTask('build', 'Make the EPUB', function() { ... }

from epub-gen.

cyrilis avatar cyrilis commented on August 21, 2024

Hi, @timtribers
Could you provide the script or configuration you run with grunt?
Thanks.

from epub-gen.

timtribers avatar timtribers commented on August 21, 2024

Hi @cyrilis

Actually, think I might just have worked out the problem . . .

Grunt tasks are synchronous by default, so wrapping epub-gen is fine, up until it hits some async stuff such as using fs to write a file.

There is a way to flag to make a Grunt task async - will try that.

Thx

from epub-gen.

cyrilis avatar cyrilis commented on August 21, 2024

@timtribers
You can try:

    new Epub(option [, output]).promise.then(function(){
        console.log("Ebook Generated Successfully!")
    }, function(err){
        console.error("Failed to generate Ebook because of ", err)
    })

for asynchronous usage.

cheers.

from epub-gen.

timtribers avatar timtribers commented on August 21, 2024

Yay, that was the problem - should have guessed sooner.

Here's how to wrap in Grunt, for anyone coming to this in the future . . .

  // Custom task to write epub file
  grunt.registerTask('epubGen', function(){
    var done = this.async();
    var Epub = require("epub-gen");
    ...
    new Epub(option [, output]).promise.then(function(){
        console.log("Ebook Generated Successfully!")
        setTimeout(function(){done();}, 1000);
    }, function(err){
        console.error("Failed to generate Ebook because of ", err)
        done(err);
    });
   });

Sorry to have raised an issue.

Thx for a great library.

from epub-gen.

timtribers avatar timtribers commented on August 21, 2024

Postscript
After using the above for around a month, I was still getting random times when the produced epub file was corrupted and unreadable. I spent a frustrating day trying to debug the problem, and eventually concluded that it was another timing issue.

It's crude, but the only way I found to make it go away altogether was to amend the code immediately above to replace:
done();
with:
setTimeout(function(){done();}, 1000);

Hope that helps someone.

from epub-gen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.