jinrai 1.0.0 → 1.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "semi": false,
3
+ "trailingComma": "all",
4
+ "printWidth": 120,
5
+ "tabWidth": 4,
6
+ "arrowParens": "avoid"
7
+ }
package/lib/bin.js CHANGED
@@ -16,7 +16,7 @@ var getUserConfig = async () => {
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(), "jinrai.config")).href;
20
20
  const configModule = await jiti.import(configPath);
21
21
  return configModule.default;
22
22
  };
@@ -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 date = [];
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);
3305
- task.next(`Export: ${config.export.outDir} (${templates.length})`);
3306
- await mkdir(config.export.outDir, { recursive: true });
3307
- await writeFile(path.join(config.export.outDir, "config.json"), JSON.stringify(routes, null, 2));
3331
+ var { routes, templates } = getRoutesAndTemplates(data.pages);
3332
+ task.next(`Export: ${config.outDir} (${templates.length})`);
3333
+ await mkdir(config.outDir, { recursive: true });
3334
+ await writeFile(path.join(config.outDir, "config.json"), JSON.stringify(routes, null, 2));
3335
+ await writeFile(path.join(config.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, {
@@ -3317,6 +3345,6 @@ for await (let [index, template] of templates.entries()) {
3317
3345
  });
3318
3346
  } catch (error2) {
3319
3347
  }
3320
- await writeFile(path.join(config.export.outDir, `${index}.html`), template);
3348
+ await writeFile(path.join(config.outDir, `${index}.html`), template);
3321
3349
  }
3322
3350
  task.success();
@@ -1,14 +1,9 @@
1
- interface ExportHTML {
2
- index: string;
3
- outDir: string;
4
- }
5
1
  export interface Config {
6
2
  url: string;
7
3
  pages: string[];
8
4
  api: string;
9
5
  dev?: boolean;
10
6
  meta: string;
11
- export: ExportHTML;
7
+ outDir: string;
12
8
  }
13
9
  export declare const getUserConfig: () => Promise<Config>;
14
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jinrai",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
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
- "rsr": "lib/bin.js"
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
- task.next(`Export: ${config.export.outDir} (${templates.length})`)
24
- await mkdir(config.export.outDir, { recursive: true })
24
+ task.next(`Export: ${config.outDir} (${templates.length})`)
25
+ await mkdir(config.outDir, { recursive: true })
25
26
 
26
- await writeFile(path.join(config.export.outDir, "config.json"), JSON.stringify(routes, null, 2))
27
+ await writeFile(path.join(config.outDir, "config.json"), JSON.stringify(routes, null, 2))
28
+ await writeFile(path.join(config.outDir, "index.html"), data.indexHtml ?? defaultIndexHtml)
27
29
 
28
30
  for await (let [index, template] of templates.entries()) {
29
31
  try {
@@ -37,7 +39,7 @@ for await (let [index, template] of templates.entries()) {
37
39
  })
38
40
  } catch (error) {}
39
41
 
40
- await writeFile(path.join(config.export.outDir, `${index}.html`), template)
42
+ await writeFile(path.join(config.outDir, `${index}.html`), template)
41
43
  }
42
44
 
43
45
  task.success()
@@ -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
+ `
@@ -2,23 +2,13 @@ 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
8
  api: string
19
9
  dev?: boolean
20
10
  meta: string
21
- export: ExportHTML
11
+ outDir: string
22
12
  }
23
13
 
24
14
  export const getUserConfig = async (): Promise<Config> => {
@@ -26,7 +16,7 @@ export const getUserConfig = async (): Promise<Config> => {
26
16
  debug: false,
27
17
  })
28
18
 
29
- const configPath = pathToFileURL(resolve(process.cwd(), ".ssr.config")).href
19
+ const configPath = pathToFileURL(resolve(process.cwd(), "jinrai.config")).href
30
20
 
31
21
  const configModule = (await jiti.import(configPath)) as { default: Config }
32
22
 
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 (url: string, pages: string[], debug: boolean = false): Promise<PageData[]> => {
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
  }