forked from Rocketseat/adonis-bull
-
Notifications
You must be signed in to change notification settings - Fork 0
/
instructions.ts
98 lines (81 loc) · 2.33 KB
/
instructions.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { join } from 'path'
import * as sinkStatic from '@adonisjs/sink'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'
function getStub(...relativePaths: string[]) {
return join(__dirname, 'templates', ...relativePaths)
}
export default async function instructions(
projectRoot: string,
app: ApplicationContract,
sink: typeof sinkStatic
) {
const startMethod = await sink.getPrompt().choice(
'How do you want to start your queue?',
[
{
name: 'command',
message: 'Ace command',
hint: 'Started by bull:listen command',
},
{
name: 'http',
message: 'HTTP Server',
hint: 'Started with the adonis server',
},
],
{
validate(choice) {
return choice && choice.length
? true
: 'Select a queue process start method'
},
}
)
if (startMethod === 'http') {
const preloadFilePath = app.makePath('start/bull.ts')
const bullPreloadFile = new sink.files.MustacheFile(
projectRoot,
preloadFilePath,
getStub('bull.txt')
)
bullPreloadFile.overwrite = true
bullPreloadFile.commit()
sink.logger.action('create').succeeded('start/bull.ts')
const preload = new sink.files.AdonisRcFile(projectRoot)
preload.setPreload('./start/bull')
preload.commit()
sink.logger.action('update').succeeded('.adonisrc.json')
}
const configPath = app.configPath('bull.ts')
const bullConfig = new sink.files.MustacheFile(
projectRoot,
configPath,
getStub('config.txt')
)
bullConfig.overwrite = true
bullConfig.commit()
const configDir = app.directoriesMap.get('config') || 'config'
sink.logger.action('create').succeeded(`${configDir}/bull.ts`)
const contractsPath = app.makePath('contracts/bull.ts')
const bullContract = new sink.files.MustacheFile(
projectRoot,
contractsPath,
getStub('contract.txt')
)
bullContract.overwrite = true
bullContract.commit()
sink.logger.action('create').succeeded('contracts/bull.ts')
const startsPath = app.makePath('start/jobs.ts')
const bullStart = new sink.files.MustacheFile(
projectRoot,
startsPath,
getStub('start.txt')
)
bullStart.overwrite = true
bullStart
.apply({
startJobs: [],
})
.commit()
sink.logger.action('create').succeeded('start/jobs.ts')
}