-
Notifications
You must be signed in to change notification settings - Fork 390
Expand file tree
/
Copy pathbundle-pdfjs-base.js
More file actions
88 lines (78 loc) · 2.31 KB
/
bundle-pdfjs-base.js
File metadata and controls
88 lines (78 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import fs from "fs";
import path from "path";
import { fileURLToPath } from "url";
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// const _pdfjsFiles = [];
const baseDir = `${__dirname}/../base/`;
// function scanPdfJsBaseFiles(directory) {
// fs.readdirSync(directory).forEach((file) => {
// const filePath = path.join(directory, file);
// if (fs.statSync(filePath).isDirectory()) {
// scanPdfJsBaseFiles(filePath);
// } else if (filePath.endsWith(".js")) {
// _pdfjsFiles.push(filePath);
// }
// });
// }
// scanPdfJsBaseFiles(baseDir); // order matters, will revisit this later
const _pdfjsFiles = [
"shared/util.js",
"shared/colorspace.js",
"shared/pattern.js",
"shared/function.js",
"shared/annotation.js",
"core/core.js",
"core/obj.js",
"core/charsets.js",
"core/crypto.js",
"core/evaluator.js",
"core/fonts.js",
"core/font_renderer.js",
"core/glyphlist.js",
"core/image.js",
"core/metrics.js",
"core/parser.js",
"core/stream.js",
"core/worker.js",
"core/jpx.js",
"core/jbig2.js",
"core/bidi.js",
"core/jpg.js",
"core/chunked_stream.js",
"core/pdf_manager.js",
"core/cmap.js",
"core/cidmaps.js",
"display/canvas.js",
"display/font_loader.js",
"display/metadata.js",
"display/api.js",
];
const _baseCode = _pdfjsFiles.reduce(
(preContent, fileName) =>
(preContent += fs.readFileSync(path.join(baseDir, fileName), "utf8")),
""
);
fs.writeFileSync(path.join(__dirname, "../lib/pdfjs-code.js"),
`
${"import nodeUtil from 'util';import { Blob } from 'buffer';import { DOMParser } from '@xmldom/xmldom';import PDFAnno from './pdfanno.js';import Image from './pdfimage.js';import { createScratchCanvas } from './pdfcanvas.js';"}
${"export const PDFJS = {};"}
${"const globalScope = { console, PDFJS };"}
${_baseCode}
`,
{
encoding: "utf8",
mode: 0o666,
}
);
const targetDir = path.join(__dirname, "../dist");
if (!fs.existsSync(targetDir)) {
fs.mkdirSync(targetDir);
}
fs.copyFileSync(path.join(__dirname, "../pdfparser.d.ts"), path.join(targetDir, "pdfparser.d.ts"));
// .d.cts should have "export =" instead of "export default"
const typeDefContent = fs.readFileSync(path.join(__dirname, "../pdfparser.d.ts"), "utf8");
fs.writeFileSync(
path.join(targetDir, "pdfparser.d.cts"),
typeDefContent.replace("export default", "export =")
);