-
Notifications
You must be signed in to change notification settings - Fork 7
/
configure.js
56 lines (47 loc) · 1.46 KB
/
configure.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* eslint-disable @typescript-eslint/no-var-requires */
const Figlet = require('figlet');
const chalk = require('chalk');
const fs = require('fs');
const prompts = require('prompts');
const dotenv = require('dotenv');
dotenv.config();
const productName = 'meiliNG';
const packageJson = JSON.parse(fs.readFileSync('package.json', { encoding: 'utf-8' }));
console.log(Figlet.textSync(productName, 'Small Slant'));
console.log(`${chalk.bold(productName)} Configuration Utility - ${chalk.italic`v${packageJson.version}`}`);
console.log();
(async () => {
const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();
if (!process.env.DATABASE_URL?.trim()) {
console.error(chalk.redBright('x'), 'Database URL is not properly configured.');
process.exit(1);
}
try {
await prisma.$connect();
} catch (e) {
console.error(chalk.redBright('x'), 'Failed to connect database');
process.exit(1);
}
try {
const perms = ['openid', 'profile', 'name', 'email', 'address'];
await Promise.all(
perms.map(async (n) => {
const perm = await prisma.permission.findUnique({
where: {
name: n,
},
});
if (!perm) {
await prisma.permission.create({
data: {
name: n,
},
});
}
}),
);
} catch (e) {
console.error(chalk.redBright('x'), 'Failed to generate required permission/scope on database');
}
})();