Add support to regenerate nsl cache if corrupted.

This commit is contained in:
Dirk Baeumer
2018-07-03 11:39:30 +02:00
parent e79e446e90
commit 3c0abb8d8a
6 changed files with 136 additions and 57 deletions

View File

@@ -45,6 +45,8 @@ function readFile(file) {
});
}
const writeFile = (file, content) => new Promise((c, e) => fs.writeFile(file, content, 'utf8', err => err ? e(err) : c()));
function main() {
const args = parseURLQueryArgs();
const configuration = JSON.parse(args['config'] || '{}') || {};
@@ -102,8 +104,15 @@ function main() {
let json = JSON.parse(content);
bundles[bundle] = json;
cb(undefined, json);
})
.catch(cb);
}).catch((error) => {
try {
if (nlsConfig._corruptedFile) {
writeFile(nlsConfig._corruptedFile, 'corrupted').catch(function (error) { console.error(error); });
}
} finally {
cb(error, undefined);
}
});
};
}