automatically reload auth.json when new token is generated

pull/12/head
tycrek 4 years ago
parent aac4322204
commit 6604c75d2f
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -45,6 +45,11 @@ function preStartup() {
tokens = fs.readJsonSync(path('auth.json')).tokens; tokens = fs.readJsonSync(path('auth.json')).tokens;
data = fs.readJsonSync(path('data.json')); data = fs.readJsonSync(path('data.json'));
log('Tokens & data read from filesystem'); log('Tokens & data read from filesystem');
// Monitor auth.json for changes (triggered by running 'npm run new-token')
fs.watch(path('auth.json'), { persistent: false }, (eventType, _filename) => eventType === 'change' && fs.readJson(path('auth.json'))
.then((json) => (tokens.toString() != json.tokens.toString()) && (tokens = json.tokens) && log(`New token added: ${tokens[tokens.length - 1]}`))
.catch(console.error));
} }
function startup() { function startup() {

Loading…
Cancel
Save