-
Notifications
You must be signed in to change notification settings - Fork 49
/
types.ts
193 lines (175 loc) · 5.2 KB
/
types.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import {
GluegunRunContext,
GluegunFilesystem,
GluegunStrings,
GluegunPrint,
GluegunSystem,
GluegunSemver,
GluegunHttp,
GluegunPatching,
GluegunPrompt,
GluegunTemplate,
GluegunMeta,
} from 'gluegun'
export const solidarity = {
binaryExists: require('./extensions/functions/binaryExists'),
getSolidaritySettings: require('./extensions/functions/getSolidaritySettings'),
setSolidaritySettings: require('./extensions/functions/setSolidaritySettings'),
setOutputMode: require('./extensions/functions/setOutputMode'),
checkRequirement: require('./extensions/functions/checkRequirement'),
updateRequirement: require('./extensions/functions/updateRequirement'),
skipRule: require('./extensions/functions/skipRule'),
checkENV: require('./extensions/functions/checkENV'),
checkCLI: require('./extensions/functions/checkCLI'),
checkDir: require('./extensions/functions/checkDir'),
checkFile: require('./extensions/functions/checkFile'),
updateVersions: require('./extensions/functions/updateVersions'),
removeNonVersionCharacters: require('./extensions/functions/removeNonVersionCharacters'),
getVersion: require('./extensions/functions/getVersion'),
getLineWithVersion: require('./extensions/functions/getLineWithVersion'),
printResults: require('./extensions/functions/printResults'),
reviewRule: require('./extensions/functions/reviewRule'),
buildSpecificRequirement: require('./extensions/functions/buildSpecificRequirement'),
appendSolidaritySettings: require('./extensions/functions/appendSolidaritySettings'),
ruleHandlers: require('./extensions/functions/ruleHandlers'),
createPlugin: require('./extensions/functions/createPlugin'),
}
export interface SolidarityPlugin {
readonly name: string
readonly description: string
readonly snapshot: string | SnapshotType
}
export interface SolidarityRunContext extends GluegunRunContext {
solidarity: typeof solidarity
_pluginsList: Array<SolidarityPlugin & { templateDirectory: string | null }>
addPlugin: (config: SolidarityPlugin) => void
printSeparator: () => void
outputMode: SolidarityOutputMode
envHelpers: any
filesystem: GluegunFilesystem
strings: GluegunStrings
print: GluegunPrint
system: GluegunSystem
semver: GluegunSemver
http: GluegunHttp
patching: GluegunPatching
prompt: GluegunPrompt
template: GluegunTemplate
meta: GluegunMeta
bufferSettings?: SolidaritySettings
}
export type SnapshotType = (context: SolidarityRunContext) => Promise<void>
export interface CLIRule {
readonly rule: 'cli'
readonly binary: string
semver?: string // updatable
readonly version?: string
readonly line?: string | number
error?: string // updatable
readonly matchIndex?: number
platform?: string | string[]
ci?: boolean // updatable
fix?: string
}
export interface ENVRule {
readonly rule: 'env'
readonly variable: string
error?: string
platform?: string | string[]
ci?: boolean
fix?: string
}
export interface FSRule {
readonly rule: 'dir' | 'directory' | 'file'
readonly location: string
error?: string
platform?: string | string[]
ci?: boolean
fix?: string
}
/**
* Runs a shell command and evaluates the output is what we expect.
*/
export interface ShellRule {
/**
* We're a shell rule.
*/
readonly rule: 'shell'
/**
* The command to execute.
*/
readonly command: string
/**
* A regular expression to match the output against.
*
* If you add a capture group, it will only target that instead of the whole
* expression. This is great for selecting a subset.
*/
readonly match: string
/**
* An optional error message to override.
*/
error?: string
/**
* An optional platform or platforms to target.
*/
platform?: string | string[]
/**
* An optional flag to skip rule on CI
*/
ci?: boolean
fix?: string
}
export interface CustomRule {
readonly rule: 'custom'
readonly plugin: string
readonly name: string
error?: string
platform?: string | string[]
ci?: boolean
fix?: string
}
// discriminated union for rule sets
export type SolidarityRule = CLIRule | ENVRule | FSRule | ShellRule | CustomRule
export type SolidarityChecker = (SolidarityRule, SolidarityRunContext) => any
export interface PluginFind {
success: boolean
message?: string
plugin?: SolidarityRule
}
export enum SolidarityOutputMode {
MODERATE,
VERBOSE,
SILENT,
}
export const enum FriendlyMessages {
NONE = 'NONE',
NOTHING = 'Nothing to do ¯\\_(ツ)_/¯',
}
export type SolidarityRequirement = SolidarityRule[]
export type SolidarityRequirementChunk = [string, SolidarityRequirement]
export interface SolidarityConfig {
output: SolidarityOutputMode
}
export interface SolidaritySettings {
readonly requirements: object
readonly config?: SolidarityConfig
}
export interface CustomRulesConfig {
title: string
table: Array<Array<string>>
}
export interface SolidarityReportResults {
basicInfo: Array<Array<string>>
cliRules: Array<Array<string>>
envRules: Array<Array<string>>
filesystemRules: Array<Array<string>>
shellRules: Array<Array<string>>
customRules?: Array<CustomRulesConfig>
addCLI: (cliReportConfig: CLIReportConfig) => void
}
export interface CLIReportConfig {
binary: string
version: string
desired?: string
}