improved token generator

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

@ -1,5 +1,19 @@
const uuid = require('uuid').v4;
const fs = require('fs-extra');
const path = require('path');
module.exports = () => uuid().replace(/-/g, '');
// If directly called on the command line, generate a new token
require.main === module && console.log(`Here is your new token:\n\n ${module.exports()}\n\nThis token has been automatically applied and is ready for use. You do not need to restart 'ass'.`);
if (require.main === module) {
let token = module.exports();
let authPath = path.join(__dirname, '..', 'auth.json');
fs.readJson(authPath)
.then((auth) => {
auth.tokens.push(token);
fs.writeJsonSync(authPath, auth, { spaces: 4 });
})
.then(() => console.log(`A new token has been generated and automatically applied. You do not need to restart 'ass'.\n\nYour token: ${token}`))
.catch(console.error);
}

Loading…
Cancel
Save