-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun.ts
More file actions
101 lines (93 loc) · 3.36 KB
/
run.ts
File metadata and controls
101 lines (93 loc) · 3.36 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { Messages } from '@salesforce/core'
import { Flags, SfCommand } from '@salesforce/sf-plugins-core'
import {
DEFAULT_ANCESTOR_CONFLICT_TAG,
DEFAULT_CONFLICT_MARKER_SIZE,
DEFAULT_LOCAL_CONFLICT_TAG,
DEFAULT_OTHER_CONFLICT_TAG,
} from '../../../../constant/conflictConstant.js'
import { PLUGIN_NAME } from '../../../../constant/pluginConstant.js'
import { MergeDriver } from '../../../../driver/MergeDriver.js'
import type { MergeConfig } from '../../../../types/conflictTypes.js'
import { log } from '../../../../utils/LoggingDecorator.js'
import { Logger, lazy } from '../../../../utils/LoggingService.js'
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url)
const messages = Messages.loadMessages(PLUGIN_NAME, 'run')
const ERROR_EXIT_CODE = 1
const SUCCESS_EXIT_CODE = 0
export default class Run extends SfCommand<void> {
public static override readonly summary = messages.getMessage('summary')
public static override readonly description =
messages.getMessage('description')
public static override readonly examples = messages.getMessages('examples')
public static override readonly flags = {
'ancestor-file': Flags.string({
char: 'O',
summary: messages.getMessage('flags.ancestor-file.summary'),
required: true,
exists: true,
}),
'local-file': Flags.string({
char: 'A',
summary: messages.getMessage('flags.local-file.summary'),
required: true,
exists: true,
}),
'other-file': Flags.string({
char: 'B',
summary: messages.getMessage('flags.other-file.summary'),
required: true,
exists: true,
}),
'output-file': Flags.string({
char: 'P',
summary: messages.getMessage('flags.output-file.summary'),
required: true,
exists: true,
}),
'conflict-marker-size': Flags.integer({
char: 'L',
summary: messages.getMessage('flags.conflict-marker-size.summary'),
min: 1,
default: DEFAULT_CONFLICT_MARKER_SIZE,
}),
'ancestor-conflict-tag': Flags.string({
char: 'S',
summary: messages.getMessage('flags.ancestor-conflict-tag.summary'),
default: DEFAULT_ANCESTOR_CONFLICT_TAG,
}),
'local-conflict-tag': Flags.string({
char: 'X',
summary: messages.getMessage('flags.local-conflict-tag.summary'),
default: DEFAULT_LOCAL_CONFLICT_TAG,
}),
'other-conflict-tag': Flags.string({
char: 'Y',
summary: messages.getMessage('flags.other-conflict-tag.summary'),
default: DEFAULT_OTHER_CONFLICT_TAG,
}),
}
@log
public async run(): Promise<void> {
Logger.info('Merge starting')
const { flags } = await this.parse(Run)
const config: MergeConfig = {
conflictMarkerSize: flags['conflict-marker-size'],
ancestorConflictTag: flags['ancestor-conflict-tag'],
localConflictTag: flags['local-conflict-tag'],
otherConflictTag: flags['other-conflict-tag'],
}
Logger.debug(lazy`flags: ${() => JSON.stringify(flags)}`)
Logger.debug(lazy`config: ${() => JSON.stringify(config)}`)
const mergeDriver = new MergeDriver(config)
const hasConflict = await mergeDriver.mergeFiles(
flags['ancestor-file'],
flags['local-file'],
flags['other-file']
)
Logger.info(
`Merge completed with ${hasConflict ? 'conflicts' : 'no conflicts'}`
)
process.exitCode = hasConflict ? ERROR_EXIT_CODE : SUCCESS_EXIT_CODE
}
}