11// tslint:disable-next-line:file-name-casing
2+ import * as chalk from 'chalk'
23import * as fs from 'fs'
34
45import Logger from './logger'
@@ -7,7 +8,7 @@ export default class Utilities {
78 public static getStringFromFile ( thisRef : any , filePath : string ) {
89 let fileStr = ''
910 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
1112 } else {
1213 let fileBuffer = fs . readFileSync ( filePath )
1314 fileStr = fileBuffer . toString ( ) // by default utf8
@@ -16,7 +17,7 @@ export default class Utilities {
1617 }
1718 public static getJsonObjectFromFile ( thisRef : any , filePath : string ) {
1819 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
2021 } else {
2122 let jsonString = fs . readFileSync ( filePath , 'utf8' )
2223 try {
@@ -32,20 +33,21 @@ export default class Utilities {
3233 if ( flags . string ) //if -s given
3334 return flags . string
3435 else if ( flags . file ) {
35- Logger . info ( thisRef , `reading file: ${ flags . file } ` )
36+ Logger . info ( thisRef , `reading file: ${ chalk . green ( flags . file ) } ` )
3637 return Utilities . getStringFromFile ( thisRef , flags . file )
3738 } else
3839 return args . string
3940 }
4041
4142 public static writeStringToFile ( thisRef : any , filePath : string , string : string ) {
4243 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
4445 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
4647
4748 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}`
4951
5052 }
5153}
0 commit comments