Skip to content

Commit

Permalink
Package binaries for various architectures to gem and npm packages (#168
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Envek authored Apr 23, 2021
1 parent 065b24f commit 7b44ebf
Show file tree
Hide file tree
Showing 26 changed files with 64 additions and 33 deletions.
47 changes: 38 additions & 9 deletions .npm/bin/lefthook
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,50 @@

dir="$(cd "$(dirname "$0")" >/dev/null 2>&1 || exit ; pwd -P)"

UNAME=$(uname)
case "$UNAME" in
OS=$(uname -s)
ARCH=$(uname -m)
EXT=

# Detect OS
case $OS in
Linux)
"$dir/lefthook-linux" "$@"
GOOS=linux
;;
Darwin)
"$dir/lefthook-mac" "$@"
GOOS=darwin
;;
Windows*|CYGWIN*)
GOOS=windows
EXT=.exe
;;
Windows*)
"$dir/lefthook-win.exe" "$@"
*)
echo "Unsupported OS: ${OS}"
exit 1
;;
CYGWIN*)
"$dir/lefthook-win.exe" "$@"
esac

# Detect architecture
case $ARCH in
x86_64)
GOARCH=amd64
;;
x86)
GOARCH=386
;;
arm64)
GOOS=arm64
;;
*)
echo "Unsupported OS"
echo "Unsupported CPU architecture: ${ARCH}"
exit 1
;;
esac

executable="$dir/lefthook_${GOOS}_${GOARCH}/lefthook${EXT}"

if [ -x "$executable" ]; then
exec "$executable" "$@"
else
echo "Lefthook wasn't build for ${OS} ${ARCH}"
exit 1
fi
Binary file removed .npm/bin/lefthook-linux
Binary file not shown.
Binary file removed .npm/bin/lefthook-mac
Binary file not shown.
Binary file removed .npm/bin/lefthook-win.exe
Binary file not shown.
Binary file added .npm/bin/lefthook_darwin_amd64/lefthook
Binary file not shown.
Binary file added .npm/bin/lefthook_darwin_arm64/lefthook
Binary file not shown.
Binary file added .npm/bin/lefthook_linux_386/lefthook
Binary file not shown.
Binary file added .npm/bin/lefthook_linux_amd64/lefthook
Binary file not shown.
Binary file added .npm/bin/lefthook_linux_arm64/lefthook
Binary file not shown.
Binary file added .npm/bin/lefthook_windows_386/lefthook.exe
Binary file not shown.
Binary file added .npm/bin/lefthook_windows_amd64/lefthook.exe
Binary file not shown.
7 changes: 6 additions & 1 deletion .npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@arkweid/lefthook",
"version": "0.7.2",
"version": "0.7.3",
"description": "Simple git hooks manager",
"main": "index.js",
"bin": {
Expand All @@ -23,6 +23,11 @@
"linux",
"win32"
],
"cpu": [
"x64",
"arm64",
"x32"
],
"scripts": {
"postinstall": "node postinstall.js"
}
Expand Down
13 changes: 1 addition & 12 deletions .npm/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,7 @@ const { join } = require("path");
const isCI = process.env.CI;

if (!isCI) {
if (process.platform === 'darwin') {
binary = 'lefthook-mac';
} else if (process.platform === 'linux') {
binary = 'lefthook-linux';
} else if (process.platform === 'win32') {
binary = 'lefthook-win.exe';
} else {
console.log("Unsupported OS");
process.exit(0);
}

binpath = join(__dirname, 'bin', binary);
binpath = join(__dirname, 'bin', 'lefthook');

result = spawn(binpath, ["install", "-f"], {
cwd: process.env.INIT_CWD,
Expand Down
27 changes: 17 additions & 10 deletions .rubygems/bin/lefthook
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
#!/usr/bin/env ruby

binary = case RUBY_PLATFORM
when /linux/
'lefthook-linux'
when /darwin/
'lefthook-mac'
when /windows/
'lefthook-win.exe'
else
raise "Invalid platform."
end
require "rubygems"

platform = Gem::Platform.new(RUBY_PLATFORM)
arch =
case platform.cpu.sub(/\Auniversal\./, '')
when /\Aarm64/ then "arm64" # Apple reports arm64e on M1 macs
when "x86_64" then "amd64"
when "x86" then "386"
else raise "Unknown architecture: #{platform.os}"
end

binary = "lefthook_#{platform.os}_#{arch}/lefthook"
binary = "#{binary}.exe" if platform.os == "windows"

args = $*.map { |x| x.include?(' ') ? "'" + x + "'" : x }
cmd = File.expand_path "#{File.dirname(__FILE__)}/../libexec/#{binary}"

unless File.exists?(cmd)
raise "Invalid platform. Lefthook wasn't build for #{RUBY_PLATFORM}"
end

puts "#{cmd} #{args.join(' ')}"

pid = spawn("#{cmd} #{args.join(' ')}")
Expand Down
2 changes: 1 addition & 1 deletion .rubygems/lefthook.gemspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "lefthook"
spec.version = "0.7.2"
spec.version = "0.7.3"
spec.authors = ["A.A.Abroskin"]
spec.email = ["[email protected]"]

Expand Down
Loading

0 comments on commit 7b44ebf

Please sign in to comment.