-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfigure.ts
60 lines (54 loc) · 1.81 KB
/
configure.ts
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
57
58
59
60
/*
|--------------------------------------------------------------------------
| Configure hook
|--------------------------------------------------------------------------
|
| The configure hook is called when someone runs "node ace configure <package>"
| command. You are free to perform any operations inside this function to
| configure the package.
|
| To make things easier, you have access to the underlying "ConfigureCommand"
| instance and you can use codemods to modify the source files.
|
*/
import ConfigureCommand from '@adonisjs/core/commands/configure'
import string from '@adonisjs/core/helpers/string'
import { DIALECTS, presetPrisma } from './src/preset_prisma.js'
export async function configure(command: ConfigureCommand) {
let dialect: string | undefined = command.parsedFlags.db
let shouldInstallPackages: boolean | undefined = command.parsedFlags.install
if (dialect === undefined) {
dialect = await command.prompt.choice(
'Select the database you want to use',
Object.keys(DIALECTS),
{
name: 'dialect',
validate(value) {
return !!value
},
}
)
}
if (dialect! in DIALECTS === false) {
command.logger.error(
`The selected database "${dialect}" is invalid. Select one from: ${string.sentence(
Object.keys(DIALECTS)
)}`
)
command.exitCode = 1
return
}
if (shouldInstallPackages === undefined) {
shouldInstallPackages = await command.prompt.confirm(
'Do you want to install additional packages required by "@arthurfranckpat/adonis-prisma"?',
{
name: 'shouldInstallPackages',
}
)
}
const codemods = await command.createCodemods()
await presetPrisma(codemods, command.app, {
dialect: dialect as keyof typeof DIALECTS,
installPackages: !!shouldInstallPackages,
})
}