-
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send 404 when env is invalid. Don't use default importmap file. Resolves
- Loading branch information
1 parent
2796fec
commit 3c947e2
Showing
9 changed files
with
90 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,17 @@ | ||
"use strict"; | ||
const fs = require("fs"); | ||
const config = require("../config").config; | ||
const fs = require("fs/promises"); | ||
const { getConfig } = require("../config"); | ||
const jsHelpers = require("./js-file-helpers.js"); | ||
|
||
exports.readManifest = function (filePath) { | ||
return new Promise((resolve, reject) => { | ||
//create file if not already created | ||
fs.open(filePath, "a", function (err, fd) { | ||
if (err) reject(`Could not open file ${filePath}`); | ||
else { | ||
fs.readFile(filePath, "utf8", function (err2, data) { | ||
if (err2) { | ||
console.error(err2); | ||
reject(`Could not read file ${filePath}`); | ||
} else resolve(data); | ||
}); | ||
} | ||
}); | ||
}); | ||
return fs.readFile(filePath, "utf-8"); | ||
}; | ||
|
||
exports.writeManifest = function (filePath, data) { | ||
const jsonPromise = new Promise((resolve, reject) => { | ||
fs.writeFile(filePath, data, function (err) { | ||
if (err) reject(`Could not write file ${filePath}`); | ||
else resolve(); | ||
}); | ||
}); | ||
const config = getConfig(); | ||
const useJsHelpers = config && config.writeJsFile; | ||
const finalFilePath = useJsHelpers ? jsHelpers.getJsPath(filePath) : filePath; | ||
const finalData = useJsHelpers ? jsHelpers.createJsString(data) : data; | ||
|
||
const jsPromise = new Promise((resolve, reject) => { | ||
if (!config || !config.writeJsFile) { | ||
resolve(); | ||
} else { | ||
fs.writeFile( | ||
jsHelpers.getJsPath(filePath), | ||
jsHelpers.createJsString(data), | ||
function (err) { | ||
if (err) reject(`Could not write file ${filePath}`); | ||
else resolve(); | ||
} | ||
); | ||
} | ||
}); | ||
|
||
return Promise.all([jsonPromise, jsPromise]); | ||
return fs.writeFile(finalFilePath, finalData, "utf-8"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters