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 CHANGED
@@ -1,15 +1,12 @@
1
1
  <!doctype html>
2
2
  <html lang="ru">
3
-
4
- <head>
5
- <meta charset="UTF-8" />
6
- <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
7
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
8
- @META
9
- @DATA
10
- @ASSETS
11
- </head>
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(), ".ssr.config")).href;
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 requests = await page.evaluate(() => {
3282
- return window.__ssr_preload;
3281
+ const input2 = await page.evaluate(() => {
3282
+ return window.__page_requests;
3283
3283
  });
3284
- const input2 = requests ? JSON.parse(requests) : [];
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
- task.do("Load config");
3327
- var config = await getUserConfig();
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.dev);
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.export.outDir} (${templates.length})`);
3333
- await mkdir(config.export.outDir, { recursive: true });
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);
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.export.outDir, `${index}.html`), template);
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
- api: string;
9
- dev?: boolean;
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.1",
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
- task.do("Load config")
16
- const config: Config = await getUserConfig()
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.dev)
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.export.outDir} (${templates.length})`)
25
- await mkdir(config.export.outDir, { recursive: true })
25
+ task.next(`Export: ${config.outDir} (${templates.length})`)
26
+ await mkdir(config.outDir, { recursive: true })
26
27
 
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)
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.export.outDir, `${index}.html`), template)
43
+ await writeFile(path.join(config.outDir, `${index}.html`), template)
43
44
  }
44
45
 
45
46
  task.success()
@@ -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
- api: string
19
- dev?: boolean
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(), ".ssr.config")).href
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 requests = await page.evaluate(() => {
55
- return (window as any).__ssr_preload
54
+ const input = await page.evaluate(() => {
55
+ return (window as any).__page_requests
56
56
  })
57
57
 
58
- const input = requests ? (JSON.parse(requests) as input[]) : []
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
+ })
@@ -0,0 +1,8 @@
1
+ import { defineConfig } from "../src/config/define"
2
+
3
+ export default defineConfig({
4
+ url: "http://localhost:3580",
5
+ pages: ["/", "/{courses}"],
6
+ outDir: "export",
7
+ // debug: true,
8
+ })
@@ -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
- });