node-riner 1.1.2 → 1.1.4
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/README.md +19 -1
- package/index.ts +15 -13
- package/package.json +1 -1
- package/runs.js +1 -1
package/README.md
CHANGED
|
@@ -7,4 +7,22 @@ XMLファイルをベースに動的なHTMLページを生成し、Expressサー
|
|
|
7
7
|
プロジェクトのルートディレクトリで以下のコマンドを実行してください。
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
npm i node-riner@latest
|
|
10
|
+
npm i node-riner@latest
|
|
11
|
+
```
|
|
12
|
+
## Example
|
|
13
|
+
index.rd
|
|
14
|
+
``` RideFrameworks
|
|
15
|
+
<Root>
|
|
16
|
+
<Page route="/">
|
|
17
|
+
<h1>hello world</h1>
|
|
18
|
+
</Page>
|
|
19
|
+
</Root>
|
|
20
|
+
```
|
|
21
|
+
main.ts
|
|
22
|
+
```
|
|
23
|
+
import Riner from 'node-riner'
|
|
24
|
+
|
|
25
|
+
let App = new Riner("my app")
|
|
26
|
+
App.Ride("index.rd")
|
|
27
|
+
App.serve(3000)
|
|
28
|
+
```
|
package/index.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import fs, { readFileSync, writeFileSync } from 'fs'
|
|
2
2
|
import { XMLParser } from 'fast-xml-parser'
|
|
3
|
-
import exp
|
|
3
|
+
import exp from 'express'
|
|
4
4
|
import path from 'path'
|
|
5
|
-
import
|
|
5
|
+
import { execSync } from 'node:child_process'
|
|
6
6
|
export default class Ride {
|
|
7
7
|
F: string
|
|
8
8
|
parsedJson: object
|
|
9
9
|
pages: object
|
|
10
10
|
name: string
|
|
11
|
+
defaultinfo: string
|
|
11
12
|
constructor(name: string) {
|
|
12
13
|
this.F = ""
|
|
13
14
|
this.parsedJson = {}
|
|
14
15
|
this.pages = {}
|
|
15
16
|
this.name = name
|
|
17
|
+
this.defaultinfo = ""
|
|
16
18
|
}
|
|
17
19
|
|
|
18
20
|
Ride(name: string) {
|
|
@@ -24,25 +26,25 @@ export default class Ride {
|
|
|
24
26
|
const parser = new XMLParser(options);
|
|
25
27
|
try {
|
|
26
28
|
this.parsedJson = parser.parse(this.F)
|
|
27
|
-
|
|
29
|
+
// debug
|
|
28
30
|
if (Array.isArray(this.parsedJson["Root"]["Page"])) {
|
|
29
31
|
this.parsedJson["Root"]["Page"].forEach((page: { [x: string]: { [x: string]: any } }) => {
|
|
30
32
|
let route = page['@_route']
|
|
31
33
|
let generatedhtml = Object.keys(page['Content']).map(tags => {
|
|
32
34
|
let match = page['Content'][tags].match(/{.*}/g)
|
|
33
|
-
|
|
35
|
+
// debug
|
|
34
36
|
|
|
35
37
|
if(match) {
|
|
36
|
-
|
|
38
|
+
// debug
|
|
37
39
|
let matched : string = match[0]
|
|
38
40
|
matched = matched.replace("{", "")
|
|
39
41
|
matched = matched.replace("}", "")
|
|
40
42
|
writeFileSync("./runs.js", matched)
|
|
41
43
|
let out = execSync("node runs.js").toString()
|
|
42
|
-
|
|
44
|
+
// debug
|
|
43
45
|
page['Content'][tags] = page['Content'][tags].replace(/{.*}/, out)
|
|
44
46
|
}
|
|
45
|
-
|
|
47
|
+
// debug
|
|
46
48
|
return `<${tags}>${page['Content'][tags]}</${tags}>`
|
|
47
49
|
}).join('')
|
|
48
50
|
this.pages[route] = `<title>${this.name}</title>` + generatedhtml
|
|
@@ -52,19 +54,19 @@ export default class Ride {
|
|
|
52
54
|
let route = this.parsedJson["Root"]["Page"]['@_route']
|
|
53
55
|
let generatedhtml = Object.keys(page['Content']).map(tags => {
|
|
54
56
|
let match = page['Content'][tags].match(/{.*}/g)
|
|
55
|
-
|
|
57
|
+
// debug
|
|
56
58
|
|
|
57
59
|
if(match) {
|
|
58
|
-
|
|
60
|
+
// debug
|
|
59
61
|
let matched : string = match[0]
|
|
60
62
|
matched = matched.replace("{", "")
|
|
61
63
|
matched = matched.replace("}", "")
|
|
62
64
|
writeFileSync("./runs.js", matched)
|
|
63
65
|
let out = execSync("node runs.js").toString()
|
|
64
|
-
|
|
66
|
+
// debug
|
|
65
67
|
page['Content'][tags] = page['Content'][tags].replace(/{.*}/, out)
|
|
66
68
|
}
|
|
67
|
-
|
|
69
|
+
// debug
|
|
68
70
|
return `<${tags}>${page['Content'][tags]}</${tags}>`
|
|
69
71
|
}).join('')
|
|
70
72
|
this.pages[route] = generatedhtml
|
|
@@ -74,11 +76,11 @@ export default class Ride {
|
|
|
74
76
|
}
|
|
75
77
|
}
|
|
76
78
|
serve(port: number) {
|
|
77
|
-
|
|
79
|
+
// debug
|
|
78
80
|
let app = exp();
|
|
79
81
|
(Object.keys(this.pages)).forEach(route => {
|
|
80
82
|
app.get(route, (req, res) => {
|
|
81
|
-
|
|
83
|
+
// debug
|
|
82
84
|
res.send(this.pages[route])
|
|
83
85
|
})
|
|
84
86
|
})
|
package/package.json
CHANGED
package/runs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
// debug
|