e68500e33b5821a2dc5d9f5876949b7d3ac28d9f
1 import chalk from
'chalk';
2 import logger from
'./Logger';
4 export default class FileUtils
{
5 static handleFileException(logPrefix
: string, fileType
: string, filePath
: string, error
: NodeJS
.ErrnoException
, consoleOut
= false): void {
6 const prefix
= logPrefix
.length
!== 0 ? logPrefix
+ ' ' : '';
7 if (error
.code
=== 'ENOENT') {
9 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' not found: '), error
);
11 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' not found: %j', error
);
13 } else if (error
.code
=== 'EEXIST') {
15 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' already exists: '), error
);
17 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' already exists: %j', error
);
19 } else if (error
.code
=== 'EACCES') {
21 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' access denied: '), error
);
23 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' access denied: %j', error
);
27 console
.warn(chalk
.green(prefix
) + chalk
.yellow(fileType
+ ' file ' + filePath
+ ' error: '), error
);
29 logger
.warn(prefix
+ fileType
+ ' file ' + filePath
+ ' error: %j', error
);