@repdf/preview 0.3.2 → 0.5.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/dist/index.mjs +381 -0
- package/dist/preview/.next/BUILD_ID +1 -1
- package/dist/preview/.next/build-manifest.json +27 -29
- package/dist/preview/.next/cache/.previewinfo +1 -0
- package/dist/preview/.next/cache/.rscinfo +1 -0
- package/dist/preview/.next/cache/.tsbuildinfo +1 -1
- package/dist/preview/.next/cache/webpack/client-production/0.pack +0 -0
- package/dist/preview/.next/cache/webpack/client-production/index.pack +0 -0
- package/dist/preview/.next/cache/webpack/edge-server-production/0.pack +0 -0
- package/dist/preview/.next/cache/webpack/edge-server-production/index.pack +0 -0
- package/dist/preview/.next/cache/webpack/server-production/0.pack +0 -0
- package/dist/preview/.next/cache/webpack/server-production/index.pack +0 -0
- package/dist/preview/.next/diagnostics/build-diagnostics.json +6 -0
- package/dist/preview/.next/diagnostics/framework.json +1 -0
- package/dist/preview/.next/export-marker.json +6 -1
- package/dist/preview/.next/images-manifest.json +67 -1
- package/dist/preview/.next/next-minimal-server.js.nft.json +1 -1
- package/dist/preview/.next/next-server.js.nft.json +1 -1
- package/dist/preview/.next/prerender-manifest.json +11 -1
- package/dist/preview/.next/react-loadable-manifest.json +2 -2
- package/dist/preview/.next/required-server-files.js +334 -0
- package/dist/preview/.next/required-server-files.json +334 -1
- package/dist/preview/.next/routes-manifest.json +105 -1
- package/dist/preview/.next/server/chunks/18.js +1 -0
- package/dist/preview/.next/server/chunks/504.js +1 -0
- package/dist/preview/.next/server/chunks/539.js +4 -0
- package/dist/preview/.next/server/chunks/619.js +6 -0
- package/dist/preview/.next/server/chunks/934.js +5 -0
- package/dist/preview/.next/server/chunks/937.js +19 -0
- package/dist/preview/.next/server/chunks/985.js +1 -0
- package/dist/preview/.next/server/dynamic-css-manifest.js +1 -0
- package/dist/preview/.next/server/functions-config-manifest.json +4 -1
- package/dist/preview/.next/server/middleware-build-manifest.js +1 -1
- package/dist/preview/.next/server/middleware-react-loadable-manifest.js +1 -1
- package/dist/preview/.next/server/pages/_app.js +1 -1
- package/dist/preview/.next/server/pages/_app.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/_document.js +1 -1
- package/dist/preview/.next/server/pages/_document.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/_error.js +1 -1
- package/dist/preview/.next/server/pages/_error.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/api/component.js +4 -4
- package/dist/preview/.next/server/pages/api/component.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/api/pdf.js +2 -2
- package/dist/preview/.next/server/pages/api/pdf.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/api/trpc/[trpc].js +1 -1
- package/dist/preview/.next/server/pages/api/trpc/[trpc].js.nft.json +1 -1
- package/dist/preview/.next/server/pages/en/404.html +1 -1
- package/dist/preview/.next/server/pages/en/500.html +1 -1
- package/dist/preview/.next/server/pages/en/test.html +1 -1
- package/dist/preview/.next/server/pages/index.js +3 -3
- package/dist/preview/.next/server/pages/index.js.nft.json +1 -1
- package/dist/preview/.next/server/pages/preview/[...relTemplatePath].js +1 -1
- package/dist/preview/.next/server/pages/preview/[...relTemplatePath].js.nft.json +1 -1
- package/dist/preview/.next/server/pages/test.js.nft.json +1 -1
- package/dist/preview/.next/server/pages-manifest.json +13 -1
- package/dist/preview/.next/server/webpack-api-runtime.js +1 -1
- package/dist/preview/.next/server/webpack-runtime.js +1 -1
- package/dist/preview/.next/static/chunks/440-7f86160d543d19eb.js +1 -0
- package/dist/preview/.next/static/chunks/framework-c1a985c867714b4b.js +1 -0
- package/dist/preview/.next/static/chunks/main-3c8a75f1bd6d0687.js +5 -0
- package/dist/preview/.next/static/chunks/pages/_app-6411e6a26996cdef.js +182 -0
- package/dist/preview/.next/static/chunks/pages/_error-4911830c68e733ed.js +1 -0
- package/dist/preview/.next/static/chunks/pages/index-303e0eb1a2330d43.js +55 -0
- package/dist/preview/.next/static/chunks/pages/preview/[...relTemplatePath]-9bf0ebcb9e9f9c65.js +1 -0
- package/dist/preview/.next/static/chunks/pages/test-787280cd6c1cdb85.js +1 -0
- package/dist/preview/.next/static/chunks/webpack-6f363cd1990801ba.js +1 -0
- package/dist/preview/.next/static/css/a1c9c82f00c72350.css +1 -0
- package/dist/preview/.next/static/uQjdkl4yTW6Zpf-3uNg2P/_buildManifest.js +1 -0
- package/dist/preview/.next/trace +9 -13
- package/dist/preview/.next/trace-build +1 -0
- package/dist/preview/.next/types/routes.d.ts +58 -0
- package/dist/preview/.next/types/validator.ts +97 -0
- package/package.json +47 -49
- package/dist/index.js +0 -248
- package/dist/preview/.next/server/chunks/239.js +0 -6
- package/dist/preview/.next/server/chunks/276.js +0 -1
- package/dist/preview/.next/server/chunks/444.js +0 -4
- package/dist/preview/.next/server/chunks/478.js +0 -1
- package/dist/preview/.next/server/font-manifest.json +0 -1
- package/dist/preview/.next/static/2qhpHXmKu1a7HPYW0h8qX/_buildManifest.js +0 -1
- package/dist/preview/.next/static/chunks/64-33135d2a0b032c99.js +0 -1
- package/dist/preview/.next/static/chunks/837-9d4cc2d57e81e85c.js +0 -1
- package/dist/preview/.next/static/chunks/framework-e0f347a11a70369e.js +0 -1
- package/dist/preview/.next/static/chunks/main-32f0addb06a02100.js +0 -1
- package/dist/preview/.next/static/chunks/pages/_app-1fae2008e3549d5a.js +0 -182
- package/dist/preview/.next/static/chunks/pages/_error-0577f827b4afb66a.js +0 -1
- package/dist/preview/.next/static/chunks/pages/index-0ad3d9cfeac8a6ab.js +0 -1
- package/dist/preview/.next/static/chunks/pages/preview/[...relTemplatePath]-e0152b67b748423c.js +0 -1
- package/dist/preview/.next/static/chunks/pages/test-1b0ec700afcdd64b.js +0 -1
- package/dist/preview/.next/static/chunks/webpack-0b5d8249fb15f5f3.js +0 -1
- package/dist/preview/.next/static/css/35ecb02d4842937d.css +0 -3
- /package/dist/{index.d.ts → index.d.mts} +0 -0
- /package/dist/preview/.next/{server/chunks/font-manifest.json → dynamic-css-manifest.json} +0 -0
- /package/dist/preview/.next/static/{2qhpHXmKu1a7HPYW0h8qX → uQjdkl4yTW6Zpf-3uNg2P}/_ssgManifest.js +0 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { program } from "commander";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import pino from "pino";
|
|
5
|
+
import { parse } from "node:url";
|
|
6
|
+
import path from "path";
|
|
7
|
+
import { fileURLToPath } from "url";
|
|
8
|
+
import next from "next";
|
|
9
|
+
import http from "node:http";
|
|
10
|
+
import { Server } from "socket.io";
|
|
11
|
+
import * as chokidar from "chokidar";
|
|
12
|
+
import path$1 from "node:path";
|
|
13
|
+
import dependencyTree from "dependency-tree";
|
|
14
|
+
import { glob } from "glob";
|
|
15
|
+
//#region package.json
|
|
16
|
+
var version = "0.4.0";
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/logger.ts
|
|
19
|
+
const logger = pino({
|
|
20
|
+
transport: { target: "pino-pretty" },
|
|
21
|
+
level: "info"
|
|
22
|
+
});
|
|
23
|
+
function enableDebugLogging() {
|
|
24
|
+
logger.level = "debug";
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/utils/files/dependencyTree.ts
|
|
28
|
+
function getDependencyTree({ relViewerPath, outputType }) {
|
|
29
|
+
const options = {
|
|
30
|
+
filename: relViewerPath,
|
|
31
|
+
directory: ".",
|
|
32
|
+
tsConfig: "tsconfig.json",
|
|
33
|
+
filter: (path) => path.indexOf("node_modules") === -1,
|
|
34
|
+
noTypeDefinitions: false
|
|
35
|
+
};
|
|
36
|
+
if (outputType === "list") return dependencyTree.toList(options);
|
|
37
|
+
return dependencyTree(options);
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/constants.ts
|
|
41
|
+
const RELATIVE_PATH_TO_PDF_FOLDER = () => {
|
|
42
|
+
if (!process.env.RELATIVE_PATH_TO_PDF_FOLDER) throw new Error("RELATIVE_PATH_TO_PDF_FOLDER is not set");
|
|
43
|
+
return process.env.RELATIVE_PATH_TO_PDF_FOLDER;
|
|
44
|
+
};
|
|
45
|
+
const ABSOLUTE_PATH_TO_PDF_FOLDER = () => {
|
|
46
|
+
const absoluteFromEnv = process.env.ABSOLUTE_PATH_TO_PDF_FOLDER;
|
|
47
|
+
if (absoluteFromEnv && fs.existsSync(absoluteFromEnv)) return absoluteFromEnv;
|
|
48
|
+
const resolvedFromRelative = path$1.resolve(process.cwd(), RELATIVE_PATH_TO_PDF_FOLDER());
|
|
49
|
+
if (fs.existsSync(resolvedFromRelative)) return resolvedFromRelative;
|
|
50
|
+
if (absoluteFromEnv) return absoluteFromEnv;
|
|
51
|
+
throw new Error("ABSOLUTE_PATH_TO_PDF_FOLDER is not set");
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/utils/files/getPdfTemplates.ts
|
|
55
|
+
/**
|
|
56
|
+
* checks if a file could be a pdf template
|
|
57
|
+
* @param relativeFilePath
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
function isPotentialPdfTemplate(relViewerPath) {
|
|
61
|
+
if (fs.statSync(relViewerPath).isDirectory()) return false;
|
|
62
|
+
if (path$1.basename(relViewerPath).startsWith("_")) return false;
|
|
63
|
+
const extension = path$1.extname(relViewerPath);
|
|
64
|
+
if (![
|
|
65
|
+
".tsx",
|
|
66
|
+
".ts",
|
|
67
|
+
".jsx",
|
|
68
|
+
".js"
|
|
69
|
+
].includes(extension)) return false;
|
|
70
|
+
const absoluteFilePath = path$1.resolve(relViewerPath);
|
|
71
|
+
if (!fs.existsSync(absoluteFilePath)) return false;
|
|
72
|
+
return fs.readFileSync(absoluteFilePath, "utf8").includes("export default");
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* returns a list of all potential pdf templates and relevant metadata for display
|
|
76
|
+
*/
|
|
77
|
+
function getPdfTemplates() {
|
|
78
|
+
return glob.sync(`${RELATIVE_PATH_TO_PDF_FOLDER()}/**/*.{tsx,jsx,js}`, { nodir: true }).filter(isPotentialPdfTemplate).map((file) => {
|
|
79
|
+
const relTemplatePath = file.replace(`${RELATIVE_PATH_TO_PDF_FOLDER()}/`, "");
|
|
80
|
+
const pathParts = relTemplatePath.split("/");
|
|
81
|
+
let topParentFolder = null;
|
|
82
|
+
if (pathParts.length > 1 && pathParts[0]) topParentFolder = pathParts[0];
|
|
83
|
+
return {
|
|
84
|
+
fileName: path$1.basename(file),
|
|
85
|
+
relTemplatePath,
|
|
86
|
+
relViewerPath: file,
|
|
87
|
+
absolutePath: path$1.resolve(file),
|
|
88
|
+
topParentFolder
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/utils/files/pdfTemplateWatcher.ts
|
|
94
|
+
function pdfTemplateWatcher() {
|
|
95
|
+
try {
|
|
96
|
+
const absolutePathToPdfFolder = ABSOLUTE_PATH_TO_PDF_FOLDER();
|
|
97
|
+
const watcher = chokidar.watch(absolutePathToPdfFolder, {
|
|
98
|
+
persistent: true,
|
|
99
|
+
ignoreInitial: true,
|
|
100
|
+
ignored: /(^|[\/\\])\../
|
|
101
|
+
});
|
|
102
|
+
logger.info(`watching ${absolutePathToPdfFolder} for changes`);
|
|
103
|
+
const getExternalDependencyFiles = () => {
|
|
104
|
+
const externalDeps = /* @__PURE__ */ new Set();
|
|
105
|
+
const templates = getPdfTemplates();
|
|
106
|
+
for (const template of templates) {
|
|
107
|
+
let dependencies = [];
|
|
108
|
+
try {
|
|
109
|
+
dependencies = getDependencyTree({
|
|
110
|
+
relViewerPath: template.relViewerPath,
|
|
111
|
+
outputType: "list"
|
|
112
|
+
});
|
|
113
|
+
} catch (error) {
|
|
114
|
+
logger.debug({
|
|
115
|
+
err: error,
|
|
116
|
+
template: template.relViewerPath
|
|
117
|
+
}, "failed to resolve dependency tree for template");
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
for (const dependency of dependencies) {
|
|
121
|
+
const absoluteDependencyPath = path$1.resolve(dependency);
|
|
122
|
+
if (absoluteDependencyPath.startsWith(absolutePathToPdfFolder) || !path$1.isAbsolute(absoluteDependencyPath)) continue;
|
|
123
|
+
externalDeps.add(absoluteDependencyPath);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return [...externalDeps];
|
|
127
|
+
};
|
|
128
|
+
let watchedExternalDependencies = getExternalDependencyFiles();
|
|
129
|
+
if (watchedExternalDependencies.length > 0) watcher.add(watchedExternalDependencies);
|
|
130
|
+
const syncExternalDependencyWatches = () => {
|
|
131
|
+
const nextExternalDependencies = getExternalDependencyFiles();
|
|
132
|
+
for (const filePath of watchedExternalDependencies) if (!nextExternalDependencies.includes(filePath)) watcher.unwatch(filePath);
|
|
133
|
+
for (const filePath of nextExternalDependencies) if (!watchedExternalDependencies.includes(filePath)) watcher.add(filePath);
|
|
134
|
+
watchedExternalDependencies = nextExternalDependencies;
|
|
135
|
+
};
|
|
136
|
+
watcher.on("add", (filePath) => {
|
|
137
|
+
logger.info(`file added: ${filePath}`);
|
|
138
|
+
syncExternalDependencyWatches();
|
|
139
|
+
}).on("change", (filePath) => {
|
|
140
|
+
logger.info(`file changed: ${filePath}`);
|
|
141
|
+
syncExternalDependencyWatches();
|
|
142
|
+
}).on("unlink", (filePath) => {
|
|
143
|
+
logger.info(`file removed: ${filePath}`);
|
|
144
|
+
syncExternalDependencyWatches();
|
|
145
|
+
}).on("error", (error) => {
|
|
146
|
+
logger.error({ err: error }, "watcher error");
|
|
147
|
+
});
|
|
148
|
+
return watcher;
|
|
149
|
+
} catch (error) {
|
|
150
|
+
logger.error({ err: error }, "watcher failed to start");
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
155
|
+
//#region src/cli/commands/server.ts
|
|
156
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
157
|
+
const __dirname = path.dirname(__filename);
|
|
158
|
+
const resolvePreviewServerLocation = () => {
|
|
159
|
+
const candidates = [
|
|
160
|
+
path.resolve(__dirname, "preview"),
|
|
161
|
+
path.resolve(__dirname, "../preview"),
|
|
162
|
+
path.resolve(__dirname, "../../preview"),
|
|
163
|
+
path.resolve(__dirname, "../../..")
|
|
164
|
+
];
|
|
165
|
+
for (const candidate of candidates) if (fs.existsSync(path.join(candidate, ".next"))) return candidate;
|
|
166
|
+
return path.resolve(__dirname, "../../..");
|
|
167
|
+
};
|
|
168
|
+
const previewServerLocation = resolvePreviewServerLocation();
|
|
169
|
+
logger.debug({ previewServerLocation }, "resolved preview server location");
|
|
170
|
+
const getEnvVariablesForPreviewApp = (relativePathToPdfsDirectory, cwd) => {
|
|
171
|
+
return {
|
|
172
|
+
RELATIVE_PATH_TO_PDF_FOLDER: relativePathToPdfsDirectory,
|
|
173
|
+
ABSOLUTE_PATH_TO_PDF_FOLDER: path.resolve(cwd, relativePathToPdfsDirectory),
|
|
174
|
+
USER_PROJECT_LOCATION: cwd
|
|
175
|
+
};
|
|
176
|
+
};
|
|
177
|
+
let previewServer;
|
|
178
|
+
const activeSockets = /* @__PURE__ */ new Set();
|
|
179
|
+
let nextAppInstance = null;
|
|
180
|
+
let hotReloadSocketServer = null;
|
|
181
|
+
let templateWatcher = null;
|
|
182
|
+
let hotReloadDebounce = null;
|
|
183
|
+
const safeAsyncServerListen = (server, port) => {
|
|
184
|
+
return new Promise((resolve, reject) => {
|
|
185
|
+
const onListening = () => {
|
|
186
|
+
server.off("error", onError);
|
|
187
|
+
resolve({ portAlreadyInUse: false });
|
|
188
|
+
};
|
|
189
|
+
const onError = (error) => {
|
|
190
|
+
server.off("listening", onListening);
|
|
191
|
+
if (error.code === "EADDRINUSE") {
|
|
192
|
+
resolve({ portAlreadyInUse: true });
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
reject(error);
|
|
196
|
+
};
|
|
197
|
+
server.once("listening", onListening);
|
|
198
|
+
server.once("error", onError);
|
|
199
|
+
server.listen(port);
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
const startPreviewServer = async (pdfsDirRelativePath, port) => {
|
|
203
|
+
if (port > 65535) throw new Error("No available ports found (checked through 65535)");
|
|
204
|
+
const normalizedPdfsDirPath = path.normalize(pdfsDirRelativePath);
|
|
205
|
+
const absolutePathToPdfsDir = path.resolve(process.cwd(), normalizedPdfsDirPath);
|
|
206
|
+
let nextReadyPromise = Promise.resolve();
|
|
207
|
+
let isNextReady = false;
|
|
208
|
+
let nextRequestHandler = null;
|
|
209
|
+
previewServer = http.createServer((req, res) => {
|
|
210
|
+
if (!req.url) {
|
|
211
|
+
res.writeHead(404);
|
|
212
|
+
res.end();
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const parsedUrl = parse(req.url, true);
|
|
216
|
+
res.setHeader("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store");
|
|
217
|
+
res.setHeader("Pragma", "no-cache");
|
|
218
|
+
res.setHeader("Expires", "-1");
|
|
219
|
+
if (!isNextReady) {
|
|
220
|
+
nextReadyPromise.then(() => nextRequestHandler?.(req, res, parsedUrl));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
nextRequestHandler?.(req, res, parsedUrl);
|
|
224
|
+
});
|
|
225
|
+
previewServer.on("connection", (socket) => {
|
|
226
|
+
activeSockets.add(socket);
|
|
227
|
+
socket.on("close", () => {
|
|
228
|
+
activeSockets.delete(socket);
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
const { portAlreadyInUse } = await safeAsyncServerListen(previewServer, port);
|
|
232
|
+
if (portAlreadyInUse) {
|
|
233
|
+
logger.info(`port ${port} in use, trying ${port + 1}`);
|
|
234
|
+
return startPreviewServer(pdfsDirRelativePath, port + 1);
|
|
235
|
+
}
|
|
236
|
+
process.env = {
|
|
237
|
+
NODE_ENV: "development",
|
|
238
|
+
...process.env,
|
|
239
|
+
PORT: String(port),
|
|
240
|
+
...getEnvVariablesForPreviewApp(normalizedPdfsDirPath, process.cwd())
|
|
241
|
+
};
|
|
242
|
+
const nextApp = next({
|
|
243
|
+
dev: false,
|
|
244
|
+
conf: { images: { unoptimized: true } },
|
|
245
|
+
hostname: "localhost",
|
|
246
|
+
port,
|
|
247
|
+
dir: previewServerLocation
|
|
248
|
+
});
|
|
249
|
+
nextAppInstance = nextApp;
|
|
250
|
+
logger.info("preparing next app");
|
|
251
|
+
nextReadyPromise = nextApp.prepare();
|
|
252
|
+
await nextReadyPromise;
|
|
253
|
+
nextRequestHandler = nextApp.getRequestHandler();
|
|
254
|
+
isNextReady = true;
|
|
255
|
+
hotReloadSocketServer = new Server(previewServer, { path: "/socket.io/" });
|
|
256
|
+
const pendingChanges = [];
|
|
257
|
+
const flushReloadEvents = () => {
|
|
258
|
+
if (!hotReloadSocketServer || pendingChanges.length === 0) return;
|
|
259
|
+
hotReloadSocketServer.emit("reload", pendingChanges.splice(0));
|
|
260
|
+
};
|
|
261
|
+
templateWatcher = pdfTemplateWatcher();
|
|
262
|
+
templateWatcher.on("all", (event, filePath) => {
|
|
263
|
+
const absolutePath = path.isAbsolute(filePath) ? filePath : path.resolve(absolutePathToPdfsDir, filePath);
|
|
264
|
+
const relPath = path.relative(absolutePathToPdfsDir, absolutePath);
|
|
265
|
+
pendingChanges.push({
|
|
266
|
+
event: event === "add" || event === "addDir" || event === "change" || event === "unlink" || event === "unlinkDir" ? event : "change",
|
|
267
|
+
filename: relPath
|
|
268
|
+
});
|
|
269
|
+
if (hotReloadDebounce) clearTimeout(hotReloadDebounce);
|
|
270
|
+
hotReloadDebounce = setTimeout(flushReloadEvents, 150);
|
|
271
|
+
});
|
|
272
|
+
previewServer.on("close", async () => {
|
|
273
|
+
if (hotReloadDebounce) {
|
|
274
|
+
clearTimeout(hotReloadDebounce);
|
|
275
|
+
hotReloadDebounce = null;
|
|
276
|
+
}
|
|
277
|
+
if (templateWatcher) {
|
|
278
|
+
templateWatcher.removeAllListeners();
|
|
279
|
+
await templateWatcher.close();
|
|
280
|
+
templateWatcher = null;
|
|
281
|
+
}
|
|
282
|
+
if (hotReloadSocketServer) {
|
|
283
|
+
hotReloadSocketServer.close();
|
|
284
|
+
hotReloadSocketServer = null;
|
|
285
|
+
}
|
|
286
|
+
if (!nextAppInstance || !("close" in nextAppInstance)) return;
|
|
287
|
+
await nextAppInstance.close();
|
|
288
|
+
nextAppInstance = null;
|
|
289
|
+
});
|
|
290
|
+
const url = `http://localhost:${port}`;
|
|
291
|
+
const clickableUrl = `\u001B]8;;${url}\u0007${url}\u001B]8;;\u0007`;
|
|
292
|
+
console.log(clickableUrl);
|
|
293
|
+
return previewServer;
|
|
294
|
+
};
|
|
295
|
+
const stopPreviewServer = async () => {
|
|
296
|
+
if (!previewServer) return;
|
|
297
|
+
for (const socket of activeSockets) socket.destroy();
|
|
298
|
+
activeSockets.clear();
|
|
299
|
+
await new Promise((resolve, reject) => {
|
|
300
|
+
previewServer.close((error) => {
|
|
301
|
+
if (error) {
|
|
302
|
+
reject(error);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
resolve();
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/cli/commands/dev.ts
|
|
311
|
+
const dev = async ({ dir: relativePathToPdfFolder, port, debug }) => {
|
|
312
|
+
if (debug || process.env.DEBUG === "true" || process.env.DEBUG === "1") {
|
|
313
|
+
process.env.DEBUG = "true";
|
|
314
|
+
enableDebugLogging();
|
|
315
|
+
logger.debug("debug logging enabled");
|
|
316
|
+
}
|
|
317
|
+
try {
|
|
318
|
+
if (!fs.existsSync(relativePathToPdfFolder)) throw new Error(`Missing ${relativePathToPdfFolder} folder`);
|
|
319
|
+
await startPreviewServer(relativePathToPdfFolder, parseInt(port));
|
|
320
|
+
let isShuttingDown = false;
|
|
321
|
+
const shutdown = async (signal) => {
|
|
322
|
+
if (isShuttingDown) return;
|
|
323
|
+
isShuttingDown = true;
|
|
324
|
+
if (signal) logger.info({ signal }, "Shutting down preview server...");
|
|
325
|
+
else logger.info("Shutting down preview server...");
|
|
326
|
+
process.off("SIGINT", onSigInt);
|
|
327
|
+
process.off("SIGTERM", onSigTerm);
|
|
328
|
+
process.off("SIGHUP", onSigHup);
|
|
329
|
+
process.off("SIGQUIT", onSigQuit);
|
|
330
|
+
process.stdin.off("end", onStdinEnd);
|
|
331
|
+
const forceExitTimer = setTimeout(() => {
|
|
332
|
+
logger.warn("Shutdown timed out after 5s; forcing process exit to release terminal control.");
|
|
333
|
+
process.exit(1);
|
|
334
|
+
}, 5e3);
|
|
335
|
+
try {
|
|
336
|
+
await stopPreviewServer();
|
|
337
|
+
clearTimeout(forceExitTimer);
|
|
338
|
+
process.exit(0);
|
|
339
|
+
} catch (error) {
|
|
340
|
+
clearTimeout(forceExitTimer);
|
|
341
|
+
logger.error({ err: error }, "Failed during preview server shutdown");
|
|
342
|
+
process.exit(1);
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
const onSigInt = () => {
|
|
346
|
+
shutdown("SIGINT");
|
|
347
|
+
};
|
|
348
|
+
const onSigTerm = () => {
|
|
349
|
+
shutdown("SIGTERM");
|
|
350
|
+
};
|
|
351
|
+
const onSigHup = () => {
|
|
352
|
+
shutdown("SIGHUP");
|
|
353
|
+
};
|
|
354
|
+
const onSigQuit = () => {
|
|
355
|
+
shutdown("SIGQUIT");
|
|
356
|
+
};
|
|
357
|
+
const onStdinEnd = () => {
|
|
358
|
+
shutdown("STDIN_END");
|
|
359
|
+
};
|
|
360
|
+
process.on("SIGINT", onSigInt);
|
|
361
|
+
process.on("SIGTERM", onSigTerm);
|
|
362
|
+
process.on("SIGHUP", onSigHup);
|
|
363
|
+
process.on("SIGQUIT", onSigQuit);
|
|
364
|
+
process.stdin.on("end", onStdinEnd);
|
|
365
|
+
if (!process.stdin.isTTY) process.stdin.resume();
|
|
366
|
+
} catch (error) {
|
|
367
|
+
logger.error(error);
|
|
368
|
+
process.exit(1);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
//#endregion
|
|
372
|
+
//#region src/cli/index.ts
|
|
373
|
+
program.name("repdf").description("A live preview of your pdf templates").version(version);
|
|
374
|
+
program.command("dev").description("Starts the preview pdf development app").option("-d --dir <path>", "Directory containing pdf templates", "./src/pdfs").option("-p --port <port>", "Port to run dev server on", "3000").option("--debug", "Enable debug logging").action(dev);
|
|
375
|
+
if (!process.argv.slice(2).length) {
|
|
376
|
+
program.outputHelp();
|
|
377
|
+
process.exit(0);
|
|
378
|
+
}
|
|
379
|
+
program.parse();
|
|
380
|
+
//#endregion
|
|
381
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
uQjdkl4yTW6Zpf-3uNg2P
|
|
@@ -3,47 +3,45 @@
|
|
|
3
3
|
"static/chunks/polyfills-42372ed130431b0a.js"
|
|
4
4
|
],
|
|
5
5
|
"devFiles": [],
|
|
6
|
-
"ampDevFiles": [],
|
|
7
6
|
"lowPriorityFiles": [
|
|
8
|
-
"static/
|
|
9
|
-
"static/
|
|
7
|
+
"static/uQjdkl4yTW6Zpf-3uNg2P/_buildManifest.js",
|
|
8
|
+
"static/uQjdkl4yTW6Zpf-3uNg2P/_ssgManifest.js"
|
|
10
9
|
],
|
|
11
10
|
"rootMainFiles": [],
|
|
11
|
+
"rootMainFilesTree": {},
|
|
12
12
|
"pages": {
|
|
13
13
|
"/": [
|
|
14
|
-
"static/chunks/webpack-
|
|
15
|
-
"static/chunks/framework-
|
|
16
|
-
"static/chunks/main-
|
|
17
|
-
"static/chunks/
|
|
18
|
-
"static/chunks/pages/index-
|
|
14
|
+
"static/chunks/webpack-6f363cd1990801ba.js",
|
|
15
|
+
"static/chunks/framework-c1a985c867714b4b.js",
|
|
16
|
+
"static/chunks/main-3c8a75f1bd6d0687.js",
|
|
17
|
+
"static/chunks/440-7f86160d543d19eb.js",
|
|
18
|
+
"static/chunks/pages/index-303e0eb1a2330d43.js"
|
|
19
19
|
],
|
|
20
20
|
"/_app": [
|
|
21
|
-
"static/chunks/webpack-
|
|
22
|
-
"static/chunks/framework-
|
|
23
|
-
"static/chunks/main-
|
|
24
|
-
"static/css/
|
|
25
|
-
"static/chunks/pages/_app-
|
|
21
|
+
"static/chunks/webpack-6f363cd1990801ba.js",
|
|
22
|
+
"static/chunks/framework-c1a985c867714b4b.js",
|
|
23
|
+
"static/chunks/main-3c8a75f1bd6d0687.js",
|
|
24
|
+
"static/css/a1c9c82f00c72350.css",
|
|
25
|
+
"static/chunks/pages/_app-6411e6a26996cdef.js"
|
|
26
26
|
],
|
|
27
27
|
"/_error": [
|
|
28
|
-
"static/chunks/webpack-
|
|
29
|
-
"static/chunks/framework-
|
|
30
|
-
"static/chunks/main-
|
|
31
|
-
"static/chunks/pages/_error-
|
|
28
|
+
"static/chunks/webpack-6f363cd1990801ba.js",
|
|
29
|
+
"static/chunks/framework-c1a985c867714b4b.js",
|
|
30
|
+
"static/chunks/main-3c8a75f1bd6d0687.js",
|
|
31
|
+
"static/chunks/pages/_error-4911830c68e733ed.js"
|
|
32
32
|
],
|
|
33
33
|
"/preview/[...relTemplatePath]": [
|
|
34
|
-
"static/chunks/webpack-
|
|
35
|
-
"static/chunks/framework-
|
|
36
|
-
"static/chunks/main-
|
|
37
|
-
"static/chunks/
|
|
38
|
-
"static/chunks/
|
|
39
|
-
"static/chunks/pages/preview/[...relTemplatePath]-e0152b67b748423c.js"
|
|
34
|
+
"static/chunks/webpack-6f363cd1990801ba.js",
|
|
35
|
+
"static/chunks/framework-c1a985c867714b4b.js",
|
|
36
|
+
"static/chunks/main-3c8a75f1bd6d0687.js",
|
|
37
|
+
"static/chunks/440-7f86160d543d19eb.js",
|
|
38
|
+
"static/chunks/pages/preview/[...relTemplatePath]-9bf0ebcb9e9f9c65.js"
|
|
40
39
|
],
|
|
41
40
|
"/test": [
|
|
42
|
-
"static/chunks/webpack-
|
|
43
|
-
"static/chunks/framework-
|
|
44
|
-
"static/chunks/main-
|
|
45
|
-
"static/chunks/pages/test-
|
|
41
|
+
"static/chunks/webpack-6f363cd1990801ba.js",
|
|
42
|
+
"static/chunks/framework-c1a985c867714b4b.js",
|
|
43
|
+
"static/chunks/main-3c8a75f1bd6d0687.js",
|
|
44
|
+
"static/chunks/pages/test-787280cd6c1cdb85.js"
|
|
46
45
|
]
|
|
47
|
-
}
|
|
48
|
-
"ampFirstPages": []
|
|
46
|
+
}
|
|
49
47
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"previewModeId":"5f739dd66df2bf0113e6397704146612","previewModeSigningKey":"3e30d460d9841ae936dac02de5699520f6320e828e4abd538d486f9690129811","previewModeEncryptionKey":"72ee6230aaed11e742c6358be39da1f9ca4c55d1ddf746837e23a6e493d02856","expireAt":1774379152992}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"encryption.key":"y8rBNN9f5CqnZkTMrMg2bW1z7Z+WN1OTeLAibgr6Wpg=","encryption.expire_at":1774379152987}
|