-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
37 lines (28 loc) · 908 Bytes
/
Copy pathindex.ts
File metadata and controls
37 lines (28 loc) · 908 Bytes
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
import csvv from "csvv";
import { sync } from "fast-glob";
import { existsSync, mkdirSync, writeFileSync, readFileSync } from "fs";
import template from "./template";
const { stringify } = JSON;
if (!existsSync("dist")) {
mkdirSync("dist");
}
let list: string[] = [];
const semuaData = sync("data/*.txt");
type NamaKota = {
kota: string;
file: string;
};
let namaKota: NamaKota[] = [];
for (const x of semuaData) {
let isi = readFileSync(x).toString();
isi = csvv(isi, "\t");
let judul = x.replace("data", "dist").replace(".txt", ".json");
list.push(judul.slice(5).slice(0, -5));
writeFileSync(judul, stringify(isi, null, 2));
namaKota.push({
kota: x.replace("data/", "").replace(".txt", ""),
file: x.replace("data/", "").replace(".txt", ".json"),
});
}
writeFileSync("dist/index.html", template(list));
writeFileSync("dist/namaKota.json", stringify(namaKota, null, 2));