'use strict';
const BinBuild = require('bin-build');
const log = require('logalot');
const bin = require('.');

bin.run(['--help'], err => {
	if (err) {
		log.warn(err.message);
		log.warn('zopflipng pre-build test failed');
		log.info('compiling from source');

		let makeBin = 'make';
		let makeArgs = '';

		if (process.platform === 'freebsd') {
			makeBin = 'gmake';
			makeArgs = 'CC=cc CXX=c++';
		}

		const builder = new BinBuild()
			.src('https://github.com/google/zopfli/archive/6818a0859063b946094fb6f94732836404a0d89a.zip')
			.cmd(`mkdir -p ${bin.dest()}`)
			.cmd(`${makeBin} zopflipng ${makeArgs} && mv ./zopflipng ${bin.path()}`);

		return builder.run(err => {
			if (err) {
				log.error(err.stack);
				return;
			}

			log.success('zopflipng built successfully');
		});
	}

	log.success('zopflipng pre-build test passed successfully');
});

@@ -488,47 +488,47 @@
 ve/6
-818a0859063b946094fb6f94732836404a0d89a
+4c6f362fefd56dccbf31906fdb3e31f6a6faf80
 .zip

Update zopfli binary URL to the latest commit