Skip to content

Instantly share code, notes, and snippets.

@taoyuan
Created October 28, 2018 15:47
Show Gist options
  • Save taoyuan/7782b709db494c6f0ffbc1452a6dd9c9 to your computer and use it in GitHub Desktop.
Save taoyuan/7782b709db494c6f0ffbc1452a6dd9c9 to your computer and use it in GitHub Desktop.
Pack the nodejs application using `pkg`
# Pack the nodejs application using `pkg` (https://github.com/zeit/pkg)
# dependencies: rimraf, cpx and pkg
# > npm i rimraf cpx pkg -D
.PHONY: init clean build
OS := $(shell uname)
ARCH := $(shell uname -p)
all: dist
init:
ifndef OS
@echo "Can not detect OS or not supported"
@exit 1
endif
ifeq ($(OS),Windows)
PLATFORM := win
endif
ifeq ($(OS),Darwin)
PLATFORM := macos
endif
ifeq ($(OS),Linux)
PLATFORM := linux
endif
ifndef PLATFORM
@echo "Platform $(OS) is not supported"
@exit 1
endif
DIST_PLATFORM := ./dist/$(PLATFORM)-$(ARCH)
clean:
npx rimraf lib dist
lib:
# build typescript
npm run build
build: clean lib
dist: init build
mkdir -p $(DIST_PLATFORM)
npx cpx "node_modules/**/*.node" $(DIST_PLATFORM)/node_modules
cp process.dist.yml $(DIST_PLATFORM)/process.yml
npx pkg . -o $(DIST_PLATFORM)/pinestd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment