2017-01-18 16:39:21 -05:00
#!/bin/bash
2017-01-16 14:06:53 -05:00
2017-03-06 17:17:03 -05:00
set -euo pipefail
2017-01-16 14:06:53 -05:00
2017-03-09 13:21:46 -05:00
ROOT = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) /.. " && pwd ) "
2017-03-02 22:43:34 -05:00
cd " $ROOT "
2017-03-09 13:21:46 -05:00
BUILD_DIR = " $ROOT /build "
2017-03-02 22:43:34 -05:00
2017-04-11 10:38:32 -04:00
LINUX = false
OSX = false
2017-01-25 01:24:04 -05:00
if [ " $( uname) " = = "Darwin" ] ; then
2017-09-21 09:29:51 -04:00
echo -e "\033[0;32mBuilding for OSX\x1b[m"
2017-04-11 10:38:32 -04:00
OSX = true
elif [ " $( expr substr $( uname -s) 1 5) " = = "Linux" ] ; then
2017-09-21 09:29:51 -04:00
echo -e "\033[0;32mBuilding for Linux\x1b[m"
2017-04-11 10:38:32 -04:00
LINUX = true
else
2017-09-08 23:46:26 -07:00
echo -e "\033[1;31mPlatform detection failed\x1b[m"
2017-04-11 10:38:32 -04:00
exit 1
fi
if $OSX ; then
2017-03-09 13:21:46 -05:00
ICON = " $BUILD_DIR /icon.icns "
2017-01-25 01:24:04 -05:00
else
2017-09-06 19:16:21 -04:00
ICON = " $BUILD_DIR /icons/48x48.png "
2017-01-25 01:24:04 -05:00
fi
2017-09-21 09:29:51 -04:00
2017-02-10 13:11:26 -06:00
FULL_BUILD = " ${ FULL_BUILD :- false } "
2017-03-02 22:43:34 -05:00
if [ -n " ${ TEAMCITY_VERSION :- } " -o -n " ${ APPVEYOR :- } " ] ; then
2017-02-10 13:11:26 -06:00
FULL_BUILD = "true"
fi
2017-11-10 10:47:51 -05:00
DEPS = " ${ DEPS :- $FULL_BUILD } "
if [ " $DEPS " != "true" ] ; then
2017-10-26 23:30:48 -04:00
echo -e "\033[1;36mDependencies will NOT be installed. Run with \"INSTALL_DEPENDENCIES=true\" to install dependencies, or \"FULL_BUILD=true\" to install dependencies and build a complete app.\x1b[m"
else
2017-01-18 14:43:35 -05:00
# install dependencies
2017-09-12 22:19:50 -07:00
echo -e "\033[0;32mInstalling Dependencies\x1b[m"
2017-11-10 10:47:51 -05:00
" $BUILD_DIR /install_deps.sh "
2017-01-18 16:35:06 -05:00
fi
2017-01-18 16:33:27 -05:00
2017-03-07 10:28:37 -05:00
[ -d " $ROOT /dist " ] && rm -rf " $ROOT /dist "
mkdir -p " $ROOT /dist "
[ -d " $ROOT /app/dist " ] && rm -rf " $ROOT /app/dist "
2017-03-06 18:00:57 -05:00
mkdir -p " $ROOT /app/dist "
2017-03-06 17:17:03 -05:00
2017-06-23 15:18:03 -04:00
yarn install
2017-03-06 17:17:03 -05:00
############
# UI #
############
2017-09-12 22:19:50 -07:00
echo -e "\033[0;32mCompiling UI\x1b[m"
2017-01-18 11:37:44 -05:00
(
2017-03-09 12:31:07 -05:00
cd " $ROOT /ui "
2017-06-23 15:18:03 -04:00
yarn install
npm rebuild node-sass
2017-06-21 08:25:57 -04:00
node extractLocals.js
2017-01-18 11:37:44 -05:00
node_modules/.bin/node-sass --output dist/css --sourcemap= none scss/
2017-11-09 18:46:33 -08:00
node_modules/.bin/webpack --config webpack.prod.js
2017-03-07 10:28:37 -05:00
cp -r dist/* " $ROOT /app/dist/ "
2017-01-18 11:37:44 -05:00
)
2017-01-16 14:06:53 -05:00
2017-01-26 12:30:02 -06:00
2017-03-07 10:28:37 -05:00
####################
2017-03-15 21:23:04 -04:00
# daemon and cli #
2017-03-07 10:28:37 -05:00
####################
2017-09-12 22:19:50 -07:00
echo -e "\033[0;32mGrabbing Daemon and CLI\x1b[m"
2017-04-19 15:16:29 -04:00
if $OSX ; then
OSNAME = "macos"
else
OSNAME = "linux"
2017-04-11 10:38:32 -04:00
fi
2017-07-19 17:05:08 -04:00
DAEMON_VER = $( node -e " console.log(require(\" $ROOT /app/package.json\").lbrySettings.lbrynetDaemonVersion) " )
2017-08-10 21:02:14 -05:00
DAEMON_URL_TEMPLATE = $( node -e " console.log(require(\" $ROOT /app/package.json\").lbrySettings.lbrynetDaemonUrlTemplate) " )
DAEMON_URL = $( echo ${ DAEMON_URL_TEMPLATE //DAEMONVER/ $DAEMON_VER } | sed " s/OSNAME/ $OSNAME /g " )
2017-08-15 22:15:03 -04:00
DAEMON_VER_PATH = " $BUILD_DIR /daemon.ver "
echo " $DAEMON_VER_PATH "
2017-08-21 12:06:56 -04:00
if [ [ ! -f $DAEMON_VER_PATH || ! -f $ROOT /app/dist/lbrynet-daemon || " $( < " $DAEMON_VER_PATH " ) " != " $DAEMON_VER " ] ] ; then
2017-10-26 23:30:48 -04:00
curl -sL -o " $BUILD_DIR /daemon.zip " " $DAEMON_URL "
2017-08-15 22:15:03 -04:00
unzip " $BUILD_DIR /daemon.zip " -d " $ROOT /app/dist/ "
rm " $BUILD_DIR /daemon.zip "
echo " $DAEMON_VER " > " $DAEMON_VER_PATH "
else
2017-09-08 23:46:26 -07:00
echo -e " \033[4;31mAlready have daemon version $DAEMON_VER , skipping download\x1b[m "
2017-08-15 22:15:03 -04:00
fi
2017-03-07 10:28:37 -05:00
2017-07-19 17:05:08 -04:00
2017-03-06 17:17:03 -05:00
###################
# Build the app #
###################
2017-09-12 22:19:50 -07:00
echo -e '\033[0;32mBuilding Lbry-app\x1b[m'
2017-03-06 17:17:03 -05:00
(
cd " $ROOT /app "
2017-06-23 15:18:03 -04:00
yarn install
2017-06-26 10:47:49 -04:00
# necessary to ensure native Node modules (e.g. keytar) are built against the correct version of Node)
# yes, it needs to be run twice. it fails the first time, not sure why
set +e
# DEBUG=electron-rebuild node_modules/.bin/electron-rebuild .
node_modules/.bin/electron-rebuild " $ROOT /app "
set -e
node_modules/.bin/electron-rebuild " $ROOT /app "
2017-03-06 17:17:03 -05:00
)
2017-02-10 13:11:26 -06:00
if [ " $FULL_BUILD " = = "true" ] ; then
2017-04-11 10:38:32 -04:00
if $OSX ; then
2017-01-26 20:36:05 -06:00
security unlock-keychain -p ${ KEYCHAIN_PASSWORD } osx-build.keychain
fi
2017-01-18 13:03:10 -05:00
2017-02-09 18:54:42 -06:00
node_modules/.bin/build -p never
2017-03-07 10:28:37 -05:00
2017-04-11 10:38:32 -04:00
if $OSX ; then
binary_name = $( find " $ROOT /dist " -iname "*dmg" )
new_name = $( basename " $binary_name " | sed 's/-/_/' )
mv " $binary_name " " $( dirname " $binary_name " ) / $new_name "
fi
2017-03-07 10:28:37 -05:00
# electron-build has a publish feature, but I had a hard time getting
# it to reliably work and it also seemed difficult to configure. Not proud of
# this, but it seemed better to write my own.
2017-11-10 10:47:51 -05:00
VENV = " $BUILD_DIR /venv "
if [ -d " $VENV " ] ; then
rm -rf " $VENV "
fi
virtualenv " $VENV "
" $VENV /bin/pip " install -r " $BUILD_DIR /requirements.txt "
" $VENV /bin/python " " $BUILD_DIR /upload_assets.py "
2017-03-06 17:17:03 -05:00
2017-09-08 23:46:26 -07:00
echo -e '\033[0;32mBuild and packaging complete.\x1b[m'
2017-01-18 12:05:46 -05:00
else
2017-09-08 23:46:26 -07:00
echo -e 'Build complete. Run \033[1;31m./node_modules/.bin/electron app\x1b[m to launch the app'
2017-04-19 15:16:29 -04:00
fi