chore: adopt new build command convention for OS X (#903)

The `darwin.sh` script now accepts the following commands:

- `develop-electron`
- `installer-dmg`
- `installer-zip`

In order to accomplish this, `./scripts/darwin/package.sh` is no longer
relying on `electron-packager`.

Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
This commit is contained in:
Juan Cruz Viotti 2016-11-28 09:56:14 -04:00 committed by GitHub
parent 7794bf06d1
commit 0ed4f5d3c8
8 changed files with 169 additions and 63 deletions

View File

@ -51,7 +51,7 @@ install:
brew install afsctool;
fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
./scripts/build/darwin.sh install;
./scripts/build/darwin.sh develop-electron;
fi
before_script:

View File

@ -36,7 +36,8 @@ The resulting installers will be saved to `etcher-release/installers`.
Run the following command:
```sh
$ ./scripts/build/darwin.sh all
$ ./scripts/build/darwin.sh installer-dmg
$ ./scripts/build/darwin.sh installer-zip
```
### GNU/Linux

View File

@ -50,7 +50,7 @@ the application might not run successfully.
### OS X
```sh
./scripts/build/darwin.sh install
./scripts/build/darwin.sh develop-electron
```
### GNU/Linux

View File

@ -33,11 +33,6 @@ if [ "$#" -ne 1 ]; then
fi
COMMAND=$1
if [ "$COMMAND" != "install" ] && [ "$COMMAND" != "package" ] && [ "$COMMAND" != "cli" ] && [ "$COMMAND" != "all" ]; then
echo "Unknown command: $COMMAND" 1>&2
exit 1
fi
SIGN_IDENTITY_OSX="Developer ID Application: Rulemotion Ltd (66H43P8FRG)"
ELECTRON_VERSION=`node -e "console.log(require('./package.json').devDependencies['electron-prebuilt'])"`
APPLICATION_NAME=`node -e "console.log(require('./package.json').displayName)"`
@ -55,14 +50,20 @@ if [ "$COMMAND" == "cli" ]; then
exit 0
fi
if [ "$COMMAND" == "install" ] || [ "$COMMAND" == "all" ]; then
if [ "$COMMAND" == "develop-electron" ]; then
./scripts/unix/dependencies.sh \
-r x64 \
-v "$ELECTRON_VERSION" \
-t electron
exit 0
fi
if [ "$COMMAND" == "package" ] || [ "$COMMAND" == "all" ]; then
if [ "$COMMAND" == "installer-dmg" ]; then
./scripts/unix/dependencies.sh -p \
-r x64 \
-v "$ELECTRON_VERSION" \
-t electron
./scripts/darwin/package.sh \
-n $APPLICATION_NAME \
-r x64 \
@ -70,6 +71,8 @@ if [ "$COMMAND" == "package" ] || [ "$COMMAND" == "all" ]; then
-b io.resin.etcher \
-c "$APPLICATION_COPYRIGHT" \
-t public.app-category.developer-tools \
-l LICENSE \
-f "package.json,lib,node_modules,bower_components,build,assets" \
-i assets/icon.icns \
-e $ELECTRON_VERSION \
-o etcher-release/$APPLICATION_NAME-darwin-x64
@ -83,6 +86,28 @@ if [ "$COMMAND" == "package" ] || [ "$COMMAND" == "all" ]; then
-b assets/osx/installer.png \
-o etcher-release/installers/$APPLICATION_NAME-$APPLICATION_VERSION-darwin-x64.dmg
exit 0
fi
if [ "$COMMAND" == "installer-zip" ]; then
./scripts/unix/dependencies.sh -p \
-r x64 \
-v "$ELECTRON_VERSION" \
-t electron
./scripts/darwin/package.sh \
-n $APPLICATION_NAME \
-r x64 \
-v $APPLICATION_VERSION \
-b io.resin.etcher \
-c "$APPLICATION_COPYRIGHT" \
-t public.app-category.developer-tools \
-l LICENSE \
-f "package.json,lib,node_modules,bower_components,build,assets" \
-i assets/icon.icns \
-e $ELECTRON_VERSION \
-o etcher-release/$APPLICATION_NAME-darwin-x64
./scripts/darwin/sign.sh \
-a etcher-release/$APPLICATION_NAME-darwin-x64/$APPLICATION_NAME.app \
-i "$SIGN_IDENTITY_OSX"
@ -90,4 +115,9 @@ if [ "$COMMAND" == "package" ] || [ "$COMMAND" == "all" ]; then
./scripts/darwin/installer-zip.sh \
-a etcher-release/$APPLICATION_NAME-darwin-x64/$APPLICATION_NAME.app \
-o etcher-release/installers/$APPLICATION_NAME-$APPLICATION_VERSION-darwin-x64.zip
exit 0
fi
echo "Unknown command: $COMMAND" 1>&2
exit 1

View File

@ -103,11 +103,6 @@ pushd "$VOLUME_DIRECTORY"
ln -s /Applications
popd
# Symlink MacOS/Etcher to MacOS/Electron since for some reason, the Electron
# binary tries to be ran in some systems.
# See https://github.com/Microsoft/vscode/issues/92
cp -p "$VOLUME_APPLICATION/Contents/MacOS/Etcher" "$VOLUME_APPLICATION/Contents/MacOS/Electron"
# Set the DMG icon image
# Writing this hexadecimal buffer to the com.apple.FinderInfo
# extended attribute does the trick.

View File

@ -36,6 +36,8 @@ function usage() {
echo " -b <application bundle id>"
echo " -c <application copyright>"
echo " -t <application category>"
echo " -l <application license file>"
echo " -f <application files (comma separated)>"
echo " -i <application icon (.icns)>"
echo " -e <electron version>"
echo " -o <output>"
@ -48,11 +50,13 @@ ARGV_VERSION=""
ARGV_BUNDLE_ID=""
ARGV_COPYRIGHT=""
ARGV_CATEGORY=""
ARGV_LICENSE=""
ARGV_FILES=""
ARGV_ICON=""
ARGV_ELECTRON_VERSION=""
ARGV_OUTPUT=""
while getopts ":n:r:v:b:c:t:i:e:o:" option; do
while getopts ":n:r:v:b:c:t:l:f:i:e:o:" option; do
case $option in
n) ARGV_APPLICATION_NAME="$OPTARG" ;;
r) ARGV_ARCHITECTURE="$OPTARG" ;;
@ -60,6 +64,8 @@ while getopts ":n:r:v:b:c:t:i:e:o:" option; do
b) ARGV_BUNDLE_ID="$OPTARG" ;;
c) ARGV_COPYRIGHT="$OPTARG" ;;
t) ARGV_CATEGORY="$OPTARG" ;;
l) ARGV_LICENSE="$OPTARG" ;;
f) ARGV_FILES="$OPTARG" ;;
i) ARGV_ICON="$OPTARG" ;;
e) ARGV_ELECTRON_VERSION="$OPTARG" ;;
o) ARGV_OUTPUT="$OPTARG" ;;
@ -73,6 +79,8 @@ if [ -z "$ARGV_APPLICATION_NAME" ] \
|| [ -z "$ARGV_BUNDLE_ID" ] \
|| [ -z "$ARGV_COPYRIGHT" ] \
|| [ -z "$ARGV_CATEGORY" ] \
|| [ -z "$ARGV_LICENSE" ] \
|| [ -z "$ARGV_FILES" ] \
|| [ -z "$ARGV_ICON" ] \
|| [ -z "$ARGV_ELECTRON_VERSION" ] \
|| [ -z "$ARGV_OUTPUT" ]
@ -80,40 +88,64 @@ then
usage
fi
ELECTRON_PACKAGER=./node_modules/.bin/electron-packager
./scripts/unix/download-electron.sh \
-r "$ARGV_ARCHITECTURE" \
-v "$ARGV_ELECTRON_VERSION" \
-s darwin \
-o "$ARGV_OUTPUT"
if [ ! -x $ELECTRON_PACKAGER ]; then
echo "Couldn't find $ELECTRON_PACKAGER" 1>&2
echo "Have you installed the dependencies first?" 1>&2
exit 1
fi
APPLICATION_OUTPUT="$ARGV_OUTPUT/$ARGV_APPLICATION_NAME.app"
mv "$ARGV_OUTPUT/Electron.app" "$APPLICATION_OUTPUT"
rm "$APPLICATION_OUTPUT/Contents/Resources/default_app.asar"
cp "$ARGV_LICENSE" "$ARGV_OUTPUT/LICENSE"
echo "$ARGV_VERSION" > $ARGV_OUTPUT/version
OUTPUT_DIRNAME=$(dirname "$ARGV_OUTPUT")
function plist_set() {
local plist_file=$1
local plist_key=$2
local plist_value=$3
mkdir -p "$OUTPUT_DIRNAME"
/usr/libexec/PlistBuddy -c "Set $plist_key \"$plist_value\"" "$plist_file"
}
$ELECTRON_PACKAGER . "$ARGV_APPLICATION_NAME" \
--platform=darwin \
--arch="$ARGV_ARCHITECTURE" \
--version="$ARGV_ELECTRON_VERSION" \
--ignore="$(node scripts/packageignore.js)" \
--asar \
--app-copyright="$ARGV_COPYRIGHT" \
--app-version="$ARGV_VERSION" \
--build-version="$ARGV_VERSION" \
--helper-bundle-id="$ARGV_BUNDLE_ID-helper" \
--app-bundle-id="$ARGV_BUNDLE_ID" \
--app-category-type="$ARGV_CATEGORY" \
--icon="$ARGV_ICON" \
--overwrite \
--out="$OUTPUT_DIRNAME"
INFO_PLIST="$APPLICATION_OUTPUT/Contents/Info.plist"
plist_set "$INFO_PLIST" CFBundleName "$ARGV_APPLICATION_NAME"
plist_set "$INFO_PLIST" CFBundleDisplayName "$ARGV_APPLICATION_NAME"
plist_set "$INFO_PLIST" CFBundleIdentifier "$ARGV_BUNDLE_ID"
plist_set "$INFO_PLIST" CFBundleVersion "$ARGV_VERSION"
plist_set "$INFO_PLIST" CFBundleShortVersionString "$ARGV_VERSION"
plist_set "$INFO_PLIST" LSApplicationCategoryType "$ARGV_CATEGORY"
ELECTRON_PACKAGE_OUTPUT=$OUTPUT_DIRNAME/$ARGV_APPLICATION_NAME-darwin-$ARGV_ARCHITECTURE
# Rename executable
plist_set "$INFO_PLIST" CFBundleExecutable "$ARGV_APPLICATION_NAME"
mv "$APPLICATION_OUTPUT/Contents/MacOS/Electron" "$APPLICATION_OUTPUT/Contents/MacOS/$ARGV_APPLICATION_NAME"
if [ "$ELECTRON_PACKAGE_OUTPUT" != "$ARGV_OUTPUT" ]; then
mv "$ELECTRON_PACKAGE_OUTPUT" "$ARGV_OUTPUT"
fi
# Change application icon
ICON_FILENAME=$(echo "$ARGV_APPLICATION_NAME" | tr '[:upper:]' '[:lower:]').icns
plist_set "$INFO_PLIST" CFBundleIconFile "$ICON_FILENAME"
rm "$APPLICATION_OUTPUT/Contents/Resources/electron.icns"
cp "$ARGV_ICON" "$APPLICATION_OUTPUT/Contents/Resources/$ICON_FILENAME"
rm "$ARGV_OUTPUT/LICENSE"
rm "$ARGV_OUTPUT/LICENSES.chromium.html"
rm "$ARGV_OUTPUT/version"
# Configure Electron Helper.app
HELPER_APP="$APPLICATION_OUTPUT/Contents/Frameworks/Electron Helper.app"
HELPER_INFO_PLIST="$HELPER_APP/Contents/Info.plist"
plist_set "$HELPER_INFO_PLIST" CFBundleIdentifier "$ARGV_BUNDLE_ID.helper"
plist_set "$HELPER_INFO_PLIST" CFBundleName "$ARGV_APPLICATION_NAME Helper"
mv "$HELPER_APP/Contents/MacOS/Electron Helper" "$HELPER_APP/Contents/MacOS/$ARGV_APPLICATION_NAME Helper"
mv "$HELPER_APP" "$APPLICATION_OUTPUT/Contents/Frameworks/$ARGV_APPLICATION_NAME Helper.app"
for id in EH NP; do
HELPER_INFO_PLIST="$APPLICATION_OUTPUT/Contents/Frameworks/Electron Helper $id.app/Contents/Info.plist"
plist_set "$HELPER_INFO_PLIST" CFBundleName "$ARGV_APPLICATION_NAME Helper $id"
plist_set "$HELPER_INFO_PLIST" CFBundleDisplayName "$ARGV_APPLICATION_NAME Helper $id"
plist_set "$HELPER_INFO_PLIST" CFBundleExecutable "$ARGV_APPLICATION_NAME Helper $id"
plist_set "$HELPER_INFO_PLIST" CFBundleIdentifier "$ARGV_BUNDLE_ID.helper.$id"
mv "$APPLICATION_OUTPUT/Contents/Frameworks/Electron Helper $id.app/Contents/MacOS/Electron Helper $id" \
"$APPLICATION_OUTPUT/Contents/Frameworks/Electron Helper $id.app/Contents/MacOS/$ARGV_APPLICATION_NAME Helper $id"
mv "$APPLICATION_OUTPUT/Contents/Frameworks/Electron Helper $id.app" \
"$APPLICATION_OUTPUT/Contents/Frameworks/$ARGV_APPLICATION_NAME Helper $id.app"
done
./scripts/unix/create-asar.sh \
-f "$ARGV_FILES" \
-o "$APPLICATION_OUTPUT/Contents/Resources/app.asar"

View File

@ -25,16 +25,6 @@ if [[ "$OS" != "Linux" ]]; then
exit 1
fi
if ! command -v asar 2>/dev/null 1>&2; then
echo "Dependency missing: asar" 1>&2
exit 1
fi
if ! command -v wget 2>/dev/null 1>&2; then
echo "Dependency missing: wget" 1>&2
exit 1
fi
function usage() {
echo "Usage: $0"
echo ""
@ -92,11 +82,7 @@ mv $ARGV_OUTPUT/electron $ARGV_OUTPUT/$(echo "$ARGV_APPLICATION_NAME" | tr '[:up
cp $ARGV_LICENSE $ARGV_OUTPUT/LICENSE
echo "$ARGV_VERSION" > $ARGV_OUTPUT/version
rm $ARGV_OUTPUT/resources/default_app.asar
mkdir -p $ARGV_OUTPUT/resources/app
for file in $(echo $ARGV_FILES | sed "s/,/ /g"); do
cp -rf "$file" $ARGV_OUTPUT/resources/app
done
asar pack $ARGV_OUTPUT/resources/app $ARGV_OUTPUT/resources/app.asar --unpack *.node
rm -rf $ARGV_OUTPUT/resources/app
./scripts/unix/create-asar.sh \
-f "$ARGV_FILES" \
-o "$ARGV_OUTPUT/resources/app.asar"

62
scripts/unix/create-asar.sh Executable file
View File

@ -0,0 +1,62 @@
#!/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
if ! command -v asar 2>/dev/null 1>&2; then
echo "Dependency missing: asar" 1>&2
exit 1
fi
function usage() {
echo "Usage: $0"
echo ""
echo "Options"
echo ""
echo " -f <files (comma separated)>"
echo " -o <output>"
exit 0
}
ARGV_FILES=""
ARGV_OUTPUT=""
while getopts ":f:o:" option; do
case $option in
f) ARGV_FILES=$OPTARG ;;
o) ARGV_OUTPUT=$OPTARG ;;
*) usage ;;
esac
done
if [ -z "$ARGV_FILES" ] || [ -z "$ARGV_OUTPUT" ]; then
usage
fi
TEMPORAL_DIRECTORY="$ARGV_OUTPUT.tmp"
rm -rf "$TEMPORAL_DIRECTORY"
mkdir -p "$TEMPORAL_DIRECTORY"
for file in $(echo "$ARGV_FILES" | sed "s/,/ /g"); do
cp -rf "$file" "$TEMPORAL_DIRECTORY"
done
mkdir -p $(dirname "$ARGV_OUTPUT")
asar pack "$TEMPORAL_DIRECTORY" "$ARGV_OUTPUT" --unpack *.node
rm -rf "$TEMPORAL_DIRECTORY"