-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Saving progress: making a Makefile to handle building and publishing * Adding some platform specific builds and publishing commands to the Makefile; Adding directories for platform binary output * Changing package json bin location and adding a default bin created by makefile * Typo in Makefile * Adding a postinstall script to swap default bin with os viable bin * Fixing a couple typos * Got Makefile mostly working * Finished with Makefile * Adding a clean action to Makefile * Tweaking publish checks in Makefile * Adjusting optionalDeps versions
- Loading branch information
1 parent
d065548
commit 9de9bec
Showing
7 changed files
with
217 additions
and
3 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
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
VERSION := $(shell go run scripts/version.go) | ||
# Strip debug info (symbol table and DWARF) | ||
# Also add version info to binary | ||
GO_FLAGS += "-ldflags=-s -w -X 'github.com/ev-the-dev/tmplts/cmd.version=$(VERSION)'" | ||
|
||
# Avoid embedding build path in executable | ||
GO_FLAGS += -trimpath | ||
|
||
.PHONY version: | ||
version: | ||
@echo "Version: $(VERSION)" | ||
|
||
.PHONY clean: | ||
clean: | ||
rm -f npm/README.md npm/LICENSE &&\ | ||
rm -rf npm/bin | ||
|
||
cd npm/@tmplts && \ | ||
rm -rf \ | ||
darwin-arm64/bin \ | ||
darwin-x64/bin \ | ||
linux-x64/bin | ||
|
||
cd npm/@tmplts && \ | ||
rm -f\ | ||
darwin-arm64/README.md darwin-arm64/LICENSE \ | ||
darwin-x64/README.md darwin-x64/LICENSE \ | ||
linux-x64/README.md linux-x64/LICENSE | ||
|
||
.PHONY copy-files: | ||
copy-files: | ||
cp README.md LICENSE npm/ | ||
cp README.md LICENSE npm/@tmplts/darwin-arm64/ | ||
cp README.md LICENSE npm/@tmplts/darwin-x64/ | ||
cp README.md LICENSE npm/@tmplts/linux-x64/ | ||
|
||
############## | ||
# Publishing # | ||
############## | ||
.PHONY: publish-all | ||
publish-all: copy-files | ||
@echo "Attempting to publish all supported binaries..." | ||
@npm --version > /dev/null || (echo "The 'npm' command must be in your path to publish" && false) | ||
@echo "Checking for uncommitted & untracked changes..." && test -z "`git status --porcelain | grep -vE '(README\.md|LICENSE)'`" || \ | ||
(echo "Cannot publish with uncommited/untracked changes:" && \ | ||
git status --porcelain | grep -vE '(README\.md|LICENSE)' && false) | ||
@echo "Checking for main branch..." && test main = "`git rev-parse --abbrev-ref HEAD`" || \ | ||
(echo "Cannot publish from non-main branch `git rev-parse --abbrev-ref HEAD`" && false) | ||
@echo "Checking for unpushed commits..." && git fetch | ||
@test "" = "`git cherry`" || (echo "Cannot publish with unpushed commits" && false) | ||
|
||
@$(MAKE) --no-print-directory -j4 \ | ||
publish-default \ | ||
publish-darwin-arm64 \ | ||
publish-darwin-x64 \ | ||
publish-linux-x64 | ||
|
||
publish-default: platform-default | ||
cd npm && npm publish | ||
|
||
publish-darwin-arm64: platform-darwin-arm64 | ||
cd npm/@tmplts/darwin-arm64 && npm publish | ||
|
||
publish-darwin-x64: platform-darwin-x64 | ||
cd npm/@tmplts/darwin-x64 && npm publish | ||
|
||
publish-linux-x64: platform-linux-x64 | ||
cd npm/@tmplts/linux-x64 && npm publish | ||
|
||
|
||
################## | ||
# Platform Build # | ||
################## | ||
platform-unixlike: | ||
@test -n "$(GOOS)" || (echo "The environment variable GOOS must be provided" && false) | ||
@test -n "$(GOARCH)" || (echo "The environment variable GOARCH must be provided" && false) | ||
@test -n "$(NPMDIR)" || (echo "The environment variable NPMDIR must be provided" && false) | ||
CGO_ENABLED=0 GOOS="$(GOOS)" GOARCH="$(GOARCH)" go build $(GO_FLAGS) -o "$(NPMDIR)/bin/tmplts" | ||
|
||
platform-default: | ||
@$(MAKE) --no-print-directory GOOS=darwin GOARCH=arm64 NPMDIR=npm platform-unixlike | ||
|
||
platform-darwin-arm64: | ||
@$(MAKE) --no-print-directory GOOS=darwin GOARCH=arm64 NPMDIR=npm/@tmplts/darwin-arm64 platform-unixlike | ||
|
||
platform-darwin-x64: | ||
@$(MAKE) --no-print-directory GOOS=darwin GOARCH=amd64 NPMDIR=npm/@tmplts/darwin-x64 platform-unixlike | ||
|
||
platform-linux-x64: | ||
@$(MAKE) --no-print-directory GOOS=linux GOARCH=amd64 NPMDIR=npm/@tmplts/linux-x64 platform-unixlike |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@tmplts/darwin-arm64", | ||
"author": "ev-the-dev", | ||
"version": "0.1.1", | ||
"description": "MacOS ARM 64-bit (Mac Silicon) binary for TmplTS", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ev-the-dev/tmplts.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"os": [ | ||
"darwin" | ||
], | ||
"cpu": [ | ||
"arm64" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@tmplts/darwin-x64", | ||
"author": "ev-the-dev", | ||
"version": "0.1.1", | ||
"description": "MacOS AMD 64-bit (Intel) binary for TmplTS", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ev-the-dev/tmplts.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"os": [ | ||
"darwin" | ||
], | ||
"cpu": [ | ||
"x64" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@tmplts/linux-x64", | ||
"author": "ev-the-dev", | ||
"version": "0.1.1", | ||
"description": "Linux 64-bit (Intel) binary for TmplTS", | ||
"license": "Apache-2.0", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/ev-the-dev/tmplts.git" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"os": [ | ||
"linux" | ||
], | ||
"cpu": [ | ||
"x64" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const fs = require("fs") | ||
const os = require("os") | ||
const path = require("path") | ||
|
||
const supportedUnixLikePackages = { | ||
"darwin arm64 LE": "@tmplts/darwin-arm64", | ||
"darwin x64 LE": "@tmplts/darwin-x64", | ||
"linux x64 LE": "@tmplts/linux-x64" | ||
} | ||
|
||
function getPkgAndPathForPlatform() { | ||
const platformKey = `${process.platform} ${os.arch()} ${os.endianness()}` | ||
const pkgPath = supportedUnixLikePackages[platformKey] | ||
|
||
if(!pkgPath) { | ||
throw new Error(`Unsupported OS: ${platformKey}`) | ||
} | ||
|
||
return pkgPath | ||
} | ||
|
||
function main() { | ||
const pkgPath = getPkgAndPathForPlatform() | ||
const binSubPath = "bin/tmplts" | ||
|
||
const binFullPath = require.resolve(`${pkgPath}/${binSubPath}`) | ||
const tempPath = path.join(__dirname, "bin-tmplts") | ||
try { | ||
/* | ||
* First: linking binary with temp file. | ||
*/ | ||
fs.linkSync(binFullPath, tempPath) | ||
|
||
/* | ||
* Second: rename to atomically replace target file with temp file | ||
*/ | ||
fs.renameSync(tempPath, path.join(__dirname, "bin", "tmplts")) | ||
|
||
/* | ||
* Third: Remove temp file if it still exists | ||
*/ | ||
if(fs.existsSync(tempPath)){ | ||
fs.unlinkSync(tempPath) | ||
} | ||
} catch (e) { | ||
console.error("Failed to swap out default binary with platform compatible one:\nERROR:", e) | ||
} | ||
} | ||
|
||
main() |
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