wp-epub-gen 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{dist → build}/downloadImage.d.ts +0 -0
- package/{dist → build}/downloadImage.js +0 -0
- package/build/downloadImage.js.map +1 -0
- package/{dist → build}/errors.d.ts +0 -0
- package/{dist → build}/errors.js +0 -0
- package/build/errors.js.map +1 -0
- package/{dist → build}/generateTempFile.d.ts +0 -0
- package/{dist → build}/generateTempFile.js +0 -0
- package/build/generateTempFile.js.map +1 -0
- package/{dist → build}/index.d.ts +0 -0
- package/{dist → build}/index.js +0 -0
- package/build/index.js.map +1 -0
- package/{dist → build}/makeCover.d.ts +0 -0
- package/{dist → build}/makeCover.js +0 -0
- package/build/makeCover.js.map +1 -0
- package/{dist → build}/parseContent.d.ts +0 -0
- package/{dist → build}/parseContent.js +0 -0
- package/build/parseContent.js.map +1 -0
- package/{dist → build}/render.d.ts +0 -0
- package/{dist → build}/render.js +0 -0
- package/build/render.js.map +1 -0
- package/{dist → build}/utils.d.ts +0 -0
- package/{dist → build}/utils.js +0 -0
- package/build/utils.js.map +1 -0
- package/cpi.epub +0 -0
- package/package.json +17 -21
- package/templates/epub3/content.opf.ejs +19 -22
- package/test.epub +0 -0
- package/tsconfig.json +1 -1
- package/src/downloadImage.ts +0 -83
- package/src/errors.ts +0 -11
- package/src/generateTempFile.ts +0 -144
- package/src/index.ts +0 -152
- package/src/makeCover.ts +0 -52
- package/src/parseContent.ts +0 -351
- package/src/render.ts +0 -84
- package/src/types.d.ts +0 -79
- package/src/utils.ts +0 -39
- package/test/basic.test.js +0 -28
- package/test/child-page-image.test.js +0 -21
- package/test/data/1.json +0 -21
- package/test/tt.js +0 -16
- package/webpack.config.js +0 -75
package/src/utils.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* utils
|
|
3
|
-
* @author: oldj
|
|
4
|
-
* @homepage: https://oldj.net
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import * as fs from 'fs'
|
|
8
|
-
import { promisify } from 'util'
|
|
9
|
-
|
|
10
|
-
export const readFile = promisify(fs.readFile)
|
|
11
|
-
export const writeFile = promisify(fs.writeFile)
|
|
12
|
-
|
|
13
|
-
export const USER_AGENT =
|
|
14
|
-
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36'
|
|
15
|
-
|
|
16
|
-
export const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
|
|
17
|
-
|
|
18
|
-
export async function fileIsStable(filename: string, max_wait: number = 30000): Promise<boolean> {
|
|
19
|
-
let start_time = new Date().getTime()
|
|
20
|
-
let last_size = fs.statSync(filename).size
|
|
21
|
-
|
|
22
|
-
while (new Date().getTime() - start_time <= max_wait) {
|
|
23
|
-
await wait(1000)
|
|
24
|
-
let size = fs.statSync(filename).size
|
|
25
|
-
if (size === last_size) return true
|
|
26
|
-
last_size = size
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return false
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function simpleMinifier(xhtml: string) {
|
|
33
|
-
xhtml = xhtml
|
|
34
|
-
.replace(/\s+<\/a>/gi, '</a>')
|
|
35
|
-
.replace(/\n\s+</g, '\n<')
|
|
36
|
-
.replace(/\n+/g, '\n')
|
|
37
|
-
|
|
38
|
-
return xhtml
|
|
39
|
-
}
|
package/test/basic.test.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author: oldj
|
|
3
|
-
* @homepage: https://oldj.net
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { assert } from 'chai'
|
|
7
|
-
import { epubGen } from '../dist/index'
|
|
8
|
-
import { errors } from '../dist/errors'
|
|
9
|
-
import * as data from './data/1.json'
|
|
10
|
-
|
|
11
|
-
describe('Basic', () => {
|
|
12
|
-
it('no output path error', async () => {
|
|
13
|
-
let out = await epubGen({ ...data, verbose: false })
|
|
14
|
-
assert.equal(out.success, false)
|
|
15
|
-
assert.equal(out.message, errors.no_output_path)
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
it('basic test', async () => {
|
|
19
|
-
let out = { options: {} }
|
|
20
|
-
try {
|
|
21
|
-
out = await epubGen({ ...data }, 'test.epub')
|
|
22
|
-
} catch (e) {
|
|
23
|
-
console.error('Error 24: ' + e.message)
|
|
24
|
-
}
|
|
25
|
-
assert.equal(out.success, true)
|
|
26
|
-
assert.equal(typeof out.options.tmpDir, 'string')
|
|
27
|
-
}).timeout(60 * 1000)
|
|
28
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author: oldj
|
|
3
|
-
* @homepage: https://oldj.net
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { assert } from 'chai'
|
|
7
|
-
import { epubGen } from '../dist/index'
|
|
8
|
-
import * as data from './data/1.json'
|
|
9
|
-
|
|
10
|
-
describe('Child page image', () => {
|
|
11
|
-
it.only('should has image', async () => {
|
|
12
|
-
let out = { options: {} }
|
|
13
|
-
try {
|
|
14
|
-
out = await epubGen({ ...data }, 'cpi.epub')
|
|
15
|
-
} catch (e) {
|
|
16
|
-
console.error('Error 24: ' + e.message)
|
|
17
|
-
}
|
|
18
|
-
assert.equal(out.success, true)
|
|
19
|
-
assert.equal(typeof out.options.tmpDir, 'string')
|
|
20
|
-
}).timeout(60 * 1000)
|
|
21
|
-
})
|
package/test/data/1.json
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"title": "多层目录",
|
|
3
|
-
"author": "Andy",
|
|
4
|
-
"lang": "zh-cn",
|
|
5
|
-
"content": [
|
|
6
|
-
{
|
|
7
|
-
"title": "aaa",
|
|
8
|
-
"data": "<div>aa</div>"
|
|
9
|
-
},
|
|
10
|
-
{
|
|
11
|
-
"title": "bbb",
|
|
12
|
-
"data": "bb",
|
|
13
|
-
"children": [
|
|
14
|
-
{
|
|
15
|
-
"title": "cc1",
|
|
16
|
-
"data": "<div><img src=\"https://media.zine.la/booklet/81/a3/23/8b05c1faa4fb7ffe84727d99a2_1593030700_James-Turrell-2.jpg?imageMogr2/thumbnail/!400x520r/gravity/Center/crop/400x520\"/></div>"
|
|
17
|
-
}
|
|
18
|
-
]
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
}
|
package/test/tt.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* t.js
|
|
3
|
-
* @author: oldj
|
|
4
|
-
* @homepage: https://oldj.net
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const {epubGen} = require('../dist/index')
|
|
8
|
-
const data = require('./data/1.json')
|
|
9
|
-
|
|
10
|
-
;(async () => {
|
|
11
|
-
try {
|
|
12
|
-
await epubGen({...data, tocAutoNumber: true}, 'test.epub')
|
|
13
|
-
} catch (e) {
|
|
14
|
-
console.error('Error 24: ' + e.message)
|
|
15
|
-
}
|
|
16
|
-
})()
|
package/webpack.config.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @author oldj
|
|
3
|
-
* @blog http://oldj.net
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
'use strict'
|
|
7
|
-
|
|
8
|
-
const path = require('path')
|
|
9
|
-
const webpack = require('webpack')
|
|
10
|
-
const WebpackNotifierPlugin = require('webpack-notifier')
|
|
11
|
-
//const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
12
|
-
//const TerserPlugin = require('terser-webpack-plugin')
|
|
13
|
-
const basedir = __dirname
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
mode: process.env.ENV === 'dev' ? 'development' : 'production',
|
|
17
|
-
entry: {
|
|
18
|
-
index: ['./src/index.ts']
|
|
19
|
-
},
|
|
20
|
-
devtool: 'source-map',
|
|
21
|
-
output: {
|
|
22
|
-
filename: '[name].js',
|
|
23
|
-
path: path.join(basedir, 'dist')
|
|
24
|
-
},
|
|
25
|
-
target: 'node',
|
|
26
|
-
resolve: {
|
|
27
|
-
modules: ['node_modules', 'src'],
|
|
28
|
-
alias: {
|
|
29
|
-
'@': path.join(basedir, 'src')
|
|
30
|
-
},
|
|
31
|
-
extensions: ['.ts', '.js', '.d.ts']
|
|
32
|
-
},
|
|
33
|
-
watchOptions: {
|
|
34
|
-
ignored: []
|
|
35
|
-
},
|
|
36
|
-
module: {
|
|
37
|
-
rules: [
|
|
38
|
-
{
|
|
39
|
-
test: /\.ts$/,
|
|
40
|
-
loader: 'ts-loader'
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
},
|
|
44
|
-
optimization: {
|
|
45
|
-
minimize: true,
|
|
46
|
-
minimizer: [
|
|
47
|
-
//new TerserPlugin({
|
|
48
|
-
// terserOptions: {
|
|
49
|
-
// output: {
|
|
50
|
-
// ecma: 6,
|
|
51
|
-
// comments: false,
|
|
52
|
-
// ascii_only: true
|
|
53
|
-
// }
|
|
54
|
-
// },
|
|
55
|
-
// parallel: true,
|
|
56
|
-
// cache: true,
|
|
57
|
-
// sourceMap: true
|
|
58
|
-
//})
|
|
59
|
-
]
|
|
60
|
-
},
|
|
61
|
-
plugins: [
|
|
62
|
-
new webpack.DefinePlugin({
|
|
63
|
-
'process.env': {
|
|
64
|
-
NODE_ENV: JSON.stringify('production')
|
|
65
|
-
}
|
|
66
|
-
}),
|
|
67
|
-
new webpack.IgnorePlugin(new RegExp('^(fs|path|window)$')),
|
|
68
|
-
new WebpackNotifierPlugin({
|
|
69
|
-
title: 'epub-gen',
|
|
70
|
-
alwaysNotify: true,
|
|
71
|
-
excludeWarnings: true
|
|
72
|
-
})
|
|
73
|
-
//new webpack.BannerPlugin(`WonderPen ${s_version}, ${moment().format('YYYY-MM-DD HH:mm:ss')}`)
|
|
74
|
-
]
|
|
75
|
-
}
|