-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
46 lines (43 loc) · 1.27 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env node
import fs from "fs";
import path from "path";
import { parse } from "./utils/Parser";
import { render } from "./utils/Renderer";
const express = require("express");
const yargs = require("yargs/yargs");
const { hideBin } = require("yargs/helpers");
const argv = yargs(hideBin(process.argv)).argv;
const { port, p } = argv;
const config = {
port: p || port || 3000,
};
const fileName = String(argv._[0]);
if (fileName.length > 0) {
if (fileName.includes(".txt")) {
const app = express();
app.get("/", (req: any, res: any) => {
res.send(
render(
JSON.stringify(
parse(
fs
.readFileSync(path.join(fileName), "utf-8")
.split("\n")
),
null,
4
)
)
);
});
app.listen(config.port, () => {
console.info(
`🌲 SVG Tree available on http://127.0.0.1:${config.port}`
);
});
} else {
console.error("[ERROR] Only *.txt files are supported");
}
} else {
console.error("[ERROR] No file specified");
}