-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigure.ts
More file actions
81 lines (71 loc) · 2.04 KB
/
Copy pathconfigure.ts
File metadata and controls
81 lines (71 loc) · 2.04 KB
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
71
72
73
74
75
76
77
78
79
80
81
/*
* mongo-adonis
*
* (c) Thomas Reichling
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import type Configure from '@adonisjs/core/commands/configure'
import { stubsRoot } from './stubs/main.js'
/**
* Configures the package
*/
export async function configure(command: Configure) {
let shouldInstallPackages: boolean | undefined = command.parsedFlags.install
/**
* 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 "mongo-adonis"?'
)
}
const codemods = await command.createCodemods()
/**
* Create MongoDB config file
*/
await codemods.makeUsingStub(stubsRoot, 'mongodb.stub', {})
/**
* Add environment variables
*/
await codemods.defineEnvVariables({
DB_CONNECTION: 'mongodb',
DB_HOST: '127.0.0.1',
DB_PORT: '27017',
DB_USER: 'admin',
DB_PASSWORD: '',
DB_DATABASE: 'mongo-adonis',
DB_AUTH_SOURCE: 'admin',
})
/**
* Add environment validations
*/
await codemods.defineEnvValidations({
leadingComment: 'App environment variables',
variables: {
DB_CONNECTION: 'Env.schema.string()',
DB_HOST: 'Env.schema.string({ format: "host" })',
DB_PORT: 'Env.schema.number()',
DB_USER: 'Env.schema.string.optional()',
DB_PASSWORD: 'Env.schema.string.optional()',
DB_DATABASE: 'Env.schema.string()',
DB_AUTH_SOURCE: 'Env.schema.string.optional()',
}
})
/**
* Register provider
*/
await codemods.updateRcFile((rcFile: any) => {
rcFile.addProvider('mongo-adonis/database_provider')
})
/**
* Install required packages
*/
if (shouldInstallPackages) {
// Log a message to install the package manually
command.logger.info('Please install the mongodb package manually: npm install mongodb@6.5.0')
}
command.logger.success('Configured mongo-adonis package')
}