forked from adonisjs/lucid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure.ts
70 lines (64 loc) · 1.79 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
61
62
63
64
65
66
67
68
69
70
/*
* @adonisjs/lucid
*
* (c) AdonisJS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import string from '@poppinss/utils/string'
import { presetLucid, DIALECTS } from '@adonisjs/presets/lucid'
import type Configure from '@adonisjs/core/commands/configure'
/**
* Configures the package
*/
export async function configure(command: Configure) {
let dialect: string | undefined = command.parsedFlags.db
let shouldInstallPackages: boolean | undefined = command.parsedFlags.install
/**
* Prompt to select the dialect when --db flag
* is not used.
*/
if (dialect === undefined) {
dialect = await command.prompt.choice(
'Select the database you want to use',
Object.keys(DIALECTS).map((dialectKey) => {
return {
name: dialectKey,
message: DIALECTS[dialectKey as keyof typeof DIALECTS].name,
}
}),
{
validate(value) {
return !!value
},
}
)
}
/**
* Show error when selected dialect is not supported
*/
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
}
/**
* Prompt when `install` or `--no-install` flags are
* not used
*/
if (shouldInstallPackages === undefined) {
shouldInstallPackages = await command.prompt.confirm(
'Do you want to install additional packages required by "@adonisjs/lucid"?'
)
}
const codemods = await command.createCodemods()
await presetLucid(codemods, command.app, {
dialect: dialect as keyof typeof DIALECTS,
installPackages: !!shouldInstallPackages,
})
}