Skip to content

Commit 592d901

Browse files
committed
[ISSUE#21]: minified added
Signed-off-by: ashish <[email protected]> Signed-off-by: ashish <[email protected]>
1 parent 3780d76 commit 592d901

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/commands/minify.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export default class Minify extends Command {
1212
help: flags.help({char: 'h'}),
1313
type: flags.string({char: 't' , description: 'type of file to be minified, it will try to find type with extension supported: JS, HTML/HTM, CSS'}),
1414
file: flags.string({char: 'f' , description: 'file to be minified'}),
15+
outputFile: flags.string({char: 'o' , description: 'output file path'}),
1516
}
1617

1718
static args = [{name: 'file'}]
@@ -96,9 +97,12 @@ export default class Minify extends Command {
9697
default:
9798
Logger.error(this, 'Invalid Minifier Type')
9899
}
99-
Logger.progressStop(this, 'minified')
100+
Logger.progressStop(this, `file: ${flags.file} minified`)
100101
// }, 1000)
101-
Logger.success(this, `\n${output}`)
102102

103+
if (flags.outputFile) { // if output path is provided then write to file also
104+
Utilities.writeStringToFile(this, flags.outputFile, output)
105+
} else
106+
Logger.success(this, `minified output: \n${output}`)
103107
}
104108
}

src/utilities/utilities.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// tslint:disable-next-line:file-name-casing
2+
import * as chalk from 'chalk'
23
import * as fs from 'fs'
34

45
import 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

Comments
 (0)