wp-epub-gen 0.1.3 → 0.2.0

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.
File without changes
File without changes
File without changes
@@ -45,7 +45,7 @@ export interface IEpubData extends IEpubGenOptions {
45
45
  baseDir: string
46
46
  _coverMediaType?: string
47
47
  _coverExtension?: string
48
- log: (msg) => void
48
+ log: (msg: any) => void
49
49
  content: IChapterData[]
50
50
  timeoutSeconds: number
51
51
  }
File without changes
package/cpi.epub ADDED
Binary file
package/package.json CHANGED
@@ -1,14 +1,15 @@
1
1
  {
2
2
  "name": "wp-epub-gen",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Epub generator.",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
5
+ "main": "build/index.js",
6
+ "types": "build/index.d.ts",
7
7
  "scripts": {
8
8
  "tsc": "tsc",
9
9
  "test": "mocha -r espower-typescript/guess -r tsconfig-paths/register test/*.test.js",
10
10
  "tt": "npm run build && node ./test/tt.js",
11
- "build": "tsc",
11
+ "build": "cross-env NODE_ENV=production vite build --config vite.config.ts",
12
+ "build:0": "rm -rf ./build && tsc",
12
13
  "bt": "npm run build && npm run test",
13
14
  "w": "tsc -w",
14
15
  "p": "npm run build && npm run test && npm publish --access public"
@@ -24,43 +25,42 @@
24
25
  },
25
26
  "homepage": "https://github.com/oldj/wp-epub-gen#readme",
26
27
  "dependencies": {
27
- "@types/diacritics": "^1.3.1",
28
- "@types/uslug": "^1.0.1",
29
- "@types/uuid": "^8.3.4",
30
28
  "archiver": "^5.3.1",
31
29
  "cheerio": "^0.22.0",
32
30
  "diacritics": "^1.3.0",
33
31
  "ejs": "^3.1.8",
34
32
  "entities": "^4.4.0",
35
- "fs-extra": "^10.1.0",
33
+ "fs-extra": "^11.1.0",
36
34
  "mime": "^3.0.0",
37
- "superagent": "^8.0.3",
35
+ "superagent": "^8.0.6",
38
36
  "uslug": "^1.0.4",
39
37
  "uuid": "^9.0.0"
40
38
  },
41
39
  "devDependencies": {
42
40
  "@types/archiver": "^5.3.1",
43
41
  "@types/cheerio": "^0.22.31",
42
+ "@types/diacritics": "^1.3.1",
44
43
  "@types/ejs": "^3.1.1",
45
44
  "@types/fs-extra": "^9.0.13",
46
45
  "@types/mime": "^3.0.1",
47
- "@types/superagent": "^4.1.15",
48
- "@typescript-eslint/eslint-plugin": "^5.43.0",
49
- "@typescript-eslint/parser": "^5.43.0",
46
+ "@types/superagent": "^4.1.16",
47
+ "@types/uslug": "^1.0.1",
48
+ "@types/uuid": "^9.0.0",
49
+ "@typescript-eslint/eslint-plugin": "^5.47.0",
50
+ "@typescript-eslint/parser": "^5.47.0",
50
51
  "chai": "^4.3.7",
51
52
  "cross-env": "^7.0.3",
52
- "eslint": "^8.28.0",
53
+ "eslint": "^8.30.0",
53
54
  "eslint-config-prettier": "^8.5.0",
54
55
  "eslint-plugin-import": "^2.26.0",
55
56
  "espower-typescript": "^10.0.1",
56
- "mocha": "^10.1.0",
57
- "prettier": "^2.7.1",
58
- "terser-webpack-plugin": "^5.3.6",
59
- "ts-loader": "^9.4.1",
60
- "tsconfig-paths": "^4.1.0",
61
- "typescript": "^4.9.3",
62
- "webpack": "^5.75.0",
63
- "webpack-cli": "^5.0.0",
64
- "webpack-notifier": "^1.15.0"
57
+ "mocha": "^10.2.0",
58
+ "prettier": "^2.8.1",
59
+ "ts-loader": "^9.4.2",
60
+ "tsconfig-paths": "^4.1.1",
61
+ "typescript": "^4.9.4",
62
+ "vite": "^4.0.3",
63
+ "vite-plugin-dts": "^1.7.1",
64
+ "vite-tsconfig-paths": "^4.0.3"
65
65
  }
66
66
  }
package/test.epub ADDED
Binary file
package/tsconfig.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "compilerOptions": {
3
- "target": "es6",
3
+ "target": "es5",
4
4
  "module": "commonjs",
5
5
  "allowJs": true,
6
6
  "sourceMap": true,
7
7
  "declaration": true,
8
- "outDir": "./dist",
8
+ "outDir": "./build",
9
9
  "resolveJsonModule": true,
10
10
  "forceConsistentCasingInFileNames": true,
11
11
  "skipLibCheck": true,
@@ -15,8 +15,16 @@
15
15
  "noImplicitReturns": true,
16
16
  "moduleResolution": "node",
17
17
  "experimentalDecorators": true,
18
+ "esModuleInterop": true,
19
+ "allowSyntheticDefaultImports": true,
18
20
  "plugins": [
19
- ]
21
+ ],
22
+ "baseUrl": "./",
23
+ "paths": {
24
+ "@/*": [
25
+ "src/*"
26
+ ]
27
+ }
20
28
  },
21
29
  "include": [
22
30
  "src"
package/vite.config.ts ADDED
@@ -0,0 +1,40 @@
1
+ import * as path from 'path'
2
+ import { defineConfig } from 'vite'
3
+ import dts from 'vite-plugin-dts'
4
+ import tsconfigPaths from 'vite-tsconfig-paths'
5
+
6
+ // https://vitejs.dev/config/
7
+ export default defineConfig({
8
+ // root: path.join(__dirname, 'src', 'main'),
9
+ base: './',
10
+ build: {
11
+ rollupOptions: {
12
+ input: {
13
+ index: path.join(__dirname, 'src', 'index.ts'),
14
+ },
15
+ },
16
+ lib: {
17
+ entry: path.join(__dirname, 'src', 'index.ts'),
18
+ name: 'index',
19
+ formats: ['cjs'],
20
+ // fileName: (format) => `main.${format}.js`,
21
+ fileName: () => `index.js`,
22
+ },
23
+ outDir: path.join(__dirname, 'build'),
24
+ minify: false,
25
+ ssr: true,
26
+ // emptyOutDir: false,
27
+ },
28
+ resolve: {
29
+ alias: {
30
+ '@': path.resolve(__dirname, 'src'),
31
+ },
32
+ },
33
+ plugins: [
34
+ tsconfigPaths(),
35
+ dts({
36
+ entryRoot: path.join(__dirname, 'src'),
37
+ // outputDir: path.join(__dirname, 'build', 'types'),
38
+ }),
39
+ ],
40
+ })
@@ -1,88 +0,0 @@
1
- "use strict";
2
- /**
3
- * downloadImage
4
- * @author: oldj
5
- * @homepage: https://oldj.net
6
- */
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.downloadAllImages = void 0;
18
- const fs = require("fs-extra");
19
- const path = require("path");
20
- const request = require("superagent");
21
- const utils_1 = require("./utils");
22
- const downloadImage = (epubData, options) => __awaiter(void 0, void 0, void 0, function* () {
23
- let { url } = options;
24
- let { log } = epubData;
25
- let epub_dir = epubData.dir;
26
- if (!url) {
27
- return;
28
- }
29
- let image_dir = path.join(epub_dir, 'OEBPS', 'images');
30
- fs.ensureDirSync(image_dir);
31
- let filename = path.join(image_dir, options.id + '.' + options.extension);
32
- if (url.startsWith('file://') || url.startsWith('/')) {
33
- let auxPath = url.replace(/^file:\/\//i, '');
34
- if (process.platform === 'win32') {
35
- // Windows 下,把 /C:/ 转换成 C:/ 这样的形式
36
- if (auxPath.match(/^\/[a-zA-Z]:/)) {
37
- auxPath = auxPath.replace(/^\//, '');
38
- }
39
- }
40
- log(`[Copy 1] '${auxPath}' to '${filename}'`);
41
- if (fs.existsSync(auxPath)) {
42
- try {
43
- fs.copySync(auxPath, filename);
44
- }
45
- catch (e) {
46
- log('[Copy 1 Error] ' + e.message);
47
- }
48
- }
49
- else {
50
- log(`[Copy 1 Fail] '${url}' not exists!`);
51
- }
52
- return;
53
- }
54
- let requestAction;
55
- if (url.startsWith('http')) {
56
- requestAction = request.get(url).set({ 'User-Agent': utils_1.USER_AGENT });
57
- requestAction.pipe(fs.createWriteStream(filename));
58
- }
59
- else {
60
- log(`[Copy 2] '${url}' to '${filename}'`);
61
- requestAction = fs.createReadStream(path.join(options.dir || '', url));
62
- requestAction.pipe(fs.createWriteStream(filename));
63
- }
64
- return new Promise((resolve, reject) => {
65
- requestAction.on('error', (err) => {
66
- log('[Download Error] Error while downloading: ' + url);
67
- log(err);
68
- fs.unlinkSync(filename);
69
- // reject(err)
70
- resolve();
71
- });
72
- requestAction.on('end', () => {
73
- log('[Download Success] ' + url);
74
- resolve();
75
- });
76
- });
77
- });
78
- const downloadAllImages = (epubData) => __awaiter(void 0, void 0, void 0, function* () {
79
- let { images } = epubData;
80
- if (images.length === 0)
81
- return;
82
- fs.ensureDirSync(path.join(epubData.dir, 'OEBPS', 'images'));
83
- for (let image of images) {
84
- yield downloadImage(epubData, image);
85
- }
86
- });
87
- exports.downloadAllImages = downloadAllImages;
88
- //# sourceMappingURL=downloadImage.js.map
package/dist/errors.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- /**
3
- * errors
4
- * @author: oldj
5
- * @homepage: https://oldj.net
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.errors = void 0;
9
- exports.errors = {
10
- no_output_path: 'No output path!',
11
- no_title: 'Title is required.',
12
- no_content: 'Content is required.',
13
- };
14
- //# sourceMappingURL=errors.js.map
@@ -1,121 +0,0 @@
1
- "use strict";
2
- /**
3
- * generateTempFile
4
- * @author: oldj
5
- * @homepage: https://oldj.net
6
- */
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.generateTempFile = void 0;
18
- const ejs = require("ejs");
19
- const entities = require("entities");
20
- const fs = require("fs-extra");
21
- const path = require("path");
22
- const utils_1 = require("./utils");
23
- const generateTempFile = (epubData) => __awaiter(void 0, void 0, void 0, function* () {
24
- var _a;
25
- let { log } = epubData;
26
- let oebps_dir = path.join(epubData.dir, 'OEBPS');
27
- yield fs.ensureDir(oebps_dir);
28
- const templates_dir = path.join(epubData.baseDir, 'templates');
29
- epubData.css =
30
- epubData.css ||
31
- (yield (0, utils_1.readFile)(path.join(epubData.baseDir, 'templates', 'template.css'), 'utf-8'));
32
- yield (0, utils_1.writeFile)(path.join(oebps_dir, 'style.css'), epubData.css, 'utf-8');
33
- if ((_a = epubData.fonts) === null || _a === void 0 ? void 0 : _a.length) {
34
- let fonts_dir = path.join(oebps_dir, 'fonts');
35
- yield fs.ensureDir(fonts_dir);
36
- epubData.fonts = epubData.fonts.map((font) => {
37
- let filename = path.basename(font);
38
- if (!fs.existsSync(font)) {
39
- log(`Custom font not found at '${font}'.`);
40
- }
41
- else {
42
- fs.copySync(font, path.join(fonts_dir, filename));
43
- }
44
- return filename;
45
- });
46
- }
47
- const isAppendTitle = (global_append, local_append) => {
48
- if (typeof local_append === 'boolean')
49
- return local_append;
50
- return !!global_append;
51
- };
52
- const saveContentToFile = (content) => {
53
- var _a;
54
- let title = entities.encodeXML(content.title || '');
55
- let html = `${epubData.docHeader}
56
- <head>
57
- <meta charset="UTF-8" />
58
- <title>${title}</title>
59
- <link rel="stylesheet" type="text/css" href="style.css" />
60
- </head>
61
- <body>
62
- `;
63
- if (content.title && isAppendTitle(epubData.appendChapterTitles, content.appendChapterTitle)) {
64
- html += `<h1>${title}</h1>`;
65
- }
66
- html +=
67
- content.title && content.author && ((_a = content.author) === null || _a === void 0 ? void 0 : _a.length)
68
- ? `<p class='epub-author'>${entities.encodeXML(content.author.join(', '))}</p>`
69
- : '';
70
- html +=
71
- content.title && content.url
72
- ? `<p class="epub-link"><a href="${content.url}">${content.url}</a></p>`
73
- : '';
74
- html += `${content.data}`;
75
- html += '\n</body>\n</html>';
76
- fs.ensureDirSync(path.dirname(content.filePath));
77
- fs.writeFileSync(content.filePath, html, 'utf-8');
78
- if (Array.isArray(content.children)) {
79
- content.children.map(saveContentToFile);
80
- }
81
- };
82
- epubData.content.map(saveContentToFile);
83
- // write meta-inf/container.xml
84
- let metainf_dir = path.join(epubData.dir, 'META-INF');
85
- fs.ensureDirSync(metainf_dir);
86
- fs.writeFileSync(path.join(metainf_dir, 'container.xml'), `<?xml version="1.0" encoding="UTF-8" ?>
87
- <container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
88
- <rootfiles><rootfile full-path="OEBPS/content.opf" media-type="application/oebps-package+xml"/></rootfiles>
89
- </container>`, 'utf-8');
90
- if (epubData.version === 2) {
91
- let fn = path.join(metainf_dir, 'com.apple.ibooks.display-options.xml');
92
- fs.writeFileSync(fn, `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
93
- <display_options>
94
- <platform name="*">
95
- <option name="specified-fonts">true</option>
96
- </platform>
97
- </display_options>
98
- `, 'utf-8');
99
- }
100
- let opfPath = epubData.customOpfTemplatePath ||
101
- path.join(templates_dir, `epub${epubData.version}`, 'content.opf.ejs');
102
- if (!fs.existsSync(opfPath)) {
103
- throw new Error('Custom file to OPF template not found.');
104
- }
105
- let ncxTocPath = epubData.customNcxTocTemplatePath || path.join(templates_dir, `toc.ncx.ejs`);
106
- if (!fs.existsSync(ncxTocPath)) {
107
- throw new Error('Custom file the NCX toc template not found.');
108
- }
109
- let htmlTocPath = epubData.customHtmlTocTemplatePath ||
110
- path.join(templates_dir, `epub${epubData.version}`, 'toc.xhtml.ejs');
111
- if (!fs.existsSync(htmlTocPath)) {
112
- throw new Error('Custom file to HTML toc template not found.');
113
- }
114
- let toc_depth = 1;
115
- fs.writeFileSync(path.join(oebps_dir, 'content.opf'), yield ejs.renderFile(opfPath, epubData), 'utf-8');
116
- fs.writeFileSync(path.join(oebps_dir, 'toc.ncx'), yield ejs.renderFile(ncxTocPath, Object.assign(Object.assign({}, epubData), { toc_depth })), 'utf-8');
117
- // 说明:toc.xhtml 的内容在 macOS 自带的 Books 会被当作目录显示,如果空格太多,目录显示可能会不正常,因此这儿简单去掉了不必要的空格
118
- fs.writeFileSync(path.join(oebps_dir, 'toc.xhtml'), (0, utils_1.simpleMinifier)(yield ejs.renderFile(htmlTocPath, epubData)), 'utf-8');
119
- });
120
- exports.generateTempFile = generateTempFile;
121
- //# sourceMappingURL=generateTempFile.js.map
package/dist/index.js DELETED
@@ -1,128 +0,0 @@
1
- "use strict";
2
- /**
3
- * index.ts
4
- * @author: oldj
5
- * @homepage: https://oldj.net
6
- */
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.gen = exports.epubGen = void 0;
18
- const mime = require("mime");
19
- const os = require("os");
20
- const path = require("path");
21
- const uuid_1 = require("uuid");
22
- const errors_1 = require("./errors");
23
- const parseContent_1 = require("./parseContent");
24
- const render_1 = require("./render");
25
- const baseDir = path.dirname(__dirname);
26
- function result(success, message, options) {
27
- if (options && options.verbose) {
28
- if (!success) {
29
- console.error(new Error(message));
30
- }
31
- }
32
- let out = {
33
- success,
34
- };
35
- if (typeof message === 'string') {
36
- out.message = message;
37
- }
38
- if (options) {
39
- out.options = options;
40
- }
41
- return out;
42
- }
43
- function check(options) {
44
- if (!options.output) {
45
- return result(false, errors_1.errors.no_output_path, options);
46
- }
47
- if (!options.title) {
48
- return result(false, errors_1.errors.no_title, options);
49
- }
50
- if (!options.content) {
51
- return result(false, errors_1.errors.no_content, options);
52
- }
53
- return result(true, undefined, options);
54
- }
55
- function parseOptions(options) {
56
- let tmpDir = options.tmpDir || os.tmpdir();
57
- let id = (0, uuid_1.v4)();
58
- let data = Object.assign(Object.assign({ description: options.title, publisher: 'anonymous', author: ['anonymous'], tocTitle: 'Table Of Contents', appendChapterTitles: true, date: new Date().toISOString(), lang: 'en', fonts: [], version: 3, verbose: true, timeoutSeconds: 15 * 60, tocAutoNumber: false }, options), { id,
59
- tmpDir, dir: path.resolve(tmpDir, id), baseDir, docHeader: '', images: [], content: [], log: (msg) => options.verbose && console.log(msg) });
60
- if (data.version === 2) {
61
- data.docHeader = `<?xml version="1.0" encoding="UTF-8"?>
62
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
63
- <html xmlns="http://www.w3.org/1999/xhtml" lang="#{self.options.lang}">
64
- `;
65
- }
66
- else {
67
- data.docHeader = `<?xml version="1.0" encoding="UTF-8"?>
68
- <!DOCTYPE html>
69
- <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="#{self.options.lang}">
70
- `;
71
- }
72
- if (Array.isArray(data.author) && data.author.length === 0) {
73
- data.author = ['anonymous'];
74
- }
75
- if (typeof data.author === 'string') {
76
- data.author = [data.author];
77
- }
78
- data.content = options.content.map((content, index) => (0, parseContent_1.default)(content, index, data));
79
- if (data.cover) {
80
- data._coverMediaType = mime.getType(data.cover) || '';
81
- data._coverExtension = mime.getExtension(data._coverMediaType) || '';
82
- }
83
- return data;
84
- }
85
- function epubGen(options, output) {
86
- return __awaiter(this, void 0, void 0, function* () {
87
- options = Object.assign({}, options);
88
- if (output) {
89
- options.output = output;
90
- }
91
- let o = check(options);
92
- let verbose = options.verbose !== false;
93
- if (!o.success) {
94
- if (verbose)
95
- console.error(o.message);
96
- return o;
97
- }
98
- let t;
99
- try {
100
- let data = parseOptions(options);
101
- let timeoutSeconds = data.timeoutSeconds || 0;
102
- if (timeoutSeconds > 0) {
103
- if (verbose)
104
- console.log(`TIMEOUT: ${timeoutSeconds}s`);
105
- t = setTimeout(() => {
106
- throw new Error('timeout!');
107
- }, timeoutSeconds * 1000);
108
- }
109
- else {
110
- if (verbose)
111
- console.log(`TIMEOUT: N/A`);
112
- }
113
- yield (0, render_1.render)(data);
114
- return result(true, undefined, data);
115
- }
116
- catch (e) {
117
- if (verbose)
118
- console.error(e);
119
- return result(false, e.message, options);
120
- }
121
- finally {
122
- clearTimeout(t);
123
- }
124
- });
125
- }
126
- exports.epubGen = epubGen;
127
- exports.gen = epubGen;
128
- //# sourceMappingURL=index.js.map
package/dist/makeCover.js DELETED
@@ -1,63 +0,0 @@
1
- "use strict";
2
- /**
3
- * makeCover
4
- * @author: oldj
5
- * @homepage: https://oldj.net
6
- */
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- const fs = require("fs-extra");
18
- const path = require("path");
19
- const request = require("superagent");
20
- const utils_1 = require("./utils");
21
- function makeCover(data) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- let { cover, _coverExtension, log } = data;
24
- if (!cover)
25
- return;
26
- let destPath = path.join(data.dir, 'OEBPS', `cover.${_coverExtension}`);
27
- let writeStream = null;
28
- if (cover.startsWith('http')) {
29
- writeStream = request.get(cover).set({ 'User-Agent': utils_1.USER_AGENT });
30
- writeStream.pipe(fs.createWriteStream(destPath));
31
- }
32
- else {
33
- if (!fs.existsSync(cover))
34
- return;
35
- log('local cover image: ' + cover);
36
- writeStream = fs.createReadStream(cover);
37
- writeStream.pipe(fs.createWriteStream(destPath));
38
- }
39
- return new Promise((resolve) => {
40
- writeStream.on('end', () => {
41
- log('[Success] cover image saved.');
42
- resolve();
43
- });
44
- writeStream.on('error', (e) => {
45
- log('[Error] cover image error: ' + e.message);
46
- log('destPath: ' + destPath);
47
- if (fs.existsSync(destPath)) {
48
- try {
49
- fs.unlinkSync(destPath);
50
- log('destPath removed.');
51
- }
52
- catch (e) {
53
- log('[Error] remove cover image error: ' + e.message);
54
- }
55
- }
56
- resolve(e);
57
- // throw new Error('[Fail] cover image save fail!')
58
- });
59
- });
60
- });
61
- }
62
- exports.default = makeCover;
63
- //# sourceMappingURL=makeCover.js.map