@@ -5,7 +5,7 @@ var trace = require("./trace");
5
5
const deprecatedRunners = [ "Node6" , "Node10" , "Node16" ] ;
6
6
7
7
export interface TaskJson {
8
- id : string ;
8
+ id : string ;
9
9
}
10
10
11
11
/*
@@ -16,55 +16,55 @@ export interface TaskJson {
16
16
* @throws InvalidDirectoryException if json file doesn't exist, InvalidJsonException on failed parse or *first* invalid field in json
17
17
*/
18
18
export function validate ( jsonFilePath : string , jsonMissingErrorMessage ?: string ) : TaskJson {
19
- trace . debug ( "Validating task json..." ) ;
20
- var jsonMissingErrorMsg : string = jsonMissingErrorMessage || "specified json file does not exist." ;
21
- this . exists ( jsonFilePath , jsonMissingErrorMsg ) ;
19
+ trace . debug ( "Validating task json..." ) ;
20
+ var jsonMissingErrorMsg : string = jsonMissingErrorMessage || "specified json file does not exist." ;
21
+ this . exists ( jsonFilePath , jsonMissingErrorMsg ) ;
22
22
23
- var taskJson ;
24
- try {
25
- taskJson = require ( jsonFilePath ) ;
26
- } catch ( jsonError ) {
27
- trace . debug ( "Invalid task json: %s" , jsonError ) ;
28
- throw new Error ( "Invalid task json: " + jsonError ) ;
29
- }
23
+ var taskJson ;
24
+ try {
25
+ taskJson = require ( jsonFilePath ) ;
26
+ } catch ( jsonError ) {
27
+ trace . debug ( "Invalid task json: %s" , jsonError ) ;
28
+ throw new Error ( "Invalid task json: " + jsonError ) ;
29
+ }
30
30
31
- var issues : string [ ] = this . validateTask ( jsonFilePath , taskJson ) ;
32
- if ( issues . length > 0 ) {
33
- var output : string = "Invalid task json:" ;
34
- for ( var i = 0 ; i < issues . length ; i ++ ) {
35
- output += "\n\t" + issues [ i ] ;
36
- }
37
- trace . debug ( output ) ;
38
- throw new Error ( output ) ;
39
- }
31
+ var issues : string [ ] = this . validateTask ( jsonFilePath , taskJson ) ;
32
+ if ( issues . length > 0 ) {
33
+ var output : string = "Invalid task json:" ;
34
+ for ( var i = 0 ; i < issues . length ; i ++ ) {
35
+ output += "\n\t" + issues [ i ] ;
36
+ }
37
+ trace . debug ( output ) ;
38
+ throw new Error ( output ) ;
39
+ }
40
40
41
- trace . debug ( "Json is valid." ) ;
42
- validateRunner ( taskJson ) ;
43
- return taskJson ;
41
+ trace . debug ( "Json is valid." ) ;
42
+ validateRunner ( taskJson ) ;
43
+ return taskJson ;
44
44
}
45
45
46
46
/*
47
47
* Wrapper for fs.existsSync that includes a user-specified errorMessage in an InvalidDirectoryException
48
48
*/
49
49
export function exists ( path : string , errorMessage : string ) {
50
- if ( ! fs . existsSync ( path ) ) {
51
- trace . debug ( errorMessage ) ;
52
- throw new Error ( errorMessage ) ;
53
- }
50
+ if ( ! fs . existsSync ( path ) ) {
51
+ trace . debug ( errorMessage ) ;
52
+ throw new Error ( errorMessage ) ;
53
+ }
54
54
}
55
55
56
56
/*
57
57
* Validates a task against deprecated runner
58
58
* @param taskData the parsed json file
59
59
*/
60
60
export function validateRunner ( taskData : any ) {
61
- if ( taskData == undefined || taskData . execution == undefined )
62
- return
61
+ if ( taskData == undefined || taskData . execution == undefined )
62
+ return
63
63
64
- const validRunnerCount = Object . keys ( taskData . execution ) . filter ( itm => deprecatedRunners . indexOf ( itm ) == - 1 ) || 0 ;
65
- if ( validRunnerCount == 0 ) {
66
- trace . warn ( "Task %s is dependent on a task runner that is end-of-life and will be removed in the future. Authors should review Node upgrade guidance: https://aka.ms/node-runner-guidance." , taskData . name )
67
- }
64
+ const validRunnerCount = Object . keys ( taskData . execution ) . filter ( itm => deprecatedRunners . indexOf ( itm ) == - 1 ) || 0 ;
65
+ if ( validRunnerCount == 0 ) {
66
+ trace . warn ( "Task %s is dependent on a task runner that is end-of-life and will be removed in the future. Please visit https://aka.ms/node-runner-guidance to learn how to upgrade the task ." , taskData . name )
67
+ }
68
68
}
69
69
70
70
/*
@@ -74,23 +74,23 @@ export function validateRunner(taskData: any) {
74
74
* @return list of issues with the json file
75
75
*/
76
76
export function validateTask ( taskPath : string , taskData : any ) : string [ ] {
77
- var vn = taskData . name || taskPath ;
78
- var issues : string [ ] = [ ] ;
77
+ var vn = taskData . name || taskPath ;
78
+ var issues : string [ ] = [ ] ;
79
79
80
- if ( ! taskData . id || ! check . isUUID ( taskData . id ) ) {
81
- issues . push ( vn + ": id is a required guid" ) ;
82
- }
80
+ if ( ! taskData . id || ! check . isUUID ( taskData . id ) ) {
81
+ issues . push ( vn + ": id is a required guid" ) ;
82
+ }
83
83
84
- if ( ! taskData . name || ! check . matches ( taskData . name , / ^ [ A - Z a - z 0 - 9 \- ] + $ / ) ) {
85
- issues . push ( vn + ": name is a required alphanumeric string" ) ;
86
- }
84
+ if ( ! taskData . name || ! check . matches ( taskData . name , / ^ [ A - Z a - z 0 - 9 \- ] + $ / ) ) {
85
+ issues . push ( vn + ": name is a required alphanumeric string" ) ;
86
+ }
87
87
88
- if ( ! taskData . friendlyName || ! check . isLength ( taskData . friendlyName , 1 , 40 ) ) {
89
- issues . push ( vn + ": friendlyName is a required string <= 40 chars" ) ;
90
- }
88
+ if ( ! taskData . friendlyName || ! check . isLength ( taskData . friendlyName , 1 , 40 ) ) {
89
+ issues . push ( vn + ": friendlyName is a required string <= 40 chars" ) ;
90
+ }
91
91
92
- if ( ! taskData . instanceNameFormat ) {
93
- issues . push ( vn + ": instanceNameFormat is required" ) ;
94
- }
95
- return issues ;
92
+ if ( ! taskData . instanceNameFormat ) {
93
+ issues . push ( vn + ": instanceNameFormat is required" ) ;
94
+ }
95
+ return issues ;
96
96
}
0 commit comments