-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstructions.ts
84 lines (71 loc) · 2.8 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
import { join } from 'path'
import * as sinkStatic from '@adonisjs/sink'
import { ApplicationContract } from '@ioc:Adonis/Core/Application'
function getStub(path: string) {
return join(__dirname, 'templates', path)
}
function makeConfig(projectRoot: string, app: ApplicationContract, sink: typeof sinkStatic) {
const configPath = app.makePath('config/microservices.ts')
const kafkaConfig = new sink.files.MustacheFile(projectRoot, configPath, getStub('config.txt'))
if (kafkaConfig.exists()) {
sink.logger.action('skip').succeeded(configPath)
return
}
kafkaConfig.commit()
sink.logger.action('create').succeeded(configPath)
}
function makeDecorator(projectRoot: string, app: ApplicationContract, sink: typeof sinkStatic) {
const configPath = app.makePath('app/Decorators/MsMessage.ts')
const kafkaConfig = new sink.files.MustacheFile(projectRoot, configPath, getStub('decorator.txt'))
if (kafkaConfig.exists()) {
sink.logger.action('skip').succeeded(configPath)
return
}
kafkaConfig.commit()
sink.logger.action('create').succeeded(configPath)
}
function makeHelper(projectRoot: string, app: ApplicationContract, sink: typeof sinkStatic) {
const configPath = app.makePath('app/Helpers/Types/Microservice.ts')
const kafkaConfig = new sink.files.MustacheFile(projectRoot, configPath, getStub('helper.txt'))
if (kafkaConfig.exists()) {
sink.logger.action('skip').succeeded(configPath)
return
}
kafkaConfig.commit()
sink.logger.action('create').succeeded(configPath)
}
function makeContract(projectRoot: string, app: ApplicationContract, sink: typeof sinkStatic) {
const contractsPath = app.makePath('contracts/microservices.ts')
const kafkaContract = new sink.files.MustacheFile(
projectRoot,
contractsPath,
getStub('contract.txt')
)
if (kafkaContract.exists()) {
sink.logger.action('skip').succeeded('contracts/microservices.ts')
return
}
kafkaContract.commit()
sink.logger.action('create').succeeded('contracts/microservices.ts')
}
function makeProvider(projectRoot: string, app: ApplicationContract, sink: typeof sinkStatic) {
const providerPath = app.makePath('providers/MicroserviceProvider.ts')
const kafkaStart = new sink.files.MustacheFile(projectRoot, providerPath, getStub('provider.txt'))
if (kafkaStart.exists()) {
sink.logger.action('skip').succeeded('providers/MicroserviceProvider.ts')
return
}
kafkaStart.commit()
sink.logger.action('create').succeeded('providers/MicroserviceProvider.ts')
}
export default async function instructions(
projectRoot: string,
app: ApplicationContract,
sink: typeof sinkStatic
): Promise<void> {
makeConfig(projectRoot, app, sink)
makeContract(projectRoot, app, sink)
makeProvider(projectRoot, app, sink)
makeDecorator(projectRoot, app, sink)
makeHelper(projectRoot, app, sink)
}