made the serve_style.add and addStyle functions async and return promises
This commit is contained in:
parent
1d60dd6afc
commit
a062d92582
2 changed files with 17 additions and 9 deletions
|
@ -198,9 +198,9 @@ export const serve_style = {
|
|||
* @param {object} programOpts - An object containing the program options
|
||||
* @param {Function} reportTiles Function for reporting tile sources.
|
||||
* @param {Function} reportFont Function for reporting font usage
|
||||
* @returns {boolean} true if add is succesful
|
||||
* @returns {Promise<boolean>} true if add is successful
|
||||
*/
|
||||
add: function (
|
||||
add: async function (
|
||||
options,
|
||||
repo,
|
||||
params,
|
||||
|
@ -214,13 +214,20 @@ export const serve_style = {
|
|||
|
||||
let styleFileData;
|
||||
try {
|
||||
styleFileData = fs.readFileSync(styleFile); // TODO: could be made async if this function was
|
||||
styleFileData = await fs.promises.readFile(styleFile);
|
||||
} catch (e) {
|
||||
console.log(`Error reading style file "${params.style}"`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const styleJSON = JSON.parse(styleFileData);
|
||||
let styleJSON;
|
||||
try {
|
||||
styleJSON = JSON.parse(styleFileData);
|
||||
} catch (e) {
|
||||
console.log(`Error parsing style JSON from "${params.style}"`);
|
||||
return false;
|
||||
}
|
||||
|
||||
const validationErrors = validateStyleMin(styleJSON);
|
||||
if (validationErrors.length > 0) {
|
||||
console.log(`The file "${params.style}" is not a valid style file:`);
|
||||
|
|
|
@ -178,12 +178,12 @@ async function start(opts) {
|
|||
* @param {object} item - The style configuration object.
|
||||
* @param {boolean} allowMoreData - Whether to allow adding more data sources.
|
||||
* @param {boolean} reportFonts - Whether to report fonts.
|
||||
* @returns {void}
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
function addStyle(id, item, allowMoreData, reportFonts) {
|
||||
async function addStyle(id, item, allowMoreData, reportFonts) {
|
||||
let success = true;
|
||||
if (item.serve_data !== false) {
|
||||
success = serve_style.add(
|
||||
success = await serve_style.add(
|
||||
options,
|
||||
serving.styles,
|
||||
item,
|
||||
|
@ -271,6 +271,7 @@ async function start(opts) {
|
|||
item.serve_rendered = false;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
for (const id of Object.keys(config.styles || {})) {
|
||||
|
@ -280,7 +281,7 @@ async function start(opts) {
|
|||
continue;
|
||||
}
|
||||
|
||||
addStyle(id, item, true, true);
|
||||
startupPromises.push(addStyle(id, item, true, true));
|
||||
}
|
||||
startupPromises.push(
|
||||
serve_font(options, serving.fonts, opts).then((sub) => {
|
||||
|
|
Loading…
Reference in a new issue