From 6604c75d2ffeb8996f163b1266aedacf2e3fa8a8 Mon Sep 17 00:00:00 2001 From: tycrek Date: Wed, 7 Apr 2021 11:56:29 -0600 Subject: [PATCH] automatically reload auth.json when new token is generated --- ass.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ass.js b/ass.js index d561737..c2ebe4b 100755 --- a/ass.js +++ b/ass.js @@ -45,6 +45,11 @@ function preStartup() { tokens = fs.readJsonSync(path('auth.json')).tokens; data = fs.readJsonSync(path('data.json')); 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() {