Minify: Asyncify `getAceFile()`
parent
5cc191f185
commit
e573276755
|
@ -190,9 +190,8 @@ const minify = (req, res) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
// find all includes in ace.js and embed them.
|
// find all includes in ace.js and embed them.
|
||||||
const getAceFile = (callback) => {
|
const getAceFile = async () => {
|
||||||
fs.readFile(`${ROOT_DIR}js/ace.js`, 'utf8', (err, data) => {
|
let data = await util.promisify(fs.readFile)(`${ROOT_DIR}js/ace.js`, 'utf8');
|
||||||
if (ERR(err, callback)) return;
|
|
||||||
|
|
||||||
// Find all includes in ace.js and embed them
|
// Find all includes in ace.js and embed them
|
||||||
const filenames = [];
|
const filenames = [];
|
||||||
|
@ -213,7 +212,7 @@ const getAceFile = (callback) => {
|
||||||
|
|
||||||
// Request the contents of the included file on the server-side and write
|
// Request the contents of the included file on the server-side and write
|
||||||
// them into the file.
|
// them into the file.
|
||||||
Promise.all(filenames.map(async (filename) => {
|
await Promise.all(filenames.map(async (filename) => {
|
||||||
// Hostname "invalid.invalid" is a dummy value to allow parsing as a URI.
|
// Hostname "invalid.invalid" is a dummy value to allow parsing as a URI.
|
||||||
const baseURI = 'http://invalid.invalid';
|
const baseURI = 'http://invalid.invalid';
|
||||||
let resourceURI = baseURI + path.normalize(path.join('/static/', filename));
|
let resourceURI = baseURI + path.normalize(path.join('/static/', filename));
|
||||||
|
@ -227,8 +226,8 @@ const getAceFile = (callback) => {
|
||||||
} else {
|
} else {
|
||||||
console.error(`getAceFile(): error getting ${resourceURI}. Status code: ${status}`);
|
console.error(`getAceFile(): error getting ${resourceURI}. Status code: ${status}`);
|
||||||
}
|
}
|
||||||
})).then(() => callback(null, data), (err) => callback(err || new Error(err)));
|
}));
|
||||||
});
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check for the existance of the file and get the last modification date.
|
// Check for the existance of the file and get the last modification date.
|
||||||
|
@ -348,7 +347,7 @@ const getFileCompressed = (filename, contentType, callback) => {
|
||||||
|
|
||||||
const getFile = (filename, callback) => {
|
const getFile = (filename, callback) => {
|
||||||
if (filename === 'js/ace.js') {
|
if (filename === 'js/ace.js') {
|
||||||
getAceFile(callback);
|
util.callbackify(getAceFile)(callback);
|
||||||
} else if (filename === 'js/require-kernel.js') {
|
} else if (filename === 'js/require-kernel.js') {
|
||||||
callback(undefined, requireDefinition());
|
callback(undefined, requireDefinition());
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue