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.
- package/.vscode/launch.json +21 -0
- package/config.ts +1 -0
- package/front.config.json +24 -0
- package/index.ts +6 -1
- package/lib/bin/bin.js +12 -0
- package/lib/config/config.d.ts +1 -0
- package/lib/config/config.js +1 -0
- package/lib/config/src/bin/config/userConfig.d.ts +14 -0
- package/lib/index.d.ts +6 -1
- package/lib/index.js +6 -7
- package/lib/src/front/server-state/DataProxy.d.ts +8 -0
- package/lib/src/front/server-state/DataProxy.js +104 -0
- package/lib/src/front/server-state/SSR.d.ts +4 -0
- package/lib/src/front/server-state/SSR.js +6 -0
- package/lib/src/front/server-state/real.d.ts +1 -0
- package/lib/src/front/server-state/real.js +36 -0
- package/lib/src/front/server-state/serverStates.d.ts +5 -0
- package/lib/src/front/server-state/serverStates.js +29 -0
- package/lib/src/front/server-state/useServerState.d.ts +10 -0
- package/lib/src/front/server-state/useServerState.js +28 -0
- package/lib/src/front/url/JinraiContext.d.ts +6 -0
- package/lib/src/front/url/JinraiContext.js +8 -0
- package/lib/src/front/url/adapter/def.d.ts +2 -0
- package/lib/src/front/url/adapter/def.js +9 -0
- package/lib/src/front/url/adapter/rrd6.d.ts +2 -0
- package/lib/src/front/url/adapter/rrd6.js +12 -0
- package/lib/src/front/url/adapter/rrd7.d.ts +2 -0
- package/lib/src/front/url/adapter/rrd7.js +11 -0
- package/lib/src/front/url/params/useParamsIndex.d.ts +1 -0
- package/lib/src/front/url/params/useParamsIndex.js +15 -0
- package/lib/src/front/url/search/useSearch.d.ts +1 -0
- package/lib/src/front/url/search/useSearch.js +15 -0
- package/lib/src/front/url/search/useSearchValue.d.ts +16 -0
- package/lib/src/front/url/search/useSearchValue.js +49 -0
- package/lib/src/front/wrapper/Custom.d.ts +8 -0
- package/lib/src/front/wrapper/Custom.js +9 -0
- package/lib/vite/plugin.js +1 -0
- package/package.json +42 -7
- package/readme.md +34 -8
- package/rollup.front.config.mjs +57 -0
- package/src/bin/bin.ts +10 -0
- package/src/bin/build/build.ts +69 -0
- package/src/{config → bin/config}/defaultIndexHtml.ts +2 -2
- package/src/{config → bin/config}/userConfig.ts +11 -3
- package/src/bin/content/normalizeContent.ts +7 -0
- package/src/bin/playwright/pageCollector.ts +11 -0
- package/src/{templates.ts → bin/playwright/templates.ts} +28 -21
- package/src/bin/routes/Parser.ts +148 -0
- package/src/{routes → bin/routes}/getRoutes.ts +9 -6
- package/src/bin/routes/replaceDevScripts.ts +16 -0
- package/src/bin/server/vitePreview.ts +13 -0
- package/src/front/server-state/DataProxy.ts +120 -0
- package/src/front/server-state/SSR.ts +4 -0
- package/src/front/server-state/real.ts +41 -0
- package/src/front/server-state/serverStates.ts +36 -0
- package/src/front/server-state/useServerState.ts +44 -0
- package/src/front/url/JinraiContext.tsx +10 -0
- package/src/front/url/adapter/def.tsx +10 -0
- package/src/front/url/adapter/rrd6.tsx +16 -0
- package/src/front/url/adapter/rrd7.tsx +15 -0
- package/src/front/url/params/useParamsIndex.ts +16 -0
- package/src/front/url/search/useSearch.ts +15 -0
- package/src/front/url/search/useSearchValue.ts +72 -0
- package/src/front/wrapper/Custom.tsx +14 -0
- package/tests/content/1.html +12 -0
- package/tests/content/1_result.json +54 -0
- package/tests/content/2.html +16 -0
- package/tests/content/2_result.json +28 -0
- package/tests/content/3.html +21 -0
- package/tests/content/3_result.json +39 -0
- package/tests/content/4.html +4 -0
- package/tests/content/4_result.json +9 -0
- package/tests/content/custom.html +5 -0
- package/tests/content/custom.json +5 -0
- package/tests/content/index.html +543 -0
- package/tests/content/index.json +49 -0
- package/tests/content/index_with_templates.json +31 -0
- package/tests/content/templates.json +13 -0
- package/tests/custom.test.ts +16 -0
- package/tests/parse.test.ts +52 -0
- package/tsconfig.json +2 -2
- package/vite/plugin.ts +83 -0
- package/vitest.config.ts +14 -0
- package/lib/bin.js +0 -3351
- package/lib/generate.js +0 -26
- package/lib/src/config/userConfig.d.ts +0 -7
- package/src/bin.ts +0 -46
- package/src/routes/parser.ts +0 -58
- package/src/routes/splitByTag.ts +0 -38
- package/test/fld.config.ts +0 -13
- package/test/jinrai.config.ts +0 -8
- /package/lib/{src → config/src/bin}/config/define.d.ts +0 -0
- /package/src/{config → bin/config}/define.ts +0 -0
- /package/src/{types → bin/types}/shims.d.ts +0 -0
- /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
|
-
}
|
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()
|
package/src/routes/parser.ts
DELETED
|
@@ -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
|
-
}
|
package/src/routes/splitByTag.ts
DELETED
|
@@ -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
|
-
|
package/test/fld.config.ts
DELETED
|
@@ -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
|
-
})
|
package/test/jinrai.config.ts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|