-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·59 lines (51 loc) · 1.59 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
59
#! /usr/bin/env node
/*
LazyLoad Commands
watch: watches directory and automatically creates resized replicas of new images
create: manually resize image at desired widths
*/
var lazyset = require('commander'); // to easily parse input
var pkg = require('./package.json'); // to access package information
var watcher = require('./watcher');
var resize = require('./resize');
var log = console.log.bind(console);
function missingWidth() {
log('What sizes do you want? e.g. --width 400,700,1200');
process.exit();
}
lazyset
.version(pkg.version)
.usage('[subcommand] [options]')
lazyset
.command('watch <dir>')
.description('watch directory and automically resize any new images')
.option('-w, --width [width]')
.option('-q, --quality [quality]')
.action(function (dir, ops) {
if (ops.width == undefined) {
missingWidth();
}
else {
var widths = ops.width.split(',');
log('Start writing, I\'ll take care of the images');
watcher(dir, widths,parseInt(ops.quality));
}
});
lazyset
.command('create <path>')
.description('manually resize chosen image')
.option('-w, --width [width]')
.option('-q, --quality [quality]')
.action(function (path, ops) {
if (ops.width == undefined) {
missingWidth();
}
else {
var dir = path.substring(0, path.lastIndexOf("/")+1);
var file = path.split('/').pop();
var widths = ops.width.split(',');
log('Resized images coming right up!');
resize.createImg(dir, file, widths,parseInt(ops.quality));
}
});
lazyset.parse(process.argv);