const cheerio = require("cheerio"); const mustache = require("./js/mustache.4.1.0.js"); const fs = require("fs"); const stores = require("./stores.json"); fs.readFile("./index.html", function (err, data) { if (err) { throw err; } const $ = cheerio.load(data); stores.sort(function (a, b) { var aname = a.name.toLowerCase(); var bname = b.name.toLowerCase(); return aname === bname ? 0 : +(aname > bname) || -1; }); $("#Stores").html(mustache.render($("#Table").html(), { rows: stores })); $("#storeCount").html(stores.length); $("#updatedOn").html( new Date().toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric", }) ); const cssurl = $("link[type='text/css']").attr("href"); $("link[type='text/css']").attr("href", cssurl + "?" + new Date().getTime()); fs.writeFile("./index.html", $.html(), (err) => { if (err) throw err; console.log("Default view updated."); }); });