-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.