2023-03-08 01:36:34 +00:00
|
|
|
import { load } from "cheerio";
|
|
|
|
import { readFile, writeFile } from "fs";
|
2023-10-12 01:37:28 +00:00
|
|
|
import process from "child_process";
|
2024-07-08 23:13:48 +00:00
|
|
|
import stores from "./stores.json" with { type: "json" };
|
2017-05-28 22:54:01 +00:00
|
|
|
|
2023-10-12 01:37:28 +00:00
|
|
|
function GetRecentChanges() {
|
|
|
|
const res = process
|
2023-10-12 01:51:08 +00:00
|
|
|
.execSync('git log -15 --pretty=format:"%ct %s"')
|
2023-10-12 01:37:28 +00:00
|
|
|
.toString();
|
|
|
|
return res.split("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function ChangeLog(logs) {
|
|
|
|
let res = "\n";
|
2023-10-12 01:51:08 +00:00
|
|
|
let i = 0;
|
|
|
|
logs.forEach((l) => {
|
|
|
|
if (
|
|
|
|
i > 3 ||
|
|
|
|
l.includes("[skip]") ||
|
2024-02-22 02:53:42 +00:00
|
|
|
l.includes("[ignore]") ||
|
2023-10-12 01:51:08 +00:00
|
|
|
l.includes("caddy") ||
|
|
|
|
l.includes("renovate")
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i++;
|
2023-10-12 01:37:28 +00:00
|
|
|
const s = l.split(" ");
|
|
|
|
const date = new Date(s[0] * 1000).toLocaleDateString("en-US", {
|
|
|
|
year: "numeric",
|
|
|
|
month: "long",
|
|
|
|
day: "numeric",
|
|
|
|
});
|
|
|
|
res = res + `<li>${date} - ${s.slice(1).join(" ")}</li>\n`;
|
|
|
|
});
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2023-03-07 22:56:58 +00:00
|
|
|
function TableViewTemplate(rows) {
|
2023-03-08 01:36:34 +00:00
|
|
|
let table = "<table>";
|
2023-03-07 22:56:58 +00:00
|
|
|
rows.forEach((row, key) => {
|
|
|
|
row.rowNumber = key;
|
|
|
|
table = table + TableRowTemplate(row);
|
|
|
|
});
|
|
|
|
return table + "</table>";
|
|
|
|
}
|
|
|
|
|
|
|
|
function TableRowTemplate({ rowNumber, name, address, city }) {
|
|
|
|
return `
|
|
|
|
<tr id="${rowNumber}" class="spotRow">
|
|
|
|
<td class="name">${name}</td>
|
|
|
|
<td>${address}, ${city}</td>
|
|
|
|
</tr>`;
|
|
|
|
}
|
|
|
|
|
2023-03-08 01:36:34 +00:00
|
|
|
readFile("./index.html", function (err, data) {
|
2023-10-12 01:37:28 +00:00
|
|
|
const changeList = GetRecentChanges();
|
2022-03-19 15:45:05 +00:00
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
2023-03-08 01:36:34 +00:00
|
|
|
const $ = load(data);
|
2017-05-28 22:54:01 +00:00
|
|
|
|
2022-03-19 15:45:05 +00:00
|
|
|
stores.sort(function (a, b) {
|
|
|
|
var aname = a.name.toLowerCase();
|
|
|
|
var bname = b.name.toLowerCase();
|
|
|
|
return aname === bname ? 0 : +(aname > bname) || -1;
|
|
|
|
});
|
2017-05-28 22:54:01 +00:00
|
|
|
|
2023-03-07 22:56:58 +00:00
|
|
|
$("#Stores").html(TableViewTemplate(stores));
|
2022-03-19 15:45:05 +00:00
|
|
|
$("#storeCount").html(stores.length);
|
2022-03-19 20:28:26 +00:00
|
|
|
$("#updatedOn").html(
|
|
|
|
new Date().toLocaleDateString("en-US", {
|
|
|
|
year: "numeric",
|
|
|
|
month: "long",
|
|
|
|
day: "numeric",
|
|
|
|
})
|
|
|
|
);
|
2023-10-12 01:37:28 +00:00
|
|
|
$("#changesList").html(ChangeLog(changeList));
|
2023-03-08 00:06:13 +00:00
|
|
|
const cssurl = $("link[type='text/css']").attr("href").split("?")[0];
|
2022-03-20 14:43:25 +00:00
|
|
|
$("link[type='text/css']").attr("href", cssurl + "?" + new Date().getTime());
|
2023-03-08 01:36:34 +00:00
|
|
|
writeFile("./index.html", $.html(), (err) => {
|
2017-05-28 22:54:01 +00:00
|
|
|
if (err) throw err;
|
2022-03-19 15:45:05 +00:00
|
|
|
console.log("Default view updated.");
|
2017-05-28 22:54:01 +00:00
|
|
|
});
|
2022-03-19 15:45:05 +00:00
|
|
|
});
|