node-riner 1.0.1
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 +63 -0
- package/package.json +22 -0
package/index.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import fs, { readFileSync } from 'fs'
|
|
2
|
+
import { XMLParser } from 'fast-xml-parser'
|
|
3
|
+
import exp, { application } from 'express'
|
|
4
|
+
export default class Ride {
|
|
5
|
+
F: string
|
|
6
|
+
parsedJson: object
|
|
7
|
+
pages: object
|
|
8
|
+
name: string
|
|
9
|
+
constructor(name: string) {
|
|
10
|
+
this.F = ""
|
|
11
|
+
this.parsedJson = {}
|
|
12
|
+
this.pages = {}
|
|
13
|
+
this.name = name
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
Ride(name: String) {
|
|
17
|
+
this.F = readFileSync(__dirname + name, { encoding: "utf-8"})
|
|
18
|
+
console.log(this.F);
|
|
19
|
+
let options = {
|
|
20
|
+
ignoreAttributes: false,
|
|
21
|
+
}
|
|
22
|
+
const parser = new XMLParser(options);
|
|
23
|
+
try {
|
|
24
|
+
this.parsedJson = parser.parse(this.F)
|
|
25
|
+
console.log(this.parsedJson["Root"]["Page"]);
|
|
26
|
+
if (Array.isArray(this.parsedJson["Root"]["Page"])) {
|
|
27
|
+
this.parsedJson["Root"]["Page"].forEach(page => {
|
|
28
|
+
let route = page['@_route']
|
|
29
|
+
let generatedhtml = Object.keys(page['Content']).map(tags => {
|
|
30
|
+
if( tags == "#text") {
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
return `<${tags}>${page['Content'][tags]}</${tags}>`
|
|
34
|
+
}).join('')
|
|
35
|
+
this.pages[route] = `<title>${this.name}</title>` + generatedhtml
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
let route = this.parsedJson["Root"]["Page"]['@_route']
|
|
39
|
+
let generatedhtml = Object.keys(this.parsedJson["Root"]["Page"]['Content']).map(tags => {
|
|
40
|
+
return `<${tags}>${this.parsedJson["Root"]["Page"]['Content'][tags]}</${tags}>`
|
|
41
|
+
}).join('');
|
|
42
|
+
this.pages[route] = generatedhtml
|
|
43
|
+
}
|
|
44
|
+
} catch (e) {
|
|
45
|
+
console.error("Whoops, an error occurred during analysis : " + e)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
serve(port: number) {
|
|
49
|
+
let app = exp();
|
|
50
|
+
(Object.keys(this.pages)).forEach(route => {
|
|
51
|
+
app.get(route, (req, res) => {
|
|
52
|
+
console.log("get-" + route)
|
|
53
|
+
res.send(this.pages[route])
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
app.listen(port, () => {
|
|
57
|
+
console.log(`Server is running on http://localhost:${port}`);
|
|
58
|
+
})
|
|
59
|
+
return app
|
|
60
|
+
}
|
|
61
|
+
config(options: object) {
|
|
62
|
+
}
|
|
63
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "node-riner",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"main": "index.ts",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
|
+
"dev": "tsx script.ts"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"description": "",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"express": "^5.2.1",
|
|
15
|
+
"fast-xml-parser": "^5.3.3",
|
|
16
|
+
"ts-node": "^10.9.2",
|
|
17
|
+
"typescript": "^5.9.3"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@types/express": "^5.0.6"
|
|
21
|
+
}
|
|
22
|
+
}
|