@@ -15,46 +15,39 @@ import {Utils} from "./utils";
15
15
import { assert } from "./asserts" ;
16
16
import * as path from "path" ;
17
17
import { WriteStreams } from "./types/write-streams" ;
18
+ import { ParserOptions } from "./types/parser-options" ;
18
19
19
20
export class Parser {
20
21
21
22
private readonly jobs : Map < string , Job > = new Map ( ) ;
22
23
private readonly stages : Map < string , Stage > = new Map ( ) ;
23
- private readonly cwd : string ;
24
- private readonly writeStreams : WriteStreams ;
25
- private readonly file ?: string ;
26
- private readonly home ?: string ;
27
- private readonly pipelineIid : number ;
24
+ private readonly opt : ParserOptions ;
28
25
29
26
private gitRemote : GitRemote | null = null ;
30
27
private homeVariables : any ;
31
28
32
29
private gitlabData : any ;
33
30
private _jobNamePad = 0 ;
34
- private readonly tabCompletionPhase : boolean ;
35
-
36
- private constructor ( cwd : string , writeStreams : WriteStreams , pipelineIid : number , tabCompletionPhase : boolean , home ?: string , file ?: string ) {
37
- this . cwd = cwd ;
38
- this . pipelineIid = pipelineIid ;
39
- this . tabCompletionPhase = tabCompletionPhase ;
40
- this . file = file ;
41
- this . home = home ;
42
- this . writeStreams = writeStreams ;
31
+
32
+ private constructor ( opt : ParserOptions ) {
33
+ this . opt = opt ;
43
34
}
44
35
45
36
get jobNamePad ( ) : number {
46
37
return this . _jobNamePad ;
47
38
}
48
39
49
- static async create ( cwd : string , writeStreams : WriteStreams , pipelineIid : number , tabCompletionPhase : boolean , home ?: string , file ?: string ) {
50
- const parser = new Parser ( cwd , writeStreams , pipelineIid , tabCompletionPhase , file , home ) ;
40
+ static async create ( opt : ParserOptions ) {
41
+ const writeStreams = opt . writeStreams ;
42
+ const parser = new Parser ( opt ) ;
51
43
52
44
const time = process . hrtime ( ) ;
53
45
await parser . init ( ) ;
54
46
await parser . initJobs ( ) ;
55
47
await parser . validateNeedsTags ( ) ;
56
48
const parsingTime = process . hrtime ( time ) ;
57
- if ( ! tabCompletionPhase ) {
49
+
50
+ if ( ! opt . tabCompletionPhase ) {
58
51
writeStreams . stdout ( chalk `{cyan ${ "yml files" . padEnd ( parser . jobNamePad ) } } {magentaBright processed} in {magenta ${ prettyHrtime ( parsingTime ) } }\n` ) ;
59
52
}
60
53
@@ -146,20 +139,23 @@ export class Parser {
146
139
}
147
140
148
141
async init ( ) {
149
- const cwd = this . cwd ;
150
- const writeStreams = this . writeStreams ;
142
+ const cwd = this . opt . cwd ;
143
+ const writeStreams = this . opt . writeStreams ;
144
+ const home = this . opt . home ;
145
+ const file = this . opt . file ;
146
+ const tabCompletionPhase = this . opt . tabCompletionPhase ;
151
147
152
148
this . gitRemote = await Parser . initGitRemote ( cwd ) ;
153
- this . homeVariables = await Parser . initHomeVariables ( cwd , this . gitRemote , this . home ?? process . env . HOME ?? "" ) ;
149
+ this . homeVariables = await Parser . initHomeVariables ( cwd , this . gitRemote , home ?? process . env . HOME ?? "" ) ;
154
150
155
151
let ymlPath , yamlDataList : any [ ] = [ ] ;
156
- ymlPath = this . file ? `${ cwd } /${ this . file } ` : `${ cwd } /.gitlab-ci.yml` ;
152
+ ymlPath = file ? `${ cwd } /${ file } ` : `${ cwd } /.gitlab-ci.yml` ;
157
153
const gitlabCiData = await Parser . loadYaml ( ymlPath ) ;
158
- yamlDataList = yamlDataList . concat ( await Parser . prepareIncludes ( gitlabCiData , cwd , writeStreams , this . gitRemote , this . tabCompletionPhase ) ) ;
154
+ yamlDataList = yamlDataList . concat ( await Parser . prepareIncludes ( gitlabCiData , cwd , writeStreams , this . gitRemote , tabCompletionPhase ) ) ;
159
155
160
156
ymlPath = `${ cwd } /.gitlab-ci-local.yml` ;
161
157
const gitlabCiLocalData = await Parser . loadYaml ( ymlPath ) ;
162
- yamlDataList = yamlDataList . concat ( await Parser . prepareIncludes ( gitlabCiLocalData , cwd , writeStreams , this . gitRemote , this . tabCompletionPhase ) ) ;
158
+ yamlDataList = yamlDataList . concat ( await Parser . prepareIncludes ( gitlabCiLocalData , cwd , writeStreams , this . gitRemote , tabCompletionPhase ) ) ;
163
159
164
160
const gitlabData : any = deepExtend ( { } , ...yamlDataList ) ;
165
161
@@ -235,8 +231,10 @@ export class Parser {
235
231
async initJobs ( ) {
236
232
assert ( this . gitRemote != null , "GitRemote isn't set in parser initJobs function" ) ;
237
233
238
- const pipelineIid = this . pipelineIid ;
239
- const cwd = this . cwd ;
234
+ const writeStreams = this . opt . writeStreams ;
235
+ const pipelineIid = this . opt . pipelineIid ;
236
+ const cwd = this . opt . cwd ;
237
+ const extraHosts = this . opt . extraHosts || [ ] ;
240
238
const gitlabData = this . gitlabData ;
241
239
242
240
const gitUser = await Parser . initGitUser ( cwd ) ;
@@ -249,7 +247,8 @@ export class Parser {
249
247
250
248
const jobId = await state . getJobId ( cwd ) ;
251
249
const job = new Job ( {
252
- writeStreams : this . writeStreams ,
250
+ extraHosts,
251
+ writeStreams,
253
252
name : jobName ,
254
253
namePad : this . jobNamePad ,
255
254
homeVariables : this . homeVariables ,
0 commit comments