-
-
Save da1nerd/a1d8bd217b97084475dee4e089b852b3 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
ELECTRON_REPO="https://github.com/electron/electron" | |
BRANCH="" | |
VARIANT=Release | |
APP_NAME=test-app | |
# git cache | |
export GIT_CACHE_PATH="${HOME}/.git_cache" | |
mkdir -p "${GIT_CACHE_PATH}" | |
# sccache | |
export SCCACHE_BUCKET="electronjs-sccache" | |
export SCCACHE_TWO_TIER=true | |
# use local visual studio instead of Google's internal one | |
export DEPOT_TOOLS_WIN_TOOLCHAIN=0 | |
COMMAND=$1 | |
set -e | |
if [ "$COMMAND" == "get" ]; then | |
# get code url | |
if [ $# -ge 2 ]; then | |
ELECTRON_REPO=$2 | |
# get branch name | |
repo_parts=($(echo $ELECTRON_REPO | tr "@" "\n")) | |
if [ ${#repo_parts[@]} -eq 2 ]; then | |
ELECTRON_REPO=${repo_parts[0]} | |
BRANCH=${repo_parts[1]} | |
echo "NOTE: Using \"$BRANCH\" branch/tag on $ELECTRON_REPO as electron source" | |
else | |
echo "NOTE: Using $ELECTRON_REPO as electron source" | |
fi | |
fi | |
echo "Fetching code. This may take awhile." | |
mkdir -p electron-gn | |
cd electron-gn | |
gclient config --name "src/electron" --unmanaged $ELECTRON_REPO | |
# checkout correct electron branch | |
if [ "$BRANCH" != "" ]; then | |
# checkout all modules | |
# TRICKY: this pulls down electron without running hooks | |
gclient sync --with_branch_heads --with_tags --nohooks --noprehooks | |
# change electron branch | |
echo "Checking out \"$BRANCH\"" | |
cd src/electron | |
git checkout $BRANCH | |
cd - | |
fi | |
# checkout/update all modules | |
gclient sync --with_branch_heads --with_tags | |
# set up push/pull from remote instead of cache | |
cd src/electron | |
git remote set-url origin $ELECTRON_REPO | |
cd - | |
fi | |
if [ "$COMMAND" == "build" ]; then | |
# get build variant | |
if [ $# == 2 ] && [ "$2" == "Debug" ]; then | |
VARIANT="Debug" | |
fi | |
cd electron-gn/src | |
VARIANT_CONFIG=$(echo $VARIANT | tr A-Z a-z) | |
export CHROMIUM_BUILDTOOLS_PATH=`pwd`/buildtools | |
export GN_EXTRA_ARGS="${GN_EXTRA_ARGS} cc_wrapper=\"${PWD}/electron/external_binaries/sccache\"" | |
echo "Generating $VARIANT configuration" | |
gn gen out/$VARIANT --args="import(\"//electron/build/args/$VARIANT_CONFIG.gn\") $GN_EXTRA_ARGS" | |
echo "Building $VARIANT" | |
ninja -C out/$VARIANT electron | |
cd - | |
fi | |
if [ "$COMMAND" == "dist" ]; then | |
# get build variant | |
if [ $# == 2 ] && [ "$2" == "Debug" ]; then | |
VARIANT="Debug" | |
fi | |
cd electron-gn/src | |
./electron/script/strip-binaries.py -d out/$VARIANT | |
ninja -C out/$VARIANT electron:electron_dist_zip | |
fi | |
if [ "$COMMAND" == "test" ]; then | |
# get app name | |
if [ $# -ge 2 ]; then | |
APP_NAME=$2 | |
fi | |
# get build variant | |
if [ $# -ge 3 ]; then | |
VARIANT=$3 | |
fi | |
ELECTRON_APP=`pwd`/$APP_NAME | |
ELECTRON_BUILD=`pwd`/electron-gn/src/out/$VARIANT/electron | |
# create test app | |
if [ ! -d "$ELECTRON_APP" ]; then | |
echo "Creating test application \"$APP_NAME\"" | |
yo react-app-electron --name $APP_NAME | |
fi | |
echo "Running application \"$APP_NAME\" on $VARIANT" | |
BIN=$ELECTRON_APP/node_modules/.bin | |
CONCURRENTLY=$BIN/concurrently | |
WAIT_ON=$BIN/wait-on | |
CROSS_ENV=$BIN/cross-env | |
cd $ELECTRON_APP | |
$CONCURRENTLY "yarn react-start" "$WAIT_ON http://localhost:3000/ && $CROSS_ENV NODE_ENV=development $ELECTRON_BUILD $ELECTRON_APP" | |
cd - | |
fi | |
if [ "$COMMAND" == "" ]; then | |
echo "# Electron Tools. | |
# This script makes it easy to build and test electron. | |
# You'll need yarn and the following npm packages if running *test*: yo, generator-react-app-electron. | |
# To get started, put this script in an empty directory and run these commands in order. | |
# The arguments are optional. | |
1. get [electron remote repository] - fetches all of the code (there's a lot of it). Set to a custom fork if needed. | |
2. build [Debug|Release] - compiles electron. Compiles release by default. | |
3. dist [Debug|Release] - creates a distributable. Uses release by default. | |
4. test [test-app] [Debug|Release] - creates an electron app from | |
https://github.com/neutrinog/generator-react-app-electron and runs it on the build. | |
For detailed instructions on building Electron see https://github.com/electron/electron/blob/master/docs/development/build-instructions-gn.md | |
" | |
fi |
Instructions
Run the script without any arguments to see the help doc.
electron-tools.sh get
clones chromium and electron. This can take a long time the first time.electron-tools.sh build
links everything together. This may take 2 days on an older computer or 20 minutes on modern one.electron-tools.sh dist
cleans up some stuff and zips up the distributable.
Arguments
See the help doc for details about all available arguments.
One important argument is a custom electron source. You can optionally pass a custom electron source to the get
command such as https://github.com/unfoldingWord-dev/electronite
. Additionally, you can specify a specific branch by appending it to the end with an @
.
Here's a complete example electron-tools.sh get https://github.com/unfoldingWord-dev/electronite@graphite
.
Prerequisites
Make sure you properly install/configure your Platform prerequisites
and GN prerequisites
before running this script. See https://github.com/electron/electron/blob/master/docs/development/build-instructions-gn.md.
If you would like to run the test
command you'll need a few more things. See the help doc for details.
Caveats
Every once in awhile a bare repository will be cloned into the cache 🤔. If so, run the script again and it should properly clone the repo.
Successfully tested on