1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
1
/* eslint-disable @typescript-eslint/no-use-before-define */
3
2
import commander from "commander" ;
4
3
import fs from "fs" ;
@@ -31,9 +30,9 @@ interface CommandOptions {
31
30
}
32
31
33
32
export interface SourceInformation {
34
- source ? : string ;
35
- template ? : string ;
36
- version ? : string ;
33
+ source : string ;
34
+ template : string ;
35
+ version : string ;
37
36
}
38
37
39
38
export enum DefinitionYAMLExistence {
@@ -57,6 +56,8 @@ export const execute = async (
57
56
parentPath ,
58
57
projectPath
59
58
) ;
59
+ // validateTemplateSources makes sure that
60
+ // sourceConfig has values for source, template and version
60
61
await validateRemoteSource ( sourceConfig ) ;
61
62
await generateConfig (
62
63
parentPath ,
@@ -142,7 +143,11 @@ export const validateTemplateSources = (
142
143
const sourceKeys = [ "source" , "template" , "version" ] as Array <
143
144
keyof SourceInformation
144
145
> ;
145
- const source : SourceInformation = { } ;
146
+ const source : SourceInformation = {
147
+ source : "" ,
148
+ template : "" ,
149
+ version : "" ,
150
+ } ;
146
151
let parentInfraConfig : InfraConfigYaml ;
147
152
let leafInfraConfig : InfraConfigYaml ;
148
153
@@ -163,18 +168,18 @@ export const validateTemplateSources = (
163
168
source [ k ] = parentInfraConfig [ k ] ;
164
169
}
165
170
} ) ;
166
- if ( ! source . source || ! source . template || ! source . version ) {
167
- throw new Error (
168
- `The ${ DEFINITION_YAML } file is invalid. \
169
- There is a missing field for it's sources. \
170
- Template: ${ source . template } source: ${ source . source } version: ${ source . version } `
171
+ if ( source . source && source . template && source . version ) {
172
+ const safeLoggingUrl = safeGitUrlForLogging ( source . source ) ;
173
+ logger . info (
174
+ `Checking for locally stored template: ${ source . template } from remote repository: ${ safeLoggingUrl } at version: ${ source . version } `
171
175
) ;
176
+ return source ;
172
177
}
173
- const safeLoggingUrl = safeGitUrlForLogging ( source . source ! ) ;
174
- logger . info (
175
- `Checking for locally stored template: ${ source . template } from remote repository: ${ safeLoggingUrl } at version: ${ source . version } `
178
+ throw new Error (
179
+ `The ${ DEFINITION_YAML } file is invalid. \
180
+ There is a missing field for it's sources. \
181
+ Template: ${ source . template } source: ${ source . source } version: ${ source . version } `
176
182
) ;
177
- return source ;
178
183
} ;
179
184
180
185
export const checkRemoteGitExist = async (
@@ -226,8 +231,8 @@ export const gitCheckout = async (
226
231
export const validateRemoteSource = async (
227
232
sourceConfig : SourceInformation
228
233
) : Promise < void > => {
229
- const source = sourceConfig . source ! ;
230
- const version = sourceConfig . version ! ;
234
+ const source = sourceConfig . source ;
235
+ const version = sourceConfig . version ;
231
236
232
237
// Converting source name to storable folder name
233
238
const sourceFolder = getSourceFolderNameFromURL ( source ) ;
@@ -378,11 +383,11 @@ export const generateConfig = async (
378
383
outputPath : string
379
384
) : Promise < void > => {
380
385
const parentDirectory = getParentGeneratedFolder ( parentPath , outputPath ) ;
381
- const sourceFolder = getSourceFolderNameFromURL ( sourceConfig . source ! ) ;
386
+ const sourceFolder = getSourceFolderNameFromURL ( sourceConfig . source ) ;
382
387
const templatePath = path . join (
383
388
spkTemplatesPath ,
384
389
sourceFolder ,
385
- sourceConfig . template !
390
+ sourceConfig . template
386
391
) ;
387
392
const childDirectory =
388
393
projectPath === parentPath
@@ -405,7 +410,9 @@ export const generateConfig = async (
405
410
}
406
411
407
412
combineVariable (
413
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
408
414
parentInfraConfig . variables ! ,
415
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
409
416
leafInfraConfig . variables ! ,
410
417
childDirectory ,
411
418
SPK_TFVARS
0 commit comments