jinrai 1.0.0 → 1.0.1
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/.prettierrc +7 -0
- package/lib/bin.js +31 -3
- package/package.json +2 -2
- package/src/bin.ts +3 -1
- package/src/config/defaultIndexHtml.ts +16 -0
- package/src/templates.ts +16 -4
package/.prettierrc
ADDED
package/lib/bin.js
CHANGED
|
@@ -3263,11 +3263,18 @@ var getRawPageData = async (url, pages, debug = false) => {
|
|
|
3263
3263
|
const context = await browser.newContext({
|
|
3264
3264
|
userAgent: "____fast-ssr-tool___"
|
|
3265
3265
|
});
|
|
3266
|
-
let
|
|
3266
|
+
let indexHtml = void 0;
|
|
3267
3267
|
for await (const mask of pages) {
|
|
3268
3268
|
task2.next(mask, "yellow", cli_spinners_default.dotsCircle, 1);
|
|
3269
3269
|
const page = await context.newPage();
|
|
3270
3270
|
const path2 = mask.replaceAll("{", "").replaceAll("}", "");
|
|
3271
|
+
if (!indexHtml) {
|
|
3272
|
+
page.on("response", async (responce) => {
|
|
3273
|
+
if (responce.status() == 200 && responce.url() == url + path2) {
|
|
3274
|
+
indexHtml = await responce.text();
|
|
3275
|
+
}
|
|
3276
|
+
});
|
|
3277
|
+
}
|
|
3271
3278
|
await page.goto(url + path2);
|
|
3272
3279
|
await page.waitForLoadState("networkidle");
|
|
3273
3280
|
await page.waitForTimeout(1e3);
|
|
@@ -3288,23 +3295,44 @@ var getRawPageData = async (url, pages, debug = false) => {
|
|
|
3288
3295
|
}
|
|
3289
3296
|
await browser.close();
|
|
3290
3297
|
task2.success();
|
|
3291
|
-
return result;
|
|
3298
|
+
return { pages: result, indexHtml };
|
|
3292
3299
|
};
|
|
3293
3300
|
|
|
3294
3301
|
// src/bin.ts
|
|
3295
3302
|
import path from "node:path";
|
|
3296
3303
|
import { mkdir } from "node:fs/promises";
|
|
3297
3304
|
import prettier from "prettier";
|
|
3305
|
+
|
|
3306
|
+
// src/config/defaultIndexHtml.ts
|
|
3307
|
+
var defaultIndexHtml = `
|
|
3308
|
+
<!doctype html>
|
|
3309
|
+
<html lang="eng">
|
|
3310
|
+
<head>
|
|
3311
|
+
<meta charset="UTF-8" />
|
|
3312
|
+
<link rel="icon" type="image/svg+xml" href="/images/favicon.svg" />
|
|
3313
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
3314
|
+
<title>Jinrai app</title>
|
|
3315
|
+
<!--app-head-->
|
|
3316
|
+
</head>
|
|
3317
|
+
<body>
|
|
3318
|
+
<div id="root"><!--app-html--></div>
|
|
3319
|
+
</body>
|
|
3320
|
+
</html>
|
|
3321
|
+
|
|
3322
|
+
`;
|
|
3323
|
+
|
|
3324
|
+
// src/bin.ts
|
|
3298
3325
|
var task = new Task();
|
|
3299
3326
|
task.do("Load config");
|
|
3300
3327
|
var config = await getUserConfig();
|
|
3301
3328
|
task.success();
|
|
3302
3329
|
var data = await getRawPageData(config.url, config.pages, config.dev);
|
|
3303
3330
|
task.do("Format");
|
|
3304
|
-
var { routes, templates } = getRoutesAndTemplates(data);
|
|
3331
|
+
var { routes, templates } = getRoutesAndTemplates(data.pages);
|
|
3305
3332
|
task.next(`Export: ${config.export.outDir} (${templates.length})`);
|
|
3306
3333
|
await mkdir(config.export.outDir, { recursive: true });
|
|
3307
3334
|
await writeFile(path.join(config.export.outDir, "config.json"), JSON.stringify(routes, null, 2));
|
|
3335
|
+
await writeFile(path.join(config.export.outDir, "index.html"), data.indexHtml ?? defaultIndexHtml);
|
|
3308
3336
|
for await (let [index, template] of templates.entries()) {
|
|
3309
3337
|
try {
|
|
3310
3338
|
template = await prettier.format(template, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jinrai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A powerful library that analyzes your modern web application and automatically generates a perfectly rendered, static snapshot of its pages. Experience unparalleled loading speed and SEO clarity without the complexity of traditional SSR setups. Simply point Jinrai at your SPA and witness divine speed.",
|
|
5
5
|
"main": "lib/index.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"typescript": "^5.9.2"
|
|
24
24
|
},
|
|
25
25
|
"bin": {
|
|
26
|
-
"
|
|
26
|
+
"jinrai": "lib/bin.js"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@types/prettier": "^2.7.3",
|
package/src/bin.ts
CHANGED
|
@@ -8,6 +8,7 @@ import path from "node:path"
|
|
|
8
8
|
import { mkdir } from "node:fs/promises"
|
|
9
9
|
import prettier from "prettier"
|
|
10
10
|
import Task from "./ui/task"
|
|
11
|
+
import { defaultIndexHtml } from "./config/defaultIndexHtml"
|
|
11
12
|
|
|
12
13
|
const task = new Task()
|
|
13
14
|
|
|
@@ -18,12 +19,13 @@ task.success()
|
|
|
18
19
|
const data = await getRawPageData(config.url, config.pages, config.dev)
|
|
19
20
|
|
|
20
21
|
task.do("Format")
|
|
21
|
-
const { routes, templates } = getRoutesAndTemplates(data)
|
|
22
|
+
const { routes, templates } = getRoutesAndTemplates(data.pages)
|
|
22
23
|
|
|
23
24
|
task.next(`Export: ${config.export.outDir} (${templates.length})`)
|
|
24
25
|
await mkdir(config.export.outDir, { recursive: true })
|
|
25
26
|
|
|
26
27
|
await writeFile(path.join(config.export.outDir, "config.json"), JSON.stringify(routes, null, 2))
|
|
28
|
+
await writeFile(path.join(config.export.outDir, "index.html"), data.indexHtml ?? defaultIndexHtml)
|
|
27
29
|
|
|
28
30
|
for await (let [index, template] of templates.entries()) {
|
|
29
31
|
try {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const defaultIndexHtml = `
|
|
2
|
+
<!doctype html>
|
|
3
|
+
<html lang="eng">
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<link rel="icon" type="image/svg+xml" href="/images/favicon.svg" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
8
|
+
<title>Jinrai app</title>
|
|
9
|
+
<!--app-head-->
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"><!--app-html--></div>
|
|
13
|
+
</body>
|
|
14
|
+
</html>
|
|
15
|
+
|
|
16
|
+
`
|
package/src/templates.ts
CHANGED
|
@@ -14,7 +14,11 @@ export interface PageData {
|
|
|
14
14
|
input: input[]
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const getRawPageData = async (
|
|
17
|
+
export const getRawPageData = async (
|
|
18
|
+
url: string,
|
|
19
|
+
pages: string[],
|
|
20
|
+
debug: boolean = false,
|
|
21
|
+
): Promise<{ pages: PageData[]; indexHtml?: string }> => {
|
|
18
22
|
const task = new Task()
|
|
19
23
|
task.next("Parsing pages", "yellow", spinners.dotsCircle)
|
|
20
24
|
|
|
@@ -25,14 +29,22 @@ export const getRawPageData = async (url: string, pages: string[], debug: boolea
|
|
|
25
29
|
userAgent: "____fast-ssr-tool___",
|
|
26
30
|
})
|
|
27
31
|
|
|
28
|
-
let date: any[] = []
|
|
32
|
+
// let date: any[] = [];
|
|
33
|
+
let indexHtml: string | undefined = undefined
|
|
29
34
|
|
|
30
35
|
for await (const mask of pages) {
|
|
31
36
|
task.next(mask, "yellow", spinners.dotsCircle, 1)
|
|
32
37
|
|
|
33
38
|
const page = await context.newPage()
|
|
34
|
-
|
|
35
39
|
const path = mask.replaceAll("{", "").replaceAll("}", "")
|
|
40
|
+
if (!indexHtml) {
|
|
41
|
+
page.on("response", async responce => {
|
|
42
|
+
if (responce.status() == 200 && responce.url() == url + path) {
|
|
43
|
+
indexHtml = await responce.text()
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
36
48
|
await page.goto(url + path)
|
|
37
49
|
|
|
38
50
|
await page.waitForLoadState("networkidle")
|
|
@@ -63,5 +75,5 @@ export const getRawPageData = async (url: string, pages: string[], debug: boolea
|
|
|
63
75
|
await browser.close()
|
|
64
76
|
|
|
65
77
|
task.success()
|
|
66
|
-
return result
|
|
78
|
+
return { pages: result, indexHtml }
|
|
67
79
|
}
|