@@ -6,10 +6,10 @@ import fs = require("fs");
66
77export class Utility {
88
9- public static async getScriptPath ( scriptLocation :string , fileExtensions :string [ ] ) : Promise < string > {
9+ public static async getScriptPath ( scriptLocation : string , fileExtensions : string [ ] ) : Promise < string > {
1010 if ( scriptLocation === "scriptPath" ) {
1111 let filePath : string = tl . getPathInput ( "scriptPath" , true , true ) ;
12- if ( Utility . checkIfFileExists ( filePath , fileExtensions ) ) {
12+ if ( Utility . checkIfFileExists ( filePath , fileExtensions ) ) {
1313 return filePath ;
1414 }
1515 throw new Error ( tl . loc ( 'JS_InvalidFilePath' , filePath ) ) ;
@@ -33,14 +33,18 @@ export class Utility {
3333 }
3434
3535 let contents : string [ ] = [ ] ;
36- contents . push ( `$ErrorActionPreference = '${ powerShellErrorActionPreference } '` ) ;
36+ contents . push ( `$ErrorActionPreference = '${ powerShellErrorActionPreference } '` ) ;
3737
3838 if ( scriptLocation === "scriptPath" ) {
3939 let filePath : string = tl . getPathInput ( "scriptPath" , true , true ) ;
40- if ( Utility . checkIfFileExists ( filePath , fileExtensions ) ) {
41- contents . push ( `. '${ filePath . replace ( "'" , "''" ) } ' ${ scriptArguments } ` . trim ( ) ) ;
40+ if ( Utility . checkIfFileExists ( filePath , fileExtensions ) ) {
41+ let content : string = `. '${ filePath . replace ( "'" , "''" ) } ' ` ;
42+ if ( scriptArguments ) {
43+ content += scriptArguments ;
44+ }
45+ contents . push ( content . trim ( ) ) ;
4246 }
43- else {
47+ else {
4448 throw new Error ( tl . loc ( 'JS_InvalidFilePath' , filePath ) ) ;
4549 }
4650 }
@@ -64,7 +68,7 @@ export class Utility {
6468 tl . checkPath ( tempDirectory , `${ tempDirectory } (agent.tempDirectory)` ) ;
6569 let scriptPath : string = path . join ( tempDirectory , `azureclitaskscript${ new Date ( ) . getTime ( ) } .${ fileExtensions [ 0 ] } ` ) ;
6670
67- await Utility . createFile ( scriptPath , '\ufeff' + contents . join ( os . EOL ) , { encoding : 'utf8' } ) ;
71+ await Utility . createFile ( scriptPath , '\ufeff' + contents . join ( os . EOL ) , { encoding : 'utf8' } ) ;
6872 return scriptPath ;
6973 }
7074
@@ -82,7 +86,7 @@ export class Utility {
8286 }
8387 }
8488
85- public static async createFile ( filePath : string , data : string , options ?:any ) : Promise < void > {
89+ public static async createFile ( filePath : string , data : string , options ?: any ) : Promise < void > {
8690 try {
8791 fs . writeFileSync ( filePath , data , options ) ;
8892 }
@@ -93,12 +97,12 @@ export class Utility {
9397 }
9498
9599 public static checkIfFileExists ( filePath : string , fileExtensions : string [ ] ) : boolean {
96- let matchingFiles :string [ ] = fileExtensions . filter ( ( fileExtension :string ) => {
100+ let matchingFiles : string [ ] = fileExtensions . filter ( ( fileExtension : string ) => {
97101 if ( tl . stats ( filePath ) . isFile ( ) && filePath . toUpperCase ( ) . match ( new RegExp ( `\.${ fileExtension . toUpperCase ( ) } $` ) ) ) {
98102 return true ;
99103 }
100104 } ) ;
101- if ( matchingFiles . length > 0 ) {
105+ if ( matchingFiles . length > 0 ) {
102106 return true ;
103107 }
104108 return false ;
0 commit comments