-
Notifications
You must be signed in to change notification settings - Fork 4
/
install-pngcrush.js
executable file
·57 lines (47 loc) · 1.51 KB
/
install-pngcrush.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
/*global require:true*/
/*global console:true*/
/*global process:true*/
(function(){
"use strict";
var os = require( 'os' );
var which = require( 'which' ),
pngc, pci, data, url, isWin, isWin64;
// Credit to Obvious Corp for finding this fix.
var originalPath = process.env.PATH;
// NPM adds bin directories to the path, which will cause `which` to find the
// bin for this package not the actual pngcrush bin.
process.env.PATH = originalPath.replace(/:[^:]*node_modules[^:]*/g, '');
isWin = os.platform() === "win32";
isWin64 = isWin && (os.arch() === "x64");
// try {
// pngc = which.sync( "pngcrush" );
// if( pngc ){
// console.log( "PNGCrush already installed!" );
// process.exit();
// }
//} catch( e ){
pci = require( "./lib/pngcrush-installer" );
var install = function(isWin, isWin64, archived){
url = pci.getFileURL( isWin, isWin64, archived );
pci.downloadAndSave( url )
.then( pci.build )
.then( pci.move )
.then( pci.deleteTemp )
.then( function( _null , err ){
if( err ){
console.log( err );
process.exit(1);
}
process.exit(0);
}).on( 'error' , function( err ) {
if ( err.detail == '404 - File not found' && !archived ) {
install( isWin, isWin64, true );
} else {
console.log("An error occurred: " + err.detail);
process.exit(1);
}
});
};
install( isWin, isWin64, false );
//}
}());