diff --git a/.dockerignore b/.dockerignore index 698f33a6..95c03cbd 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,7 +15,7 @@ config/*.p8 /docs /logs .flatpak-builder -flatpak/generated-sources.json +**/generated-sources.* flatpak/.flatpak-builder docsite/build docsite/node_modules diff --git a/.gitignore b/.gitignore index 7954a998..ead98818 100644 --- a/.gitignore +++ b/.gitignore @@ -132,3 +132,4 @@ flatpak/generated-sources.json build !setupProxy.js +**/generated-sources.* diff --git a/docsite/docs/development/flatpak.md b/docsite/docs/development/flatpak.md new file mode 100644 index 00000000..7f37a73a --- /dev/null +++ b/docsite/docs/development/flatpak.md @@ -0,0 +1,104 @@ +--- +toc_min_heading_level: 2 +toc_max_heading_level: 5 +sidebar_position: 4 +title: Flatpak +description: Building Flatpak App locally +--- + +:::note + +These steps are for building the flatpak from source. If you want to install the application normally then [get it through flathub](../installation/installation.md#flatpak) + +::: + +The final build repo for the flathub version can be found at [flathub/io.github.foxxmd.multiscrobbler](https://github.com/flathub/io.github.foxxmd.multiscrobbler) + +## Install Requirements + +### Flatpak and flatpak-builder + +Install [Flatpak](https://flatpak.org/setup/) + +Install [flatpak-builder](https://docs.flatpak.org/en/latest/first-build.html#building-your-first-flatpak) + +#### [flatpak-node-generator](https://github.com/flatpak/flatpak-builder-tools/tree/master/node) + +Requires python 3.7+, [pip](https://pip.pypa.io/en/stable/)/[pipx](https://pypa.github.io/pipx/) + +## Update Project source + +Set the `branch` `tag` or `commit` to use for MS in the `source` section of [`io.github.foxxmd.multiscrobbler.yml`](https://github.com/FoxxMD/multi-scrobbler/blob/master/flatpak/io.github.foxxmd.multiscrobbler.yml) + +## Generate Sources and Build + +### Use Setup Script + +A convenience bash script is provided that automates generating offline sources and building the flatpak app for you. This is the recommend method to use. + +Located in the project at [`flatpak/setup.sh`](https://github.com/FoxxMD/multi-scrobbler/blob/master/flatpak/setup.sh), run it from the `flatpak` directory with this syntax: + +```shell +./setup.sh -o -b /path/to/flatpak/build/dir +``` + +``` +Args: + +-o => Delete and overwrite any existing generated sources +-b => The absolute path to the directory that should be used for flatpak build/artifacts. If not defined will use `CWD/build` +-y => Proceed without confirming settings +``` + +### Manual Setup + +If you cannot use `setup.sh` follow the below to manually generate sources and build the flatpak app: + +
+ +Instructions + +#### Use `flatpak-node-generator` to generate sources + +First, [make sure `node_modules` is deleted or empty](https://github.com/flatpak/flatpak-builder-tools/issues/354#issuecomment-1478518442) for both the project and `docsite` directories. + +Then, from MS project root: + +```shell title="PROJECT_DIR" +flatpak-node-generator npm package-lock.json +``` + +Move `generated-sources.json` into `PROJECT_DIR/flatpak` and rename `generated-sources.0.json` + +Then, generate `docsite` sources: + +```shell title="PROJECT_DIR" +flatpak-node-generator npm docsite/package-lock.json +``` + +Move `generated-sources.json` into `PROJECT_DIR/flatpak` and rename `generated-sources.1.json` + +#### Build flatpak + +In the below command replace `/home/yourUser/multi-scrobbler-flatpak` with a directory to use for storing flatpak build/artifacts. + +```shell title="PROJECT_DIR/flatpak" +flatpak-builder --repo=/home/yourUser/multi-scrobbler-flatpak/repo --state-dir=/home/yourUser/multi-scrobbler-flatpak/state /home/yourUser/multi-scrobbler-flatpak/build io.github.foxxmd.multiscrobbler.yml --force-clean +``` + +:::info + +Append `--install --user` to the above command to have the app installed immediately. + +:::: + +
+ + +# Run App + +If built with `--install --user` (default when using `setup.sh`) you can now run MS using the command + +```shell +flatpak run -u io.github.foxxmd.multiscrobbler +``` diff --git a/flatpak/README.md b/flatpak/README.md index b22923b9..99c42ab1 100644 --- a/flatpak/README.md +++ b/flatpak/README.md @@ -1,48 +1 @@ -NOTE: This steps are for building the flatpak entirely locally, from source. If you want to install the application normally then [get it through flathub](/docs/installation.md#flatpak) - -The final build repo for the flathub version can be found at [flathub/io.github.foxxmd.multiscrobbler](https://github.com/flathub/io.github.foxxmd.multiscrobbler) - -# 1. Install Requirements - -## Flatpak and flatpak-builder - -Install [Flatpak](https://flatpak.org/setup/) - -Install [flatpak-builder](https://docs.flatpak.org/en/latest/first-build.html#building-your-first-flatpak) - -## [flatpak-node-generator](https://github.com/flatpak/flatpak-builder-tools/tree/master/node) - -Requires python 3.7+, [pip](https://pip.pypa.io/en/stable/)/[pipx](https://pypa.github.io/pipx/) - -# 2. Update Project source - -Set the `branch` `tag` or `commit` to use for MS in the `git` source in [`io.github.foxxmd.multiscrobbler.yml`](/flatpak/io.github.foxxmd.multiscrobbler.yml) - -# 3. Use `flatpak-node-generator` to generate sources - -First, [make sure `node_modules` is deleted or empty.](https://github.com/flatpak/flatpak-builder-tools/issues/354#issuecomment-1478518442) - -Then, from MS project root: - -```shell -flatpak-node-generator npm package-lock.json -``` - -Move `generated-sources.json` into [`/flatpak`](/flatpak) - -# 4. Build flatpak - -From MS project root: - -```shell -cd flatpak -flatpak-builder --repo=/home/yourUser/multi-scrobbler-flatpak/repo --state-dir=/home/yourUser/multi-scrobbler-flatpak/state /home/yourUser/multi-scrobbler-flatpak/build io.github.foxxmd.multiscrobbler.yml --force-clean --install --user -``` -Add `--install --user` to have the app installed immediately. -# 5. Run (Locally) - -If built with `--install --user` you can now run MS using the command - -```shell -flatpak run -u io.github.foxxmd.multiscrobbler -``` +See flatpak docs on the [docs website](https://foxxmd.github.io/multi-scrobbler/docs/development/dev-client) or at [`/docsite/docs/development/flatpak.md`](../docsite/docs/development/flatpak.md) diff --git a/flatpak/io.github.foxxmd.multiscrobbler.yml b/flatpak/io.github.foxxmd.multiscrobbler.yml index a3fe0585..2e442be9 100644 --- a/flatpak/io.github.foxxmd.multiscrobbler.yml +++ b/flatpak/io.github.foxxmd.multiscrobbler.yml @@ -21,7 +21,8 @@ modules: npm_config_offline: 'true' build-commands: # install npm dependencies - - npm install --offline + - npm ci --offline + - cd docsite && npm ci --offline && cd ../ # build app - NODE_ENV=production npm run build @@ -34,6 +35,8 @@ modules: # remove dev dependencies - npm prune --production + # remove docsite dependencies since we've built static site + - rm -r docsite/node_modules # copy node_modules needed to run app - cp -r node_modules/. /app/lib/node_modules @@ -45,6 +48,7 @@ modules: # copy app files to runtime dir - cp -r dist/. /app/lib/dist - cp -r src/. /app/lib/src + - cp -r docsite/. /app/lib/docsite - cp -r config /app/lib/config - cp -r assets /app/lib/assets - cp -r public /app/lib/public @@ -89,4 +93,5 @@ modules: fi - cd /app/lib && CONFIG_DIR=$XDG_CONFIG_HOME LOG_DIR=$XDG_CONFIG_HOME IS_LOCAL=true NODE_ENV=production node_modules/.bin/tsx src/backend/index.ts - - generated-sources.json + - generated-sources.0.json + - generated-sources.1.json diff --git a/flatpak/setup.sh b/flatpak/setup.sh new file mode 100755 index 00000000..e01021af --- /dev/null +++ b/flatpak/setup.sh @@ -0,0 +1,101 @@ +#!/bin/bash + +OVERWRITE="0" +CONFIRM="1" +# https://stackoverflow.com/a/14203146 +POSITIONAL_ARGS=() + +while [[ $# -gt 0 ]]; do + case $1 in + -b|--buildpath) + BUILDPATH="$2" + shift # past argument + shift # past value + ;; + -o|--overwrite) + OVERWRITE="1" + shift # past argument + ;; + -y|--yes) + CONFIRM="0" + shift # past argument + ;; + -*|--*) + echo "Unknown option $1" + exit 1 + ;; + *) + POSITIONAL_ARGS+=("$1") # save positional arg + shift # past argument + ;; + esac +done + +set -- "${POSITIONAL_ARGS[@]}" + +if [ ! -f "./io.github.foxxmd.multiscrobbler.yml" ]; then + echo "Run this script inside the 'flatpak' directory!" + exit 1 +fi + +if [ -z "${BUILDPATH}" ]; then + printf "\nNo build path set, using ./build\n" + BUILDPATH="${PWD##*/}/build" +fi + +printf '\nBuild Path: %s' "${BUILDPATH}" +if [ "$OVERWRITE" = "1" ]; then echo 'Overwrite Sources: True'; else printf 'Overwrite Sources: False\n'; fi + +if [ "$CONFIRM" = "1" ]; then + read -p "Continue? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1 +fi + +printf '\n' + +cd ../ + +if [ -d ./node_modules ]; then + echo 'Project node_modules exists, deleting...' + rm -r node_modules +fi + +if [ -d ./docsite/node_modules ]; then + echo 'Docsite node_modules exists, deleting...' + rm -r docsite/node_modules +fi + +GENERATE_SOURCES="1" + +if [ -f "flatpak/generated-sources.0.json" ] || [ -f "flatpak/generated-sources.1.json" ]; then + if [ "$OVERWRITE" = "0" ]; then + echo 'Generated sources exist, will not overwrite.'; + GENERATE_SOURCES=0 + else + echo 'Deleting existing sources...'; + rm -f flatpak/generated-sources.0.json + rm -f flatpak/generated-sources.1.json + fi +fi + +if [ "$GENERATE_SOURCES" = "1" ]; then + printf '\nGenerating project sources...\n' + rm -f generated-sources.json + flatpak-node-generator npm package-lock.json + mv generated-sources.json flatpak/generated-sources.0.json + + printf '\nGenerating docsite sources...\n' + flatpak-node-generator npm docsite/package-lock.json + mv generated-sources.json flatpak/generated-sources.1.json +fi + +cd flatpak || exit + +mkdir -p "$BUILDPATH" + +printf '\nBuilding flatpak app...\n' +set -x +flatpak-builder --repo="$BUILDPATH"/repo --state-dir="$BUILDPATH"/state "$BUILDPATH"/build io.github.foxxmd.multiscrobbler.yml --force-clean --install --user +# https://stackoverflow.com/questions/2853803/how-to-echo-shell-commands-as-they-are-executed#comment135696350_13718771 +{ set +x; } &> /dev/null + +echo 'Done!'