-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfigure.ts
52 lines (50 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
import type Configure from '@adonisjs/core/commands/configure'
import { packageName, stubsRoot } from './index.js'
import { access } from 'fs/promises'
/**
* Configures the package
*/
export async function configure(command: Configure) {
const codemods = await command.createCodemods()
/**
* Check if @adonisjs/redis installed, or provide some suggestion.
*/
if (await doesDependencyPackageMissing(command)) {
const dependencyPackage = '@adonisjs/redis'
const shouldInstallPackages = await command.prompt.confirm(
`Do you want to install dependencies ${dependencyPackage}?`,
{ name: 'install', default: true }
)
const packagesToInstall = [
{
name: dependencyPackage,
isDevDependency: false
}
]
if (shouldInstallPackages) {
await codemods.installPackages(packagesToInstall)
command.logger.warning(`Run ${command.colors.bgMagenta(command.colors.red(`node ace configure ${dependencyPackage}`))} after installing`)
} else {
await codemods.listPackagesToInstall(packagesToInstall)
}
command.logger.warning(`and configure ${command.colors.red(dependencyPackage)} correctly before using this package`)
command.logger.action
}
await codemods.makeUsingStub(stubsRoot, 'config/resque.stub', {})
/**
* Register provider
*/
await codemods.updateRcFile((rcFile) => {
rcFile.addProvider(`${packageName}/providers/resque_provider`)
rcFile.addCommand(`${packageName}/commands`)
})
}
async function doesDependencyPackageMissing(command: Configure) {
const redisConfigFile = command.app.configPath('redis.ts')
try {
await access(redisConfigFile)
return false
} catch (err: any) {
return true
}
}