1
1
// tslint:disable-next-line:file-name-casing
2
+ import * as chalk from 'chalk'
2
3
import * as fs from 'fs'
3
4
4
5
import Logger from './logger'
@@ -7,7 +8,7 @@ export default class Utilities {
7
8
public static getStringFromFile ( thisRef : any , filePath : string ) {
8
9
let fileStr = ''
9
10
if ( ! fs . existsSync ( filePath ) ) {
10
- Logger . error ( thisRef , `Could not find file: ${ filePath } ` ) // this will output error and exit command
11
+ Logger . error ( thisRef , `Could not find file: ${ chalk . red ( filePath ) } ` ) // this will output error and exit command
11
12
} else {
12
13
let fileBuffer = fs . readFileSync ( filePath )
13
14
fileStr = fileBuffer . toString ( ) // by default utf8
@@ -16,7 +17,7 @@ export default class Utilities {
16
17
}
17
18
public static getJsonObjectFromFile ( thisRef : any , filePath : string ) {
18
19
if ( ! fs . existsSync ( filePath ) ) {
19
- Logger . error ( thisRef , `Could not find file: ${ filePath } ` ) // this will output error and exit command
20
+ Logger . error ( thisRef , `Could not find file: ${ chalk . red ( filePath ) } ` ) // this will output error and exit command
20
21
} else {
21
22
let jsonString = fs . readFileSync ( filePath , 'utf8' )
22
23
try {
@@ -32,20 +33,21 @@ export default class Utilities {
32
33
if ( flags . string ) //if -s given
33
34
return flags . string
34
35
else if ( flags . file ) {
35
- Logger . info ( thisRef , `reading file: ${ flags . file } ` )
36
+ Logger . info ( thisRef , `reading file: ${ chalk . green ( flags . file ) } ` )
36
37
return Utilities . getStringFromFile ( thisRef , flags . file )
37
38
} else
38
39
return args . string
39
40
}
40
41
41
42
public static writeStringToFile ( thisRef : any , filePath : string , string : string ) {
42
43
if ( ! fs . existsSync ( filePath ) )
43
- Logger . info ( thisRef , `Could not find file: ${ filePath } , creating new one` ) // this will output error and exit command
44
+ Logger . info ( thisRef , `Could not find file: ${ chalk . yellow ( filePath + ' , creating new one' ) } ` ) // this will output error and exit command
44
45
else
45
- Logger . info ( thisRef , `File already exists: ${ filePath } , overriding content` ) // this will output error and exit command
46
+ Logger . warn ( thisRef , `File already exists: ${ chalk . green ( filePath ) } , ${ chalk . yellow ( ' overriding content' ) } ` ) // this will output error and exit command
46
47
47
48
fs . writeFileSync ( filePath , string )
48
- Logger . success ( thisRef , `Hash written to file: ${ filePath } ` ) // this will output error and exit command
49
+ Logger . success ( thisRef , `output written to file: ${ chalk . green ( filePath ) } ` ) // this will output error and exit command
50
+ // return `${chalk.red(pkg)} ${message}`
49
51
50
52
}
51
53
}
0 commit comments