-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·58 lines (48 loc) · 1.33 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env node
const chalk = require('chalk');
const clear = require('clear');
const figlet = require('figlet');
const pkgJson = require('./package.json');
const file = require('./lib/file');
const resizer = require('./lib/resizer');
argv = require('yargs')
.usage('Usage: $0 <command> [options]')
.command('webimgo', 'Batch width resize and optimise images')
.example('$0 optimg -w 500', 'Resize images width to 500px and optimise')
.alias('w', 'width')
.nargs('w', 1)
.describe('w', 'Provide resize width in pixels')
.number('width')
.help('h')
.alias('h', 'help')
.argv
clear();
console.log(
chalk.white(
figlet.textSync('WebIMGo', { horizontalLayout: 'full' })
)
);
console.log('\nVersion: ' + pkgJson.version + '\n');
const run = async () => {
try{
file.scanDir(process.cwd(),/\.(jpe?g|png)$/)
}
catch(err){
console.log('Error: '+ err)
}
if (file.imageFiles.length !=0){
if (argv.width && Number.isInteger(argv.width) && argv.width > 0){
resizer.doResizeAndOptimise(file.imageFiles, argv.width)
}
else if (argv.width == null){
resizer.runOptimisationOnly(file.imageFiles)
}
else{
console.log(chalk.yellowBright('Width provided is not a positive integer!'))
}
}
else {
console.log(chalk.yellowBright('No JPG/PNG files found!'))
}
}
run();