wp-epub-gen 0.3.0 → 0.4.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.
@@ -0,0 +1,40 @@
1
+ import { ILogger } from './types';
2
+ /**
3
+ * 全局 Logger 单例类
4
+ */
5
+ declare class GlobalLogger {
6
+ private static instance;
7
+ private customLogger;
8
+ private constructor();
9
+ /**
10
+ * 获取 Logger 单例实例
11
+ */
12
+ static getInstance(): GlobalLogger;
13
+ /**
14
+ * 设置自定义 logger
15
+ * @param logger 自定义 logger 实例
16
+ */
17
+ setLogger(logger: ILogger | null): void;
18
+ /**
19
+ * 获取当前使用的 logger
20
+ */
21
+ private getLogger;
22
+ /**
23
+ * 输出普通日志
24
+ */
25
+ log(msg: any): void;
26
+ /**
27
+ * 输出信息日志
28
+ */
29
+ info(msg: any): void;
30
+ /**
31
+ * 输出错误日志
32
+ */
33
+ error(msg: any): void;
34
+ /**
35
+ * 输出警告日志
36
+ */
37
+ warn(msg: any): void;
38
+ }
39
+ export declare const logger: GlobalLogger;
40
+ export { GlobalLogger };
@@ -0,0 +1 @@
1
+ export {};
@@ -6,6 +6,6 @@
6
6
  export declare const epub2_content_opf_ejs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<package xmlns=\"http://www.idpf.org/2007/opf\"\n version=\"2.0\"\n unique-identifier=\"BookId\">\n\n <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n xmlns:opf=\"http://www.idpf.org/2007/opf\">\n\n <dc:identifier id=\"BookId\" opf:scheme=\"URN\"><%= id %></dc:identifier>\n <dc:title><%= title %></dc:title>\n <dc:description><%= description %></dc:description>\n <dc:publisher><%= publisher || \"anonymous\" %></dc:publisher>\n <dc:creator opf:role=\"aut\" opf:file-as=\"<%= author.length ? author.join(\",\") : author %>\"><%= author.length ? author.join(\",\") : author %></dc:creator>\n <dc:date opf:event=\"modification\"><%= date %></dc:date>\n <dc:language><%= lang || \"en\" %></dc:language>\n <meta name=\"cover\" content=\"image_cover\"/>\n <meta name=\"generator\" content=\"epub-gen\"/>\n\n </metadata>\n\n <manifest>\n <item id=\"ncx\" href=\"toc.ncx\" media-type=\"application/x-dtbncx+xml\"/>\n <item id=\"toc\" href=\"toc.xhtml\" media-type=\"application/xhtml+xml\"/>\n <item id=\"css\" href=\"style.css\" media-type=\"text/css\"/>\n\n <% if(locals.cover) { %>\n <item id=\"image_cover\" href=\"cover.<%= _coverExtension %>\" media-type=\"<%= _coverMediaType %>\"/>\n <% } %>\n\n <% images.forEach(function(image, index){ %>\n <item id=\"image_<%= index %>\" href=\"images/<%= image.id %>.<%= image.extension %>\" media-type=\"<%= image.mediaType %>\"/>\n <% }) %>\n\n <% content.forEach(function(content, index){ %>\n <item id=\"content_<%= index %>_<%= content.id %>\" href=\"<%= content.href %>\" media-type=\"application/xhtml+xml\"/>\n <% }) %>\n\n <% fonts.forEach(function(font, index) { %>\n <item id=\"font_<%= index %>\" href=\"fonts/<%= font %>\" media-type=\"application/x-font-ttf\"/>\n <% }) %>\n </manifest>\n\n <spine toc=\"ncx\">\n <% content.forEach(function(content, index){ %>\n <% if(content.beforeToc && !content.excludeFromToc){ %>\n <itemref idref=\"content_<%= index %>_<%= content.id %>\"/>\n <% } %>\n <% }) %>\n <itemref idref=\"toc\"/>\n <% content.forEach(function(content, index){ %>\n <% if(!content.beforeToc && !content.excludeFromToc){ %>\n <itemref idref=\"content_<%= index %>_<%= content.id %>\"/>\n <% } %>\n <% }) %>\n </spine>\n <guide/>\n</package>\n";
7
7
  export declare const epub2_toc_xhtml_ejs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n<html xml:lang=\"<%- lang %>\" xmlns=\"http://www.w3.org/1999/xhtml\">\n<head>\n <title><%= title %></title>\n <meta charset=\"UTF-8\"/>\n <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"/>\n</head>\n<body>\n<h1 class=\"h1\"><%= tocTitle %></h1>\n<% content.forEach(function(content, index){ %>\n <% if(!content.excludeFromToc){ %>\n <p class=\"table-of-content\">\n <a href=\"<%= content.href %>\"><%= (1 + index) + \". \" + (content.title || \"Chapter \" + (1 + index)) %>\n <% if(content.author.length){ %>\n - <small class=\"toc-author\"><%= content.author.join(\",\") %></small>\n <% } %>\n <% if(content.url){ %><span class=\"toc-link\"><%= content.url %></span>\n <% }else{ %><span class=\"toc-link\"></span>\n <% } %>\n </a>\n </p>\n <% } %>\n<% }) %>\n</body>\n</html>\n";
8
8
  export declare const epub3_content_opf_ejs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<package xmlns=\"http://www.idpf.org/2007/opf\"\n version=\"3.0\"\n unique-identifier=\"BookId\"\n xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n xmlns:dcterms=\"http://purl.org/dc/terms/\"\n xml:lang=\"en\"\n xmlns:media=\"http://www.idpf.org/epub/vocab/overlays/#\"\n prefix=\"ibooks: http://vocabulary.itunes.apple.com/rdf/ibooks/vocabulary-extensions-1.0/\">\n\n <metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:opf=\"http://www.idpf.org/2007/opf\">\n\n <dc:identifier id=\"BookId\"><%= id %></dc:identifier>\n <meta refines=\"#BookId\" property=\"identifier-type\" scheme=\"onix:codelist5\">22</meta>\n <meta property=\"dcterms:identifier\" id=\"meta-identifier\">BookId</meta>\n <dc:title><%= title %></dc:title>\n <meta property=\"dcterms:title\" id=\"meta-title\"><%= title %></meta>\n <dc:language><%= lang || \"en\" %></dc:language>\n <meta property=\"dcterms:language\" id=\"meta-language\"><%= lang || \"en\" %></meta>\n <meta property=\"dcterms:modified\"><%= (new Date()).toISOString().split(\".\")[0] + \"Z\" %></meta>\n <dc:creator id=\"creator\"><%= author.length ? author.join(\",\") : author %></dc:creator>\n <meta refines=\"#creator\" property=\"file-as\"><%= author.length ? author.join(\",\") : author %></meta>\n <meta property=\"dcterms:publisher\"><%= publisher || \"anonymous\" %></meta>\n <dc:publisher><%= publisher || \"anonymous\" %></dc:publisher>\n <% var date = new Date(); var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var stringDate = \"\" + year + \"-\" + month + \"-\" + day; %>\n <meta property=\"dcterms:date\"><%= stringDate %></meta>\n <dc:date><%= stringDate %></dc:date>\n <meta property=\"dcterms:rights\">All rights reserved</meta>\n <dc:rights>Copyright &#x00A9; <%= (new Date()).getFullYear() %> by <%= publisher || \"anonymous\" %></dc:rights>\n <% if(locals.cover) { %>\n <meta name=\"cover\" content=\"image_cover\" />\n <% } %>\n <meta name=\"generator\" content=\"epub-gen\" />\n <meta property=\"ibooks:specified-fonts\">true</meta>\n </metadata>\n\n <manifest>\n <item id=\"ncx\" href=\"toc.ncx\" media-type=\"application/x-dtbncx+xml\" />\n <item id=\"toc\" href=\"toc.xhtml\" media-type=\"application/xhtml+xml\" properties=\"nav\" />\n <item id=\"css\" href=\"style.css\" media-type=\"text/css\" />\n\n <% if(locals.cover) { %>\n <item id=\"image_cover\" href=\"cover.<%= _coverExtension %>\" media-type=\"<%= _coverMediaType %>\" />\n <% } %>\n\n <% images.forEach(function(image, index){ %>\n <item id=\"image_<%= index %>\" href=\"images/<%= image.id %>.<%= image.extension %>\" media-type=\"<%= image.mediaType %>\" />\n <% }) %>\n\n <% function renderContentItem(content) { %>\n <% content.forEach(function(content){ %>\n <item id=\"content_<%= content.id %>\" href=\"<%= content.href %>\" media-type=\"application/xhtml+xml\" />\n <% if (Array.isArray(content.children)) { %>\n <% renderContentItem(content.children) %>\n <% } %>\n <% }) %>\n <% } %>\n <% renderContentItem(content) %>\n\n <% fonts.forEach(function(font, index){ %>\n <item id=\"font_<%= index %>\" href=\"fonts/<%= font %>\" media-type=\"application/x-font-ttf\" />\n <% }) %>\n </manifest>\n\n <spine toc=\"ncx\">\n <% var nodes_1 = content.filter(item => !item.excludeFromToc && item.beforeToc) %>\n <% var nodes_2 = content.filter(item => !item.excludeFromToc && !item.beforeToc) %>\n <% function renderToc(nodes) { %>\n <% nodes.forEach(function(content){ %>\n <itemref idref=\"content_<%= content.id %>\" />\n <% if (Array.isArray(content.children)) { %>\n <% renderToc(content.children) %>\n <% } %>\n <% }) %>\n <% } %>\n <% renderToc(nodes_1) %>\n <itemref idref=\"toc\" />\n <% renderToc(nodes_2) %>\n </spine>\n <guide>\n <reference type=\"text\" title=\"Table of Content\" href=\"toc.xhtml\" />\n </guide>\n</package>\n";
9
- export declare const epub3_toc_xhtml_ejs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html>\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" xml:lang=\"<%- lang %>\"\n lang=\"<%- lang %>\">\n<head>\n <title><%= title %></title>\n <meta charset=\"UTF-8\" />\n <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n</head>\n<body>\n<h1 class=\"h1\"><%= tocTitle %></h1>\n<nav id=\"toc\" class=\"TOC\" epub:type=\"toc\">\n <% var nodes_1 = content.filter(item => !item.excludeFromToc && item.beforeToc) %>\n <% var nodes_2 = content.filter(item => !item.excludeFromToc && !item.beforeToc) %>\n <% function renderToc(nodes, indent = 0) { %>\n <ol>\n <% nodes.forEach(function(content, index){ %>\n <li class=\"table-of-content\">\n <a href=\"<%= content.href %>\"><%= (content.title || \"Chapter \" + (1 + index)) %>\n <% if(content.author.length){ %> - <small\n class=\"toc-author\"><%= content.author.join(\",\") %></small>\n <% } %>\n <% if(content.url){ %><span class=\"toc-link\"><%= content.url %></span>\n <% } %>\n </a>\n <% if (Array.isArray(content.children) && content.children.length > 0) { %>\n <% renderToc(content.children, indent + 1) %>\n <% } %>\n </li>\n <% }) %>\n </ol>\n <% } %>\n <% renderToc(nodes_1) %>\n <% renderToc(nodes_2) %>\n</nav>\n\n</body>\n</html>\n";
9
+ export declare const epub3_toc_xhtml_ejs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\" xml:lang=\"<%- lang %>\"\n lang=\"<%- lang %>\">\n<head>\n <title><%= title %></title>\n <meta charset=\"UTF-8\" />\n <link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />\n</head>\n<body>\n<h1 class=\"h1\"><%= tocTitle %></h1>\n<nav id=\"toc\" class=\"TOC\" epub:type=\"toc\">\n <% var nodes_1 = content.filter(item => !item.excludeFromToc && item.beforeToc) %>\n <% var nodes_2 = content.filter(item => !item.excludeFromToc && !item.beforeToc) %>\n <% function renderToc(nodes, indent = 0) { %>\n <ol>\n <% nodes.forEach(function(content, index){ %>\n <li class=\"table-of-content\">\n <a href=\"<%= content.href %>\"><%= (content.title || \"Chapter \" + (1 + index)) %>\n <% if(content.author.length){ %> - <small\n class=\"toc-author\"><%= content.author.join(\",\") %></small>\n <% } %>\n <% if(content.url){ %><span class=\"toc-link\"><%= content.url %></span>\n <% } %>\n </a>\n <% if (Array.isArray(content.children) && content.children.length > 0) { %>\n <% renderToc(content.children, indent + 1) %>\n <% } %>\n </li>\n <% }) %>\n </ol>\n <% } %>\n <% renderToc(nodes_1) %>\n <% renderToc(nodes_2) %>\n</nav>\n\n</body>\n</html>\n";
10
10
  export declare const template_css = ".epub-author {\n color: #555;\n}\n\n.epub-link {\n margin-bottom: 30px;\n}\n\n.epub-link a {\n color: #666;\n font-size: 90%;\n}\n\n.toc-author {\n font-size: 90%;\n color: #555;\n}\n\n.toc-link {\n color: #999;\n font-size: 85%;\n display: block;\n}\n\nhr {\n border: 0;\n border-bottom: 1px solid #dedede;\n margin: 60px 10%;\n}\n\n.TOC > ol {\n margin: 0;\n padding: 0;\n}\n\n.TOC > ol ol {\n padding: 0;\n margin-left: 2em;\n}\n\n.TOC li {\n font-size: 16px;\n list-style: none;\n margin: 0 auto;\n padding: 0;\n}\n";
11
11
  export declare const toc_ncx_ejs = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<ncx xmlns=\"http://www.daisy.org/z3986/2005/ncx/\" version=\"2005-1\">\n <head>\n <meta name=\"dtb:uid\" content=\"<%= id %>\"/>\n <meta name=\"dtb:generator\" content=\"epub-gen\"/>\n <meta name=\"dtb:depth\" content=\"<%= (toc_depth || 1)%>\"/>\n <meta name=\"dtb:totalPageCount\" content=\"0\"/>\n <meta name=\"dtb:maxPageNumber\" content=\"0\"/>\n </head>\n <docTitle>\n <text><%= title %></text>\n </docTitle>\n <docAuthor>\n <text><%= author %></text>\n </docAuthor>\n <navMap>\n <% var _index = 1; %>\n <% var nodes_1 = content.filter(c => !c.excludeFromToc && c.beforeToc) %>\n <% var nodes_2 = content.filter(c => !c.excludeFromToc && !c.beforeToc) %>\n <% function renderToc(nodes) { %>\n <% nodes.forEach(function(content, index){ %>\n <navPoint id=\"content_<%= content.id %>\" playOrder=\"<%= _index++ %>\" class=\"chapter\">\n <navLabel>\n <text><%= (tocAutoNumber ? ((1 + index) + \". \") : \"\") + (content.title || \"Chapter \" + (1 + index)) %></text>\n </navLabel>\n <content src=\"<%= content.href %>\"/>\n <% if (Array.isArray(content.children)) { %>\n <% renderToc(content.children) %>\n <% } %>\n </navPoint>\n <% }) %>\n <% } %>\n\n <% renderToc(nodes_1) %>\n\n <navPoint id=\"toc\" playOrder=\"<%= _index++ %>\" class=\"chapter\">\n <navLabel>\n <text><%= tocTitle %></text>\n </navLabel>\n <content src=\"toc.xhtml\"/>\n </navPoint>\n\n <% renderToc(nodes_2) %>\n </navMap>\n</ncx>\n";
package/build/types.d.ts CHANGED
@@ -70,3 +70,12 @@ export interface IOut {
70
70
  message?: string;
71
71
  options?: IEpubGenOptions;
72
72
  }
73
+ export interface ILogger {
74
+ log: (msg: any) => void;
75
+ info: (msg: any) => void;
76
+ error: (msg: any) => void;
77
+ warn: (msg: any) => void;
78
+ }
79
+ export interface IGenConfigs {
80
+ logger?: ILogger;
81
+ }
@@ -0,0 +1,33 @@
1
+ import js from '@eslint/js'
2
+ import tseslint from 'typescript-eslint'
3
+
4
+ export default tseslint.createConfig(
5
+ js.configs.recommended,
6
+ ...tseslint.configs.recommended,
7
+ {
8
+ languageOptions: {
9
+ parser: tseslint.parser,
10
+ parserOptions: {
11
+ project: './tsconfig.json',
12
+ sourceType: 'module',
13
+ },
14
+ globals: {
15
+ node: true,
16
+ jest: true,
17
+ },
18
+ },
19
+ rules: {
20
+ '@typescript-eslint/interface-name-prefix': 'off',
21
+ '@typescript-eslint/explicit-function-return-type': 'off',
22
+ '@typescript-eslint/no-explicit-any': 'off',
23
+ '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
24
+ },
25
+ ignores: ['build/**', 'node_modules/**', '*.js', '*.mjs'],
26
+ },
27
+ {
28
+ files: ['**/*.test.ts', '**/*.spec.ts'],
29
+ rules: {
30
+ '@typescript-eslint/no-explicit-any': 'off',
31
+ },
32
+ },
33
+ )
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "wp-epub-gen",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Epub generator.",
5
+ "type": "module",
5
6
  "main": "build/index.js",
6
7
  "module": "build/index.mjs",
7
8
  "types": "build/index.d.ts",
@@ -9,6 +10,8 @@
9
10
  "tsc": "tsc",
10
11
  "test": "vitest --watch=false run",
11
12
  "tt": "npm run build && node ./test/tt.js",
13
+ "lint": "eslint src/**/*.ts",
14
+ "lint:fix": "eslint src/**/*.ts --fix",
12
15
  "build": "cross-env NODE_ENV=production vite build --config vite.config.ts",
13
16
  "bt": "npm run build && npm run test",
14
17
  "w": "tsc -w",
@@ -37,6 +40,7 @@
37
40
  "uuid": "^11.1.0"
38
41
  },
39
42
  "devDependencies": {
43
+ "@eslint/js": "^9.34.0",
40
44
  "@types/archiver": "^6.0.3",
41
45
  "@types/cheerio": "^1.0.0",
42
46
  "@types/diacritics": "^1.3.3",
@@ -46,15 +50,19 @@
46
50
  "@types/superagent": "^8.1.9",
47
51
  "@types/uslug": "^1.0.4",
48
52
  "@types/uuid": "^10.0.0",
53
+ "@typescript-eslint/eslint-plugin": "^8.42.0",
54
+ "@typescript-eslint/parser": "^8.42.0",
55
+ "@vitest/ui": "^2.1.8",
49
56
  "cross-env": "^10.0.0",
50
- "vitest": "^2.1.8",
57
+ "eslint": "^9.34.0",
51
58
  "prettier": "^3.6.2",
52
59
  "ts-loader": "^9.5.2",
53
60
  "tsconfig-paths": "^4.2.0",
54
- "@vitest/ui": "^2.1.8",
55
61
  "typescript": "^5.8.3",
62
+ "typescript-eslint": "^8.42.0",
56
63
  "vite": "^7.0.6",
57
64
  "vite-plugin-dts": "^4.5.4",
58
- "vite-tsconfig-paths": "^5.1.4"
65
+ "vite-tsconfig-paths": "^5.1.4",
66
+ "vitest": "^2.1.8"
59
67
  }
60
68
  }
@@ -1,5 +1,5 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE html>
2
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
3
  <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" xml:lang="<%- lang %>"
4
4
  lang="<%- lang %>">
5
5
  <head>
package/vitest.config.ts CHANGED
@@ -1,9 +1,15 @@
1
1
  import { defineConfig } from 'vitest/config'
2
+ import * as path from 'path'
2
3
 
3
4
  export default defineConfig({
4
5
  test: {
5
6
  globals: true,
6
7
  environment: 'node',
7
- include: ['test/**/*.test.js'],
8
+ include: ['test/**/*.test.js', 'src/**/*.test.ts'],
9
+ },
10
+ resolve: {
11
+ alias: {
12
+ '@': path.resolve(__dirname, 'src'),
13
+ },
8
14
  },
9
15
  })
package/.eslintrc.js DELETED
@@ -1,24 +0,0 @@
1
- module.exports = {
2
- parser: '@typescript-eslint/parser',
3
- parserOptions: {
4
- project: 'tsconfig.json',
5
- sourceType: 'module'
6
- },
7
- plugins: ['@typescript-eslint/eslint-plugin'],
8
- extends: [
9
- 'plugin:@typescript-eslint/eslint-recommended',
10
- 'plugin:@typescript-eslint/recommended',
11
- 'prettier',
12
- 'prettier/@typescript-eslint'
13
- ],
14
- root: true,
15
- env: {
16
- node: true,
17
- jest: true
18
- },
19
- rules: {
20
- '@typescript-eslint/interface-name-prefix': 'off',
21
- '@typescript-eslint/explicit-function-return-type': 'off',
22
- '@typescript-eslint/no-explicit-any': 'off'
23
- }
24
- }
package/.mocharc.json DELETED
@@ -1,3 +0,0 @@
1
- {
2
- "enable-source-maps": true
3
- }