wp-epub-gen 0.2.3 → 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.
- package/.vscode/settings.json +26 -0
- package/README.md +261 -75
- package/build/downloadImage.d.ts +0 -5
- package/build/errors.d.ts +0 -1
- package/build/generateTempFile.d.ts +0 -5
- package/build/index.cjs +1279 -0
- package/build/index.d.ts +3 -7
- package/build/index.js +927 -425
- package/build/libs/safeFineName.d.ts +0 -1
- package/build/libs/utils.d.ts +1 -7
- package/build/logger.d.ts +40 -0
- package/build/makeCover.d.ts +0 -5
- package/build/parseContent.d.ts +0 -5
- package/build/parseContent.test.d.ts +1 -0
- package/build/render.d.ts +0 -5
- package/build/templates.d.ts +11 -0
- package/build/types.d.ts +9 -1
- package/eslint.config.js +33 -0
- package/package.json +37 -35
- package/templates/epub3/toc.xhtml.ejs +1 -1
- package/tsconfig.json +8 -7
- package/vite.config.ts +76 -3
- package/vitest.config.ts +15 -0
- package/.eslintrc.js +0 -24
- package/.mocharc.json +0 -3
package/build/libs/utils.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* utils
|
|
3
|
-
* @author: oldj
|
|
4
|
-
* @homepage: https://oldj.net
|
|
5
|
-
*/
|
|
6
|
-
/// <reference types="node" />
|
|
7
|
-
import * as fs from 'fs';
|
|
1
|
+
import { default as fs } from 'fs';
|
|
8
2
|
export declare const readFile: typeof fs.readFile.__promisify__;
|
|
9
3
|
export declare const writeFile: typeof fs.writeFile.__promisify__;
|
|
10
4
|
export declare const USER_AGENT = "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";
|
|
@@ -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 };
|
package/build/makeCover.d.ts
CHANGED
package/build/parseContent.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/render.d.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 嵌入式模板内容
|
|
3
|
+
* 此文件由构建脚本自动生成,请勿手动编辑
|
|
4
|
+
* 源文件位于 templates/ 目录下
|
|
5
|
+
*/
|
|
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
|
+
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
|
+
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 © <%= (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 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
|
+
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
|
+
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
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* types.ts
|
|
3
2
|
* @author: oldj
|
|
4
3
|
* @homepage: https://oldj.net
|
|
5
4
|
*/
|
|
@@ -71,3 +70,12 @@ export interface IOut {
|
|
|
71
70
|
message?: string;
|
|
72
71
|
options?: IEpubGenOptions;
|
|
73
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
|
+
}
|
package/eslint.config.js
ADDED
|
@@ -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,15 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wp-epub-gen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Epub generator.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "build/index.js",
|
|
7
|
+
"module": "build/index.mjs",
|
|
6
8
|
"types": "build/index.d.ts",
|
|
7
9
|
"scripts": {
|
|
8
10
|
"tsc": "tsc",
|
|
9
|
-
"test": "
|
|
11
|
+
"test": "vitest --watch=false run",
|
|
10
12
|
"tt": "npm run build && node ./test/tt.js",
|
|
13
|
+
"lint": "eslint src/**/*.ts",
|
|
14
|
+
"lint:fix": "eslint src/**/*.ts --fix",
|
|
11
15
|
"build": "cross-env NODE_ENV=production vite build --config vite.config.ts",
|
|
12
|
-
"build:0": "rm -rf ./build && tsc",
|
|
13
16
|
"bt": "npm run build && npm run test",
|
|
14
17
|
"w": "tsc -w",
|
|
15
18
|
"p": "npm run build && npm run test && npm publish --access public"
|
|
@@ -25,42 +28,41 @@
|
|
|
25
28
|
},
|
|
26
29
|
"homepage": "https://github.com/oldj/wp-epub-gen#readme",
|
|
27
30
|
"dependencies": {
|
|
28
|
-
"archiver": "^
|
|
29
|
-
"cheerio": "^
|
|
31
|
+
"archiver": "^7.0.1",
|
|
32
|
+
"cheerio": "^1.1.2",
|
|
30
33
|
"diacritics": "^1.3.0",
|
|
31
|
-
"ejs": "^3.1.
|
|
32
|
-
"entities": "^
|
|
33
|
-
"fs-extra": "^11.
|
|
34
|
-
"mime": "^
|
|
35
|
-
"superagent": "^
|
|
34
|
+
"ejs": "^3.1.10",
|
|
35
|
+
"entities": "^6.0.1",
|
|
36
|
+
"fs-extra": "^11.3.0",
|
|
37
|
+
"mime": "^4.0.7",
|
|
38
|
+
"superagent": "^10.2.3",
|
|
36
39
|
"uslug": "^1.0.4",
|
|
37
|
-
"uuid": "^
|
|
40
|
+
"uuid": "^11.1.0"
|
|
38
41
|
},
|
|
39
42
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@types/
|
|
42
|
-
"@types/
|
|
43
|
-
"@types/
|
|
44
|
-
"@types/
|
|
45
|
-
"@types/
|
|
46
|
-
"@types/
|
|
47
|
-
"@types/
|
|
48
|
-
"@types/
|
|
49
|
-
"@
|
|
50
|
-
"@typescript-eslint/
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"eslint
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"mocha": "^10.2.0",
|
|
58
|
-
"prettier": "^3.0.1",
|
|
59
|
-
"ts-loader": "^9.4.4",
|
|
43
|
+
"@eslint/js": "^9.34.0",
|
|
44
|
+
"@types/archiver": "^6.0.3",
|
|
45
|
+
"@types/cheerio": "^1.0.0",
|
|
46
|
+
"@types/diacritics": "^1.3.3",
|
|
47
|
+
"@types/ejs": "^3.1.5",
|
|
48
|
+
"@types/fs-extra": "^11.0.4",
|
|
49
|
+
"@types/mime": "^4.0.0",
|
|
50
|
+
"@types/superagent": "^8.1.9",
|
|
51
|
+
"@types/uslug": "^1.0.4",
|
|
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",
|
|
56
|
+
"cross-env": "^10.0.0",
|
|
57
|
+
"eslint": "^9.34.0",
|
|
58
|
+
"prettier": "^3.6.2",
|
|
59
|
+
"ts-loader": "^9.5.2",
|
|
60
60
|
"tsconfig-paths": "^4.2.0",
|
|
61
|
-
"typescript": "^5.
|
|
62
|
-
"
|
|
63
|
-
"vite
|
|
64
|
-
"vite-
|
|
61
|
+
"typescript": "^5.8.3",
|
|
62
|
+
"typescript-eslint": "^8.42.0",
|
|
63
|
+
"vite": "^7.0.6",
|
|
64
|
+
"vite-plugin-dts": "^4.5.4",
|
|
65
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
66
|
+
"vitest": "^2.1.8"
|
|
65
67
|
}
|
|
66
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/tsconfig.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"module": "
|
|
3
|
+
"target": "es2020",
|
|
4
|
+
"module": "es2020",
|
|
5
5
|
"allowJs": true,
|
|
6
6
|
"sourceMap": true,
|
|
7
7
|
"declaration": true,
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
"noImplicitThis": true,
|
|
15
15
|
"noImplicitReturns": true,
|
|
16
16
|
"moduleResolution": "node",
|
|
17
|
+
"lib": [
|
|
18
|
+
"es2020"
|
|
19
|
+
],
|
|
17
20
|
"experimentalDecorators": true,
|
|
18
21
|
"esModuleInterop": true,
|
|
19
22
|
"allowSyntheticDefaultImports": true,
|
|
20
|
-
"plugins": [
|
|
21
|
-
],
|
|
23
|
+
"plugins": [],
|
|
22
24
|
"baseUrl": "./",
|
|
23
25
|
"paths": {
|
|
24
26
|
"@/*": [
|
|
@@ -34,6 +36,5 @@
|
|
|
34
36
|
"test",
|
|
35
37
|
"dist"
|
|
36
38
|
],
|
|
37
|
-
"externals": {
|
|
38
|
-
|
|
39
|
-
}
|
|
39
|
+
"externals": {}
|
|
40
|
+
}
|
package/vite.config.ts
CHANGED
|
@@ -2,6 +2,73 @@ import * as path from 'path'
|
|
|
2
2
|
import { defineConfig } from 'vite'
|
|
3
3
|
import dts from 'vite-plugin-dts'
|
|
4
4
|
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
5
|
+
import { readFileSync, writeFileSync, existsSync, readdirSync, statSync } from 'fs'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 生成模板文件的 TypeScript 代码
|
|
9
|
+
*/
|
|
10
|
+
function generateTemplatesFile() {
|
|
11
|
+
const templatesDir = path.join(__dirname, 'templates')
|
|
12
|
+
const outputFile = path.join(__dirname, 'src', 'templates.ts')
|
|
13
|
+
|
|
14
|
+
if (!existsSync(templatesDir)) {
|
|
15
|
+
throw new Error('Templates directory not found')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// 递归读取所有模板文件
|
|
19
|
+
const templates: Array<{ exportName: string; content: string; originalPath: string }> = []
|
|
20
|
+
|
|
21
|
+
function readTemplateFiles(dir: string, prefix = '') {
|
|
22
|
+
const files = readdirSync(dir)
|
|
23
|
+
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
const fullPath = path.join(dir, file)
|
|
26
|
+
const stat = statSync(fullPath)
|
|
27
|
+
|
|
28
|
+
if (stat.isDirectory()) {
|
|
29
|
+
readTemplateFiles(fullPath, prefix + file + '/')
|
|
30
|
+
} else {
|
|
31
|
+
const relativePath = prefix + file
|
|
32
|
+
const content = readFileSync(fullPath, 'utf-8')
|
|
33
|
+
|
|
34
|
+
// 将文件路径转换为 export 名称:特殊字符用 _ 替换
|
|
35
|
+
const exportName = relativePath.replace(/\//g, '_').replace(/\./g, '_')
|
|
36
|
+
|
|
37
|
+
templates.push({
|
|
38
|
+
exportName,
|
|
39
|
+
content,
|
|
40
|
+
originalPath: relativePath,
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
readTemplateFiles(templatesDir)
|
|
47
|
+
|
|
48
|
+
// 生成 TypeScript 文件内容
|
|
49
|
+
const tsContent = `/**
|
|
50
|
+
* 嵌入式模板内容
|
|
51
|
+
* 此文件由构建脚本自动生成,请勿手动编辑
|
|
52
|
+
* 源文件位于 templates/ 目录下
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
${templates
|
|
56
|
+
.map(({ exportName, content, originalPath }) => {
|
|
57
|
+
// 转义字符串中的反引号和反斜杠
|
|
58
|
+
const escapedContent = content
|
|
59
|
+
.replace(/\\/g, '\\\\')
|
|
60
|
+
.replace(/`/g, '\\`')
|
|
61
|
+
.replace(/\$\{/g, '\\${')
|
|
62
|
+
|
|
63
|
+
return `// ${originalPath}
|
|
64
|
+
export const ${exportName} = \`${escapedContent}\``
|
|
65
|
+
})
|
|
66
|
+
.join('\n\n')}`
|
|
67
|
+
|
|
68
|
+
// 写入文件
|
|
69
|
+
writeFileSync(outputFile, tsContent, 'utf-8')
|
|
70
|
+
console.log(`Generated ${outputFile} with ${templates.length} templates`)
|
|
71
|
+
}
|
|
5
72
|
|
|
6
73
|
// https://vitejs.dev/config/
|
|
7
74
|
export default defineConfig({
|
|
@@ -16,9 +83,8 @@ export default defineConfig({
|
|
|
16
83
|
lib: {
|
|
17
84
|
entry: path.join(__dirname, 'src', 'index.ts'),
|
|
18
85
|
name: 'index',
|
|
19
|
-
formats: ['cjs'],
|
|
20
|
-
|
|
21
|
-
fileName: () => `index.js`,
|
|
86
|
+
formats: ['cjs', 'es'],
|
|
87
|
+
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'js'}`,
|
|
22
88
|
},
|
|
23
89
|
outDir: path.join(__dirname, 'build'),
|
|
24
90
|
minify: false,
|
|
@@ -31,6 +97,13 @@ export default defineConfig({
|
|
|
31
97
|
},
|
|
32
98
|
},
|
|
33
99
|
plugins: [
|
|
100
|
+
// 在构建前生成模板文件
|
|
101
|
+
{
|
|
102
|
+
name: 'generate-templates',
|
|
103
|
+
buildStart() {
|
|
104
|
+
generateTemplatesFile()
|
|
105
|
+
},
|
|
106
|
+
},
|
|
34
107
|
tsconfigPaths(),
|
|
35
108
|
dts({
|
|
36
109
|
entryRoot: path.join(__dirname, 'src'),
|
package/vitest.config.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { defineConfig } from 'vitest/config'
|
|
2
|
+
import * as path from 'path'
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
globals: true,
|
|
7
|
+
environment: 'node',
|
|
8
|
+
include: ['test/**/*.test.js', 'src/**/*.test.ts'],
|
|
9
|
+
},
|
|
10
|
+
resolve: {
|
|
11
|
+
alias: {
|
|
12
|
+
'@': path.resolve(__dirname, 'src'),
|
|
13
|
+
},
|
|
14
|
+
},
|
|
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