Comments (6)
Hope that helps someone.
You're damn right it did. If you were standing here, I'd kiss you.
This is also relevant:
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.
Hi, @timtribers
Could you provide the script or configuration you run with grunt?
Thanks.
from epub-gen.
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.
@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.
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.
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)
- Alternative: cpiber/epub-gen-memory for both node and browser
- Error with image URL HOT 3
- Custom fonts not getting applied in Epub Reader/Kindle Previewer
- The process randomly stop when downloading lots of images HOT 2
- Epub to html HOT 1
- Handle images which starts with relative path HOT 2
- Missing Hard timeout & Retry mechanism when downloading images. HOT 2
- insert video or audio into epub HOT 2
- Error: ENOTDIR, not a directory HOT 2
- fixed layout or reflowable layout
- Images and fonts do not appear on Apple Books HOT 3
- Custom ids gets converted to something another
- verbose: false outputs some logs
- verbose: false not working
- Showing different pub on different reader.
- Add tempDir option to documentation HOT 1
- a couple of bugs when using epub-gen HOT 1
- Object prototype may only be an Object or null: undefined
- [Question] Remove Table of Contents
- Please mark epub-gen as deprecated if it's no longer maintained. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from epub-gen.