diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2ba9d22 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +/dist +/webapp +/webapp.asar +/packages +/deploys +/node_modules diff --git a/README b/README index 3786bb1..ffdd78a 100644 --- a/README +++ b/README @@ -5,3 +5,72 @@ This is *not* where the source for Riot desktop lives... yet. As of now, it still lives in the main riot-web repo: https://github.com/vector-im/riot-web This is an experimental split-out of the Riot desktop code from the main repo. + +Fetching Riot +============= +Since this package is just the Electron wrapper for Riot, it doesn't contain any of the Riot code, +so the first step is to get a working copy of Riot. There are a few ways of doing this: + +``` +# Fetch the prebuilt release Riot package from the riot.im GitHub releases page. The version +# fetched will be the same as the local riot-desktop package. +yarn run fetch --noverify +``` + +...or if you'd like to use GPG to verify the downloaded package: +``` +# Fetch the Riot public key from the riot.im web server over a secure connection and import +# it into your local GPG keychain (you'll need GPG installed). You only need to to do this +# once. +yarn run fetch --importkey +# Fetch the package and verify the signature +yarn run fetch +``` + +...or either of the above, but fetching a specific version of Riot: +``` +# Fetch the prebuilt release Riot package from the riot.im GitHub releases page. The version +# fetched will be the same as the local riot-desktop package. +yarn run fetch --noverify v1.5.6 +``` + +If you only want to run the app locally and don't need to build packages, you can +provide the `webapp` directory directly: +``` +# Assuming you've checked out and built a copy of riot-web in ../riot-web +ln -s ../riot-web/webapp ./ +``` + +[TODO: add support for fetching develop builds, arbitrary URLs and arbitrary paths] + + +Building +======== +Now you have a copy of Riot, you're ready to build packages. If you'd just like to +run Riot locally, skip to the next section. + +``` +yarn run build +``` +This will do a couple of things: + * Run the `setversion` script to set the local package version to match whatever + version of Riot you installed above. + * Run electron-builder to build a package. The package built will match the operating system + you're running the build process on. + +You can also build using docker, which will always produce the linux package: +``` +yarn run dockerbuild +``` + +After running, the packages should be in `dist/`. + +Starting +======== +If you'd just like to run the electron app locally for development: +``` +# Install electron - we don't normally need electron itself as it's provided +# by electron-builder when building packages +yarn add electron +yarn start +``` diff --git a/package.json b/package.json index 73e14d4..4131463 100644 --- a/package.json +++ b/package.json @@ -14,10 +14,10 @@ "scripts": { "mkdirs": "mkdirp packages deploys", "fetch": "yarn run mkdirs && node scripts/fetch-package.js", - "check": "node scripts/check-webapp.js", + "setversion": "node scripts/set-version.js", "start": "electron .", "lint": "eslint src/", - "build": "yarn run check && electron-builder", + "build": "yarn run setversion && electron-builder", "clean": "rimraf webapp.asar dist packages deploys" }, "dependencies": { diff --git a/scripts/check-webapp.js b/scripts/check-webapp.js deleted file mode 100755 index 8cbabb9..0000000 --- a/scripts/check-webapp.js +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env node - -const fs = require('fs').promises; - -async function main() { - try { - const webappDir = await fs.stat('webapp.asar'); - return 0; - } catch (e) { - console.log("No 'webapp.asar' found. Run 'yarn run fetch'"); - return 1; - } -} - -main().then((ret) => process.exit(ret)); diff --git a/scripts/dockerbuild.sh b/scripts/dockerbuild.sh new file mode 100755 index 0000000..19b22b9 --- /dev/null +++ b/scripts/dockerbuild.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Taken from https://www.electron.build/multi-platform-build#docker +docker run --rm -ti \ + --env-file <(env | grep -iE 'DEBUG|NODE_|ELECTRON_|YARN_|NPM_|CI|CIRCLE|TRAVIS_TAG|TRAVIS|TRAVIS_REPO_|TRAVIS_BUILD_|TRAVIS_BRANCH|TRAVIS_PULL_REQUEST_|APPVEYOR_|CSC_|GH_|GITHUB_|BT_|AWS_|STRIP|BUILD_') \ + --env ELECTRON_CACHE="/root/.cache/electron" \ + --env ELECTRON_BUILDER_CACHE="/root/.cache/electron-builder" \ + -v ${PWD}:/project \ + -v ${PWD##*/}-node-modules:/project/node_modules \ + -v ~/.cache/electron:/root/.cache/electron \ + -v ~/.cache/electron-builder:/root/.cache/electron-builder \ + electronuserland/builder yarn run build diff --git a/scripts/set-version.js b/scripts/set-version.js new file mode 100755 index 0000000..5786d3c --- /dev/null +++ b/scripts/set-version.js @@ -0,0 +1,39 @@ +#!/usr/bin/env node + +/* + * Checks for the pre3sence of a webapp, inspects its version and sets the + * version metadata of the package to match. + */ + +const fs = require('fs').promises; +const asar = require('asar'); +const child_process = require('child_process'); + +async function main() { + try { + const webappDir = await fs.stat('webapp.asar'); + } catch (e) { + console.log("No 'webapp.asar' found. Run 'yarn run fetch'"); + return 1; + } + + const ver = asar.extractFile('webapp.asar', 'version').toString().trim(); + await new Promise((resolve, reject) => { + child_process.execFile('yarn', [ + 'version', + '-s', + '--no-git-tag-version', // This also means "don't commit to git" as it turns out + '--new-version', + ver, + ], (err) => { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + console.log("Version set to " + ver); +} + +main().then((ret) => process.exit(ret));