Skip to content

Commit

Permalink
chore: Add arm64 linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
tkwiatek committed Jul 4, 2023
1 parent 8f19248 commit 8e190b4
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
71 changes: 56 additions & 15 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,62 @@
import { spawn } from 'child_process';
import fs from 'node:fs';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import BinWrapper from 'bin-wrapper';


const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
const url = `https://raw.githubusercontent.com/imagemin/optipng-bin/v${pkg.version}/vendor/`;
const url = `https://raw.githubusercontent.com/imagemin/optipng-bin/v${pkg.version}/vendor`;

function getArch() {
switch (process.arch) {
case 'x32':
return 'x86';
case 'x64':
return 'x64'
case 'arm':
return 'arm';
case 'arm64':
return 'arm64';
default:
return null;
}
}

function getPlatform() {
switch (process.platform) {
case 'darwin':
return 'macos';
case 'freebsd':
return 'freebsd'
case 'linux':
return 'linux';
case 'sunos':
return 'sunos';
case 'win32':
return 'win';
default:
return null;
}
}

const binWrapper = new BinWrapper()
.src(`${url}macos/optipng`, 'darwin')
.src(`${url}linux/x86/optipng`, 'linux', 'x86')
.src(`${url}linux/x64/optipng`, 'linux', 'x64')
.src(`${url}freebsd/x86/optipng`, 'freebsd', 'x86')
.src(`${url}freebsd/x64/optipng`, 'freebsd', 'x64')
.src(`${url}sunos/x86/optipng`, 'sunos', 'x86')
.src(`${url}sunos/x64/optipng`, 'sunos', 'x64')
.src(`${url}win/optipng.exe`, 'win32')
.dest(fileURLToPath(new URL('../vendor', import.meta.url)))
.use(process.platform === 'win32' ? 'optipng.exe' : 'optipng');
const lib = {
path: function () {
const arch = getArch();
const platform = getPlatform();
if (!arch || !platform) {
return null;
}
const url = './vendor'
return platform == 'win'
? `${url}/${platform}/optipng.exe`
: `${url}/${platform}/${arch}/optipng`
},
dest: function () {
console.log('meta', import.meta.url);
return import.meta.url;
},
run: function (args) {
return spawn(this.path(), args);
}
}

export default binWrapper;
export default lib;
3 changes: 2 additions & 1 deletion lib/install.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import { fileURLToPath } from 'node:url';
import binBuild from 'bin-build';
import bin from './index.js';


(async () => {
try {
await bin.run(['--version']);
Expand Down
Binary file added vendor/linux/arm64/optipng
Binary file not shown.

0 comments on commit 8e190b4

Please sign in to comment.