mirror of
https://github.com/SchildiChat/element-web.git
synced 2024-10-01 01:26:12 -04:00
Auto-update & build process with NSIS for windows
Amalgamate the electron build packaging into one script. Use update_base_url so we can compute the actual URL in the script for windows (because we need to put it in the build) and at runtime for mac os.
This commit is contained in:
parent
2930a94c79
commit
9f51e2c407
@ -107,6 +107,9 @@ You can configure the app by copying `vector/config.sample.json` to
|
|||||||
valid location on this network. This is used as a hint to the user to indicate
|
valid location on this network. This is used as a hint to the user to indicate
|
||||||
when a valid location has been entered so it's not necessary for this to be
|
when a valid location has been entered so it's not necessary for this to be
|
||||||
exactly correct. Optional.
|
exactly correct. Optional.
|
||||||
|
1. `update_base_url` (electron app only): HTTPS URL to a web server to download
|
||||||
|
updates from. This should be the path to the directory containing `install`
|
||||||
|
and `update`.
|
||||||
|
|
||||||
Running as a Desktop app
|
Running as a Desktop app
|
||||||
========================
|
========================
|
||||||
|
@ -99,9 +99,9 @@ function pollForUpdates() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function startAutoUpdate(update_url) {
|
function startAutoUpdate() {
|
||||||
if (update_url.slice(-1) !== '/') {
|
if (process.platform != 'darwin' && process.platform != 'win32') {
|
||||||
update_url = update_url + '/';
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
// Since writing, the electron auto update process has changed from being
|
// Since writing, the electron auto update process has changed from being
|
||||||
@ -111,7 +111,19 @@ function startAutoUpdate(update_url) {
|
|||||||
// package.json. There is no autoupdate for Linux: it's expected that
|
// package.json. There is no autoupdate for Linux: it's expected that
|
||||||
// the distro will provide it.
|
// the distro will provide it.
|
||||||
if (process.platform == 'darwin') {
|
if (process.platform == 'darwin') {
|
||||||
autoUpdater.setFeedURL(update_base_url + 'update/macos/');
|
const update_base_url = vectorConfig.update_base_url;
|
||||||
|
if (!update_base_url) {
|
||||||
|
console.log("No update_base_url: disabling auto-update");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (update_base_url.slice(-1) !== '/') {
|
||||||
|
update_base_url = update_url + '/';
|
||||||
|
}
|
||||||
|
const update_url = update_base_url + 'update/macos/tmp/';
|
||||||
|
console.log("Starting auto update with URL: " + update_url);
|
||||||
|
autoUpdater.setFeedURL(update_url);
|
||||||
|
} else {
|
||||||
|
console.log("Starting auto update with baked-in URL");
|
||||||
}
|
}
|
||||||
// We check for updates ourselves rather than using 'updater' because we need to
|
// We check for updates ourselves rather than using 'updater' because we need to
|
||||||
// do it in the main process (and we don't really need to check every 10 minutes:
|
// do it in the main process (and we don't really need to check every 10 minutes:
|
||||||
@ -138,12 +150,7 @@ process.on('uncaughtException', function (error) {
|
|||||||
electron.ipcMain.on('install_update', installUpdate);
|
electron.ipcMain.on('install_update', installUpdate);
|
||||||
|
|
||||||
electron.app.on('ready', () => {
|
electron.app.on('ready', () => {
|
||||||
if (vectorConfig.update_url) {
|
startAutoUpdate();
|
||||||
console.log("Starting auto update with URL: " + vectorConfig.update_url);
|
|
||||||
startAutoUpdate(vectorConfig.update_url);
|
|
||||||
} else {
|
|
||||||
console.log("No update_url is defined: auto update is disabled");
|
|
||||||
}
|
|
||||||
|
|
||||||
mainWindow = new electron.BrowserWindow({
|
mainWindow = new electron.BrowserWindow({
|
||||||
icon: `${__dirname}/../img/riot.ico`,
|
icon: `${__dirname}/../img/riot.ico`,
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
"build:compile": "babel --source-maps -d lib src",
|
"build:compile": "babel --source-maps -d lib src",
|
||||||
"build:bundle": "NODE_ENV=production webpack -p --progress",
|
"build:bundle": "NODE_ENV=production webpack -p --progress",
|
||||||
"build:bundle:dev": "webpack --optimize-occurence-order --progress",
|
"build:bundle:dev": "webpack --optimize-occurence-order --progress",
|
||||||
"build:electron": "rimraf electron/dist && npm run clean && npm run build && build -wml --ia32 --x64 && scripts/check-electron.sh",
|
"build:electron": "rimraf electron/dist && npm run clean && npm run build && build -wml --ia32 --x64",
|
||||||
"build": "node scripts/babelcheck.js && npm run build:res && npm run build:config && npm run build:emojione && npm run build:css && npm run build:bundle",
|
"build": "node scripts/babelcheck.js && npm run build:res && npm run build:config && npm run build:emojione && npm run build:css && npm run build:bundle",
|
||||||
"build:dev": "node scripts/babelcheck.js && npm run build:res && npm run build:config && npm run build:emojione && npm run build:css && npm run build:bundle:dev",
|
"build:dev": "node scripts/babelcheck.js && npm run build:res && npm run build:config && npm run build:emojione && npm run build:css && npm run build:bundle:dev",
|
||||||
"dist": "scripts/package.sh",
|
"dist": "scripts/package.sh",
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
update_url=`jq .update_url webapp/config.json`
|
|
||||||
echo "***************************************************"
|
|
||||||
echo
|
|
||||||
if [ $? = 0 ]; then
|
|
||||||
echo "Built electron package with update url: $update_url"
|
|
||||||
else
|
|
||||||
echo "Built electron package with no update url"
|
|
||||||
echo "This build will not auto-update."
|
|
||||||
fi
|
|
||||||
echo
|
|
||||||
echo "***************************************************"
|
|
@ -1,54 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
set -x
|
|
||||||
|
|
||||||
if [ $# = 0 ]; then
|
|
||||||
echo "Usage: $0 <target directory>"
|
|
||||||
echo ""
|
|
||||||
echo "Adds the build in electron/dist/ to a given Riot electron"
|
|
||||||
echo "download tree. If target directory is empty, create a new"
|
|
||||||
echo "download tree. This tree can be placed on a web server to"
|
|
||||||
echo "serve auto-updates (although auto-update for Mac requires"
|
|
||||||
echo "additional logic)."
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
ver=`basename electron/dist/mac/*.dmg | cut -d '-' -f 2 | sed -e 's/\.dmg$//'`
|
|
||||||
dir=$1
|
|
||||||
|
|
||||||
echo "Copying files for version $ver to $dir"
|
|
||||||
|
|
||||||
# Install packages: what the user downloads the first time,
|
|
||||||
# (DMGs for mac, exe installer for windows)
|
|
||||||
mkdir -p "$dir/install/macos"
|
|
||||||
cp electron/dist/mac/*.dmg "$dir/install/macos/"
|
|
||||||
echo "$ver" > "$dir/install/macos/latest"
|
|
||||||
|
|
||||||
mkdir -p "$dir/install/win32/ia32"
|
|
||||||
cp electron/dist/win-ia32/*.exe "$dir/install/win32/ia32/"
|
|
||||||
|
|
||||||
mkdir -p "$dir/install/win32/x64"
|
|
||||||
cp electron/dist/win/*.exe "$dir/install/win32/x64/"
|
|
||||||
|
|
||||||
|
|
||||||
# Packages for auto-update. It would be nice if squirrel's
|
|
||||||
# auto update used the installer packages, but it doesn't
|
|
||||||
# for Reasons. zip for mac, nupkg for windows.
|
|
||||||
mkdir -p "$dir/update/macos"
|
|
||||||
cp electron/dist/mac/*.zip "$dir/update/macos/"
|
|
||||||
echo "$ver" > "$dir/update/macos/latest"
|
|
||||||
|
|
||||||
mkdir -p "$dir/update/win32/ia32"
|
|
||||||
cp electron/dist/win-ia32/*.nupkg "$dir/update/win32/ia32/"
|
|
||||||
cat electron/dist/win-ia32/RELEASES >> "$dir/update/win32/ia32/RELEASES"
|
|
||||||
echo >> "$dir/update/win32/ia32/RELEASES"
|
|
||||||
|
|
||||||
mkdir -p "$dir/update/win32/x64"
|
|
||||||
cp electron/dist/win/*.nupkg "$dir/update/win32/x64/"
|
|
||||||
cat electron/dist/win/RELEASES >> "$dir/update/win32/x64/RELEASES"
|
|
||||||
echo >> "$dir/update/win32/x64/RELEASES"
|
|
||||||
|
|
||||||
|
|
||||||
echo "All done!"
|
|
||||||
echo "$dir can now be copied to your web server."
|
|
133
scripts/electron-package.sh
Executable file
133
scripts/electron-package.sh
Executable file
@ -0,0 +1,133 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: $0 -v <version> -c <config file> [-n]"
|
||||||
|
echo
|
||||||
|
echo "version: commit-ish to check out and build"
|
||||||
|
echo "config file: a path to a json config file to"
|
||||||
|
echo "ship with the build. In addition, update_base_url:"
|
||||||
|
echo "from this file is used to set up auto-update."
|
||||||
|
echo "-n: build with no config file."
|
||||||
|
echo
|
||||||
|
echo "Values may also be passed as environment variables"
|
||||||
|
}
|
||||||
|
|
||||||
|
conffile=
|
||||||
|
version=
|
||||||
|
skipcfg=0
|
||||||
|
while getopts "c:v:n" opt; do
|
||||||
|
case $opt in
|
||||||
|
c)
|
||||||
|
conffile=$OPTARG
|
||||||
|
;;
|
||||||
|
v)
|
||||||
|
version=$OPTARG
|
||||||
|
;;
|
||||||
|
n)
|
||||||
|
skipcfg=1
|
||||||
|
;;
|
||||||
|
\?)
|
||||||
|
echo "Invalid option: -$OPTARG" >&2
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -z "$version" ]; then
|
||||||
|
echo "No version supplied"
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$conffile" ] && [ "$skipcfg" = 0 ]; then
|
||||||
|
echo "No config file given. Use -c to supply a config file or"
|
||||||
|
echo "-n to build with no config file (and no auto update)."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$conffile" ]; then
|
||||||
|
update_base_url=`jq -r .update_base_url $conffile`
|
||||||
|
|
||||||
|
if [ -z "$update_base_url" ]; then
|
||||||
|
echo "No update URL supplied. Use update_base_url: null if you really"
|
||||||
|
echo "want a build with no auto-update."
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
# Make sure the base URL ends in a slash if it doesn't already
|
||||||
|
update_base_url=`echo $update_base_url | sed -e 's#\([^\/]\)$#\1\/#'`
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f package.json ]; then
|
||||||
|
echo "No package.json found. This script must be run from"
|
||||||
|
echo "the vector-web directory."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Building $version using Update base URL $update_base_url"
|
||||||
|
|
||||||
|
projdir=`pwd`
|
||||||
|
builddir=`mktemp -d 2>/dev/null || mktemp -d -t 'buildtmp'`
|
||||||
|
pushd "$builddir"
|
||||||
|
git clone "$projdir" .
|
||||||
|
git checkout "$version"
|
||||||
|
|
||||||
|
if [ -n "$conffile" ]; then
|
||||||
|
popd
|
||||||
|
cp "$conffile" "$builddir/"
|
||||||
|
pushd "$builddir"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$update_base_url" != "null" ]; then
|
||||||
|
# Inject a 'publish' configuration into the package.json. This is what
|
||||||
|
# electron-builder needs for auto-update on windows but we don't want to
|
||||||
|
# keep it in the package.json as we don't want everyone cloning the source
|
||||||
|
# and building it for themselves to get our auto-update URL.
|
||||||
|
update_url=$update_base_url/install/win32/
|
||||||
|
jq '.build.publish.provider="generic"' package.json \
|
||||||
|
| jq '.build.publish.url="$update_url"' \
|
||||||
|
> package.json.tmp
|
||||||
|
mv package.json.tmp package.json
|
||||||
|
fi
|
||||||
|
|
||||||
|
npm install
|
||||||
|
npm run build:electron
|
||||||
|
|
||||||
|
popd
|
||||||
|
|
||||||
|
distdir="$builddir/electron/dist"
|
||||||
|
pubdir="$projdir/electron/pub"
|
||||||
|
rm -r "$pubdir" || true
|
||||||
|
mkdir -p "$pubdir"
|
||||||
|
|
||||||
|
# figure out what version this build is known as
|
||||||
|
# (since we could be building from a branch or indeed
|
||||||
|
# any commit-ish, not just a version tag)
|
||||||
|
vername=`python -c 'import yaml; import sys; print yaml.load(sys.stdin)["version"]' < $builddir/electron/dist/latest.yml`
|
||||||
|
|
||||||
|
# Install packages: what the user downloads the first time,
|
||||||
|
# (DMGs for mac, exe installer for windows)
|
||||||
|
mkdir -p "$pubdir/install/macos"
|
||||||
|
cp $distdir/mac/*.dmg "$pubdir/install/macos/"
|
||||||
|
|
||||||
|
mkdir -p "$pubdir/install/win32/"
|
||||||
|
cp $distdir/*.exe "$pubdir/install/win32/"
|
||||||
|
cp $distdir/latest.yml "$pubdir/install/win32/"
|
||||||
|
|
||||||
|
# Packages for auto-update on mac (Windows (NSIS) uses the installer exe)
|
||||||
|
mkdir -p "$pubdir/update/macos"
|
||||||
|
cp $distdir/mac/*.zip "$pubdir/update/macos/"
|
||||||
|
echo "$ver" > "$pubdir/update/macos/latest"
|
||||||
|
|
||||||
|
# Move the debs to the main project dir's dist folder
|
||||||
|
rm -r "$projdir/electron/dist" || true
|
||||||
|
mkdir -p "$projdir/electron/dist"
|
||||||
|
cp $distdir/*.deb "$projdir/electron/dist/"
|
||||||
|
|
||||||
|
rm -rf "$builddir"
|
||||||
|
|
||||||
|
echo "Riot Desktop $vername is ready to go in $pubdir: this directory can be hosted on your web server."
|
||||||
|
echo "deb archives are in electron/dist/ - these should be added into your debian repository"
|
Loading…
Reference in New Issue
Block a user