mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-05 15:32:55 +02:00
WIP: Update to Webpack 4 and Babel 7 (#835)
* Update to Webpack 4 and Babel 7 * Update karma tests * Update browserlist, fix tests, remove all requires * Update karma browserlist query * Update webpack externals * remove gulp and serve * Fix webpack for karma * Fix test externals
This commit is contained in:
parent
50fcbb22f5
commit
cb4facb6c2
24 changed files with 10292 additions and 13954 deletions
8
.babelrc
8
.babelrc
|
@ -1,8 +0,0 @@
|
||||||
{
|
|
||||||
"presets": [
|
|
||||||
["es2015"]
|
|
||||||
],
|
|
||||||
"plugins": [
|
|
||||||
"add-module-exports"
|
|
||||||
]
|
|
||||||
}
|
|
11
.babelrc.json
Normal file
11
.babelrc.json
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"presets": [
|
||||||
|
["@babel/preset-env", {
|
||||||
|
"targets": "last 2 Chrome versions, last 2 Safari versions, last 2 ChromeAndroid versions, last 2 iOS versions, last 2 Firefox versions, last 2 Edge versions",
|
||||||
|
"corejs": 3,
|
||||||
|
"useBuiltIns": "usage",
|
||||||
|
"bugfixes": true,
|
||||||
|
"modules": "auto"
|
||||||
|
}]
|
||||||
|
],
|
||||||
|
}
|
14
bower.json
14
bower.json
|
@ -15,7 +15,7 @@
|
||||||
"epub"
|
"epub"
|
||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"homepage": "futurepress.org",
|
"homepage": "http://futurepress.org",
|
||||||
"ignore": [
|
"ignore": [
|
||||||
"**/.*",
|
"**/.*",
|
||||||
"node_modules",
|
"node_modules",
|
||||||
|
@ -27,11 +27,13 @@
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"event-emitter": "^0.3.5",
|
"event-emitter": "^0.3.5",
|
||||||
"jszip": "^3.1.5",
|
"jszip": "^3.4.0",
|
||||||
"lodash": "^4.17.4",
|
"localforage": "^1.7.3",
|
||||||
"marks-pane": "^1.0.7",
|
"lodash": "^4.17.15",
|
||||||
|
"marks-pane": "^1.0.9",
|
||||||
"path-webpack": "0.0.3",
|
"path-webpack": "0.0.3",
|
||||||
"stream-browserify": "^2.0.1",
|
"stream-browserify": "^3.0.0",
|
||||||
"xmldom": "^0.1.27"
|
"url-polyfill": "^1.1.9",
|
||||||
|
"xmldom": "^0.3.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
166
gulpfile.js
166
gulpfile.js
|
@ -1,166 +0,0 @@
|
||||||
var gulp = require('gulp');
|
|
||||||
var jshint = require('gulp-jshint');
|
|
||||||
var concat = require('gulp-concat');
|
|
||||||
var rename = require('gulp-rename');
|
|
||||||
var uglify = require('gulp-uglify');
|
|
||||||
var gutil = require('gulp-util');
|
|
||||||
var plumber = require('gulp-plumber');
|
|
||||||
var onError = function (err) {
|
|
||||||
gutil.log(gutil.colors.green(err));
|
|
||||||
};
|
|
||||||
var server = require("./tools/serve.js");
|
|
||||||
|
|
||||||
var source = require('vinyl-source-stream');
|
|
||||||
var buffer = require('vinyl-buffer');
|
|
||||||
var sourcemaps = require('gulp-sourcemaps');
|
|
||||||
|
|
||||||
var size = require('gulp-size');
|
|
||||||
|
|
||||||
var webpack = require("webpack");
|
|
||||||
var WebpackDevServer = require("webpack-dev-server");
|
|
||||||
var webpackConfig = require("./webpack.config");
|
|
||||||
|
|
||||||
var Server = require('karma').Server;
|
|
||||||
|
|
||||||
// modify some webpack config options
|
|
||||||
var watchConfig = Object.create(webpackConfig);
|
|
||||||
watchConfig.devtool = "sourcemap";
|
|
||||||
watchConfig.watch = true;
|
|
||||||
|
|
||||||
// create a single instance of the compiler to allow caching
|
|
||||||
var watchCompiler = webpack(watchConfig);
|
|
||||||
|
|
||||||
var buildDocs = require('gulp-documentation');
|
|
||||||
|
|
||||||
// Lint JS
|
|
||||||
gulp.task('lint', function() {
|
|
||||||
return gulp.src('src/*.js')
|
|
||||||
.pipe(jshint())
|
|
||||||
.pipe(jshint.reporter('default'));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('bundle', function (cb) {
|
|
||||||
webpack(webpackConfig, function(err, stats) {
|
|
||||||
if(err) {
|
|
||||||
throw new gutil.PluginError("webpack", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
gutil.log("[webpack-bundle]", stats.toString({
|
|
||||||
colors: true,
|
|
||||||
chunks: true
|
|
||||||
}));
|
|
||||||
|
|
||||||
cb();
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Minify JS
|
|
||||||
gulp.task('minify', ['bundle'], function(){
|
|
||||||
var uglifyOptions = {
|
|
||||||
mangle: true,
|
|
||||||
preserveComments : "license"
|
|
||||||
};
|
|
||||||
return gulp.src(['dist/epub.js', 'dist/polyfills.js'])
|
|
||||||
.pipe(plumber({ errorHandler: onError }))
|
|
||||||
.pipe(rename({suffix: '.min'}))
|
|
||||||
// .pipe(sourcemaps.init({loadMaps: true}))
|
|
||||||
.pipe(uglify(uglifyOptions))
|
|
||||||
// .pipe(sourcemaps.write('./'))
|
|
||||||
.pipe(size({ showFiles: true }))
|
|
||||||
.pipe(gulp.dest('dist'));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Watch Our Files
|
|
||||||
gulp.task('watch', function(cb) {
|
|
||||||
|
|
||||||
watchCompiler.watch({}, function(err, stats) {
|
|
||||||
if(err) {
|
|
||||||
throw new gutil.PluginError("webpack", err);
|
|
||||||
}
|
|
||||||
|
|
||||||
gutil.log("[webpack-watch]", stats.toString({
|
|
||||||
colors: true,
|
|
||||||
chunks: false
|
|
||||||
}));
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('test', function(done) {
|
|
||||||
new Server({
|
|
||||||
configFile: __dirname + '/karma.conf.js',
|
|
||||||
singleRun: false
|
|
||||||
}, done).start();
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('test:once', function(done) {
|
|
||||||
new Server({
|
|
||||||
configFile: __dirname + '/karma.conf.js',
|
|
||||||
singleRun: true
|
|
||||||
}, done).start();
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task("serve", function(callback) {
|
|
||||||
server();
|
|
||||||
/*
|
|
||||||
var serverConfig = Object.create(webpackConfig);
|
|
||||||
|
|
||||||
serverConfig.devtool = "eval";
|
|
||||||
serverConfig.debug = true;
|
|
||||||
serverConfig.watch = true;
|
|
||||||
|
|
||||||
// Start a webpack-dev-server
|
|
||||||
new WebpackDevServer(webpack(serverConfig), {
|
|
||||||
stats: {
|
|
||||||
colors: true,
|
|
||||||
chunks: false
|
|
||||||
}
|
|
||||||
}).listen(8080, "localhost", function(err) {
|
|
||||||
if(err) throw new gutil.PluginError("webpack-dev-server", err);
|
|
||||||
gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/examples/index.html");
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('docs:md', function () {
|
|
||||||
return gulp.src('./src/epub.js')
|
|
||||||
.pipe(buildDocs('md'))
|
|
||||||
.pipe(gulp.dest('documentation/md'));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('docs:html', function () {
|
|
||||||
return gulp.src('./src/epub.js')
|
|
||||||
.pipe(buildDocs('html'))
|
|
||||||
.pipe(gulp.dest('documentation/html'));
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('docs:watch', function () {
|
|
||||||
return gulp.watch('./src/**/*.js', ['docs:html']);
|
|
||||||
});
|
|
||||||
|
|
||||||
gulp.task('docs', ['docs:html', 'docs:md']);
|
|
||||||
|
|
||||||
// Default
|
|
||||||
gulp.task('default', ['lint', 'bundle']);
|
|
||||||
|
|
||||||
function bundle(done) {
|
|
||||||
if (!done) {
|
|
||||||
webpackConfig.watch = true;
|
|
||||||
} else {
|
|
||||||
webpackConfig.watch = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
webpack(webpackConfig, function(err, stats) {
|
|
||||||
if(err) throw new gutil.PluginError("webpack", err);
|
|
||||||
gutil.log("[webpack]", stats.toString({
|
|
||||||
colors: true,
|
|
||||||
chunks: false
|
|
||||||
}));
|
|
||||||
|
|
||||||
done && done();
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -1,5 +1,10 @@
|
||||||
// Karma configuration
|
let webpackConfig = require("./webpack.config.js");
|
||||||
// Generated on Wed Oct 26 2016 10:56:59 GMT+0200 (CEST)
|
webpackConfig.mode = "development";
|
||||||
|
webpackConfig.externals = {};
|
||||||
|
webpackConfig.module.rules.push({
|
||||||
|
test: /\.xhtml$/i,
|
||||||
|
use: 'raw-loader',
|
||||||
|
});
|
||||||
|
|
||||||
module.exports = function(config) {
|
module.exports = function(config) {
|
||||||
config.set({
|
config.set({
|
||||||
|
@ -19,10 +24,10 @@ module.exports = function(config) {
|
||||||
{pattern: 'src/*.js', watched: true, included: false, served: false},
|
{pattern: 'src/*.js', watched: true, included: false, served: false},
|
||||||
|
|
||||||
{pattern: 'test/*.js', watched: false},
|
{pattern: 'test/*.js', watched: false},
|
||||||
// {pattern: 'test/**/*.js', watched: false}
|
|
||||||
{pattern: 'test/fixtures/**/*', watched: false, included: false, served: true},
|
{pattern: 'test/fixtures/**/*', watched: false, included: false, served: true},
|
||||||
|
|
||||||
{pattern: 'node_modules/jszip/dist/jszip.js', watched: false, included: true, served: true},
|
// {pattern: 'node_modules/jszip/dist/jszip.js', watched: false, included: true, served: true},
|
||||||
|
|
||||||
// {pattern: 'node_modules/es6-promise/dist/es6-promise.auto.js', watched: false, included: true, served: true},
|
// {pattern: 'node_modules/es6-promise/dist/es6-promise.auto.js', watched: false, included: true, served: true},
|
||||||
|
|
||||||
|
@ -43,34 +48,39 @@ module.exports = function(config) {
|
||||||
// 'test/**/*.js': ['webpack', 'sourcemap']
|
// 'test/**/*.js': ['webpack', 'sourcemap']
|
||||||
},
|
},
|
||||||
|
|
||||||
webpack:{
|
webpack: webpackConfig,
|
||||||
externals: {
|
|
||||||
"jszip": "JSZip"
|
// {
|
||||||
// "xmldom": "xmldom"
|
// mode: "development",
|
||||||
},
|
// externals: {
|
||||||
devtool: 'inline-source-map',
|
// "jszip": "JSZip"
|
||||||
resolve: {
|
// // "xmldom": "xmldom"
|
||||||
alias: {
|
// },
|
||||||
path: "path-webpack"
|
// devtool: 'inline-source-map',
|
||||||
}
|
// resolve: {
|
||||||
},
|
// alias: {
|
||||||
module: {
|
// path: "path-webpack"
|
||||||
loaders: [
|
// }
|
||||||
{
|
// },
|
||||||
test: /\.js$/,
|
// module: {
|
||||||
exclude: /node_modules\/(?!(marks-pane)\/).*/,
|
// rules: [
|
||||||
loader: "babel-loader",
|
// {
|
||||||
query: {
|
// test: /\.js$/,
|
||||||
presets: ['es2015'],
|
// exclude: /node_modules/,
|
||||||
plugins: [
|
// loader: "babel-loader",
|
||||||
"add-module-exports",
|
// query: {
|
||||||
"transform-runtime"
|
// presets: [["@babel/preset-env", {
|
||||||
]
|
// targets: "defaults",
|
||||||
}
|
// }]],
|
||||||
}
|
// }
|
||||||
]
|
// },
|
||||||
}
|
// {
|
||||||
},
|
// test: /\.xhtml$/i,
|
||||||
|
// use: 'raw-loader',
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
// },
|
||||||
|
|
||||||
webpackMiddleware: {
|
webpackMiddleware: {
|
||||||
stats: 'errors-only'
|
stats: 'errors-only'
|
||||||
|
|
|
@ -166,6 +166,4 @@ function lookup(filename) {
|
||||||
return filename && mimeTypes[filename.split(".").pop().toLowerCase()] || defaultValue;
|
return filename && mimeTypes[filename.split(".").pop().toLowerCase()] || defaultValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
export default { lookup };
|
||||||
'lookup': lookup
|
|
||||||
}
|
|
||||||
|
|
23633
package-lock.json
generated
23633
package-lock.json
generated
File diff suppressed because it is too large
Load diff
91
package.json
91
package.json
|
@ -11,81 +11,58 @@
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "karma start --single-run --browsers ChromeHeadlessNoSandbox",
|
"test": "karma start --single-run --browsers ChromeHeadlessNoSandbox",
|
||||||
"documentation": "gulp docs",
|
"docs": "documentation build src/epub.js -f html -o documentation/html/",
|
||||||
|
"docs:html": "documentation build src/epub.js -f html -o documentation/html/",
|
||||||
|
"docs:md": "documentation build src/epub.js -f md -o documentation/md/API.md",
|
||||||
"lint": "eslint -c .eslintrc.js src; exit 0",
|
"lint": "eslint -c .eslintrc.js src; exit 0",
|
||||||
"start": "webpack-dev-server --inline --d",
|
"start": "webpack-dev-server --inline --d",
|
||||||
"build": "webpack --progress",
|
"build": "NODE_ENV=production webpack --progress",
|
||||||
"minify": "NODE_ENV=production npm run build",
|
"minify": "NODE_ENV=production MINIMIZE=true webpack --progress",
|
||||||
"legacy": "LEGACY=true npm run build",
|
"legacy": "NODE_ENV=production LEGACY=true webpack --progress",
|
||||||
"productionLegacy": "NODE_ENV=production LEGACY=true npm run build",
|
"productionLegacy": "NODE_ENV=production MINIMIZE=true LEGACY=true webpack --progress",
|
||||||
"compile": "babel --optional runtime -d lib/ src/",
|
"compile": "babel -d lib/ src/",
|
||||||
"watch": "babel --watch --optional runtime -d lib/ src/",
|
"watch": "babel --watch -d lib/ src/",
|
||||||
"serve": "gulp serve",
|
|
||||||
"prepare": "npm run compile && npm run build && npm run minify && npm run legacy && npm run productionLegacy"
|
"prepare": "npm run compile && npm run build && npm run minify && npm run legacy && npm run productionLegacy"
|
||||||
},
|
},
|
||||||
"author": "fchasen@gmail.com",
|
"author": "fchasen@gmail.com",
|
||||||
"license": "BSD-2-Clause",
|
"license": "BSD-2-Clause",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-cli": "^6.26.0",
|
"@babel/cli": "^7.10.1",
|
||||||
"babel-core": "^6.26.3",
|
"@babel/core": "^7.10.2",
|
||||||
"babel-loader": "^7.1.5",
|
"@babel/plugin-proposal-export-default-from": "^7.10.1",
|
||||||
"babel-plugin-add-module-exports": "^0.2.1",
|
"@babel/plugin-proposal-export-namespace-from": "^7.10.1",
|
||||||
"babel-plugin-transform-runtime": "^6.23.0",
|
"@babel/preset-env": "^7.10.2",
|
||||||
"babel-polyfill": "^6.26.0",
|
"@babel/runtime": "^7.10.2",
|
||||||
"babel-preset-env": "1.6.0",
|
"babel-loader": "^8.1.0",
|
||||||
"babel-preset-es2015": "^6.24.1",
|
"documentation": "^13.0.1",
|
||||||
"babili-webpack-plugin": "0.1.2",
|
"eslint": "^7.1.0",
|
||||||
"colors": "^1.3.0",
|
"jsdoc": "^3.6.4",
|
||||||
"connect": "^3.6.6",
|
"karma": "^5.0.9",
|
||||||
"documentation": "^5.5.0",
|
"karma-chrome-launcher": "^3.1.0",
|
||||||
"eslint": "^4.19.1",
|
"karma-mocha": "^2.0.1",
|
||||||
"express": "^4.16.3",
|
|
||||||
"gulp": "^3.9.1",
|
|
||||||
"gulp-concat": "^2.6.1",
|
|
||||||
"gulp-connect": "~5.0.0",
|
|
||||||
"gulp-documentation": "3.2.1",
|
|
||||||
"gulp-jshint": "^2.1.0",
|
|
||||||
"gulp-plumber": "^1.2.0",
|
|
||||||
"gulp-rename": "^1.3.0",
|
|
||||||
"gulp-size": "^2.1.0",
|
|
||||||
"gulp-sourcemaps": "^2.6.4",
|
|
||||||
"gulp-uglify": "^3.0.0",
|
|
||||||
"gulp-util": "^3.0.8",
|
|
||||||
"jsdoc": "^3.5.5",
|
|
||||||
"jshint": "^2.9.5",
|
|
||||||
"karma": "^1.7.1",
|
|
||||||
"karma-chrome-launcher": "^2.2.0",
|
|
||||||
"karma-mocha": "^1.3.0",
|
|
||||||
"karma-mocha-reporter": "^2.2.5",
|
"karma-mocha-reporter": "^2.2.5",
|
||||||
"karma-phantomjs-launcher": "^1.0.4",
|
"karma-phantomjs-launcher": "^1.0.4",
|
||||||
"karma-sourcemap-loader": "^0.3.7",
|
"karma-sourcemap-loader": "^0.3.7",
|
||||||
"karma-webpack": "^2.0.13",
|
"karma-webpack": "next",
|
||||||
"mocha": "^3.5.3",
|
"mocha": "^7.2.0",
|
||||||
"mocha-loader": "^1.1.3",
|
"mocha-loader": "^5.0.0",
|
||||||
"morgan": "^1.9.0",
|
"raw-loader": "^4.0.1",
|
||||||
"optimist": "^0.6.1",
|
"terser-webpack-plugin": "^3.0.3",
|
||||||
"portfinder": "^1.0.13",
|
"tsd-jsdoc": "^2.5.0",
|
||||||
"raw-loader": "^0.5.1",
|
"webpack": "^4.43.0",
|
||||||
"serve-static": "^1.13.2",
|
"webpack-cli": "^3.3.11",
|
||||||
"tsd-jsdoc": "^2.0.0-beta.6",
|
"webpack-dev-middleware": "^3.7.2",
|
||||||
"uglify": "^0.1.5",
|
"webpack-dev-server": "^3.11.0"
|
||||||
"vinyl-buffer": "^1.0.1",
|
|
||||||
"vinyl-source-stream": "^1.1.2",
|
|
||||||
"webpack": "^3.12.0",
|
|
||||||
"webpack-dev-middleware": "^1.12.2",
|
|
||||||
"webpack-dev-server": "^2.11.2"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/jszip": "^3.4.1",
|
|
||||||
"@types/localforage": "0.0.34",
|
"@types/localforage": "0.0.34",
|
||||||
|
"core-js": "^3.6.5",
|
||||||
"event-emitter": "^0.3.5",
|
"event-emitter": "^0.3.5",
|
||||||
"jszip": "^3.4.0",
|
"jszip": "^3.4.0",
|
||||||
"localforage": "^1.7.3",
|
"localforage": "^1.7.3",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"marks-pane": "^1.0.9",
|
"marks-pane": "^1.0.9",
|
||||||
"path-webpack": "0.0.3",
|
"path-webpack": "0.0.3",
|
||||||
"stream-browserify": "^2.0.1",
|
"xmldom": "^0.3.0"
|
||||||
"url-polyfill": "^1.1.9",
|
|
||||||
"xmldom": "^0.1.27"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ import {defer, isXml, parse} from "./utils/core";
|
||||||
import request from "./utils/request";
|
import request from "./utils/request";
|
||||||
import mime from "../libs/mime/mime";
|
import mime from "../libs/mime/mime";
|
||||||
import Path from "./utils/path";
|
import Path from "./utils/path";
|
||||||
|
import JSZip from "jszip/dist/jszip";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles Unzipping a requesting files from an Epub Archive
|
* Handles Unzipping a requesting files from an Epub Archive
|
||||||
|
@ -24,12 +25,7 @@ class Archive {
|
||||||
*/
|
*/
|
||||||
checkRequirements(){
|
checkRequirements(){
|
||||||
try {
|
try {
|
||||||
if (typeof JSZip === "undefined") {
|
this.zip = new JSZip();
|
||||||
let JSZip = require("jszip");
|
|
||||||
this.zip = new JSZip();
|
|
||||||
} else {
|
|
||||||
this.zip = new JSZip();
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw new Error("JSZip lib not loaded");
|
throw new Error("JSZip lib not loaded");
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import CFI from "./epubcfi";
|
||||||
import Contents from "./contents";
|
import Contents from "./contents";
|
||||||
import * as utils from "./utils/core";
|
import * as utils from "./utils/core";
|
||||||
import { EPUBJS_VERSION } from "./utils/constants";
|
import { EPUBJS_VERSION } from "./utils/constants";
|
||||||
import * as URLpolyfill from "url-polyfill";
|
|
||||||
|
|
||||||
import IframeView from "./managers/views/iframe";
|
import IframeView from "./managers/views/iframe";
|
||||||
import DefaultViewManager from "./managers/default";
|
import DefaultViewManager from "./managers/default";
|
||||||
|
|
|
@ -147,6 +147,7 @@ class Rendition {
|
||||||
* @memberof Rendition
|
* @memberof Rendition
|
||||||
*/
|
*/
|
||||||
this.started = this.starting.promise;
|
this.started = this.starting.promise;
|
||||||
|
|
||||||
// Block the queue until rendering is started
|
// Block the queue until rendering is started
|
||||||
this.q.enqueue(this.start);
|
this.q.enqueue(this.start);
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,8 +141,7 @@ class Resources {
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
var replacements = this.urls.
|
var replacements = this.urls.map( (url) => {
|
||||||
map( (url) => {
|
|
||||||
var absolute = this.settings.resolver(url);
|
var absolute = this.settings.resolver(url);
|
||||||
|
|
||||||
return this.createUrl(absolute).
|
return this.createUrl(absolute).
|
||||||
|
|
|
@ -3,6 +3,8 @@ import EpubCFI from "./epubcfi";
|
||||||
import Hook from "./utils/hook";
|
import Hook from "./utils/hook";
|
||||||
import { sprint } from "./utils/core";
|
import { sprint } from "./utils/core";
|
||||||
import { replaceBase } from "./utils/replacements";
|
import { replaceBase } from "./utils/replacements";
|
||||||
|
import Request from "./utils/request";
|
||||||
|
import { XMLDOMParser as XMLDOMSerializer } from "xmldom";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a Section of the Book
|
* Represents a Section of the Book
|
||||||
|
@ -44,7 +46,7 @@ class Section {
|
||||||
* @return {document} a promise with the xml document
|
* @return {document} a promise with the xml document
|
||||||
*/
|
*/
|
||||||
load(_request){
|
load(_request){
|
||||||
var request = _request || this.request || require("./utils/request");
|
var request = _request || this.request || Request;
|
||||||
var loading = new defer();
|
var loading = new defer();
|
||||||
var loaded = loading.promise;
|
var loaded = loading.promise;
|
||||||
|
|
||||||
|
@ -95,7 +97,7 @@ class Section {
|
||||||
var isIE = userAgent.indexOf('Trident') >= 0;
|
var isIE = userAgent.indexOf('Trident') >= 0;
|
||||||
var Serializer;
|
var Serializer;
|
||||||
if (typeof XMLSerializer === "undefined" || isIE) {
|
if (typeof XMLSerializer === "undefined" || isIE) {
|
||||||
Serializer = require("xmldom/dom-parser").XMLSerializer;
|
Serializer = XMLDOMSerializer;
|
||||||
} else {
|
} else {
|
||||||
Serializer = XMLSerializer;
|
Serializer = XMLSerializer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import httpRequest from "./utils/request";
|
||||||
import mime from "../libs/mime/mime";
|
import mime from "../libs/mime/mime";
|
||||||
import Path from "./utils/path";
|
import Path from "./utils/path";
|
||||||
import EventEmitter from "event-emitter";
|
import EventEmitter from "event-emitter";
|
||||||
|
import localforage from "localforage";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles saving and requesting files from local storage
|
* Handles saving and requesting files from local storage
|
||||||
|
@ -38,8 +39,6 @@ class Store {
|
||||||
try {
|
try {
|
||||||
let store;
|
let store;
|
||||||
if (typeof localforage === "undefined") {
|
if (typeof localforage === "undefined") {
|
||||||
store = require("localforage");
|
|
||||||
} else {
|
|
||||||
store = localforage;
|
store = localforage;
|
||||||
}
|
}
|
||||||
this.storage = store.createInstance({
|
this.storage = store.createInstance({
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* Core Utilities and Helpers
|
* Core Utilities and Helpers
|
||||||
* @module Core
|
* @module Core
|
||||||
*/
|
*/
|
||||||
|
import { DOMParser as XMLDOMParser } from "xmldom";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vendor prefixed requestAnimationFrame
|
* Vendor prefixed requestAnimationFrame
|
||||||
|
@ -476,7 +477,7 @@ export function parse(markup, mime, forceXMLDom) {
|
||||||
var Parser;
|
var Parser;
|
||||||
|
|
||||||
if (typeof DOMParser === "undefined" || forceXMLDom) {
|
if (typeof DOMParser === "undefined" || forceXMLDom) {
|
||||||
Parser = require("xmldom").DOMParser;
|
Parser = XMLDOMParser;
|
||||||
} else {
|
} else {
|
||||||
Parser = DOMParser;
|
Parser = DOMParser;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
var assert = require('assert');
|
import Book from '../src/book';
|
||||||
|
import assert from 'assert';
|
||||||
|
|
||||||
describe('Book', function() {
|
describe('Book', function() {
|
||||||
|
|
||||||
var Book = require('../src/book');
|
|
||||||
|
|
||||||
describe('Unarchived', function() {
|
describe('Unarchived', function() {
|
||||||
var book = new Book("/fixtures/alice/OPS/package.opf");
|
var book = new Book("/fixtures/alice/OPS/package.opf");
|
||||||
it('should open a epub', async function() {
|
it('should open a epub', async function() {
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
var assert = require('assert');
|
import assert from 'assert';
|
||||||
|
import Url from '../src/utils/url';
|
||||||
|
import Path from '../src/utils/path';
|
||||||
|
|
||||||
describe('Core', function() {
|
describe('Core', function() {
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,8 +12,6 @@ describe('Core', function() {
|
||||||
|
|
||||||
describe('Url', function () {
|
describe('Url', function () {
|
||||||
|
|
||||||
var Url = require('../src/utils/url');
|
|
||||||
|
|
||||||
it("Url()", function() {
|
it("Url()", function() {
|
||||||
var url = new Url("http://example.com/fred/chasen/derf.html");
|
var url = new Url("http://example.com/fred/chasen/derf.html");
|
||||||
|
|
||||||
|
@ -90,8 +91,6 @@ describe('Core', function() {
|
||||||
|
|
||||||
describe('Path', function () {
|
describe('Path', function () {
|
||||||
|
|
||||||
var Path = require('../src/utils/path');
|
|
||||||
|
|
||||||
it("Path()", function() {
|
it("Path()", function() {
|
||||||
var path = new Path("/fred/chasen/derf.html");
|
var path = new Path("/fred/chasen/derf.html");
|
||||||
|
|
||||||
|
|
10
test/epub.js
10
test/epub.js
|
@ -1,16 +1,16 @@
|
||||||
var assert = require('assert');
|
import assert from 'assert';
|
||||||
|
import ePub from '../src/epub';
|
||||||
// var sinon = require('sinon');
|
// var sinon = require('sinon');
|
||||||
|
|
||||||
|
|
||||||
describe('ePub', function() {
|
describe('ePub', function() {
|
||||||
var ePub = require('../src/epub');
|
|
||||||
var server;
|
var server;
|
||||||
before(function(){
|
before(function(){
|
||||||
/*
|
/*
|
||||||
// var packageContents = fs.readFileSync(__dirname + '/../books/moby-dick/OPS/package.opf', 'utf8');
|
// var packageContents = fs.readFileSync(__dirname + '/../books/moby-dick/OPS/package.opf', 'utf8');
|
||||||
// var tocContents = fs.readFileSync(__dirname + '/../books/moby-dick/OPS/toc.xhtml', 'utf8');
|
// var tocContents = fs.readFileSync(__dirname + '/../books/moby-dick/OPS/toc.xhtml', 'utf8');
|
||||||
var packageContents = require('raw-loader!./fixtures/moby-dick/OPS/package.opf');
|
var packageContents = require('./fixtures/moby-dick/OPS/package.opf');
|
||||||
var tocContents = require('raw-loader!./fixtures/moby-dick/OPS/toc.xhtml');
|
var tocContents = require('./fixtures/moby-dick/OPS/toc.xhtml');
|
||||||
|
|
||||||
server = sinon.fakeServer.create();
|
server = sinon.fakeServer.create();
|
||||||
server.autoRespond = true;
|
server.autoRespond = true;
|
||||||
|
@ -41,7 +41,7 @@ describe('ePub', function() {
|
||||||
it('should open a archived epub', function() {
|
it('should open a archived epub', function() {
|
||||||
var book = ePub("/fixtures/alice.epub");
|
var book = ePub("/fixtures/alice.epub");
|
||||||
|
|
||||||
assert(typeof (JSZip) !== "undefined", "JSZip is present" );
|
// assert(typeof (JSZip) !== "undefined", "JSZip is present" );
|
||||||
|
|
||||||
return book.opened.then(function(){
|
return book.opened.then(function(){
|
||||||
assert.equal( book.isOpen, true, "book is opened" );
|
assert.equal( book.isOpen, true, "book is opened" );
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
var assert = require('assert');
|
import assert from 'assert';
|
||||||
|
import EpubCFI from '../src/epubcfi.js';
|
||||||
// var fs = require('fs');
|
// var fs = require('fs');
|
||||||
if (typeof DOMParser === "undefined") {
|
if (typeof DOMParser === "undefined") {
|
||||||
global.DOMParser = require('xmldom').DOMParser;
|
global.DOMParser = require('xmldom').DOMParser;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('EpubCFI', function() {
|
describe('EpubCFI', function() {
|
||||||
var EpubCFI = require('../src/epubcfi.js');
|
|
||||||
|
|
||||||
it('parse a cfi on init', function() {
|
it('parse a cfi on init', function() {
|
||||||
var cfi = new EpubCFI("epubcfi(/6/2[cover]!/6)");
|
var cfi = new EpubCFI("epubcfi(/6/2[cover]!/6)");
|
||||||
|
@ -152,7 +152,7 @@ describe('EpubCFI', function() {
|
||||||
describe('#fromNode()', function() {
|
describe('#fromNode()', function() {
|
||||||
var base = "/6/4[chap01ref]";
|
var base = "/6/4[chap01ref]";
|
||||||
// var contents = fs.readFileSync(__dirname + '/fixtures/chapter1-highlights.xhtml', 'utf8');
|
// var contents = fs.readFileSync(__dirname + '/fixtures/chapter1-highlights.xhtml', 'utf8');
|
||||||
var contents = require('raw-loader!./fixtures/chapter1-highlights.xhtml');
|
var contents = require('./fixtures/chapter1-highlights.xhtml').default;
|
||||||
|
|
||||||
// var serializer = new XMLSerializer();
|
// var serializer = new XMLSerializer();
|
||||||
// var doc = serializer.serializeToString(contents);
|
// var doc = serializer.serializeToString(contents);
|
||||||
|
@ -201,16 +201,16 @@ describe('EpubCFI', function() {
|
||||||
var base = "/6/4[chap01ref]";
|
var base = "/6/4[chap01ref]";
|
||||||
|
|
||||||
// var contentsClean = fs.readFileSync(__dirname + '/fixtures/chapter1.xhtml', 'utf8');
|
// var contentsClean = fs.readFileSync(__dirname + '/fixtures/chapter1.xhtml', 'utf8');
|
||||||
var contentsClean = require('raw-loader!./fixtures/chapter1.xhtml');
|
var contentsClean = require('./fixtures/chapter1.xhtml').default;
|
||||||
|
|
||||||
var doc = new DOMParser().parseFromString(contentsClean, "application/xhtml+xml");
|
var doc = new DOMParser().parseFromString(contentsClean, "application/xhtml+xml");
|
||||||
|
|
||||||
// var contentsHighlights = fs.readFileSync(__dirname + '/fixtures/chapter1-highlights.xhtml', 'utf8');
|
// var contentsHighlights = fs.readFileSync(__dirname + '/fixtures/chapter1-highlights.xhtml', 'utf8');
|
||||||
var contentsHighlights = require('raw-loader!./fixtures/chapter1-highlights.xhtml');
|
var contentsHighlights = require('./fixtures/chapter1-highlights.xhtml').default;
|
||||||
var docHighlights = new DOMParser().parseFromString(contentsHighlights, "application/xhtml+xml");
|
var docHighlights = new DOMParser().parseFromString(contentsHighlights, "application/xhtml+xml");
|
||||||
|
|
||||||
// var highlightContents = fs.readFileSync(__dirname + '/fixtures/highlight.xhtml', 'utf8');
|
// var highlightContents = fs.readFileSync(__dirname + '/fixtures/highlight.xhtml', 'utf8');
|
||||||
var highlightContents = require('raw-loader!./fixtures/highlight.xhtml');
|
var highlightContents = require('./fixtures/highlight.xhtml').default;
|
||||||
var docHighlightsAlice = new DOMParser().parseFromString(highlightContents, "application/xhtml+xml");
|
var docHighlightsAlice = new DOMParser().parseFromString(highlightContents, "application/xhtml+xml");
|
||||||
|
|
||||||
it('get a cfi from a collapsed range', function() {
|
it('get a cfi from a collapsed range', function() {
|
||||||
|
@ -317,7 +317,8 @@ describe('EpubCFI', function() {
|
||||||
describe('#toRange()', function() {
|
describe('#toRange()', function() {
|
||||||
var base = "/6/4[chap01ref]";
|
var base = "/6/4[chap01ref]";
|
||||||
// var contents = fs.readFileSync(__dirname + '/fixtures/chapter1-highlights.xhtml', 'utf8');
|
// var contents = fs.readFileSync(__dirname + '/fixtures/chapter1-highlights.xhtml', 'utf8');
|
||||||
var contents = require('raw-loader!./fixtures/chapter1-highlights.xhtml');
|
var contents = require('./fixtures/chapter1-highlights.xhtml').default;
|
||||||
|
|
||||||
var doc = new DOMParser().parseFromString(contents, "application/xhtml+xml");
|
var doc = new DOMParser().parseFromString(contents, "application/xhtml+xml");
|
||||||
|
|
||||||
// var serializer = new XMLSerializer();
|
// var serializer = new XMLSerializer();
|
||||||
|
@ -388,7 +389,6 @@ describe('EpubCFI', function() {
|
||||||
|
|
||||||
// Check the range
|
// Check the range
|
||||||
newRange = cfi.toRange(doc, 'annotator-hl');
|
newRange = cfi.toRange(doc, 'annotator-hl');
|
||||||
console.log(".startContainer", newRange);
|
|
||||||
|
|
||||||
assert.ok(newRange.startContainer);
|
assert.ok(newRange.startContainer);
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
var assert = require('assert');
|
import assert from 'assert';
|
||||||
|
import Locations from '../src/locations';
|
||||||
|
import * as core from '../src/utils/core';
|
||||||
|
|
||||||
describe('Locations', function() {
|
describe('Locations', function() {
|
||||||
var Locations = require('../src/locations');
|
|
||||||
var core = require('../src/utils/core');
|
|
||||||
|
|
||||||
describe('#parse', function() {
|
describe('#parse', function() {
|
||||||
var Locations = require('../src/locations');
|
var chapter = require('./fixtures/locations.xhtml').default;
|
||||||
var chapter = require('raw-loader!./fixtures/locations.xhtml');
|
|
||||||
|
|
||||||
it('parse locations from a document', function() {
|
it('parse locations from a document', function() {
|
||||||
var doc = core.parse(chapter, "application/xhtml+xml");
|
var doc = core.parse(chapter, "application/xhtml+xml");
|
||||||
var contents = doc.documentElement;
|
var contents = doc.documentElement;
|
||||||
var locations = new Locations();
|
var locations = new Locations();
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
var assert = require("assert");
|
import assert from 'assert';
|
||||||
var ePub = require('../src/epub');
|
import ePub from '../src/epub';
|
||||||
|
|
||||||
describe("section", function() {
|
describe("section", function() {
|
||||||
it("finds a single result in a section", function() {
|
it("finds a single result in a section", function() {
|
||||||
|
|
12
tools/serve
12
tools/serve
|
@ -1,12 +0,0 @@
|
||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
var argv = require('optimist').argv;
|
|
||||||
var server = require('./serve.js');
|
|
||||||
|
|
||||||
var port = argv.p;
|
|
||||||
|
|
||||||
if (!argv.p) {
|
|
||||||
server();
|
|
||||||
} else {
|
|
||||||
server(port);
|
|
||||||
}
|
|
|
@ -1,64 +0,0 @@
|
||||||
var connect = require('connect');
|
|
||||||
var express = require('express');
|
|
||||||
var http = require('http');
|
|
||||||
var fs = require('fs');
|
|
||||||
var serveStatic = require('serve-static');
|
|
||||||
var morgan = require('morgan');
|
|
||||||
var colors = require('colors');
|
|
||||||
var argv = require('optimist').argv;
|
|
||||||
var portfinder = require('portfinder');
|
|
||||||
var path = require('path');
|
|
||||||
var logger, port;
|
|
||||||
var log = console.log;
|
|
||||||
|
|
||||||
function start(_port) {
|
|
||||||
if (!_port) {
|
|
||||||
portfinder.basePort = 8080;
|
|
||||||
portfinder.getPort(function (err, openPort) {
|
|
||||||
if (err) throw err;
|
|
||||||
port = openPort
|
|
||||||
listen(port);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
listen(_port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//CORS middleware
|
|
||||||
function allowCrossDomain(req, res, next) {
|
|
||||||
res.header('Access-Control-Allow-Origin', '*');
|
|
||||||
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
|
|
||||||
res.header('Access-Control-Allow-Headers', 'Content-Type');
|
|
||||||
|
|
||||||
next();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function listen(port) {
|
|
||||||
|
|
||||||
var app = express();
|
|
||||||
var staticServer = serveStatic(path.resolve(__dirname, '../'), {'index': ['index.html', 'index.htm']})
|
|
||||||
|
|
||||||
var server = http.createServer(app);
|
|
||||||
|
|
||||||
app.use(allowCrossDomain);
|
|
||||||
app.use(staticServer);
|
|
||||||
|
|
||||||
if(!logger) app.use(morgan('dev'))
|
|
||||||
|
|
||||||
server.listen(port);
|
|
||||||
|
|
||||||
log('Starting up Server, serving '.yellow
|
|
||||||
+ __dirname.replace("tools", '').green
|
|
||||||
+ ' on port: '.yellow
|
|
||||||
+ port.toString().cyan);
|
|
||||||
log('Hit CTRL-C to stop the server');
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
process.on('SIGINT', function () {
|
|
||||||
log('Server stopped.'.red);
|
|
||||||
process.exit();
|
|
||||||
});
|
|
||||||
|
|
||||||
module.exports = start;
|
|
|
@ -1,35 +1,47 @@
|
||||||
var webpack = require("webpack");
|
var webpack = require("webpack");
|
||||||
var path = require('path');
|
var path = require("path");
|
||||||
var BabiliPlugin = require("babili-webpack-plugin");
|
var PROD = (process.env.NODE_ENV === "production")
|
||||||
var PROD = (process.env.NODE_ENV === 'production')
|
|
||||||
var LEGACY = (process.env.LEGACY)
|
var LEGACY = (process.env.LEGACY)
|
||||||
|
var MINIMIZE = (process.env.MINIMIZE === "true")
|
||||||
var hostname = "localhost";
|
var hostname = "localhost";
|
||||||
var port = 8080;
|
var port = 8080;
|
||||||
var enter = LEGACY ? {
|
|
||||||
"epub.legacy": ["babel-polyfill", "./src/epub.js"]
|
var filename = "[name]";
|
||||||
} : {
|
var sourceMapFilename = "[name]";
|
||||||
"epub": "./src/epub.js",
|
if (LEGACY) {
|
||||||
};
|
filename += ".legacy";
|
||||||
|
}
|
||||||
|
if (MINIMIZE) {
|
||||||
|
filename += ".min.js";
|
||||||
|
sourceMapFilename += ".min.js.map";
|
||||||
|
} else {
|
||||||
|
filename += ".js";
|
||||||
|
sourceMapFilename += ".js.map";
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
entry: enter,
|
mode: process.env.NODE_ENV,
|
||||||
devtool: PROD ? false : 'source-map',
|
entry: {
|
||||||
|
"epub": "./src/epub.js",
|
||||||
|
},
|
||||||
|
devtool: MINIMIZE ? false : 'source-map',
|
||||||
output: {
|
output: {
|
||||||
path: path.resolve("./dist"),
|
path: path.resolve("./dist"),
|
||||||
// path: "./dist",
|
filename: filename,
|
||||||
filename: PROD ? "[name].min.js" : "[name].js",
|
sourceMapFilename: sourceMapFilename,
|
||||||
sourceMapFilename: "[name].js.map",
|
|
||||||
library: "ePub",
|
library: "ePub",
|
||||||
libraryTarget: "umd",
|
libraryTarget: "umd",
|
||||||
|
libraryExport: "default",
|
||||||
publicPath: "/dist/"
|
publicPath: "/dist/"
|
||||||
},
|
},
|
||||||
|
optimization: {
|
||||||
|
minimize: MINIMIZE
|
||||||
|
},
|
||||||
externals: {
|
externals: {
|
||||||
"jszip": "jszip",
|
"jszip/dist/jszip": "JSZip",
|
||||||
"xmldom": "xmldom"
|
"xmldom": "xmldom"
|
||||||
},
|
},
|
||||||
plugins: PROD ? [
|
plugins: [],
|
||||||
new BabiliPlugin()
|
|
||||||
] : [],
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
path: "path-webpack"
|
path: "path-webpack"
|
||||||
|
@ -38,33 +50,34 @@ module.exports = {
|
||||||
devServer: {
|
devServer: {
|
||||||
host: hostname,
|
host: hostname,
|
||||||
port: port,
|
port: port,
|
||||||
inline: true
|
inline: true,
|
||||||
|
headers: {
|
||||||
|
"Access-Control-Allow-Origin": "*",
|
||||||
|
"Access-Control-Allow-Methods": "GET,PUT,POST,DELETE",
|
||||||
|
"Access-Control-Allow-Headers": "Content-Type"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
loaders: [
|
rules: [
|
||||||
{
|
{
|
||||||
test: /\.js$/,
|
test: /\.js$/,
|
||||||
exclude: /node_modules\/(?!(marks-pane)\/).*/,
|
exclude: /node_modules/,
|
||||||
loader: "babel-loader",
|
use: {
|
||||||
query: LEGACY ? {
|
loader: "babel-loader",
|
||||||
presets: ['es2015'],
|
options: {
|
||||||
plugins: [
|
presets: [["@babel/preset-env", {
|
||||||
"add-module-exports",
|
targets: LEGACY ? "defaults" : "last 2 Chrome versions, last 2 Safari versions, last 2 ChromeAndroid versions, last 2 iOS versions, last 2 Firefox versions, last 2 Edge versions",
|
||||||
]
|
corejs: 3,
|
||||||
} : {
|
useBuiltIns: "usage",
|
||||||
presets: [["env", {
|
bugfixes: true,
|
||||||
"targets": {
|
modules: false
|
||||||
"chrome": 54,
|
}]]
|
||||||
"safari" : 10,
|
}
|
||||||
"firefox" : 50,
|
|
||||||
"edge" : 14
|
|
||||||
}
|
|
||||||
}]],
|
|
||||||
plugins: [
|
|
||||||
"add-module-exports",
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
performance: {
|
||||||
|
hints: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue