-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfigure.ts
81 lines (71 loc) · 1.84 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
71
72
73
74
75
76
77
78
79
80
81
/*
* @adonisjs/cache
*
* (c) AdonisJS
*
* 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'
const DRIVERS = ['redis', 'file', 'database', 'dynamodb'] as const
const DRIVERS_INFO: {
[K in (typeof DRIVERS)[number]]: {
envVars?: Record<string, number | string>
envValidations?: Record<string, string>
}
} = {
file: {},
redis: {},
database: {},
dynamodb: {
envValidations: {
AWS_ACCESS_KEY_ID: `Env.schema.string()`,
AWS_SECRET_ACCESS_KEY: `Env.schema.string()`,
AWS_REGION: `Env.schema.string()`,
DYNAMODB_ENDPOINT: `Env.schema.string()`,
},
envVars: {
AWS_ACCESS_KEY_ID: '',
AWS_SECRET_ACCESS_KEY: '',
AWS_REGION: '',
DYNAMODB_ENDPOINT: '',
},
},
}
/**
* Configures the package
*/
export async function configure(command: Configure) {
const driver = await command.prompt.choice(
'Select the cache driver you plan to use',
['redis', 'file', 'database', 'dynamodb'],
{
hint: 'You can always change it later',
}
)
const codemods = await command.createCodemods()
/**
* Publish provider
*/
await codemods.updateRcFile((rcFile) => {
rcFile.addProvider('@adonisjs/cache/cache_provider').addCommand('@adonisjs/cache/commands')
})
const { envVars, envValidations } = DRIVERS_INFO[driver]
/**
* Define environment variables
*/
if (envVars) {
await codemods.defineEnvVariables(envVars)
}
/**
* Define environment validations
*/
if (envValidations) {
await codemods.defineEnvValidations({ variables: envValidations })
}
/**
* Publish config
*/
await codemods.makeUsingStub(stubsRoot, 'config.stub', { driver: driver })
}