mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2025-01-01 16:36:19 +03:00
Avoid writing CLI app's elm.json to disk if the contents are exactly what would be written. Helps the Elm compiler speed up by around 1 second.
This commit is contained in:
parent
0dbb2138db
commit
335ff5f0b1
@ -1,10 +1,13 @@
|
||||
const fs = require("fs");
|
||||
|
||||
module.exports = function () {
|
||||
var elmJson = JSON.parse(fs.readFileSync("./elm.json").toString());
|
||||
module.exports = async function () {
|
||||
var elmJson = JSON.parse(
|
||||
(await fs.promises.readFile("./elm.json")).toString()
|
||||
);
|
||||
|
||||
// write new elm.json
|
||||
fs.writeFileSync(
|
||||
|
||||
await writeFileIfChanged(
|
||||
"./elm-stuff/elm-pages/elm.json",
|
||||
JSON.stringify(rewriteElmJson(elmJson))
|
||||
);
|
||||
@ -28,3 +31,18 @@ function rewriteElmJson(elmJson) {
|
||||
elmJson["source-directories"].push(".elm-pages");
|
||||
return elmJson;
|
||||
}
|
||||
|
||||
async function writeFileIfChanged(filePath, content) {
|
||||
if (
|
||||
!(await fileExists(filePath)) ||
|
||||
(await fs.promises.readFile(filePath, "utf8")) !== content
|
||||
) {
|
||||
await fs.promises.writeFile(filePath, content);
|
||||
}
|
||||
}
|
||||
function fileExists(file) {
|
||||
return fs.promises
|
||||
.access(file, fs.constants.F_OK)
|
||||
.then(() => true)
|
||||
.catch(() => false);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user