Skip to content

Commit f8a881d

Browse files
committed
[MINIFY]: added
Signed-off-by: ashish <[email protected]>
1 parent 499e4c2 commit f8a881d

File tree

5 files changed

+113
-3
lines changed

5 files changed

+113
-3
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ USAGE
3131
* [`cdt crypto [STRING]`](#cdt-crypto-string)
3232
* [`cdt hash [STRING]`](#cdt-hash-string)
3333
* [`cdt help [COMMAND]`](#cdt-help-command)
34+
* [`cdt minify [FILE]`](#cdt-minify-file)
3435

3536
## `cdt crypto [STRING]`
3637

@@ -64,7 +65,7 @@ OPTIONS
6465
-f, --file=file file to be hashed
6566
-h, --help show CLI help
6667
-s, --string=string string to be hashed
67-
-t, --type=type type of hash [SHA1(default),MD5,SHA256,SHA512,RMD160]
68+
-t, --type=type type of hash [SHA1(default), MD5, SHA256, SHA512, RMD160 or RIPEMD160]
6869
```
6970

7071
_See code: [src/commands/hash.ts](https://github.com/codingtools/cdt/blob/v0.0.1/src/commands/hash.ts)_
@@ -85,4 +86,20 @@ OPTIONS
8586
```
8687

8788
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v2.2.1/src/commands/help.ts)_
89+
90+
## `cdt minify [FILE]`
91+
92+
describe the command here
93+
94+
```
95+
USAGE
96+
$ cdt minify [FILE]
97+
98+
OPTIONS
99+
-f, --force
100+
-h, --help show CLI help
101+
-n, --name=name name to print
102+
```
103+
104+
_See code: [src/commands/minify.ts](https://github.com/codingtools/cdt/blob/v0.0.1/src/commands/minify.ts)_
88105
<!-- commandsstop -->

src/commands/crypto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Hash from './hash'
88
export default class Crypto extends Command {
99
static ENCRYPTION = 'encryption'
1010
static DECRYPTION = 'decryption'
11-
static description = 'Encryption and Decryption functionality'
11+
static description = 'Encryption and Decryption functionality for File/String'
1212
static flags = {
1313
help: flags.help({char: 'h'}),
1414

src/commands/hash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Utilities from '../utilities/utilities'
77
// TODO: all are Hexadecimal encoding for now, can also add b64
88

99
export default class Hash extends Command {
10-
static description = 'create hash for a string/file'
10+
static description = 'Hashing functionality for a string/file'
1111

1212
static flags = {
1313
help: flags.help({char: 'h'}),

src/commands/minify.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import {Command, flags} from '@oclif/command'
2+
3+
import Logger from '../utilities/logger'
4+
import Utilities from '../utilities/utilities'
5+
6+
export default class Minify extends Command {
7+
static description = 'File Minifier'
8+
9+
static flags = {
10+
help: flags.help({char: 'h'}),
11+
type: flags.string({char: 't' , description: 'type of file to be minified, it will try to find type with extension'}),
12+
file: flags.string({char: 'f' , description: 'file to be minified'}),
13+
}
14+
15+
static args = [{name: 'file'}]
16+
17+
static JS = 'JS'
18+
static HTML = 'HTML'
19+
static CSS = 'CSS'
20+
21+
// required FILE
22+
async run() {
23+
const {args, flags} = this.parse(Minify)
24+
25+
args.file = this.getFilePath(flags, args)
26+
args.string = this.getFileString(args)
27+
flags.type = this.getFileType(flags, args)
28+
29+
// this.checkParameters(flags, args)
30+
31+
}
32+
33+
// this will get file type either from flags.type or file extension ( if flag is not given)
34+
private getFileType(flags: any, args: any) {
35+
if (flags.type) //if type is given
36+
return this.getFileTypeFromExtension(flags.type)
37+
38+
let fileExtensionRegex = /\w+\.([a-z]+)/
39+
40+
args.s
41+
42+
}
43+
44+
private getFileTypeFromExtension(extension: string) {
45+
switch (extension.toUpperCase()) {
46+
case 'JS': case 'JAVASCRIPT':
47+
return Minify.JS
48+
case 'CSS':
49+
return Minify.CSS
50+
case 'HTML': case 'HTM':
51+
return Minify.HTML
52+
default:
53+
Logger.error(this, 'Invalid File Type')
54+
}
55+
}
56+
57+
// get filepath from args or flags ( if args not have file name )
58+
// this will get file path into args.file either from args or flags
59+
private getFileString(args: any) {
60+
return Utilities.getStringFromFile(this, args.file)
61+
}
62+
63+
private getFilePath(flags: any, args: any) {
64+
if (args.file)
65+
return args.file
66+
if (flags.file)
67+
return flags.file
68+
Logger.error(this, 'File path not passed')
69+
}
70+
71+
// private checkParameters(flags: unknown, args: { [p: string]: any }) {
72+
// if(validFileType)
73+
// }
74+
}

test/commands/minify.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import {expect, test} from '@oclif/test'
2+
3+
describe('minify', () => {
4+
test
5+
.stdout()
6+
.command(['minify', '-t', 'js'])
7+
.exit(0)
8+
.it('File path not passed', ctx => {
9+
expect(ctx.stdout).to.contain('File path not passed')
10+
})
11+
12+
test
13+
.stdout()
14+
.command(['minify', 'test/resources/test.txt'])
15+
.exit(0)
16+
.it('Invalid File Type', ctx => {
17+
expect(ctx.stdout).to.contain('Invalid File Type')
18+
})
19+
})

0 commit comments

Comments
 (0)