chore: use the new electron-builder version to create NSIS installer (#1510)

We've been using `electron-builder` v2 all this time to create the NSIS
installer. This commit upgrade `electron-builder` to v18.6.2, and keeps
using it just to create the NSIS installer (for now).

The final package behaves exactly like the one we have before, just that
we needed various tweaks to upgrade to the latest `electron-builder`
version.

In more detail:

- Inject data to package.json using the new `--extraMetadata` option
- Remove old `.builder` package.json property
- Change the author of the project to Resin Inc. (the company name used
  in our code-signing certificate)

As an extra, the new NSIS installer allows the user to install the
application to any location, and fixes the fact that the previous
installer copied the application to C:\Program Files (x86) even on x64
systems.

Change-Type: patch
Fixes: https://github.com/resin-io/etcher/issues/1030
Fixes: https://github.com/resin-io/etcher/issues/877
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
This commit is contained in:
Juan Cruz Viotti 2017-06-13 11:19:29 -04:00 committed by GitHub
parent 15b178a158
commit 07adafe6f3
8 changed files with 4027 additions and 746 deletions

View File

@ -2,7 +2,7 @@
# Build configuration
# ---------------------------------------------------------------------
NODE_MODULES_BIN=./node_modules/.bin
NPX=./node_modules/.bin/npx
# This directory will be completely deleted by the `clean` rule
BUILD_DIRECTORY ?= dist
@ -137,16 +137,26 @@ endif
endif
endif
# ---------------------------------------------------------------------
# Electron Builder
# ---------------------------------------------------------------------
ELECTRON_BUILDER_OPTIONS = --$(TARGET_ARCH_ELECTRON_BUILDER) --extraMetadata.version=$(APPLICATION_VERSION)
# ---------------------------------------------------------------------
# Analytics
# ---------------------------------------------------------------------
ifndef ANALYTICS_SENTRY_TOKEN
$(warning No Sentry token found (ANALYTICS_SENTRY_TOKEN is not set))
else
ELECTRON_BUILDER_OPTIONS += --extraMetadata.analytics.sentry.token=$(ANALYTICS_SENTRY_TOKEN)
endif
ifndef ANALYTICS_MIXPANEL_TOKEN
$(warning No Mixpanel token found (ANALYTICS_MIXPANEL_TOKEN is not set))
else
ELECTRON_BUILDER_OPTIONS += --extraMetadata.analytics.mixpanel.token=$(ANALYTICS_MIXPANEL_TOKEN)
endif
# ---------------------------------------------------------------------
@ -172,6 +182,8 @@ APPLICATION_VERSION_REDHAT = $(shell echo $(APPLICATION_VERSION) | tr "-" "~")
# Fix hard link Appveyor issues
CPRF = cp -RLf
TARGET_ARCH_ELECTRON_BUILDER = $(shell ./scripts/build/architecture-convert.sh -r $(TARGET_ARCH) -t electron-builder)
# ---------------------------------------------------------------------
# Rules
# ---------------------------------------------------------------------
@ -184,7 +196,7 @@ define execute-command
endef
CHANGELOG.md:
$(NODE_MODULES_BIN)/versionist
$(NPX) versionist
$(BUILD_DIRECTORY):
mkdir $@
@ -426,9 +438,9 @@ $(BUILD_OUTPUT_DIRECTORY)/$(APPLICATION_NAME)-$(APPLICATION_VERSION)-win32-$(TAR
./scripts/build/zip-file.sh -f $< -s $(TARGET_PLATFORM) -o $@
$(BUILD_OUTPUT_DIRECTORY)/$(APPLICATION_NAME)-$(APPLICATION_VERSION)-win32-$(TARGET_ARCH).exe: \
$(BUILD_DIRECTORY)/$(APPLICATION_NAME)-$(APPLICATION_VERSION)-win32-$(TARGET_ARCH) \
| $(BUILD_OUTPUT_DIRECTORY) $(BUILD_TEMPORARY_DIRECTORY)
./scripts/build/electron-installer-nsis-win32.sh -n $(APPLICATION_NAME) -a $< -t $(BUILD_TEMPORARY_DIRECTORY) -o $@
| $(BUILD_OUTPUT_DIRECTORY)
TARGET_ARCH=$(TARGET_ARCH) $(NPX) build --win nsis $(ELECTRON_BUILDER_OPTIONS)
mv $(BUILD_DIRECTORY)/$(notdir $@) $@
ifdef CODE_SIGN_CERTIFICATE
ifdef CODE_SIGN_CERTIFICATE_PASSWORD
@ -583,13 +595,13 @@ electron-develop:
-s "$(TARGET_PLATFORM)"
sass:
$(NODE_MODULES_BIN)/node-sass lib/gui/scss/main.scss > lib/gui/css/main.css
$(NPX) node-sass lib/gui/scss/main.scss > lib/gui/css/main.css
lint-js:
$(NODE_MODULES_BIN)/eslint lib tests scripts bin versionist.conf.js
$(NPX) eslint lib tests scripts bin versionist.conf.js
lint-sass:
$(NODE_MODULES_BIN)/sass-lint lib/gui/scss
$(NPX) sass-lint lib/gui/scss
lint-cpp:
cpplint --recursive src
@ -607,10 +619,10 @@ lint: lint-js lint-sass lint-cpp lint-html lint-spell
ELECTRON_MOCHA_OPTIONS=--recursive --reporter spec
test-gui:
$(NODE_MODULES_BIN)/electron-mocha $(ELECTRON_MOCHA_OPTIONS) --renderer tests/gui
$(NPX) electron-mocha $(ELECTRON_MOCHA_OPTIONS) --renderer tests/gui
test-sdk:
$(NODE_MODULES_BIN)/electron-mocha $(ELECTRON_MOCHA_OPTIONS) \
$(NPX) electron-mocha $(ELECTRON_MOCHA_OPTIONS) \
tests/shared \
tests/child-writer \
tests/image-stream

View File

@ -9,8 +9,6 @@ Preparing a new version
- Bump the version number in the `package.json`'s `version` property.
- Bump the version number in the `package.json`'s `builder.win.version`
- Bump the version number in the `npm-shrinkwrap.json`'s `version` property.
- Add a new entry to `CHANGELOG.md` by running `make CHANGELOG.md`.

4609
npm-shrinkwrap.json generated

File diff suppressed because it is too large Load Diff

View File

@ -19,8 +19,36 @@
"appId": "io.resin.etcher",
"copyright": "Copyright 2016 Resinio Ltd",
"productName": "Etcher",
"npmRebuild": true,
"nodeGypRebuild": true,
"publish": null,
"files": [
"lib",
"assets/icon.png",
"node_modules/**/*"
],
"asar": {
"smartUnpack": false
},
"asarUnpack": [
"**/*.dll",
"**/*.node"
],
"mac": {
"category": "public.app-category.developer-tools"
},
"win": {
"icon": "assets/icon.ico"
},
"nsis": {
"oneClick": false,
"allowToChangeInstallationDirectory": true,
"runAfterFinish": true,
"installerIcon": "assets/icon.ico",
"uninstallerIcon": "assets/icon.ico",
"deleteAppDataOnUninstall": true,
"license": "LICENSE",
"artifactName": "${productName}-${version}-win32-${env.TARGET_ARCH}.${ext}"
}
},
"scripts": {
@ -31,23 +59,17 @@
"build": "node-gyp build",
"install": "node-gyp rebuild"
},
"author": "Juan Cruz Viotti <juan@resin.io>",
"author": "Resin Inc. <hello@etcher.io>",
"license": "Apache-2.0",
"shrinkwrapIgnore": [
"macos-alias",
"fs-xattr",
"ds-store",
"appdmg"
"appdmg",
"7zip-bin-mac",
"7zip-bin-win",
"7zip-bin-linux"
],
"builder": {
"win": {
"title": "Etcher",
"version": "v1.0.0",
"publisher": "Resin.io",
"icon": "assets/icon.ico",
"verbosity": 1
}
},
"dependencies": {
"angular": "1.6.3",
"angular-if-state": "^1.0.0",
@ -101,7 +123,7 @@
"asar": "^0.10.0",
"browserify": "github:jviotti/node-browserify#dynamic-dirname-filename",
"electron": "1.6.6",
"electron-builder": "^2.6.0",
"electron-builder": "^18.6.2",
"electron-mocha": "^3.1.1",
"eslint": "^3.16.1",
"eslint-plugin-lodash": "^2.3.5",
@ -111,6 +133,7 @@
"nock": "^9.0.9",
"node-gyp": "^3.5.0",
"node-sass": "^4.5.3",
"npx": "^5.2.0",
"sass-lint": "^1.10.2",
"tmp": "0.0.31",
"versionist": "^2.1.0"

View File

@ -54,6 +54,14 @@ if [ "$ARGV_TYPE" == "node" ]; then
elif [ "$ARGV_ARCHITECTURE" == "armv7l" ]; then
RESULT=arm
fi
elif [ "$ARGV_TYPE" == "electron-builder" ]; then
if [ "$ARGV_ARCHITECTURE" == "x86" ]; then
RESULT=ia32
elif [ "$ARGV_ARCHITECTURE" == "x64" ]; then
RESULT=x64
elif [ "$ARGV_ARCHITECTURE" == "armv7l" ]; then
RESULT=armv7l
fi
elif [ "$ARGV_TYPE" == "debian" ]; then
if [ "$ARGV_ARCHITECTURE" == "x86" ]; then
RESULT=i386

View File

@ -1,67 +0,0 @@
#!/bin/bash
###
# Copyright 2016 resin.io
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###
set -u
set -e
./scripts/build/check-dependency.sh zip
function usage() {
echo "Usage: $0"
echo ""
echo "Options"
echo ""
echo " -n <application name>"
echo " -a <application package directory>"
echo " -t <temporary directory>"
echo " -o <output>"
exit 1
}
ARGV_APPLICATION_NAME=""
ARGV_APPLICATION=""
ARGV_TEMPORARY_DIRECTORY=""
ARGV_OUTPUT=""
while getopts ":n:a:t:o:" option; do
case $option in
n) ARGV_APPLICATION_NAME="$OPTARG" ;;
a) ARGV_APPLICATION="$OPTARG" ;;
t) ARGV_TEMPORARY_DIRECTORY="$OPTARG" ;;
o) ARGV_OUTPUT="$OPTARG" ;;
*) usage ;;
esac
done
if [ -z "$ARGV_APPLICATION_NAME" ] ||
[ -z "$ARGV_APPLICATION" ] ||
[ -z "$ARGV_TEMPORARY_DIRECTORY" ] ||
[ -z "$ARGV_OUTPUT" ]; then
usage
fi
if [ ! -d "$PWD/node_modules" ]; then
echo "Looks like you forgot to install the dependencies first!" 1>&2
exit 1
fi
./node_modules/.bin/electron-builder "$ARGV_APPLICATION" \
--platform=win \
--out="$ARGV_TEMPORARY_DIRECTORY"
mv "$ARGV_TEMPORARY_DIRECTORY/$ARGV_APPLICATION_NAME Setup.exe" "$ARGV_OUTPUT"

View File

@ -48,8 +48,8 @@ if [ "$ARGV_OPERATING_SYSTEM" == "linux" ]; then
./scripts/build/docker/run-command.sh \
-r "$TARGET_ARCH" \
-s "$(pwd)" \
-c 'make installers-all'
-c 'make electron-develop installers-all'
else
./scripts/build/check-dependency.sh make
make installers-all
make electron-develop installers-all
fi

View File

@ -16,6 +16,7 @@
'use strict';
const path = require('path');
const os = require('os');
const packageJSON = require('../package.json');
const spawn = require('child_process').spawn;
const shrinkwrapIgnore = packageJSON.shrinkwrapIgnore;
@ -28,7 +29,8 @@ console.log('Removing:', shrinkwrapIgnore.join(', '));
* @returns {ChildProcess}
*/
const npm = (command) => {
return spawn('npm', command, {
const npmBinary = os.platform() === 'win32' ? 'npm.cmd' : 'npm';
return spawn(npmBinary, command, {
cwd: path.join(__dirname, '..'),
env: process.env,
stdio: [ process.stdin, process.stdout, process.stderr ]