Skip to content

Commit

Permalink
chore: make use of pkg to package the Etcher CLI
Browse files Browse the repository at this point in the history
This commit replaces our home-grown CLI packaging mechanism based on
browserify + node-static-entry-point with pkg, an open source tool to
package Node.js applications for distribution.

Some highlights:

- Removing browserify got rid of a lot of dependencies from
  npm-shrinkwrap.json

- pkg currently has an issue where macOS binaries can't be code-signed
  (vercel/pkg#128), therefore this commit
  comments-out the binary signing section for that operating system

- pkg currently has an issue where Windows binaries can't be branded
  (vercel/pkg#149), therefore this commit
  comments-out the branding section for that operating system

See: https://github.com/zeit/pkg
Change-Type: patch
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Jun 30, 2017
1 parent 9bd987f commit bf48e12
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 901 deletions.
83 changes: 43 additions & 40 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ TARGET_ARCH_DEBIAN = $(shell ./scripts/build/architecture-convert.sh -r $(TARGET
TARGET_ARCH_REDHAT = $(shell ./scripts/build/architecture-convert.sh -r $(TARGET_ARCH) -t redhat)
TARGET_ARCH_APPIMAGE = $(shell ./scripts/build/architecture-convert.sh -r $(TARGET_ARCH) -t appimage)
TARGET_ARCH_ELECTRON_BUILDER = $(shell ./scripts/build/architecture-convert.sh -r $(TARGET_ARCH) -t electron-builder)
TARGET_PLATFORM_PKG = $(shell ./scripts/build/target-convert.sh -r $(TARGET_PLATFORM) -t pkg)
ENTRY_POINT_CLI = lib/cli/etcher.js

PRODUCT_NAME = etcher
APPLICATION_NAME_LOWERCASE = $(shell echo $(APPLICATION_NAME) | tr A-Z a-z)
Expand Down Expand Up @@ -215,64 +217,65 @@ $(BUILD_OUTPUT_DIRECTORY): | $(BUILD_DIRECTORY)
# CLI
# ---------------------------------------------------------------------

$(BUILD_DIRECTORY)/node-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies: package.json npm-shrinkwrap.json \
$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(APPLICATION_VERSION)-$(TARGET_PLATFORM)-$(TARGET_ARCH)-app/node_modules: \
package.json npm-shrinkwrap.json \
| $(BUILD_DIRECTORY)
mkdir $@
mkdir -p $@
./scripts/build/dependencies-npm.sh -p \
-r "$(TARGET_ARCH)" \
-v "$(NODE_VERSION)" \
-x $@ \
-x $(dir $@) \
-t node \
-s "$(TARGET_PLATFORM)"
git apply --directory $@/node_modules/lzma-native patches/cli/lzma-native-index-static-addon-require.patch
git apply --directory $@/lzma-native patches/cli/lzma-native-index-static-addon-require.patch

$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(APPLICATION_VERSION)-$(TARGET_PLATFORM)-$(TARGET_ARCH)-app: \
package.json lib \
$(BUILD_DIRECTORY)/node-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies \
$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(APPLICATION_VERSION)-$(TARGET_PLATFORM)-$(TARGET_ARCH)-app/node_modules \
| $(BUILD_DIRECTORY)
mkdir $@
cp $(word 1,$^) $@
$(CPRF) $(word 2,$^) $@
$(CPRF) $(word 3,$^)/* $@
cp -rf lib $@
cp -rf package.json $@

$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(APPLICATION_VERSION)-$(TARGET_PLATFORM)-$(TARGET_ARCH).js: \
$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(APPLICATION_VERSION)-$(TARGET_PLATFORM)-$(TARGET_ARCH)-app \
| $(BUILD_DIRECTORY)
./scripts/build/concatenate-javascript.sh -e lib/cli/etcher.js -b $< -o $@ -m
ETCHER_CLI_BINARY = $(APPLICATION_NAME_LOWERCASE)
ifeq ($(TARGET_PLATFORM),win32)
ETCHER_CLI_BINARY = $(APPLICATION_NAME_LOWERCASE).exe
endif

$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(APPLICATION_VERSION)-$(TARGET_PLATFORM)-$(TARGET_ARCH): \
$(BUILD_DIRECTORY)/node-$(TARGET_PLATFORM)-$(TARGET_ARCH)-dependencies \
$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(APPLICATION_VERSION)-$(TARGET_PLATFORM)-$(TARGET_ARCH).js \
$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-cli-$(APPLICATION_VERSION)-$(TARGET_PLATFORM)-$(TARGET_ARCH)-app \
| $(BUILD_DIRECTORY) $(BUILD_TEMPORARY_DIRECTORY)
mkdir $@
./scripts/build/node-package-cli.sh -o $@ -l $</node_modules \
-n $(APPLICATION_NAME) \
-e $(word 2,$^) \
-r $(TARGET_ARCH) \
-s $(TARGET_PLATFORM)

ifeq ($(TARGET_PLATFORM),win32)
./scripts/build/electron-brand-exe.sh \
-f $@/etcher.exe \
-n $(APPLICATION_NAME) \
-d "$(APPLICATION_DESCRIPTION)" \
-v "$(APPLICATION_VERSION)" \
-c "$(APPLICATION_COPYRIGHT)" \
-m "$(COMPANY_NAME)" \
-i assets/icon.ico \
-w $(BUILD_TEMPORARY_DIRECTORY)
endif

ifeq ($(TARGET_PLATFORM),darwin)
ifdef CSC_NAME
./scripts/build/electron-sign-file-darwin.sh -f $@/etcher -i "$(CSC_NAME)"
endif
endif
$(NPX) pkg --output $@/$(ETCHER_CLI_BINARY) -t node6-$(TARGET_PLATFORM_PKG)-$(TARGET_ARCH) $</$(ENTRY_POINT_CLI)
./scripts/build/dependencies-npm-extract-addons.sh \
-d $</node_modules \
-o $@/node_modules
# pkg currently has a bug where darwin executables
# can't be code-signed
# See https://github.com/zeit/pkg/issues/128
# ifeq ($(TARGET_PLATFORM),darwin)
# ifdef CSC_NAME
# ./scripts/build/electron-sign-file-darwin.sh -f $@/$(ETCHER_CLI_BINARY) -i "$(CSC_NAME)"
# endif
# endif

# pkg currently has a bug where Windows executables
# can't be branded
# See https://github.com/zeit/pkg/issues/149
# ifeq ($(TARGET_PLATFORM),win32)
# ./scripts/build/electron-brand-exe.sh \
# -f $@/$(ETCHER_CLI_BINARY) \
# -n $(APPLICATION_NAME) \
# -d "$(APPLICATION_DESCRIPTION)" \
# -v "$(APPLICATION_VERSION)" \
# -c "$(APPLICATION_COPYRIGHT)" \
# -m "$(COMPANY_NAME)" \
# -i assets/icon.ico \
# -w $(BUILD_TEMPORARY_DIRECTORY)
# endif

ifeq ($(TARGET_PLATFORM),win32)
ifdef CSC_LINK
ifdef CSC_KEY_PASSWORD
./scripts/build/electron-sign-exe-win32.sh -f $@/etcher.exe \
./scripts/build/electron-sign-exe-win32.sh -f $@/$(ETCHER_CLI_BINARY) \
-d "$(APPLICATION_NAME) - $(APPLICATION_VERSION)" \
-c $(CSC_LINK) \
-p $(CSC_KEY_PASSWORD)
Expand Down
Loading

0 comments on commit bf48e12

Please sign in to comment.