Created cli command. Updated tracker script.

This commit is contained in:
Mike Cao 2020-07-23 22:07:57 -07:00
parent 49a55b40b4
commit a6975ecedd
9 changed files with 120 additions and 35 deletions

24
cli/create-account.js Normal file
View file

@ -0,0 +1,24 @@
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
module.exports = async () => {
const account = await prisma.account.findOne({
where: {
username: 'admin',
},
});
if (!account) {
await prisma.account.create({
data: {
username: 'admin',
password: '$2a$10$BXHPV7APlV1I6WrKJt1igeJAyVsvbhMTaTAi3nHkUJFGPsYmfZq3y',
is_admin: true,
},
});
console.log('Account succesfully created.');
} else {
console.log('Account already exists.');
}
};

25
cli/index.js Normal file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env node
require('dotenv').config();
const yargs = require('yargs');
const chalk = require('chalk');
const createAccount = require('./create-account');
const cmd = yargs.usage('Usage: umami <command> [arguments]').help('h').alias('h', 'help');
const { argv } = cmd;
const {
_: [action, ...params],
} = argv;
const exec = async () => {
if (action === 'create') {
await createAccount();
} else {
cmd.showHelp();
}
process.exit(0);
};
exec();