jinrai 1.0.3 → 1.0.6

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.
Files changed (95) hide show
  1. package/.vscode/launch.json +21 -0
  2. package/config.ts +1 -0
  3. package/front.config.json +24 -0
  4. package/index.ts +6 -1
  5. package/lib/bin/bin.js +12 -0
  6. package/lib/config/config.d.ts +1 -0
  7. package/lib/config/config.js +1 -0
  8. package/lib/config/src/bin/config/userConfig.d.ts +14 -0
  9. package/lib/index.d.ts +6 -1
  10. package/lib/index.js +6 -7
  11. package/lib/src/front/server-state/DataProxy.d.ts +8 -0
  12. package/lib/src/front/server-state/DataProxy.js +104 -0
  13. package/lib/src/front/server-state/SSR.d.ts +4 -0
  14. package/lib/src/front/server-state/SSR.js +6 -0
  15. package/lib/src/front/server-state/real.d.ts +1 -0
  16. package/lib/src/front/server-state/real.js +36 -0
  17. package/lib/src/front/server-state/serverStates.d.ts +5 -0
  18. package/lib/src/front/server-state/serverStates.js +29 -0
  19. package/lib/src/front/server-state/useServerState.d.ts +10 -0
  20. package/lib/src/front/server-state/useServerState.js +28 -0
  21. package/lib/src/front/url/JinraiContext.d.ts +6 -0
  22. package/lib/src/front/url/JinraiContext.js +8 -0
  23. package/lib/src/front/url/adapter/def.d.ts +2 -0
  24. package/lib/src/front/url/adapter/def.js +9 -0
  25. package/lib/src/front/url/adapter/rrd6.d.ts +2 -0
  26. package/lib/src/front/url/adapter/rrd6.js +12 -0
  27. package/lib/src/front/url/adapter/rrd7.d.ts +2 -0
  28. package/lib/src/front/url/adapter/rrd7.js +11 -0
  29. package/lib/src/front/url/params/useParamsIndex.d.ts +1 -0
  30. package/lib/src/front/url/params/useParamsIndex.js +15 -0
  31. package/lib/src/front/url/search/useSearch.d.ts +1 -0
  32. package/lib/src/front/url/search/useSearch.js +15 -0
  33. package/lib/src/front/url/search/useSearchValue.d.ts +16 -0
  34. package/lib/src/front/url/search/useSearchValue.js +49 -0
  35. package/lib/src/front/wrapper/Custom.d.ts +8 -0
  36. package/lib/src/front/wrapper/Custom.js +9 -0
  37. package/lib/vite/plugin.js +1 -0
  38. package/package.json +42 -7
  39. package/readme.md +34 -8
  40. package/rollup.front.config.mjs +57 -0
  41. package/src/bin/bin.ts +10 -0
  42. package/src/bin/build/build.ts +69 -0
  43. package/src/{config → bin/config}/defaultIndexHtml.ts +2 -2
  44. package/src/{config → bin/config}/userConfig.ts +11 -3
  45. package/src/bin/content/normalizeContent.ts +7 -0
  46. package/src/bin/playwright/pageCollector.ts +11 -0
  47. package/src/{templates.ts → bin/playwright/templates.ts} +28 -21
  48. package/src/bin/routes/Parser.ts +148 -0
  49. package/src/{routes → bin/routes}/getRoutes.ts +9 -6
  50. package/src/bin/routes/replaceDevScripts.ts +16 -0
  51. package/src/bin/server/vitePreview.ts +13 -0
  52. package/src/front/server-state/DataProxy.ts +120 -0
  53. package/src/front/server-state/SSR.ts +4 -0
  54. package/src/front/server-state/real.ts +41 -0
  55. package/src/front/server-state/serverStates.ts +36 -0
  56. package/src/front/server-state/useServerState.ts +44 -0
  57. package/src/front/url/JinraiContext.tsx +10 -0
  58. package/src/front/url/adapter/def.tsx +10 -0
  59. package/src/front/url/adapter/rrd6.tsx +16 -0
  60. package/src/front/url/adapter/rrd7.tsx +15 -0
  61. package/src/front/url/params/useParamsIndex.ts +16 -0
  62. package/src/front/url/search/useSearch.ts +15 -0
  63. package/src/front/url/search/useSearchValue.ts +72 -0
  64. package/src/front/wrapper/Custom.tsx +14 -0
  65. package/tests/content/1.html +12 -0
  66. package/tests/content/1_result.json +54 -0
  67. package/tests/content/2.html +16 -0
  68. package/tests/content/2_result.json +28 -0
  69. package/tests/content/3.html +21 -0
  70. package/tests/content/3_result.json +39 -0
  71. package/tests/content/4.html +4 -0
  72. package/tests/content/4_result.json +9 -0
  73. package/tests/content/custom.html +5 -0
  74. package/tests/content/custom.json +5 -0
  75. package/tests/content/index.html +543 -0
  76. package/tests/content/index.json +49 -0
  77. package/tests/content/index_with_templates.json +31 -0
  78. package/tests/content/templates.json +13 -0
  79. package/tests/custom.test.ts +16 -0
  80. package/tests/parse.test.ts +52 -0
  81. package/tsconfig.json +2 -2
  82. package/vite/plugin.ts +83 -0
  83. package/vitest.config.ts +14 -0
  84. package/lib/bin.js +0 -3351
  85. package/lib/generate.js +0 -26
  86. package/lib/src/config/userConfig.d.ts +0 -7
  87. package/src/bin.ts +0 -46
  88. package/src/routes/parser.ts +0 -58
  89. package/src/routes/splitByTag.ts +0 -38
  90. package/test/fld.config.ts +0 -13
  91. package/test/jinrai.config.ts +0 -8
  92. /package/lib/{src → config/src/bin}/config/define.d.ts +0 -0
  93. /package/src/{config → bin/config}/define.ts +0 -0
  94. /package/src/{types → bin/types}/shims.d.ts +0 -0
  95. /package/src/{ui → bin/ui}/task.tsx +0 -0
package/lib/generate.js DELETED
@@ -1,26 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/config/userConfig.ts
4
- import { createJiti } from "jiti";
5
- import { pathToFileURL } from "url";
6
- import { resolve } from "path";
7
- var getUserConfig = async () => {
8
- const jiti = createJiti(import.meta.url, {
9
- debug: false
10
- });
11
- const configPath = pathToFileURL(resolve(process.cwd(), ".ssr.config")).href;
12
- console.log("#######", { configPath });
13
- const configModule = await jiti.import(configPath);
14
- return configModule.default;
15
- };
16
-
17
- // src/generate.ts
18
- import ReactDOMServer from "react-dom/server";
19
- console.log(">>");
20
- var config = await getUserConfig();
21
- for (const mask of config.pages) {
22
- console.log(" - ", mask);
23
- const url = mask.replaceAll("{", "").replaceAll("}", "");
24
- const html = ReactDOMServer.renderToString(config.renderPage(url));
25
- console.log(html);
26
- }
@@ -1,7 +0,0 @@
1
- export interface Config {
2
- url: string;
3
- pages: string[];
4
- debug?: boolean;
5
- outDir: string;
6
- }
7
- export declare const getUserConfig: (configName: string) => Promise<Config>;
package/src/bin.ts DELETED
@@ -1,46 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { writeFile } from "node:fs/promises"
4
- import { Config, getUserConfig } from "./config/userConfig"
5
- import { getRoutesAndTemplates } from "./routes/getRoutes"
6
- import { getRawPageData } from "./templates"
7
- import path from "node:path"
8
- import { mkdir } from "node:fs/promises"
9
- import prettier from "prettier"
10
- import Task from "./ui/task"
11
- import { defaultIndexHtml } from "./config/defaultIndexHtml"
12
-
13
- const task = new Task()
14
-
15
- const configName = process.argv[2] ? process.argv[2] : "jinrai.config"
16
- task.do("Init: " + configName)
17
- const config: Config = await getUserConfig(configName)
18
- task.success()
19
-
20
- const data = await getRawPageData(config.url, config.pages, config.debug)
21
-
22
- task.do("Format")
23
- const { routes, templates } = getRoutesAndTemplates(data.pages)
24
-
25
- task.next(`Export: ${config.outDir} (${templates.length})`)
26
- await mkdir(config.outDir, { recursive: true })
27
-
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)
30
-
31
- for await (let [index, template] of templates.entries()) {
32
- try {
33
- template = await prettier.format(template, {
34
- parser: "html",
35
- printWidth: 500,
36
- tabWidth: 2,
37
- useTabs: false,
38
- semi: true,
39
- singleQuote: true,
40
- })
41
- } catch (error) {}
42
-
43
- await writeFile(path.join(config.outDir, `${index}.html`), template)
44
- }
45
-
46
- task.success()
@@ -1,58 +0,0 @@
1
- import { splitByTag } from "./splitByTag.ts"
2
-
3
- export interface ParseItem {
4
- type: string
5
- template: ParseItem[] | number
6
- contentKey?: string
7
- }
8
-
9
- const toBinary = (content: string) => {
10
- return btoa(unescape(encodeURIComponent(content)))
11
- }
12
-
13
- export class Parser {
14
- templates: string[] = []
15
- ctemplates: string[] = []
16
- convertor?: (content: string) => string
17
-
18
- constructor(convertor?: (content: string) => string) {
19
- this.convertor = convertor
20
- }
21
-
22
- parse(html: string): ParseItem[] {
23
- const parts = splitByTag("loopwrapper", html)
24
-
25
- return parts.map(content => {
26
- const isArray = content.startsWith("ArrayDataKey=")
27
-
28
- let contentKey = undefined
29
- if (isArray) {
30
- ;[contentKey, content] = this.firstPypeSplit(content)
31
- }
32
-
33
- return {
34
- type: isArray ? "array" : "html",
35
- template: isArray ? this.parse(content) : this.getTemplateId(content),
36
- contentKey,
37
- }
38
- })
39
- }
40
-
41
- getTemplateId(template: string): number {
42
- const index = this.templates.indexOf(template)
43
- if (index != -1) {
44
- return index
45
- }
46
-
47
- this.templates.push(template)
48
- this.ctemplates.push(this.convertor ? this.convertor(template) : toBinary(template))
49
-
50
- return this.templates.length - 1
51
- }
52
-
53
- firstPypeSplit(content: string) {
54
- const index = content.indexOf("|")
55
-
56
- return [content.slice(13, index), content.slice(index + 1)]
57
- }
58
- }
@@ -1,38 +0,0 @@
1
- export const splitByTag = (tag: string, content: string): string[] => {
2
- const htmls = content
3
- .replace(new RegExp(`(<\/?${tag}.*?>)`, "gm"), (_, find) => {
4
- return `<**${tag}**>` + (find.startsWith('</') ? 'CLS' : 'OPN')
5
- })
6
- .split(`<**${tag}**>`)
7
-
8
- if (htmls.length == 1)
9
- return htmls
10
-
11
- let count = 0
12
- const result: string[][] = []
13
-
14
- for (let itm of htmls) {
15
- let step = 0
16
-
17
- if (itm.startsWith('OPN')) step = 1
18
- if (itm.startsWith('CLS')) step = -1
19
-
20
- if (step != 0)
21
- itm = itm.substring(3)
22
-
23
- if (step > 0) {
24
- count+=step
25
- step = 0
26
- }
27
-
28
- if (count<=1)
29
- result.push([itm])
30
- else
31
- result[result.length -1].push(itm)
32
-
33
- count+=step
34
- }
35
-
36
- return result.map(itms => itms.join(`<**${tag}**>`))
37
- };
38
-
@@ -1,13 +0,0 @@
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
- })
@@ -1,8 +0,0 @@
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
- })
File without changes
File without changes
File without changes
File without changes