jinrai 1.0.1 → 1.0.3
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/index.html +10 -13
- package/lib/bin.js +14 -13
- package/lib/src/config/userConfig.d.ts +3 -10
- package/package.json +1 -1
- package/src/bin.ts +9 -8
- package/src/config/userConfig.ts +4 -16
- package/src/templates.ts +3 -4
- package/test/fld.config.ts +13 -0
- package/test/jinrai.config.ts +8 -0
- package/test/.ssr.config.ts +0 -20
package/index.html
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
2
|
<html lang="ru">
|
|
3
|
-
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
</
|
|
12
|
-
|
|
13
|
-
<body>
|
|
14
|
-
<div id="root">@ROOT</div>
|
|
15
|
-
</body>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<!--app-head-->
|
|
8
|
+
</head>
|
|
9
|
+
<body>
|
|
10
|
+
<div id="root"><!--app-html--></div>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
package/lib/bin.js
CHANGED
|
@@ -12,11 +12,11 @@ import { writeFile } from "node:fs/promises";
|
|
|
12
12
|
import { createJiti } from "jiti";
|
|
13
13
|
import { pathToFileURL } from "url";
|
|
14
14
|
import { resolve } from "path";
|
|
15
|
-
var getUserConfig = async () => {
|
|
15
|
+
var getUserConfig = async (configName2) => {
|
|
16
16
|
const jiti = createJiti(import.meta.url, {
|
|
17
17
|
debug: false
|
|
18
18
|
});
|
|
19
|
-
const configPath = pathToFileURL(resolve(process.cwd(),
|
|
19
|
+
const configPath = pathToFileURL(resolve(process.cwd(), configName2)).href;
|
|
20
20
|
const configModule = await jiti.import(configPath);
|
|
21
21
|
return configModule.default;
|
|
22
22
|
};
|
|
@@ -3278,10 +3278,10 @@ var getRawPageData = async (url, pages, debug = false) => {
|
|
|
3278
3278
|
await page.goto(url + path2);
|
|
3279
3279
|
await page.waitForLoadState("networkidle");
|
|
3280
3280
|
await page.waitForTimeout(1e3);
|
|
3281
|
-
const
|
|
3282
|
-
return window.
|
|
3281
|
+
const input2 = await page.evaluate(() => {
|
|
3282
|
+
return window.__page_requests;
|
|
3283
3283
|
});
|
|
3284
|
-
|
|
3284
|
+
if (debug) console.log({ input: input2 });
|
|
3285
3285
|
const root = await page.locator("#root").innerHTML();
|
|
3286
3286
|
if (debug) {
|
|
3287
3287
|
await task2.ask("continue?");
|
|
@@ -3323,16 +3323,17 @@ var defaultIndexHtml = `
|
|
|
3323
3323
|
|
|
3324
3324
|
// src/bin.ts
|
|
3325
3325
|
var task = new Task();
|
|
3326
|
-
|
|
3327
|
-
|
|
3326
|
+
var configName = process.argv[2] ? process.argv[2] : "jinrai.config";
|
|
3327
|
+
task.do("Init: " + configName);
|
|
3328
|
+
var config = await getUserConfig(configName);
|
|
3328
3329
|
task.success();
|
|
3329
|
-
var data = await getRawPageData(config.url, config.pages, config.
|
|
3330
|
+
var data = await getRawPageData(config.url, config.pages, config.debug);
|
|
3330
3331
|
task.do("Format");
|
|
3331
3332
|
var { routes, templates } = getRoutesAndTemplates(data.pages);
|
|
3332
|
-
task.next(`Export: ${config.
|
|
3333
|
-
await mkdir(config.
|
|
3334
|
-
await writeFile(path.join(config.
|
|
3335
|
-
await writeFile(path.join(config.
|
|
3333
|
+
task.next(`Export: ${config.outDir} (${templates.length})`);
|
|
3334
|
+
await mkdir(config.outDir, { recursive: true });
|
|
3335
|
+
await writeFile(path.join(config.outDir, "config.json"), JSON.stringify(routes, null, 2));
|
|
3336
|
+
await writeFile(path.join(config.outDir, "index.html"), data.indexHtml ?? defaultIndexHtml);
|
|
3336
3337
|
for await (let [index, template] of templates.entries()) {
|
|
3337
3338
|
try {
|
|
3338
3339
|
template = await prettier.format(template, {
|
|
@@ -3345,6 +3346,6 @@ for await (let [index, template] of templates.entries()) {
|
|
|
3345
3346
|
});
|
|
3346
3347
|
} catch (error2) {
|
|
3347
3348
|
}
|
|
3348
|
-
await writeFile(path.join(config.
|
|
3349
|
+
await writeFile(path.join(config.outDir, `${index}.html`), template);
|
|
3349
3350
|
}
|
|
3350
3351
|
task.success();
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
interface ExportHTML {
|
|
2
|
-
index: string;
|
|
3
|
-
outDir: string;
|
|
4
|
-
}
|
|
5
1
|
export interface Config {
|
|
6
2
|
url: string;
|
|
7
3
|
pages: string[];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
meta: string;
|
|
11
|
-
export: ExportHTML;
|
|
4
|
+
debug?: boolean;
|
|
5
|
+
outDir: string;
|
|
12
6
|
}
|
|
13
|
-
export declare const getUserConfig: () => Promise<Config>;
|
|
14
|
-
export {};
|
|
7
|
+
export declare const getUserConfig: (configName: string) => Promise<Config>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jinrai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
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": {
|
package/src/bin.ts
CHANGED
|
@@ -12,20 +12,21 @@ import { defaultIndexHtml } from "./config/defaultIndexHtml"
|
|
|
12
12
|
|
|
13
13
|
const task = new Task()
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const configName = process.argv[2] ? process.argv[2] : "jinrai.config"
|
|
16
|
+
task.do("Init: " + configName)
|
|
17
|
+
const config: Config = await getUserConfig(configName)
|
|
17
18
|
task.success()
|
|
18
19
|
|
|
19
|
-
const data = await getRawPageData(config.url, config.pages, config.
|
|
20
|
+
const data = await getRawPageData(config.url, config.pages, config.debug)
|
|
20
21
|
|
|
21
22
|
task.do("Format")
|
|
22
23
|
const { routes, templates } = getRoutesAndTemplates(data.pages)
|
|
23
24
|
|
|
24
|
-
task.next(`Export: ${config.
|
|
25
|
-
await mkdir(config.
|
|
25
|
+
task.next(`Export: ${config.outDir} (${templates.length})`)
|
|
26
|
+
await mkdir(config.outDir, { recursive: true })
|
|
26
27
|
|
|
27
|
-
await writeFile(path.join(config.
|
|
28
|
-
await writeFile(path.join(config.
|
|
28
|
+
await writeFile(path.join(config.outDir, "config.json"), JSON.stringify(routes, null, 2))
|
|
29
|
+
await writeFile(path.join(config.outDir, "index.html"), data.indexHtml ?? defaultIndexHtml)
|
|
29
30
|
|
|
30
31
|
for await (let [index, template] of templates.entries()) {
|
|
31
32
|
try {
|
|
@@ -39,7 +40,7 @@ for await (let [index, template] of templates.entries()) {
|
|
|
39
40
|
})
|
|
40
41
|
} catch (error) {}
|
|
41
42
|
|
|
42
|
-
await writeFile(path.join(config.
|
|
43
|
+
await writeFile(path.join(config.outDir, `${index}.html`), template)
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
task.success()
|
package/src/config/userConfig.ts
CHANGED
|
@@ -2,31 +2,19 @@ import { createJiti } from "jiti"
|
|
|
2
2
|
import { pathToFileURL } from "url"
|
|
3
3
|
import { resolve } from "path"
|
|
4
4
|
|
|
5
|
-
interface ExportHTML {
|
|
6
|
-
// root: string
|
|
7
|
-
// assets: {
|
|
8
|
-
// root: string
|
|
9
|
-
// prefix: string
|
|
10
|
-
// }
|
|
11
|
-
index: string
|
|
12
|
-
outDir: string
|
|
13
|
-
}
|
|
14
|
-
|
|
15
5
|
export interface Config {
|
|
16
6
|
url: string
|
|
17
7
|
pages: string[]
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
meta: string
|
|
21
|
-
export: ExportHTML
|
|
8
|
+
debug?: boolean
|
|
9
|
+
outDir: string
|
|
22
10
|
}
|
|
23
11
|
|
|
24
|
-
export const getUserConfig = async (): Promise<Config> => {
|
|
12
|
+
export const getUserConfig = async (configName: string): Promise<Config> => {
|
|
25
13
|
const jiti = createJiti(import.meta.url, {
|
|
26
14
|
debug: false,
|
|
27
15
|
})
|
|
28
16
|
|
|
29
|
-
const configPath = pathToFileURL(resolve(process.cwd(),
|
|
17
|
+
const configPath = pathToFileURL(resolve(process.cwd(), configName)).href
|
|
30
18
|
|
|
31
19
|
const configModule = (await jiti.import(configPath)) as { default: Config }
|
|
32
20
|
|
package/src/templates.ts
CHANGED
|
@@ -51,12 +51,11 @@ export const getRawPageData = async (
|
|
|
51
51
|
|
|
52
52
|
await page.waitForTimeout(1000)
|
|
53
53
|
|
|
54
|
-
const
|
|
55
|
-
return (window as any).
|
|
54
|
+
const input = await page.evaluate(() => {
|
|
55
|
+
return (window as any).__page_requests
|
|
56
56
|
})
|
|
57
57
|
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
if (debug) console.log({ input })
|
|
60
59
|
const root = await page.locator("#root").innerHTML()
|
|
61
60
|
|
|
62
61
|
if (debug) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineConfig } from "../src/config/define"
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
url: "https://fld.ru",
|
|
5
|
+
pages: [
|
|
6
|
+
"/",
|
|
7
|
+
"/products",
|
|
8
|
+
"/products/{klapany}",
|
|
9
|
+
"/product/{krany_sharovye_serii_105_prohodnoj_2h_hodovoj}",
|
|
10
|
+
"/{CMC-8M-4N}",
|
|
11
|
+
],
|
|
12
|
+
outDir: "fld",
|
|
13
|
+
})
|
package/test/.ssr.config.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "../src/config/define";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
url: "https://fld.ru",
|
|
5
|
-
dev: true,
|
|
6
|
-
pages: [
|
|
7
|
-
"/",
|
|
8
|
-
"/products",
|
|
9
|
-
"/products/{klapany}",
|
|
10
|
-
"/product/{krany_sharovye_serii_105_prohodnoj_2h_hodovoj}",
|
|
11
|
-
"/{CMC-8M-4N}",
|
|
12
|
-
],
|
|
13
|
-
// dev: true,
|
|
14
|
-
api: "http://nginx",
|
|
15
|
-
meta: "http://nginx/Api/Meta/GetTags",
|
|
16
|
-
export: {
|
|
17
|
-
outDir: "export",
|
|
18
|
-
index: "index.html",
|
|
19
|
-
},
|
|
20
|
-
});
|