Skip to content

Commit

Permalink
Tabs and code style
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 22, 2013
1 parent 9b55302 commit aa7f0b3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 41 deletions.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,3 +1,2 @@
node_modules
optipng/

3 changes: 1 addition & 2 deletions bin/optipng-bin
@@ -1,7 +1,6 @@
#!/usr/bin/env node

var spawn = require('child_process').spawn;
var binPath = require('../lib/optipng-bin').path;

spawn(binPath, process.argv.slice(2), { stdio: 'inherit' })
.on('exit', process.exit);
.on('exit', process.exit);
22 changes: 11 additions & 11 deletions lib/optipng-bin.js
Expand Up @@ -2,19 +2,19 @@ var path = require('path');
var execSync = require('exec-sync');

if (process.platform === 'darwin') {
var version = execSync('sw_vers -productVersion');
var version = execSync('sw_vers -productVersion');

if (/10.8/.test(version)) {
exports.path = path.join(__dirname, '../vendor/osx/10.8', 'optipng');
} else if (/10.7/.test(version)) {
exports.path = path.join(__dirname, '../vendor/osx/10.7', 'optipng');
}
if (/10.8/.test(version)) {
exports.path = path.join(__dirname, '../vendor/osx/10.8', 'optipng');
} else if (/10.7/.test(version)) {
exports.path = path.join(__dirname, '../vendor/osx/10.7', 'optipng');
}
} else if (process.platform === 'linux') {
if (process.arch === 'x64') {
exports.path = path.join(__dirname, '../vendor/linux/x64', 'optipng');
} else {
exports.path = path.join(__dirname, '../vendor/linux/x86', 'optipng');
}
if (process.arch === 'x64') {
exports.path = path.join(__dirname, '../vendor/linux/x64', 'optipng');
} else {
exports.path = path.join(__dirname, '../vendor/linux/x86', 'optipng');
}
} else if (process.platform === 'win32') {
exports.path = path.join(__dirname, '../vendor/win32', 'optipng.exe');
} else {
Expand Down
12 changes: 5 additions & 7 deletions rebuild-optipng.js
@@ -1,29 +1,27 @@
'use strict';
var exec = require('child_process').exec;
var colors = require('colors');
var binPath = require('./lib/optipng-bin.js').path;
var which = require('which');
var path = require('path');


which('make', function(err, makepath){
which('make', function (err) {
if (err) {
console.log(err.red);
return;
return console.log(err.red);
}

if (process.platform === 'darwin' || process.platform === 'linux') {
var binDir = path.dirname(binPath);
var buildScript = 'make clean &&' +
'./configure --with-system-zlib --bindir=' + binDir + ' --mandir=man && ' +
'make install';
exec(buildScript, {cwd: './optipng/'}, function(err, stdout, stderr) {
exec(buildScript, { cwd: './optipng/' }, function (err) {
if (err) {
console.log(err.red);
return;
return console.log(err.red);
}

console.log('OptiPNG rebuilt successfully'.green);
});
}
});

21 changes: 10 additions & 11 deletions test/test-optipng-build.js
@@ -1,19 +1,18 @@
/*global describe, it, after */
/*global describe, it */
'use strict';

var assert = require('assert');
var exec = require('child_process').exec;
var binPath = require('../lib/optipng-bin.js').path;
var fs = require('fs');

describe('OptiPNG rebuild', function() {
it('it should rebuild the optipng binaries', function(cb) {
this.timeout(15000); // give this test time to build
var origCTime = fs.statSync(binPath).ctime;
exec('node rebuild-optipng.js', {}, function(err){
var actualCTime = fs.statSync(binPath).ctime;
assert(actualCTime !== origCTime);
cb(err);
}).path;
describe('OptiPNG rebuild', function () {
it('it should rebuild the optipng binaries', function (cb) {
this.timeout(15000); // give this test time to build
var origCTime = fs.statSync(binPath).ctime;
exec('node rebuild-optipng.js', {}, function (err) {
var actualCTime = fs.statSync(binPath).ctime;
assert(actualCTime !== origCTime);
cb(err);
}).path;
});
});
17 changes: 8 additions & 9 deletions test/test-optipng-path.js
@@ -1,35 +1,34 @@
/*global describe, it, after */
'use strict';

var assert = require('assert');
var path = require('path');
var fs = require('fs');
var execFile = require('child_process').execFile;

describe('OptiPNG', function() {
after(function() {
describe('OptiPNG', function () {
after(function () {
fs.unlinkSync('test/minified.png');
});

it('should return path to OptiPNG binary', function(cb) {
it('should return path to OptiPNG binary', function (cb) {
var binPath = require('../lib/optipng-bin.js').path;

execFile(binPath, ['-v'], function(err, stdout) {
execFile(binPath, ['-v'], function (err, stdout) {
assert(stdout.indexOf('OptiPNG') !== -1);
cb();
});
});

it('should proxy OptiPNG', function(cb) {
it('should proxy OptiPNG', function (cb) {
var binPath = path.join(__dirname, '../bin/optipng-bin');

execFile(binPath, ['-v'], function(err, stdout) {
execFile(binPath, ['-v'], function (err, stdout) {
assert(stdout.indexOf('OptiPNG') !== -1);
cb();
});
});

it('should minify a .png', function(cb) {
it('should minify a .png', function (cb) {
var binPath = path.join(__dirname, '../bin/optipng-bin');
var args = [
'-strip',
Expand All @@ -39,7 +38,7 @@ describe('OptiPNG', function() {
path.join(__dirname, 'fixtures', 'test.png')
];

execFile(binPath, args, function() {
execFile(binPath, args, function () {
var actual = fs.statSync('test/minified.png').size;
var original = fs.statSync('test/fixtures/test.png').size;
assert(actual < original);
Expand Down

0 comments on commit aa7f0b3

Please sign in to comment.