node-riner 1.0.4 → 1.1.0
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.ts +21 -8
- package/package.json +1 -1
- package/runs.js +1 -0
package/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import fs, { readFileSync } from 'fs'
|
|
1
|
+
import fs, { readFileSync, writeFileSync } from 'fs'
|
|
2
2
|
import { XMLParser } from 'fast-xml-parser'
|
|
3
3
|
import exp, { application } from 'express'
|
|
4
4
|
import path from 'path'
|
|
5
|
+
import child_process, { execSync } from 'node:child_process'
|
|
5
6
|
export default class Ride {
|
|
6
7
|
F: string
|
|
7
8
|
parsedJson: object
|
|
@@ -14,9 +15,9 @@ export default class Ride {
|
|
|
14
15
|
this.name = name
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
Ride(name:
|
|
18
|
+
Ride(name: string) {
|
|
18
19
|
this.F = readFileSync(path.join(__dirname, "../../", name), { encoding: "utf-8"})
|
|
19
|
-
|
|
20
|
+
// this.F = readFileSync(__dirname + "/" + name, { encoding: "utf-8"})
|
|
20
21
|
let options = {
|
|
21
22
|
ignoreAttributes: false,
|
|
22
23
|
}
|
|
@@ -25,13 +26,24 @@ export default class Ride {
|
|
|
25
26
|
this.parsedJson = parser.parse(this.F)
|
|
26
27
|
console.log(this.parsedJson["Root"]["Page"]);
|
|
27
28
|
if (Array.isArray(this.parsedJson["Root"]["Page"])) {
|
|
28
|
-
this.parsedJson["Root"]["Page"].forEach(page => {
|
|
29
|
+
this.parsedJson["Root"]["Page"].forEach((page: { [x: string]: { [x: string]: any } }) => {
|
|
29
30
|
let route = page['@_route']
|
|
30
31
|
let generatedhtml = Object.keys(page['Content']).map(tags => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
let match = page['Content'][tags].match(/{.*}/g)
|
|
33
|
+
console.log(match)
|
|
34
|
+
|
|
35
|
+
if(match) {
|
|
36
|
+
console.log("matched")
|
|
37
|
+
let matched : string = match[0]
|
|
38
|
+
matched = matched.replace("{", "")
|
|
39
|
+
matched = matched.replace("}", "")
|
|
40
|
+
writeFileSync("./runs.js", matched)
|
|
41
|
+
let out = execSync("node runs.js").toString()
|
|
42
|
+
console.log(matched)
|
|
43
|
+
page['Content'][tags] = page['Content'][tags].replace(/{.*}/, out)
|
|
44
|
+
}
|
|
45
|
+
console.log("e:" + page['Content'][tags])
|
|
46
|
+
return `<${tags}>${page['Content'][tags]}</${tags}>`
|
|
35
47
|
}).join('')
|
|
36
48
|
this.pages[route] = `<title>${this.name}</title>` + generatedhtml
|
|
37
49
|
});
|
|
@@ -47,6 +59,7 @@ export default class Ride {
|
|
|
47
59
|
}
|
|
48
60
|
}
|
|
49
61
|
serve(port: number) {
|
|
62
|
+
console.log(this.pages)
|
|
50
63
|
let app = exp();
|
|
51
64
|
(Object.keys(this.pages)).forEach(route => {
|
|
52
65
|
app.get(route, (req, res) => {
|
package/package.json
CHANGED
package/runs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
console.log("world")
|