diff --git a/.dockerignore b/.dockerignore index 4cb050aa..5db57ba2 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,12 @@ +.idea +.vscode **/node_modules **/.env +**/.env.example +*Dockerfile* +*docker-compose* +lastCommit.json +dist bfx-reports-framework/db/*.db bfx-reports-framework/db/*.json bfx-reports-framework/config/*.json @@ -9,12 +16,3 @@ bfx-reports-framework/csv bfx-report-ui/build bfx-report-ui/bfx-report-express/logs/*.log bfx-report-ui/bfx-report-express/config/*.json -docker-compose.yaml -Dockerfile.ui-builder -Dockerfile.linux-builder -Dockerfile.win-builder -Dockerfile.mac-builder -dist -.env.example -lastCommit.json -.vscode diff --git a/.env.example b/.env.example index 073a82e0..ad4da5cf 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,4 @@ -BRANCH=master -DB_DRIVER=better-sqlite +REPO_BRANCH=master +IS_BFX_API_STAGING=0 +IS_DEV_ENV=0 +EP_GH_IGNORE_TIME=true diff --git a/.github/workflows/build-electron-app.yml b/.github/workflows/build-electron-app.yml new file mode 100644 index 00000000..2fc50aa9 --- /dev/null +++ b/.github/workflows/build-electron-app.yml @@ -0,0 +1,97 @@ +name: build-electron-app + +permissions: + contents: write + +on: + push: + branches: + - master + pull_request: + branches: + - master + workflow_dispatch: + +env: + DOCKER_BUILDKIT: 1 + COMPOSE_DOCKER_CLI_BUILD: 1 + +jobs: + linux-win-docker-builder: + timeout-minutes: 90 + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + - name: Cache Docker images + uses: ScribeMD/docker-cache@0.1.4 + env: + cache-name: docker-images-cache-v1 + with: + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('Dockerfile**', 'docker-compose.yaml') }} + - name: Cache Electron binaries + id: electron-cache + uses: actions/cache@v3 + env: + cache-name: electron-cache-v1 + with: + path: | + ~/.cache/electron + ~/.cache/electron-builder + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + - name: Build release + id: release-builder + uses: nick-fields/retry@v2 + continue-on-error: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + timeout_minutes: 20 + retry_wait_seconds: 10 + max_attempts: 3 + retry_on: any + command: ./scripts/launch.sh -lwp + - name: Prepare cache folders + run: | + sudo chown -R $(id -u):$(id -g) ~/.cache/electron + sudo chown -R $(id -u):$(id -g) ~/.cache/electron-builder + + mac-builder: + timeout-minutes: 90 + runs-on: macos-11 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + submodules: recursive + - uses: actions/setup-node@v3 + with: + node-version: 14.16.0 + - name: Cache Electron binaries + id: electron-cache + uses: actions/cache@v3 + env: + cache-name: electron-cache-v1 + with: + path: | + ~/Library/Caches/electron + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + - name: Build release + id: release-builder + uses: nick-fields/retry@v2 + continue-on-error: false + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ELECTRON_CACHE: ~/Library/Caches/electron + with: + timeout_minutes: 20 + retry_wait_seconds: 10 + max_attempts: 3 + retry_on: any + command: ./scripts/build-release.sh -mp diff --git a/.gitignore b/.gitignore index 1f3dfa2a..ec5e5abb 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,4 @@ dist/* package-lock.json .env lastCommit.json -build/linux-launcher/launcher -build/linux-launcher/*.o +electronEnv.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d9534e7d..af680ed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,26 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.7.3] - 2022-07-08 + +### Added + +- Go to a specific date on the candles chart [bfx-report-ui#527](https://github.com/bitfinexcom/bfx-report-ui/pull/527) +- Add order metadata to csv [bfx-report#264](https://github.com/bitfinexcom/bfx-report/pull/264) and [bfx-report-framework#226](https://github.com/bitfinexcom/bfx-report-framework/pull/226) + +### Changed + +- Changes is calendar. Picked timezone its also used in the calendar [bfx-report-ui#529](https://github.com/bitfinexcom/bfx-report-ui/pull/529) +- Charts prices representation now has thousands separator [bfx-report-ui#523](https://github.com/bitfinexcom/bfx-report-ui/pull/523) +- Increase limit in candles sync for speed improment [bfx-report#262](https://github.com/bitfinexcom/bfx-report/pull/262) and [bfx-report-framework#224](https://github.com/bitfinexcom/bfx-report-framework/pull/224) + + +### Fixed + +- UI dependencies verification [bfx-report-ui#526](https://github.com/bitfinexcom/bfx-report-ui/pull/526) +- Fixes removing and adding sub accounts [bfx-report-framework#225](https://github.com/bitfinexcom/bfx-report-framework/pull/225) +- Fixes sub-account recalculation [bfx-report-framework#223](https://github.com/bitfinexcom/bfx-report-framework/pull/223) + ## [3.7.2] - 2022-06-01 ### Added diff --git a/Dockerfile.linux-builder b/Dockerfile.linux-builder index 5a1d7010..2a4423c9 100644 --- a/Dockerfile.linux-builder +++ b/Dockerfile.linux-builder @@ -1,10 +1,13 @@ FROM electronuserland/builder:14 -ENV NODE_VERSION 14.16.0 +ARG NODE_VERSION="14.16.0" -COPY ./scripts/install-nodejs.sh ./scripts/install-nodejs.sh +ENV IS_BFX_API_STAGING=${IS_BFX_API_STAGING:-0} +ENV IS_DEV_ENV=${IS_DEV_ENV:-0} -RUN ./scripts/install-nodejs.sh $NODE_VERSION \ +COPY ./scripts/helpers/install-nodejs.sh ./scripts/helpers/install-nodejs.sh + +RUN ./scripts/helpers/install-nodejs.sh ${NODE_VERSION} \ && apt-get update -y \ && apt-get install -y --no-install-recommends \ p7zip-full \ @@ -14,5 +17,5 @@ RUN ./scripts/install-nodejs.sh $NODE_VERSION \ COPY . . -ENTRYPOINT ["./scripts/init.sh"] -CMD ["-p", "linux", "-u"] +ENTRYPOINT ["./scripts/build-release.sh"] +CMD ["-l"] diff --git a/Dockerfile.mac-builder b/Dockerfile.mac-builder index d6602bd3..745e3831 100644 --- a/Dockerfile.mac-builder +++ b/Dockerfile.mac-builder @@ -1,10 +1,13 @@ FROM electronuserland/builder:14 -ENV NODE_VERSION 14.16.0 +ARG NODE_VERSION="14.16.0" -COPY ./scripts/install-nodejs.sh ./scripts/install-nodejs.sh +ENV IS_BFX_API_STAGING=${IS_BFX_API_STAGING:-0} +ENV IS_DEV_ENV=${IS_DEV_ENV:-0} -RUN ./scripts/install-nodejs.sh $NODE_VERSION \ +COPY ./scripts/helpers/install-nodejs.sh ./scripts/helpers/install-nodejs.sh + +RUN ./scripts/helpers/install-nodejs.sh ${NODE_VERSION} \ && apt-get update -y \ && apt-get install -y --no-install-recommends \ p7zip-full \ @@ -14,5 +17,5 @@ RUN ./scripts/install-nodejs.sh $NODE_VERSION \ COPY . . -ENTRYPOINT ["./scripts/init.sh"] -CMD ["-p", "mac", "-u"] +ENTRYPOINT ["./scripts/build-release.sh"] +CMD ["-m"] diff --git a/Dockerfile.ui-builder b/Dockerfile.ui-builder index fc979bae..8fb263d8 100644 --- a/Dockerfile.ui-builder +++ b/Dockerfile.ui-builder @@ -1,12 +1,14 @@ FROM electronuserland/builder:14 -ENV NODE_VERSION 14.16.0 +ARG NODE_VERSION="14.16.0" -COPY ./scripts/install-nodejs.sh ./scripts/install-nodejs.sh +ENV IS_BFX_API_STAGING=${IS_BFX_API_STAGING:-0} +ENV IS_DEV_ENV=${IS_DEV_ENV:-0} -RUN ./scripts/install-nodejs.sh $NODE_VERSION +COPY ./scripts/helpers/install-nodejs.sh ./scripts/helpers/install-nodejs.sh + +RUN ./scripts/helpers/install-nodejs.sh ${NODE_VERSION} COPY . . ENTRYPOINT ["./scripts/build-ui.sh"] -CMD ["-i"] diff --git a/Dockerfile.win-builder b/Dockerfile.win-builder index f7f96cc1..6521e9aa 100644 --- a/Dockerfile.win-builder +++ b/Dockerfile.win-builder @@ -1,10 +1,13 @@ FROM electronuserland/builder:14-wine -ENV NODE_VERSION 14.16.0 +ARG NODE_VERSION="14.16.0" -COPY ./scripts/install-nodejs.sh ./scripts/install-nodejs.sh +ENV IS_BFX_API_STAGING=${IS_BFX_API_STAGING:-0} +ENV IS_DEV_ENV=${IS_DEV_ENV:-0} -RUN ./scripts/install-nodejs.sh $NODE_VERSION \ +COPY ./scripts/helpers/install-nodejs.sh ./scripts/helpers/install-nodejs.sh + +RUN ./scripts/helpers/install-nodejs.sh ${NODE_VERSION} \ # Remove the `Wine` source entry to resolve # the release key expiration issue for `apt-get update` && sed -i '/Wine/d' /etc/apt/sources.list \ @@ -17,5 +20,5 @@ RUN ./scripts/install-nodejs.sh $NODE_VERSION \ COPY . . -ENTRYPOINT ["./scripts/init.sh"] -CMD ["-p", "win", "-u"] +ENTRYPOINT ["./scripts/build-release.sh"] +CMD ["-w"] diff --git a/README.md b/README.md index a3fb4a22..587a7c0e 100644 --- a/README.md +++ b/README.md @@ -2,64 +2,146 @@ ## Binaries -Already complied binaries can be found on release section [release section](https://github.com/bitfinexcom/bfx-report-electron/releases).
-Download the correspondent binary according your operating system.
+Already complied binaries can be found on release section [release section](https://github.com/bitfinexcom/bfx-report-electron/releases) + +Download the correspondent binary according your operating system ## Setup -### Install +Functionality has been tested on `Ubuntu 20.04 LTS` -Execute the following commands from the root directory of the project: +### Main Structure -- Install libraries. +To simplify setup/build/publish processes the following bash scripts are provided: -```console -npm install -``` +- `./scripts/setup.sh` - CLI as an easy way to get through the setup process. It will launch `./scripts/sync-repo.sh` script and then setup the development environment +- `./scripts/sync-repo.sh` - CLI to fetch the last changes of the repository/sub-modules from the main remote repo +- `./scripts/launch.sh` - CLI to launch docker-compose services to build releases and publish executable artifacts of the electron app with the last fetched changes + +Additional bash scripts: + +- `./scripts/build-release.sh` - CLI as the entrypoint to start the build release process, uses in the docker container, but can be used independently +- `./scripts/build-ui.sh` - CLI as the entrypoint to start the build UI process, uses in the docker container, but can be used independently +- `./scripts/helpers` - folder with addition bash functions +- `./scripts/node` - folder with addition NodeJS scripts + +### Requirements + +The setup was tested with the following dependencies: -- Install dependcies and configured them. +- Docker version 20.10.12 +- docker-compose version 1.29.2 +- git version 2.24.1 + +To install `Docker`/`docker-compose` check the corresponding sections of the official docs: + +- [install Docker](https://docs.docker.com/engine/install) +- [install docker-compose](https://docs.docker.com/compose/install) +- if you don’t want to preface the docker command with sudo, create a Unix group called docker and add users to it, [check the doc](https://docs.docker.com/engine/install/linux-postinstall) + +### Setup electron app + +After cloning the repository there's needed to configure the app. For it can be used `./scripts/setup.sh` bash script. +Available the following arguments: ```console -npm run init +./scripts/setup.sh -h + +Usage: ./scripts/setup.sh [options] [-h] + +Options: + -r Sync all repositories + -o Sync only sub-modules + -s Use staging BFX API + -d Set development environment + -h Display help ``` -### Run the electron +Also there will be executed the following steps: + +- setup backend configs +- install all backend dependencies +- setup and build the UI static files + +To launch `./scripts/setup.sh` script also can be used the following NPM script: ```console -npm run electron +npm run setup -- -r ``` -### Build distributions +### Sync repo process -For doing builds for other platforms please have “Multi Platform Build” in consideration: [electron-builder documentation](https://www.electron.build/multi-platform-build) +In case needs to fetch the last changes all repository/sub-modules might be used `./scripts/sync-repo.sh` bash script. +Available the following arguments: -#### Requirements +```console +./scripts/sync-repo.sh -h -- [Install Docker](https://docs.docker.com/engine/install) -- [Install Docker Compose](https://docs.docker.com/compose/install/#install-compose-on-linux-systems) -- For Linux, if you don’t want to preface the docker command with `sudo`, create a Unix group called docker and add users to it, [check the documentation](https://docs.docker.com/engine/install/linux-postinstall) +Usage: ./scripts/sync-repo.sh [options] | [-h] -For creating the distributions please run the following commands, after the execution is finished the file would be in */dist* folder +Options: + -a Sync all repositories + -m Sync bfx-report-electron only + -w Sync bfx-reports-framework only + -u Sync bfx-report-ui only + -e Sync bfx-report-express only + -h Display help +``` -- Individual: +To launch `./scripts/sync-repo.sh` script also can be used the following NPM script: ```console -#Distribution for Linux -docker-compose up --build --force-recreate ui-builder linux-builder +npm run sync-repo -- -wue +``` -#Distribution for Windows -docker-compose up --build --force-recreate ui-builder win-builder +### Launch Electron App for dev purpose -#Distribution for MacOs -docker-compose up --build --force-recreate ui-builder mac-builder +For Dev purpose to launch the Electron app locally might be used the following NPM script: + +```console +npm start ``` -- Linux + Windows + MacOs: +### Launch build process + +For doing builds for other platforms please have [Multi Platform Build](https://www.electron.build/multi-platform-build) in consideration + +To launch docker-compose services to build releases and publish executable artifacts of the electron app available the `./scripts/launch.sh` bash script. +Available the following arguments: ```console -docker-compose up --build --force-recreate +./scripts/launch.sh -h + +Usage: ./scripts/launch.sh [options] [-h] + +Options: + -a Build all releases + -l Build Linux release + -w Build Windows release + -m Build Mac release + -r Sync all repositories + -o Sync only sub-modules + -s Use staging BFX API + -d Set development environment + -p Publish artifacts + -h Display help ``` -## Export CSV reports +It provides the following steps: + +- if the corresponding flag is added will be fetched the last changes repository/sub-modules +- launch Docker container to build UI using `./scripts/build-ui.sh` entrypoint, compiled UI files will be used in the build process of the Electron app +- launch Docker containers for selected OSs (Linux, Windows, Mac) to build releases of the Electron app using `./scripts/build-release.sh` entrypoint +- if `-p` flag is passed and `GH_TOKEN` or `GITHUB_TOKEN` environment variable is set: + - after the binary artifacts are successfully built + - publish artifacts on the github releases page as a `draft` + - after which they can be downloaded/tested and if everything is fine, press the buttons for editing and then publishing the release with the corresponding tag, check this [Recommended GitHub Releases Workflow](https://www.electron.build/configuration/publish#recommended-github-releases-workflow) +- without `-p` flag, artifacts will be in the `./dist` folder + +To launch `./scripts/launch.sh` script also can be used the following NPM script: + +```console +npm run launch -- -aop +``` -Exported CSV reports are contained in the root folder of the application in `csv` directory for Linux and Windows releases, and in `~/Library/Application Support/bfx-report-electron/csv` directory for Mac release +> Also, we provide [GitHub Actioins workflows](https://docs.github.com/en/actions/using-workflows/about-workflows) configs for automated building and publishing of the Electron app artifacts using the above-described scripts `./scripts/launch.sh` and `./scripts/build-release.sh`, see the corresponding file `.github/workflows/build-electron-app.yml` diff --git a/bfx-report-ui b/bfx-report-ui index 96271b23..5976e111 160000 --- a/bfx-report-ui +++ b/bfx-report-ui @@ -1 +1 @@ -Subproject commit 96271b237cf78a31197f003bfba74da03fa6327d +Subproject commit 5976e1112941d0197c0626d6e56f50a565400a2f diff --git a/bfx-reports-framework b/bfx-reports-framework index 2db4ca66..bff55fbc 160000 --- a/bfx-reports-framework +++ b/bfx-reports-framework @@ -1 +1 @@ -Subproject commit 2db4ca6609569c628c5be54e7e2b008c7f1d11b6 +Subproject commit bff55fbcbe58cbb452209ce2e31d5792a0f714d7 diff --git a/build/linux-launcher/Makefile b/build/linux-launcher/Makefile deleted file mode 100644 index 1df73b4c..00000000 --- a/build/linux-launcher/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -VERBOSE = TRUE - -TARGET := launcher -OBJECTS := $(TARGET).o - -CC := gcc -CFLAGS := -g -Wall -no-pie -LIBS := - -RM := rm -rf -ERRIGNORE := 2>/dev/null - -ifeq ($(VERBOSE),TRUE) - HIDE := -else - HIDE := @ -endif - -all: cleanExe $(TARGET) clean - -$(TARGET): $(OBJECTS) - $(HIDE)$(CC) $(CFLAGS) -o $@ $(OBJECTS) $(LIBS) - -cleanExe: - $(HIDE)$(RM) $(TARGET) $(ERRIGNORE) - -clean: - $(HIDE)$(RM) *.o $(ERRIGNORE) diff --git a/build/linux-launcher/launcher.c b/build/linux-launcher/launcher.c deleted file mode 100644 index c23c0e5f..00000000 --- a/build/linux-launcher/launcher.c +++ /dev/null @@ -1,34 +0,0 @@ -#include -#include -#include -#include -#include - -void msgBox(char *s){ - char cmd[1024]; - sprintf(cmd, "./msg-box.sh \"%s\"", s); - - int state = system(cmd); - - if (state) { - system("zenity --error --ellipsize --text=\"Error with msg-box.sh\""); - } -} - -int main(int argc, char *argv[]) { - errno = 0; - - char *programName = "./launcher.sh"; - char *args[] = { programName, NULL }; - - execvp(programName, args); - perror(programName); - - char *errMess = strerror(errno); - char mess[1024]; - - sprintf(mess, "%s: %s", programName, errMess); - msgBox(mess); - - exit(1); -} diff --git a/build/linux-launcher/launcher.sh b/build/linux-launcher/launcher.sh deleted file mode 100755 index 752e6364..00000000 --- a/build/linux-launcher/launcher.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -ROOT=$PWD - -if [ ! -z "$1" ]; then - ROOT=$1 -fi - -appFilePath="$ROOT/app" -logFilePath="$ROOT/error.log" - -output=$("$appFilePath" 2>&1) -mess=$(echo "$output" | grep -v WARNING | grep -v electron\/issues\/23506 | grep -v Cannot\ download\ differentially | grep -v GtkDialog mapped without a transient parent) - -if [ "$mess" != "" ]; then - echo $mess>>"$logFilePath" - ./msg-box.sh "$mess" -fi diff --git a/build/linux-launcher/msg-box.sh b/build/linux-launcher/msg-box.sh deleted file mode 100755 index 0213ca0a..00000000 --- a/build/linux-launcher/msg-box.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -mess="" - -if [ $# -ge 1 ] -then - mess=$1 -else - exit 0 -fi - -zenity \ - --error \ - --width=600\ - --ok-label="OK" \ - --title="Error of Bitfinex Report" \ - --text="$mess" \ - 2>/dev/null diff --git a/docker-compose.yaml b/docker-compose.yaml index 2242e863..35f88545 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -7,8 +7,10 @@ services: context: . dockerfile: Dockerfile.ui-builder environment: - BRANCH: ${BRANCH} - UI_BUILD_FOLDER: /ui-build + COMMON_UI_BUILD_FOLDER: /ui-build + IS_BFX_API_STAGING: ${IS_BFX_API_STAGING:-0} + IS_DEV_ENV: ${IS_DEV_ENV:-0} + CURRENT_UID: ${CURRENT_UID:-"1000:1000"} volumes: - ui-build:/ui-build @@ -20,13 +22,20 @@ services: environment: ELECTRON_CACHE: /root/.cache/electron ELECTRON_BUILDER_CACHE: /root/.cache/electron-builder - BRANCH: ${BRANCH} - UI_BUILD_FOLDER: /ui-build + COMMON_UI_BUILD_FOLDER: /ui-build + COMMON_DIST_FOLDER: /dist + IS_BFX_API_STAGING: ${IS_BFX_API_STAGING:-0} + IS_DEV_ENV: ${IS_DEV_ENV:-0} + IS_PUBLISHED: ${IS_PUBLISHED:-0} + GH_TOKEN: ${GH_TOKEN:-} + GITHUB_TOKEN: ${GITHUB_TOKEN:-} + EP_GH_IGNORE_TIME: ${EP_GH_IGNORE_TIME:-true} + CURRENT_UID: ${CURRENT_UID:-"1000:1000"} volumes: - ui-build:/ui-build - ./dist:/dist - - electron-cache:/root/.cache/electron - - electron-builder-cache:/root/.cache/electron-builder + - ~/.cache/electron:/root/.cache/electron + - ~/.cache/electron-builder:/root/.cache/electron-builder win-builder: container_name: win-builder @@ -36,13 +45,20 @@ services: environment: ELECTRON_CACHE: /root/.cache/electron ELECTRON_BUILDER_CACHE: /root/.cache/electron-builder - BRANCH: ${BRANCH} - UI_BUILD_FOLDER: /ui-build + COMMON_UI_BUILD_FOLDER: /ui-build + COMMON_DIST_FOLDER: /dist + IS_BFX_API_STAGING: ${IS_BFX_API_STAGING:-0} + IS_DEV_ENV: ${IS_DEV_ENV:-0} + IS_PUBLISHED: ${IS_PUBLISHED:-0} + GH_TOKEN: ${GH_TOKEN:-} + GITHUB_TOKEN: ${GITHUB_TOKEN:-} + EP_GH_IGNORE_TIME: ${EP_GH_IGNORE_TIME:-true} + CURRENT_UID: ${CURRENT_UID:-"1000:1000"} volumes: - ui-build:/ui-build - ./dist:/dist - - electron-cache:/root/.cache/electron - - electron-builder-cache:/root/.cache/electron-builder + - ~/.cache/electron:/root/.cache/electron + - ~/.cache/electron-builder:/root/.cache/electron-builder mac-builder: container_name: mac-builder @@ -52,15 +68,20 @@ services: environment: ELECTRON_CACHE: /root/.cache/electron ELECTRON_BUILDER_CACHE: /root/.cache/electron-builder - BRANCH: ${BRANCH} - UI_BUILD_FOLDER: /ui-build + COMMON_UI_BUILD_FOLDER: /ui-build + COMMON_DIST_FOLDER: /dist + IS_BFX_API_STAGING: ${IS_BFX_API_STAGING:-0} + IS_DEV_ENV: ${IS_DEV_ENV:-0} + IS_PUBLISHED: ${IS_PUBLISHED:-0} + GH_TOKEN: ${GH_TOKEN:-} + GITHUB_TOKEN: ${GITHUB_TOKEN:-} + EP_GH_IGNORE_TIME: ${EP_GH_IGNORE_TIME:-true} + CURRENT_UID: ${CURRENT_UID:-"1000:1000"} volumes: - ui-build:/ui-build - ./dist:/dist - - electron-cache:/root/.cache/electron - - electron-builder-cache:/root/.cache/electron-builder + - ~/.cache/electron:/root/.cache/electron + - ~/.cache/electron-builder:/root/.cache/electron-builder volumes: ui-build: - electron-cache: - electron-builder-cache: diff --git a/electron-builder-config.js b/electron-builder-config.js new file mode 100644 index 00000000..46112a2c --- /dev/null +++ b/electron-builder-config.js @@ -0,0 +1,254 @@ +'use strict' + +const fs = require('fs') +const path = require('path') +const zlib = require('zlib') +const { promisify } = require('util') +const archiver = require('archiver') +const exec = promisify(require('child_process').exec) + +let version +const appOutDirs = new Map() + +/* eslint-disable no-template-curly-in-string */ + +const nodeModulesFilter = [ + '**/*', + '!**/*/{CHANGELOG.md,CHANGELOG,README.md,README,readme.md,readme}', + '!**/*/{test,__tests__,tests,powered-test,example,examples}', + '!**/*.d.ts', + '!**/.bin' +] + +const getNodeModulesSubSources = (mainSource) => { + const mainNodeModules = `${mainSource}/node_modules` + const mainPath = path.join(__dirname, mainNodeModules) + + const deps = fs.readdirSync( + mainPath, + { withFileTypes: true } + ) + + return deps.reduce((accum, dirDirent) => { + if (!dirDirent.isDirectory()) { + return accum + } + + const hasNodeModules = fs.readdirSync( + path.join(mainPath, dirDirent.name), + { withFileTypes: true } + ).some((subDirDirent) => ( + subDirDirent.isDirectory() && + subDirDirent.name === 'node_modules' + )) + + if (hasNodeModules) { + const from = `${mainNodeModules}/${dirDirent.name}/node_modules` + + accum.push({ from, to: from, filter: nodeModulesFilter }) + } + + return accum + }, []) +} + +module.exports = { + generateUpdatesFilesForAllChannels: true, + npmRebuild: false, + extends: null, + asar: false, + productName: 'Bitfinex Report', + artifactName: 'BitfinexReport-${version}-x64-${os}.${ext}', + appId: 'com.bitfinex.report', + publish: { + provider: 'github', + repo: 'bfx-report-electron', + owner: 'bitfinexcom', + vPrefixedTagName: true, + channel: 'latest', + + // Available: 'draft', 'prerelease', 'release' + releaseType: 'draft', + updaterCacheDirName: 'bfx-report-electron-updater' + }, + linux: { + executableName: 'app', + description: 'Bitfinex Report', + maintainer: '', + category: 'Network', + target: [ + 'dir', + 'AppImage' + ] + }, + win: { + target: [ + 'dir', + 'nsis' + ], + publisherName: 'Bitfinex Report', + verifyUpdateCodeSignature: false + }, + mac: { + type: 'development', + hardenedRuntime: true, + gatekeeperAssess: false, + entitlements: 'build/entitlements.mac.plist', + entitlementsInherit: 'build/entitlements.mas.inherit.plist', + category: 'public.app-category.finance', + target: [ + 'dir' + ] + }, + files: [ + '**/*', + 'build/icons', + 'build/icon.*', + 'build/loader.*', + '!scripts${/*}', + + '!bfx-report-ui', + 'bfx-report-ui/build', + 'bfx-report-ui/bfx-report-express/**/*', + '!bfx-report-ui/bfx-report-express/config/default.json.example', + '!bfx-report-ui/bfx-report-express/pm2.config.js', + + '!bfx-reports-framework/bfx-report-ui/${/*}', + '!bfx-reports-framework/config/*/*.json.example', + '!bfx-reports-framework/nginx-configs/${/*}', + '!bfx-reports-framework/terraform/${/*}', + '!bfx-reports-framework/test/${/*}', + '!bfx-reports-framework/scripts/${/*}', + '!bfx-reports-framework/*/*.sh', + '!bfx-reports-framework/*.sh', + '!bfx-reports-framework/.mocharc.json', + + '!**/.dockerignore', + '!**/*Dockerfile*', + '!**/*docker-compose*', + '!**/.env', + '!**/.env.example', + '!**/README.md', + '!**/LICENSE.md', + '!**/.gitmodules', + '!**/.npmrc', + { + from: 'bfx-reports-framework/node_modules', + to: 'bfx-reports-framework/node_modules', + filter: nodeModulesFilter + }, + { + from: 'bfx-report-ui/bfx-report-express/node_modules', + to: 'bfx-report-ui/bfx-report-express/node_modules', + filter: nodeModulesFilter + }, + ...getNodeModulesSubSources('bfx-reports-framework'), + ...getNodeModulesSubSources('bfx-report-ui/bfx-report-express') + ], + async afterPack (context) { + const { + appOutDir, + outDir + } = context + + await fs.promises.access(appOutDir, fs.constants.F_OK) + + try { + await exec(`chmod -fR a+xwr ${outDir}`) + } catch (err) { + console.error(err) + } + + version = context.packager.appInfo.version + appOutDirs.set( + context.packager.platform.buildConfigurationKey, + appOutDir + ) + }, + async afterAllArtifactBuild (buildResult) { + const { + outDir, + artifactPaths, + platformToTargets, + configuration: { publish: { channel } } + } = buildResult + const macBlockmapFilePaths = [] + + for (const [platform, targets] of platformToTargets) { + const { + buildConfigurationKey: targetPlatform + } = platform + + if (!appOutDirs.has(targetPlatform)) { + throw new Error('ERR_APP_DIST_DIR_IS_NOT_DEFINED') + } + + if ( + targetPlatform === 'mac' && + !targets.has('zip') + ) { + targets.set('zip', {}) + artifactPaths.push(path.join( + outDir, + `BitfinexReport-${version}-x64-${targetPlatform}.zip` + )) + } + + for (const [targetName] of targets) { + const ext = targetName === 'nsis' + ? 'exe' + : targetName + const appFilePath = artifactPaths.find((path) => ( + new RegExp(`${targetPlatform}.*${ext}$`, 'i').test(path) + )) + + if ( + targetPlatform === 'mac' && + targetName === 'zip' + ) { + macBlockmapFilePaths.push( + `${appFilePath}.blockmap`, + path.join(outDir, `${channel}-mac.yml`) + ) + + require('./scripts/node/make-mac-app-update-yml') + await new Promise((resolve, reject) => { + try { + const output = fs.createWriteStream(appFilePath) + const archive = archiver('zip', { + zlib: { level: zlib.constants.Z_BEST_COMPRESSION } + }) + + output.on('close', resolve) + output.on('error', reject) + archive.on('error', reject) + archive.on('warning', reject) + + archive.pipe(output) + archive.directory(appOutDirs.get(targetPlatform), false) + + archive.finalize() + } catch (err) { + reject(err) + } + }) + require('./scripts/node/generate-mac-zipand-blockmap') + + console.log('Mac release has been zipped successfully') + } + + await fs.promises.access(appFilePath, fs.constants.F_OK) + + try { + await fs.promises.chmod(appFilePath, '777') + } catch (err) { + console.error(err) + } + } + } + + return macBlockmapFilePaths.length > 0 + ? [...artifactPaths, ...macBlockmapFilePaths] + : [] + } +} diff --git a/index.js b/index.js index a45e6d5d..c49aad35 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,16 @@ 'use strict' +try { + const { NODE_ENV } = require('./electronEnv.json') + + if ( + !process.env.NODE_ENV && + NODE_ENV + ) { + process.env.NODE_ENV = NODE_ENV + } +} catch (err) {} + const { app } = require('electron') const productName = require('./src/helpers/product-name') diff --git a/package.json b/package.json index 0fd8b3c2..07782b48 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,13 @@ { "name": "bfx-report-electron", - "version": "3.7.2", + "version": "3.7.3", "repository": "https://github.com/bitfinexcom/bfx-report-electron", "description": "Reporting tool", "author": "bitfinex.com", "main": "index.js", + "engine": { + "node": ">=14.16.0" + }, "license": "Apache-2.0", "dependencies": { "archiver": "5.3.0", @@ -19,7 +22,7 @@ "electron-log": "4.4.1", "electron-root-path": "1.0.16", "electron-serve": "1.1.0", - "electron-updater": "4.3.8", + "electron-updater": "5.0.4", "extract-zip": "2.0.1", "find-free-port": "2.0.0", "github-markdown-css": "5.1.0", @@ -35,8 +38,7 @@ "@mapbox/node-pre-gyp": "1.0.6", "app-builder-bin": "4.1.0", "electron": "13.6.9", - "electron-builder": "22.11.7", - "node-gyp": "7.1.2", + "electron-builder": "23.0.9", "standard": "16.0.4" }, "standard": { @@ -48,185 +50,10 @@ ] }, "scripts": { - "start": "./scripts/init.sh -s&&npm run dist-linux&&npm run dist-win&&npm run dist-mac", - "startDev": "./scripts/init.sh -d -s&&npm run dist-linux&&npm run dist-win&&npm run dist-mac", - "init": "./scripts/init.sh", - "initDev": "./scripts/init.sh -d", - "dist-win": "./scripts/reinstall-deps.sh win32&&electron-builder build --win", - "dist-linux": "./scripts/reinstall-deps.sh linux&&electron-builder build --linux", - "dist-mac": "./scripts/reinstall-deps.sh darwin&&electron-builder build --mac", - "electron": "export NODE_ENV=development&&export DEBUG=*&&electron .", - "test": "standard" - }, - "build": { - "publish": { - "provider": "github", - "repo": "bfx-report-electron", - "owner": "bitfinexcom", - "channel": "latest", - "allowPrerelease": true, - "useMultipleRangeRequest": false, - "updaterCacheDirName": "bfx-report-electron-updater" - }, - "npmRebuild": false, - "extends": null, - "asar": false, - "productName": "Bitfinex Report", - "artifactName": "BitfinexReport-${version}-x64-${os}.${ext}", - "appId": "com.bitfinex.report", - "files": [ - "**/*", - "build/icons", - "build/icon.*", - "build/loader.*", - "bfx-reports-framework", - "!.dockerignore", - "!scripts", - "!bfx-reports-framework/init.sh", - "!bfx-reports-framework/bfx-report-ui", - "!bfx-reports-framework/test", - "!bfx-report-ui", - "bfx-report-ui/build", - "bfx-report-ui/bfx-report-express", - "!bfx-report-ui/bfx-report-express/pm2.config.js", - "!**/.gitmodules", - "!**/.npmrc", - "!**/.mocharc.json", - "!**/README.md", - { - "from": "bfx-reports-framework/node_modules", - "to": "bfx-reports-framework/node_modules", - "filter": [ - "**/*", - "!.bin", - "!**/node_modules/.bin", - "!**/*.md", - "!**/LICENSE", - "!**/CHANGELOG", - "!**/test" - ] - }, - { - "from": "bfx-reports-framework/node_modules/bfx-api-node-rest/node_modules", - "to": "bfx-reports-framework/node_modules/bfx-api-node-rest/node_modules", - "filter": [ - "**/*", - "!.bin", - "!**/node_modules/.bin", - "!**/*.md", - "!**/LICENSE", - "!**/CHANGELOG", - "!**/test" - ] - }, - { - "from": "bfx-reports-framework/node_modules/bfx-svc-boot-js/node_modules", - "to": "bfx-reports-framework/node_modules/bfx-svc-boot-js/node_modules", - "filter": [ - "**/*", - "!.bin", - "!**/node_modules/.bin", - "!**/*.md", - "!**/LICENSE", - "!**/CHANGELOG", - "!**/test" - ] - }, - { - "from": "bfx-reports-framework/node_modules/yargs/node_modules", - "to": "bfx-reports-framework/node_modules/yargs/node_modules", - "filter": [ - "**/*", - "!.bin", - "!**/node_modules/.bin", - "!**/*.md", - "!**/LICENSE", - "!**/CHANGELOG", - "!**/test" - ] - }, - { - "from": "bfx-reports-framework/node_modules/bfx-report/node_modules", - "to": "bfx-reports-framework/node_modules/bfx-report/node_modules", - "filter": [ - "**/*", - "!.bin", - "!**/node_modules/.bin", - "!**/*.md", - "!**/LICENSE", - "!**/CHANGELOG", - "!**/test" - ] - }, - { - "from": "bfx-reports-framework/node_modules/request/node_modules", - "to": "bfx-reports-framework/node_modules/request/node_modules", - "filter": [ - "**/*", - "!.bin", - "!**/node_modules/.bin", - "!**/*.md", - "!**/LICENSE", - "!**/CHANGELOG", - "!**/test" - ] - }, - { - "from": "bfx-reports-framework/node_modules/lokue/node_modules", - "to": "bfx-reports-framework/node_modules/lokue/node_modules", - "filter": [ - "**/*", - "!.bin", - "!**/node_modules/.bin", - "!**/*.md", - "!**/LICENSE", - "!**/CHANGELOG", - "!**/test" - ] - }, - { - "from": "bfx-report-ui/bfx-report-express/node_modules", - "to": "bfx-report-ui/bfx-report-express/node_modules", - "filter": [ - "**/*", - "!.bin", - "!**/node_modules/.bin", - "!**/*.md", - "!**/LICENSE", - "!**/CHANGELOG", - "!**/test" - ] - } - ], - "linux": { - "executableName": "app", - "description": "Bitfinex Report", - "maintainer": "", - "category": "Network", - "target": [ - "dir", - "AppImage" - ] - }, - "win": { - "target": [ - "dir", - "nsis" - ], - "publisherName": "Bitfinex Report", - "verifyUpdateCodeSignature": false - }, - "mac": { - "type": "development", - "hardenedRuntime": true, - "gatekeeperAssess": false, - "entitlements": "build/entitlements.mac.plist", - "entitlementsInherit": "build/entitlements.mas.inherit.plist", - "category": "public.app-category.finance", - "target": [ - "dir", - "zip" - ] - } + "start": "export NODE_ENV=development&&export DEBUG=*&&electron .", + "test": "standard", + "setup": "./scripts/setup.sh", + "launch": "./scripts/launch.sh", + "sync-repo": "./scripts/sync-repo.sh" } } diff --git a/scripts/build-release.sh b/scripts/build-release.sh new file mode 100755 index 00000000..913fb7b1 --- /dev/null +++ b/scripts/build-release.sh @@ -0,0 +1,243 @@ +#!/bin/bash + +set -euo pipefail + +SCRIPTPATH="${SCRIPTPATH:-"$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"}" +ROOT="${ROOT:-"$(dirname "$SCRIPTPATH")"}" +BUILD_RELEASE_CURRDIR="$PWD" +DOT_ENV_FILE_PATH="$ROOT/.env" + +set -a +[ -f "$DOT_ENV_FILE_PATH" ] && . "$DOT_ENV_FILE_PATH" +set +a + +COLOR_RED=${COLOR_RED:-"\033[31m"} +COLOR_GREEN=${COLOR_GREEN:-"\033[32m"} +COLOR_YELLOW=${COLOR_YELLOW:-"\033[33m"} +COLOR_BLUE=${COLOR_BLUE:-"\033[34m"} +COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + +ARCH="x64" +BFX_API_URL="https://api-pub.bitfinex.com" +STAGING_BFX_API_URL="https://api.staging.bitfinex.com" + +ELECTRON_BUILDER_CONFIG_FILE_NAME="electron-builder-config.js" +ELECTRON_BUILDER_CONFIG_FILE_PATH="$ROOT/$ELECTRON_BUILDER_CONFIG_FILE_NAME" +LAST_COMMIT_FILE_NAME="lastCommit.json" +ELECTRON_ENV_FILE_NAME="electronEnv.json" + +WORKER_FOLDER="$ROOT/bfx-reports-framework" +UI_FOLDER="$ROOT/bfx-report-ui" +EXPRESS_FOLDER="$UI_FOLDER/bfx-report-express" +UI_BUILD_FOLDER="$UI_FOLDER/build" +COMMON_UI_BUILD_FOLDER="${COMMON_UI_BUILD_FOLDER:-}" +DIST_FOLDER="$ROOT/dist" +COMMON_DIST_FOLDER="${COMMON_DIST_FOLDER:-}" +ELECTRON_CACHE="${ELECTRON_CACHE:-}" +ELECTRON_BUILDER_CACHE="${ELECTRON_BUILDER_CACHE:-}" + +source "$ROOT/scripts/helpers/make-last-commit-json.sh" +source "$ROOT/scripts/helpers/run-ui-watchdog.sh" +source "$ROOT/scripts/helpers/escape-string.sh" +source "$ROOT/scripts/helpers/install-backend-deps.sh" +source "$ROOT/scripts/helpers/get-conf-value.sh" +source "$ROOT/scripts/helpers/change-dir-ownership-to-curr-user.sh" + +programname=$0 +targetPlatform="" +countReqOSs=0 +bfxApiUrl="$BFX_API_URL" +productName=$(getConfValue "productName" "$ROOT" "$ELECTRON_BUILDER_CONFIG_FILE_NAME") +version=$(getConfValue "version" "$ROOT") +hasIUNotBeenBuilt=0 + +buildLinux=0 +buildWin=0 +buildMac=0 +isBfxApiStaging=${IS_BFX_API_STAGING:-0} +isDevEnv=${IS_DEV_ENV:-0} +isPublished=${IS_PUBLISHED:-0} + +function usage { + echo -e "\ +\n${COLOR_GREEN}Usage: $programname [options] [-h]${COLOR_BLUE} +\nOptions: + -l Build Linux release + -w Build Windows release + -m Build Mac release + -s Use staging BFX API + -d Set development environment + -p Publish artifacts + -h Display help\ +${COLOR_NORMAL}" 1>&2 +} + +if [ $# == 0 ]; then + echo -e "\n${COLOR_RED}Requires at least one option!${COLOR_NORMAL}" >&2 + usage + exit 1 +fi + +while getopts "lwmsdph" opt; do + case "${opt}" in + l) buildLinux=1;; + w) buildWin=1;; + m) buildMac=1;; + s) isBfxApiStaging=1;; + d) isDevEnv=1;; + p) isPublished=1;; + h) + usage + exit 0 + ;; + *) + echo -e "\n${COLOR_RED}No reasonable options found!${COLOR_NORMAL}" >&2 + usage + exit 1 + ;; + esac +done + +declare -a areqOSArr=( + $buildLinux + $buildWin + $buildMac +) + +for i in "${areqOSArr[@]}"; do + if [ $i == 1 ]; then + ((countReqOSs+=1)) + fi + if [[ $countReqOSs > 1 ]]; then + echo -e "\n${COLOR_RED}A release for only one OS may be required!${COLOR_NORMAL}" >&2 + exit 1 + fi +done + +if [ $countReqOSs != 1 ]; then + echo -e "\n${COLOR_RED}A release for at least one OS may be required!${COLOR_NORMAL}" >&2 + exit 1 +fi + +if [ $buildLinux == 1 ]; then + targetPlatform="linux" +fi +if [ $buildWin == 1 ]; then + targetPlatform="win" +fi +if [ $buildMac == 1 ]; then + targetPlatform="mac" +fi + +if [ $isBfxApiStaging == 1 ]; then + bfxApiUrl="$STAGING_BFX_API_URL" +fi +if [ $isDevEnv == 1 ]; then + echo -e "\n${COLOR_YELLOW}Developer environment is turned on!${COLOR_NORMAL}" + + echo "{\"NODE_ENV\":\"development\"}" > "$ROOT/$ELECTRON_ENV_FILE_NAME" +else + rm -f "$ROOT/$ELECTRON_ENV_FILE_NAME" +fi + +changeDirOwnershipToCurrUser "$ELECTRON_CACHE" "$(id -u):$(id -g)" +changeDirOwnershipToCurrUser "$ELECTRON_BUILDER_CACHE" "$(id -u):$(id -g)" +changeDirOwnershipToCurrUser "$COMMON_UI_BUILD_FOLDER" +changeDirOwnershipToCurrUser "$COMMON_DIST_FOLDER" + +makeLastCommitJson "$ROOT/$LAST_COMMIT_FILE_NAME" + +echo -e "\n${COLOR_BLUE}Making backend config files${COLOR_NORMAL}" + +cp "$WORKER_FOLDER/config/schedule.json.example" \ + "$WORKER_FOLDER/config/schedule.json" +cp "$WORKER_FOLDER/config/common.json.example" \ + "$WORKER_FOLDER/config/common.json" +cp "$WORKER_FOLDER/config/service.report.json.example" \ + "$WORKER_FOLDER/config/service.report.json" +cp "$WORKER_FOLDER/config/facs/grc.config.json.example" \ + "$WORKER_FOLDER/config/facs/grc.config.json" +cp "$WORKER_FOLDER/config/facs/grc-slack.config.json.example" \ + "$WORKER_FOLDER/config/facs/grc-slack.config.json" +cp "$EXPRESS_FOLDER/config/default.json.example" \ + "$EXPRESS_FOLDER/config/default.json" + +echo -e "\n${COLOR_BLUE}Setting backend configs${COLOR_NORMAL}" + +escapedBfxApiUrl=$(escapeString $bfxApiUrl) +sed -i -e \ + "s/\"restUrl\": \".*\"/\"restUrl\": \"$escapedBfxApiUrl\"/g" \ + "$WORKER_FOLDER/config/service.report.json" + +installBackendDeps "$targetPlatform" + +echo -e "\n${COLOR_BLUE}Watching for UI build...${COLOR_NORMAL}" + +if [ -d "$COMMON_UI_BUILD_FOLDER" ]; then + if ! runUIWatchdog "$COMMON_UI_BUILD_FOLDER"; then + hasIUNotBeenBuilt=1 + echo -e "\n${COLOR_YELLOW}The UI has not been built within the specified time. \ +Trying to build it again...${COLOR_NORMAL}" >&2 + else + mkdir -p "$UI_BUILD_FOLDER" 2>/dev/null + rm -rf "$UI_BUILD_FOLDER/"* + cp -rf "$COMMON_UI_BUILD_FOLDER/"* "$UI_BUILD_FOLDER" + fi +fi +if ! [ -d "$COMMON_UI_BUILD_FOLDER" ] || [ $hasIUNotBeenBuilt == 1 ]; then + COMMON_UI_BUILD_FOLDER="" + "$ROOT/scripts/build-ui.sh" + + if ! runUIWatchdog "$UI_BUILD_FOLDER" 10; then + echo -e "\n${COLOR_RED}The UI has not been built within the specified time!${COLOR_NORMAL}" >&2 + exit 1 + fi + + hasIUNotBeenBuilt=0 +fi + +echo -e "\n${COLOR_GREEN}The UI has been built successful${COLOR_NORMAL}" + +echo -e "\n${COLOR_BLUE}Electron app buiding...${COLOR_NORMAL}" + +publishOption="" + +if [ $isPublished == 1 ]; then + # Available: 'onTag', 'onTagOrDraft', 'always', 'never' + publishOption="--publish always" +fi + +rm -rf "$DIST_FOLDER/"*"$targetPlatform"* +node "$ROOT/node_modules/.bin/electron-builder" \ + "build" "--$targetPlatform" \ + "--config" "$ELECTRON_BUILDER_CONFIG_FILE_PATH" \ + $publishOption + +unpackedFolder=$(ls -d "$DIST_FOLDER/"*/ | grep $targetPlatform | head -1) + +rm -rf "$unpackedFolder" +rm -rf "$DIST_FOLDER/.icon-ico" +rm -f "$DIST_FOLDER/builder-effective-config.yaml" +rm -f "$DIST_FOLDER/builder-debug.yml" + +if ! [ -d "$COMMON_DIST_FOLDER" ]; then + chmod -fR a+xwr "$DIST_FOLDER" || [[ $? == 1 ]] + + echo -e "\n${COLOR_GREEN}The electron app has been built successful${COLOR_NORMAL}" + cd "$BUILD_RELEASE_CURRDIR" + exit 0 +fi + +if [ $buildWin == 1 ]; then + rm -f "$COMMON_DIST_FOLDER/latest.yml" + rm -f "$COMMON_DIST_FOLDER/beta.yml" + rm -f "$COMMON_DIST_FOLDER/alpha.yml" +fi + +rm -rf "$COMMON_DIST_FOLDER/"*"$targetPlatform"* +mv -f "$DIST_FOLDER/"* "$COMMON_DIST_FOLDER" + +chmod -fR a+xwr "$COMMON_DIST_FOLDER" || [[ $? == 1 ]] + +echo -e "\n${COLOR_GREEN}The electron app has been built successful${COLOR_NORMAL}" +cd "$BUILD_RELEASE_CURRDIR" diff --git a/scripts/build-ui.sh b/scripts/build-ui.sh index 77520f16..17149d2f 100755 --- a/scripts/build-ui.sh +++ b/scripts/build-ui.sh @@ -1,110 +1,152 @@ #!/bin/bash -set -x - -export CI_ENVIRONMENT_NAME=production -export SKIP_PREFLIGHT_CHECK=true - -ROOT="$PWD" -frontendFolder="$ROOT/bfx-report-ui" -pathToTriggerElectronLoad="$frontendFolder/src/utils/triggerElectronLoad.js" -pathToFonts="$frontendFolder/src/styles/fonts" -uiBuildFolder="$frontendFolder/build" -branch=master - -source $ROOT/scripts/update-submodules.sh +set -euo pipefail + +SCRIPTPATH="${SCRIPTPATH:-"$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"}" +ROOT="${ROOT:-"$(dirname "$SCRIPTPATH")"}" +UI_CURRDIR="$PWD" +DOT_ENV_FILE_PATH="$ROOT/.env" + +set -a +[ -f "$DOT_ENV_FILE_PATH" ] && . "$DOT_ENV_FILE_PATH" +set +a + +COLOR_RED=${COLOR_RED:-"\033[31m"} +COLOR_GREEN=${COLOR_GREEN:-"\033[32m"} +COLOR_YELLOW=${COLOR_YELLOW:-"\033[33m"} +COLOR_BLUE=${COLOR_BLUE:-"\033[34m"} +COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + +BFX_API_URL="${BFX_API_URL:-"https://api-pub.bitfinex.com"}" +STAGING_BFX_API_URL="${STAGING_BFX_API_URL:-"https://api.staging.bitfinex.com"}" +BACKEND_ADDRESS="${BACKEND_ADDRESS:-"localhost:34343"}" + +UI_FOLDER="${UI_FOLDER:-"$ROOT/bfx-report-ui"}" +UI_BUILD_FOLDER="$UI_FOLDER/build" +COMMON_UI_BUILD_FOLDER="${COMMON_UI_BUILD_FOLDER:-}" +UI_FONTS_FOLDER="$UI_FOLDER/src/styles/fonts" +UI_TRIGGER_ELECTRON_LOAD_SCRIPT_NAME="triggerElectronLoad.js" +UI_TRIGGER_ELECTRON_LOAD_SCRIPT="$UI_FOLDER/src/utils/$UI_TRIGGER_ELECTRON_LOAD_SCRIPT_NAME" +UI_CONFIGS_FILE="$UI_FOLDER/src/config.js" +UI_READY_FILE_NAME="READY" + +source "$ROOT/scripts/helpers/check-node-modules-dir.sh" +source "$ROOT/scripts/helpers/escape-string.sh" +source "$ROOT/scripts/helpers/change-dir-ownership-to-curr-user.sh" programname=$0 -isDevEnv=0 -isInitedSubmodules=0 +bfxApiUrl="$BFX_API_URL" -if [ "$BRANCH" != "" ] -then - branch=$BRANCH -fi -if [ "$UI_BUILD_FOLDER" != "" ] -then - uiBuildFolder=$UI_BUILD_FOLDER -fi +isBfxApiStaging=${IS_BFX_API_STAGING:-0} +isDevEnv=${IS_DEV_ENV:-0} -mkdir $uiBuildFolder 2>/dev/null -uiReadyFile="$uiBuildFolder/READY" -rm -rf $uiBuildFolder/* +export CI_ENVIRONMENT_NAME="production" +export SKIP_PREFLIGHT_CHECK=true function usage { - echo "Usage: $programname [-d] | [-h]" - echo " -d turn on developer environment" - echo " -h display help" - exit 1 + echo -e "\ +\n${COLOR_GREEN}Usage: $programname [options] [-h]${COLOR_BLUE} +\nOptions: + -s Use staging BFX API + -d Set development environment + -h Display help\ +${COLOR_NORMAL}" 1>&2 } -while [ "$1" != "" ]; do - case $1 in - -d | --dev ) isDevEnv=1 - ;; - -i | --init ) isInitedSubmodules=1 - ;; - -h | --help ) usage - exit - ;; - * ) usage - exit 1 +while getopts "sdh" opt; do + case "${opt}" in + s) isBfxApiStaging=1;; + d) isDevEnv=1;; + h) + usage + exit 0 + ;; + *) + echo -e "\n${COLOR_RED}No reasonable options found!${COLOR_NORMAL}" >&2 + usage + exit 1 + ;; esac - shift done -if [ $isDevEnv != 0 ]; then - echo "Developer environment is turned on" +if [ $isBfxApiStaging == 1 ]; then + bfxApiUrl="$STAGING_BFX_API_URL" fi - -if [ $isInitedSubmodules != 0 ]; then - updateSubmodules $branch +if [ $isDevEnv == 1 ]; then + echo -e "\n${COLOR_YELLOW}UI developer environment is turned on!${COLOR_NORMAL}" + export CI_ENVIRONMENT_NAME="development" fi -cd $frontendFolder +changeDirOwnershipToCurrUser "$COMMON_UI_BUILD_FOLDER" -if ! [ -s "$frontendFolder/package.json" ]; then - exit 1 +rm -rf "$UI_BUILD_FOLDER/"* + +if [ -d "$COMMON_UI_BUILD_FOLDER" ]; then + rm -rf "$COMMON_UI_BUILD_FOLDER/"* fi +echo -e "\n${COLOR_BLUE}Setting UI configs${COLOR_NORMAL}" + +escapedBfxApiUrl=$(escapeString $bfxApiUrl) sed -i -e \ - "s/API_URL: .*,/API_URL: \'http:\/\/localhost:34343\/api\',/g" \ - $frontendFolder/src/config.js + "s/HOME_URL: .*,/HOME_URL: \'$escapedBfxApiUrl\',/g" \ + "$UI_CONFIGS_FILE" sed -i -e \ - "s/WS_ADDRESS: .*,/WS_ADDRESS: \'ws:\/\/localhost:34343\/ws\',/g" \ - $frontendFolder/src/config.js - -if [ $isDevEnv != 0 ]; then - export CI_ENVIRONMENT_NAME=development - - sed -i -e \ - "s/KEY_URL: .*,/KEY_URL: \'https:\/\/api.staging.bitfinex.com\/api\',/g" \ - $frontendFolder/src/config.js -fi + "s/API_URL: .*,/API_URL: \'http:\/\/${BACKEND_ADDRESS}\/api\',/g" \ + "$UI_CONFIGS_FILE" +sed -i -e \ + "s/WS_ADDRESS: .*,/WS_ADDRESS: \'ws:\/\/${BACKEND_ADDRESS}\/ws\',/g" \ + "$UI_CONFIGS_FILE" +sed -i -e \ + "s/KEY_URL: .*,/KEY_URL: \'$escapedBfxApiUrl\/api\',/g" \ + "$UI_CONFIGS_FILE" sed -i -e \ "s/localExport: false/localExport: true/g" \ - $frontendFolder/src/config.js + "$UI_CONFIGS_FILE" sed -i -e \ "s/showAuthPage: false/showAuthPage: true/g" \ - $frontendFolder/src/config.js -sed -i -e \ - "s/isElectronApp: false/isElectronApp: true/g" \ - $frontendFolder/src/config.js + "$UI_CONFIGS_FILE" sed -i -e \ "s/showFrameworkMode: false/showFrameworkMode: true/g" \ - $frontendFolder/src/config.js + "$UI_CONFIGS_FILE" +sed -i -e \ + "s/hostedFrameworkMode: true/hostedFrameworkMode: false/g" \ + "$UI_CONFIGS_FILE" +sed -i -e \ + "s/isElectronApp: false/isElectronApp: true/g" \ + "$UI_CONFIGS_FILE" + +cd "$UI_FOLDER" +echo -e "\n${COLOR_BLUE}Installing the UI deps...${COLOR_NORMAL}" +rm -rf ./node_modules +npm ci --no-audit --progress=false +checkNodeModulesDir "$UI_FOLDER" +npm ls --depth=0 --only=prod 1<&- -mv -f "$ROOT/.eslintrc" "$ROOT/eslint-conf-disabled-for-ui" -npm i --no-audit +echo -e "\n${COLOR_BLUE}UI building...${COLOR_NORMAL}" +mv -f "$ROOT/.eslintrc" "$ROOT/off-eslintrc" npm run build -mv -f "$ROOT/eslint-conf-disabled-for-ui" "$ROOT/.eslintrc" +mv -f "$ROOT/off-eslintrc" "$ROOT/.eslintrc" -if ! [ -s "$frontendFolder/build/index.html" ]; then +if ! [ -s "$UI_BUILD_FOLDER/index.html" ]; then + echo -e "\n${COLOR_RED}The UI has not been built successful${COLOR_NORMAL}" >&2 exit 1 fi -mv -f $frontendFolder/build/* $uiBuildFolder -cp $pathToTriggerElectronLoad $uiBuildFolder/triggerElectronLoad.js -cp -avrf $pathToFonts $uiBuildFolder -touch $uiReadyFile +cp -f "$UI_TRIGGER_ELECTRON_LOAD_SCRIPT" "$UI_BUILD_FOLDER/$UI_TRIGGER_ELECTRON_LOAD_SCRIPT_NAME" +cp -rf "$UI_FONTS_FOLDER" "$UI_BUILD_FOLDER" + +if ! [ -d "$COMMON_UI_BUILD_FOLDER" ]; then + chmod -fR a+xwr "$UI_BUILD_FOLDER" || [[ $? == 1 ]] + touch "$UI_BUILD_FOLDER/$UI_READY_FILE_NAME" + + cd "$UI_CURRDIR" + exit 0 +fi + +mv -f "$UI_BUILD_FOLDER/"* "$COMMON_UI_BUILD_FOLDER" +chmod -fR a+xwr "$COMMON_UI_BUILD_FOLDER" || [[ $? == 1 ]] +touch "$COMMON_UI_BUILD_FOLDER/$UI_READY_FILE_NAME" + +cd "$UI_CURRDIR" diff --git a/scripts/escape-string.sh b/scripts/escape-string.sh deleted file mode 100755 index 96fdda70..00000000 --- a/scripts/escape-string.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -set -x - -function escapeString { - local str="" - - if [ $# -ge 1 ] - then - str=$1 - else - exit 1 - fi - - escapedStr=$(echo $str \ - | sed 's/\//\\\//g' \ - | sed 's/\+/\\\+/g' \ - | sed 's/\./\\\./g') - - echo $escapedStr -} diff --git a/scripts/get-conf-value.sh b/scripts/get-conf-value.sh deleted file mode 100755 index a8c4de17..00000000 --- a/scripts/get-conf-value.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -set -x - -ROOT="$PWD" - -function getConfValue { - local dep="" - local path=$ROOT - local value="" - - if [ $# -ge 1 ] - then - dep=$1 - else - exit 1 - fi - - if [ $# -ge 2 ] - then - path=$2 - else - exit 1 - fi - - version=$(cat $path/package.json \ - | grep \"$dep\" \ - | head -1 \ - | awk -F: '{ print $2($3 ? ":" : "")$3($4 ? ":" : "")$4 }' \ - | sed 's/[",]//g' \ - | sed 's/#.*$//' \ - | tr -d '[[:space:]]') - - echo $version -} diff --git a/scripts/helpers/change-dir-ownership-to-curr-user.sh b/scripts/helpers/change-dir-ownership-to-curr-user.sh new file mode 100755 index 00000000..2b8ac9e1 --- /dev/null +++ b/scripts/helpers/change-dir-ownership-to-curr-user.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +function changeDirOwnershipToCurrUser { + local path="${1:-}" + local defaultUID="${CURRENT_UID:-"1000:1000"}" + local currUID="${2:-"$defaultUID"}" + + if [ -n "$path" ] && [ -d "$path" ]; then + chown -R "$currUID" "$path" || [[ $? == 1 ]] + fi +} diff --git a/scripts/helpers/check-node-modules-dir.sh b/scripts/helpers/check-node-modules-dir.sh new file mode 100755 index 00000000..301ce6d1 --- /dev/null +++ b/scripts/helpers/check-node-modules-dir.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +function checkNodeModulesDir { + local COLOR_RED=${COLOR_RED:-"\033[31m"} + local COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + + if [ -z "${1:-}" ]; then + echo -e "\n${COLOR_RED}Requires the first argument of '${FUNCNAME[0]}' fn as path!${COLOR_NORMAL}" >&2 + exit 1 + fi + + local path="${1:-"."}" + + if ! [ -d "$path/node_modules" ]; then + echo -e "\n${COLOR_RED}NPM dependencies have not been installed \ +in the '$path' root dir!${COLOR_NORMAL}" >&2 + exit 1 + fi +} diff --git a/scripts/helpers/escape-string.sh b/scripts/helpers/escape-string.sh new file mode 100755 index 00000000..f2792eb4 --- /dev/null +++ b/scripts/helpers/escape-string.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +function escapeString { + local COLOR_RED=${COLOR_RED:-"\033[31m"} + local COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + + if [ -z "${1:-}" ]; then + echo -e "\n${COLOR_RED}Requires the first argument of '${FUNCNAME[0]}' fn as escaping string!${COLOR_NORMAL}" >&2 + exit 1 + fi + + local escapedStr=$(echo $1 \ + | sed 's/\//\\\//g' \ + | sed 's/\+/\\\+/g' \ + | sed 's/\./\\\./g') + + echo "$escapedStr" +} diff --git a/scripts/helpers/get-conf-value.sh b/scripts/helpers/get-conf-value.sh new file mode 100755 index 00000000..aa4b9841 --- /dev/null +++ b/scripts/helpers/get-conf-value.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +function getConfValue { + local COLOR_RED=${COLOR_RED:-"\033[31m"} + local COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + + if [ -z "${1:-}" ]; then + echo -e "\n${COLOR_RED}Requires the first argument of '${FUNCNAME[0]}' fn as dependency name!${COLOR_NORMAL}" >&2 + exit 1 + fi + if [ -z "${2:-}" ]; then + echo -e "\n${COLOR_RED}Requires the first argument of '${FUNCNAME[0]}' fn as path to folder where package.json!${COLOR_NORMAL}" >&2 + exit 1 + fi + + local dep="$1" + local path="$2" + local fileName="${3:-"package.json"}" + + local version=$(cat "$path/$fileName" \ + | grep -m 1 "[\'\" ]$dep[\'\"]*:" \ + | head -1 \ + | awk -F: '{ print $2($3 ? ":" : "")$3($4 ? ":" : "")$4 }' \ + | sed "s/[\'\",]//g" \ + | sed 's/#.*$//' \ + | tr -d '[[:space:]]') + + echo "$version" +} diff --git a/scripts/helpers/install-backend-deps.sh b/scripts/helpers/install-backend-deps.sh new file mode 100755 index 00000000..2009cf4d --- /dev/null +++ b/scripts/helpers/install-backend-deps.sh @@ -0,0 +1,82 @@ +#!/bin/bash + +function installBackendDeps { + local SCRIPTPATH="${SCRIPTPATH:-"$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"}" + local ROOT="${ROOT:-"$(dirname "$SCRIPTPATH")"}" + local INSTALL_BACKEND_CURRDIR="$PWD" + + local COLOR_RED=${COLOR_RED:-"\033[31m"} + local COLOR_BLUE=${COLOR_BLUE:-"\033[34m"} + local COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + + local WORKER_FOLDER="${WORKER_FOLDER:-"$ROOT/bfx-reports-framework"}" + local EXPRESS_FOLDER="${EXPRESS_FOLDER:-"$ROOT/bfx-report-ui/bfx-report-express"}" + + source "$ROOT/scripts/helpers/get-conf-value.sh" + source "$ROOT/scripts/helpers/check-node-modules-dir.sh" + + local ARCH=${ARCH:-"x64"} + local DIST_URL="https://electronjs.org/headers" + local ELECTRON_VER=$(getConfValue "electron" "$ROOT") + + local unameOut="$(uname -s)" + local machine="${1:-"$unameOut"}" + local targetPlatform="" + + case "${machine}" in + Linux*) targetPlatform="linux";; + linux) targetPlatform="linux";; + Darwin*) targetPlatform="darwin";; + mac) targetPlatform="darwin";; + CYGWIN*) targetPlatform="win32";; + MINGW*) targetPlatform="win32";; + *win) targetPlatform="win32";; + *) + echo -e "\n${COLOR_RED}Unable to recognize operating system type!${COLOR_NORMAL}" >&2 + exit 1 + ;; + esac + + echo -e "\n${COLOR_BLUE}Target platform entered is $targetPlatform${COLOR_NORMAL}" + + cd "$ROOT" + echo -e "\n${COLOR_BLUE}Installing the main dev deps...${COLOR_NORMAL}" + rm -rf ./node_modules + npm i --development --no-audit --progress=false + npm ls --depth=0 --only=dev 1<&- + + export npm_config_target_platform="$targetPlatform" + export npm_config_platform="$targetPlatform" + export npm_config_target="$ELECTRON_VER" + export npm_config_runtime="electron" + export npm_config_target_arch="$ARCH" + export npm_config_arch="$ARCH" + export npm_config_dist_url="$DIST_URL" + export npm_config_disturl="$DIST_URL" + + echo -e "\n${COLOR_BLUE}Installing the main prod deps...${COLOR_NORMAL}" + npm i --production --include=dev --no-audit --progress=false + rm -rf "$ROOT/node_modules/ed25519-supercop/build" + checkNodeModulesDir "$ROOT" + depsErr=$(npm ls --depth=0 --only=prod 2>&1 >/dev/null | grep -v "missing: eslint" || [[ $? == 1 ]]) + if [ -n "$depsErr" ]; then + echo -e "$depsErr" >&2 + exit 1 + fi + + cd "$EXPRESS_FOLDER" + echo -e "\n${COLOR_BLUE}Installing the prod express deps...${COLOR_NORMAL}" + rm -rf ./node_modules + npm i --production --no-audit --progress=false + checkNodeModulesDir "$EXPRESS_FOLDER" + npm ls --depth=0 --only=prod 1<&- + + cd "$WORKER_FOLDER" + echo -e "\n${COLOR_BLUE}Installing the prod worker deps...${COLOR_NORMAL}" + rm -rf ./node_modules + npm i --production --no-audit --progress=false + checkNodeModulesDir "$WORKER_FOLDER" + npm ls --depth=0 --only=prod 1<&- + + cd "$INSTALL_BACKEND_CURRDIR" +} diff --git a/scripts/helpers/install-nodejs.sh b/scripts/helpers/install-nodejs.sh new file mode 100755 index 00000000..b959f707 --- /dev/null +++ b/scripts/helpers/install-nodejs.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -euo pipefail + +COLOR_RED=${COLOR_RED:-"\033[31m"} +COLOR_GREEN=${COLOR_GREEN:-"\033[32m"} +COLOR_BLUE=${COLOR_BLUE:-"\033[34m"} +COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + +if [ -z "${1:-}" ]; then + echo -e "\n${COLOR_RED}Requires the first argument of '${0}' \ +script as required NodeJS version!${COLOR_NORMAL}" >&2 + exit 1 +fi + +version="${1:-"14.16.0"}" + +echo -e "\n${COLOR_BLUE}Installing the NodeJS v$version...${COLOR_NORMAL}" + +# This package is used for snapcraft and +# we should not clear apt list - to avoid apt-get update during snap build +curl -L https://nodejs.org/dist/v$version/node-v$version-linux-x64.tar.gz | tar xz -C /usr/local --strip-components=1 + +unlink /usr/local/CHANGELOG.md +unlink /usr/local/LICENSE +unlink /usr/local/README.md + +# https://github.com/npm/npm/issues/4531 +npm config set unsafe-perm true + +npm cache clear --force +npm install --global node-gyp@7.1.2 +npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js + +echo -e "\n${COLOR_GREEN}The NodeJS has been installed successful${COLOR_NORMAL}" diff --git a/scripts/helpers/make-last-commit-json.sh b/scripts/helpers/make-last-commit-json.sh new file mode 100755 index 00000000..07a9f7a9 --- /dev/null +++ b/scripts/helpers/make-last-commit-json.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +function makeLastCommitJson { + local COLOR_RED=${COLOR_RED:-"\033[31m"} + local COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + + if [ -z "${1:-}" ]; then + echo -e "\n${COLOR_RED}Requires the first argument of '${FUNCNAME[0]}' as file path!${COLOR_NORMAL}" >&2 + exit 1 + fi + + local filePath="$1" + + TZ=UTC git show \ + --quiet \ + --date='format-local:%Y-%m-%dT%H:%M:%SZ' \ + --format="{\"hash\":\"%H\",\"date\":\"%cd\"}" \ + > "$filePath" +} diff --git a/scripts/helpers/run-ui-watchdog.sh b/scripts/helpers/run-ui-watchdog.sh new file mode 100755 index 00000000..c61d14f6 --- /dev/null +++ b/scripts/helpers/run-ui-watchdog.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +function runUIWatchdog { + local COLOR_RED=${COLOR_RED:-"\033[31m"} + local COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + + if [ -z "${1:-}" ]; then + echo -e "\n${COLOR_RED}Requires the first argument of '${FUNCNAME[0]}' fn as UI build folder!${COLOR_NORMAL}" >&2 + exit 1 + fi + + local uiBuildFolder="$1" + local requiredWatchTime="${2:-$((60 * 10))}" + + local uiReadyFile="$uiBuildFolder/READY" + local watchTime=$requiredWatchTime + local interval=0.5 + + # Watch the UI build has been completed, in seconds + # if not successful return 'false' + while !(test -f "$uiReadyFile"); do + local isExpired=$(echo "$watchTime <= 0" | bc) + + if [ $isExpired == 1 ]; then + false + return + fi + + sleep $interval + watchTime=$(echo "$watchTime - $interval" | bc) + done + + true +} diff --git a/scripts/init.sh b/scripts/init.sh deleted file mode 100755 index fd702214..00000000 --- a/scripts/init.sh +++ /dev/null @@ -1,275 +0,0 @@ -#!/bin/bash - -set -x - -ROOT="$PWD" -branch=master -dbDriver=better-sqlite -lastCommitFileName=lastCommit.json -isZipReleaseFile="isZipRelease" -bfxStagingUrl="https://api.staging.bitfinex.com" - -source $ROOT/scripts/get-conf-value.sh -source $ROOT/scripts/escape-string.sh -source $ROOT/scripts/update-submodules.sh - -programname=$0 -isDevEnv=0 -isSkippedReiDeps=0 -targetPlatform=0 -isSkippedUIBuild=0 - -if [ "$BRANCH" != "" ] -then - branch=$BRANCH -fi -if [ "$DB_DRIVER" != "" ] -then - dbDriver=$DB_DRIVER -fi - -function usage { - echo "Usage: $programname [-d] | [-h]" - echo " -d turn on developer environment" - echo " -h display help" - exit 1 -} - -while [ "$1" != "" ]; do - case $1 in - -d | --dev ) isDevEnv=1 - ;; - -s | --skip-rei-deps ) isSkippedReiDeps=1 - ;; - -p | --target-platform ) targetPlatform=$2; shift - ;; - -u | --skip-ui-build ) isSkippedUIBuild=1 - ;; - -h | --help ) usage - exit - ;; - * ) usage - exit 1 - esac - shift -done - -if [ $isDevEnv != 0 ]; then - echo "Developer environment is turned on" -fi - -frontendFolder="$ROOT/bfx-report-ui" -expressFolder="$frontendFolder/bfx-report-express" -backendFolder="$ROOT/bfx-reports-framework" - -linuxLauncherFolder="$ROOT/build/linux-launcher" - -uiBuildFolder="$frontendFolder/build" -if [ "$UI_BUILD_FOLDER" != "" ] -then - uiBuildFolder=$UI_BUILD_FOLDER -fi -mkdir $uiBuildFolder 2>/dev/null -uiReadyFile="$uiBuildFolder/READY" - -mkdir $ROOT/dist 2>/dev/null -chmod a+xwr $ROOT/dist 2>/dev/null - -updateSubmodules $branch - -TZ=UTC git show \ - --quiet \ - --date='format-local:%Y-%m-%dT%H:%M:%SZ' \ - --format="{\"hash\":\"%H\",\"date\":\"%cd\"}" \ - > $ROOT/$lastCommitFileName - -if [ $isSkippedUIBuild == 0 ] -then - devFlag="" - - if [ $isDevEnv == 0 ]; then - devFlag="-d" - fi - - bash $ROOT/scripts/build-ui.sh $devFlag -fi - -cp $expressFolder/config/default.json.example \ - $expressFolder/config/default.json - -cd $backendFolder - -cp config/schedule.json.example config/schedule.json -cp config/common.json.example config/common.json -cp config/service.report.json.example config/service.report.json -cp config/facs/grc.config.json.example config/facs/grc.config.json -cp config/facs/grc-slack.config.json.example config/facs/grc-slack.config.json -sed -i -e \ - "s/\"syncMode\": false/\"syncMode\": true/g" \ - $backendFolder/config/service.report.json -sed -i -e \ - "s/\"dbDriver\": \".*\"/\"dbDriver\": \"$dbDriver\"/g" \ - $backendFolder/config/service.report.json - -if [ $isDevEnv != 0 ]; then - escapedBfxStagingUrl=$(escapeString $bfxStagingUrl) - sed -i -e \ - "s/\"restUrl\": \".*\"/\"restUrl\": \"$escapedBfxStagingUrl\"/g" \ - $backendFolder/config/service.report.json -fi - -bfxReportDep=$(getConfValue "bfx-report" $backendFolder) -escapedBfxReportDep=$(escapeString $bfxReportDep) - -if [ $branch == "master" ] -then - sed -i -e \ - "s/\"bfx-report\": \".*\"/\"bfx-report\": \"$escapedBfxReportDep\"/g" \ - $backendFolder/package.json -else - sed -i -e \ - "s/\"bfx-report\": \".*\"/\"bfx-report\": \"$escapedBfxReportDep\#$branch\"/g" \ - $backendFolder/package.json -fi - -cd $ROOT - -if [ $isSkippedReiDeps != 0 ] -then - exit 0 -fi - -if [ $targetPlatform == 0 ] -then - bash $ROOT/scripts/reinstall-deps.sh - - exit 0 -fi - -bash $ROOT/scripts/reinstall-deps.sh $targetPlatform - -if [ $isSkippedUIBuild != 0 ] -then - # Watch the UI build has been completed, in seconds - # if not successful exit with an error - requiredWatchTime=$((60 * 30)) - watchTime=$requiredWatchTime - interval=0.5 - - while !(test -f "$uiReadyFile"); do - isExpired=$(echo "$watchTime <= 0" | bc) - - if [ $isExpired == 1 ]; then - echo "Exit with error due to the UI has not been built in $requiredWatchTime seconds" - - exit 1 - fi - - sleep $interval - watchTime=$(echo "$watchTime - $interval" | bc) - done -fi - -mkdir $frontendFolder/build 2>/dev/null -rm -rf $frontendFolder/build/* -cp -avr $uiBuildFolder/* $frontendFolder/build -chmod -R a+xwr $frontendFolder/build -./node_modules/.bin/electron-builder build --$targetPlatform -chmod -R a+xwr ./dist - -productName=$(getConfValue "productName" $ROOT) -version=$(getConfValue "version" $ROOT) -versionEnding="" - -if [ $branch != 'master' ] -then - versionEnding="-$branch" -fi - -arch="x64" - -unpackedFolder=$(ls -d $ROOT/dist/*/ | grep $targetPlatform | head -1) -artifactName="$productName-$version$versionEnding-$arch-$targetPlatform" -zipFile="$ROOT/dist/$artifactName.zip" - -if ! [ -d $unpackedFolder ]; then - exit 1 -fi - -cd $unpackedFolder - -if [ $targetPlatform == "win" ] -then - touch "$isZipReleaseFile" -fi - -if [ $targetPlatform == "linux" ] -then - # Build C executable launcher file - make -C $linuxLauncherFolder - - cp -f \ - "$linuxLauncherFolder/launcher" \ - "Bitfinex Report" - cp -f \ - "$linuxLauncherFolder/launcher.sh" \ - "launcher.sh" - cp -f \ - "$linuxLauncherFolder/msg-box.sh" \ - "msg-box.sh" - - touch "$isZipReleaseFile" - node $ROOT/scripts/node/make-app-update-yml.js "$unpackedFolder" - - chmod +x "Bitfinex Report" - chmod +x "launcher.sh" - chmod +x "msg-box.sh" -fi - -if [ $targetPlatform == "mac" ] -then - rm -rf "$ROOT/dist/$targetPlatform/Bitfinex Report.app.zip" - rm -rf "$zipFile" -fi - -7z a -tzip $zipFile . -mmt | grep -v "Compressing" -cd $ROOT - -if [ $targetPlatform == "mac" ] -then - node $ROOT/scripts/node/generate-zipand-blockmap.js -fi - -rm -rf /dist/*$targetPlatform* -mv -f ./dist/*$targetPlatform*.zip /dist - -if [ $targetPlatform == "win" ] -then - appFile="/dist/$artifactName.exe" - blockmapFile="$appFile.blockmap" - latestYmlFile="/dist/latest.yml" - mv -f ./dist/*$targetPlatform*.exe "$appFile" - mv -f ./dist/*$targetPlatform*.exe.blockmap "$blockmapFile" - mv -f ./dist/latest.yml "$latestYmlFile" -fi -if [ $targetPlatform == "linux" ] -then - appFile="/dist/$artifactName.AppImage" - latestYmlFile="/dist/latest-linux.yml" - mv -f ./dist/*$targetPlatform*.AppImage "$appFile" - mv -f ./dist/latest-linux.yml "$latestYmlFile" - - chmod a+x "$appFile" -fi -if [ $targetPlatform == "mac" ] -then - appFile="/dist/$artifactName.zip" - blockmapFile="$appFile.blockmap" - latestYmlFile="/dist/latest-mac.yml" - mv -f ./dist/*$targetPlatform*.zip.blockmap "$blockmapFile" - mv -f ./dist/latest-mac.yml "$latestYmlFile" -fi - -chmod -R a+xwr /dist 2>/dev/null - -exit 0 \ No newline at end of file diff --git a/scripts/install-nodejs.sh b/scripts/install-nodejs.sh deleted file mode 100755 index 278f91e6..00000000 --- a/scripts/install-nodejs.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -set -x - -version="" - -if [ $# -ge 1 ] -then - version=$1 -else - exit 1 -fi - -# this package is used for snapcraft and we should not clear apt list - to avoid apt-get update during snap build -curl -L https://nodejs.org/dist/v$version/node-v$version-linux-x64.tar.gz | tar xz -C /usr/local --strip-components=1 && \ -unlink /usr/local/CHANGELOG.md && unlink /usr/local/LICENSE && unlink /usr/local/README.md && \ -# https://github.com/npm/npm/issues/4531 -npm config set unsafe-perm true diff --git a/scripts/launch.sh b/scripts/launch.sh new file mode 100755 index 00000000..832b3b90 --- /dev/null +++ b/scripts/launch.sh @@ -0,0 +1,155 @@ +#!/bin/bash + +set -euo pipefail + +SCRIPTPATH="${SCRIPTPATH:-"$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"}" +ROOT="${ROOT:-"$(dirname "$SCRIPTPATH")"}" +LAUNCH_CURRDIR="$PWD" +DOT_ENV_FILE_PATH="$ROOT/.env" + +export CURRENT_UID="$(id -u):$(id -g)" + +set -a +[ -f "$DOT_ENV_FILE_PATH" ] && . "$DOT_ENV_FILE_PATH" +set +a + +COLOR_RED=${COLOR_RED:-"\033[31m"} +COLOR_GREEN=${COLOR_GREEN:-"\033[32m"} +COLOR_YELLOW=${COLOR_YELLOW:-"\033[33m"} +COLOR_BLUE=${COLOR_BLUE:-"\033[34m"} +COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + +programname=$0 + +buildLinux=0 +buildWin=0 +buildMac=0 +syncRepo=0 +syncSubModules=0 +isBfxApiStaging=${IS_BFX_API_STAGING:-0} +isDevEnv=${IS_DEV_ENV:-0} +isPublished=${IS_PUBLISHED:-0} + +function usage { + echo -e "\ +\n${COLOR_GREEN}Usage: $programname [options] [-h]${COLOR_BLUE} +\nOptions: + -a Build all releases + -l Build Linux release + -w Build Windows release + -m Build Mac release + -r Sync all repositories + -o Sync only sub-modules + -s Use staging BFX API + -d Set development environment + -p Publish artifacts + -h Display help\ +${COLOR_NORMAL}" 1>&2 +} + +if [ $# == 0 ]; then + echo -e "\n${COLOR_RED}Requires at least one option!${COLOR_NORMAL}" >&2 + usage + exit 1 +fi + +while getopts "alwmrosdph" opt; do + case "${opt}" in + a) + buildLinux=1 + buildWin=1 + buildMac=1 + ;; + l) buildLinux=1;; + w) buildWin=1;; + m) buildMac=1;; + r) syncRepo=1;; + o) syncSubModules=1;; + s) isBfxApiStaging=1;; + d) isDevEnv=1;; + p) isPublished=1;; + h) + usage + exit 0 + ;; + *) + echo -e "\n${COLOR_RED}No reasonable options found!${COLOR_NORMAL}" >&2 + usage + exit 1 + ;; + esac +done + +if [ $buildLinux != 1 ] \ + && [ $buildWin != 1 ] \ + && [ $buildMac != 1 ] +then + echo -e "\n${COLOR_RED}A release for at least one OS may be required!${COLOR_NORMAL}" >&2 + exit 1 +fi + +if [ $isBfxApiStaging == 1 ]; then + export IS_BFX_API_STAGING=1 +fi +if [ $isDevEnv == 1 ]; then + export IS_DEV_ENV=1 +fi +if [ $isPublished == 1 ]; then + export IS_PUBLISHED=1 +fi + +composeCommonFlags="\ + --build \ + --force-recreate \ + --remove-orphans +" +uiBuilderService="ui-builder" +linuxBuilderService="" +winBuilderService="" +macBuilderService="" + +if [ $buildLinux == 1 ]; then + linuxBuilderService="linux-builder" +fi +if [ $buildWin == 1 ]; then + winBuilderService="win-builder" +fi +if [ $buildMac == 1 ]; then + macBuilderService="mac-builder" +fi + +if [ $syncRepo == 1 ]; then + echo -e "\n${COLOR_BLUE}Syncing all repositories...${COLOR_NORMAL}" + source "$ROOT/scripts/sync-repo.sh" "-a" +fi +if [ $syncSubModules == 1 ]; then + echo -e "\n${COLOR_BLUE}Syncing only all sub-modules...${COLOR_NORMAL}" + source "$ROOT/scripts/sync-repo.sh" "-wue" +fi + +docker-compose up $composeCommonFlags $uiBuilderService \ + $linuxBuilderService $winBuilderService $macBuilderService + +if [ $buildLinux == 1 ]; then + linuxExitCode=$(docker inspect $linuxBuilderService --format="{{.State.ExitCode}}") + + if [ $linuxExitCode != 0 ]; then + exit 1 + fi +fi +if [ $buildWin == 1 ]; then + winExitCode=$(docker inspect $winBuilderService --format="{{.State.ExitCode}}") + + if [ $winExitCode != 0 ]; then + exit 1 + fi +fi +if [ $buildMac == 1 ]; then + macExitCode=$(docker inspect $macBuilderService --format="{{.State.ExitCode}}") + + if [ $macExitCode != 0 ]; then + exit 1 + fi +fi + +cd "$LAUNCH_CURRDIR" diff --git a/scripts/node/generate-zipand-blockmap.js b/scripts/node/generate-mac-zipand-blockmap.js similarity index 77% rename from scripts/node/generate-zipand-blockmap.js rename to scripts/node/generate-mac-zipand-blockmap.js index 3641b766..644d0093 100644 --- a/scripts/node/generate-zipand-blockmap.js +++ b/scripts/node/generate-mac-zipand-blockmap.js @@ -15,6 +15,9 @@ const { const cwd = process.cwd() const packageJsonPath = path.join(cwd, 'package.json') const productName = require('../../src/helpers/product-name') +const { + publish: { channel } +} = require(path.join(cwd, 'electron-builder-config')) const { version: APP_VERSION @@ -28,14 +31,22 @@ const APP_GENERATED_BINARY_PATH = path.join( APP_DIST_PATH, appReleaseFileName ) -const ymlPath = path.join(APP_DIST_PATH, 'latest-mac.yml') +const ymlPath = path.join(APP_DIST_PATH, `${channel}-mac.yml`) try { const output = execSync(`${appBuilderPath} blockmap --input=${APP_GENERATED_BINARY_PATH} --output=${APP_GENERATED_BINARY_PATH}.blockmap --compression=gzip`) const { sha512, size } = JSON.parse(output) - const ymlData = yaml.load(fs.readFileSync(ymlPath, 'utf8')) - - console.log(ymlData) + const ymlData = { + version: '', + files: [{ + url: '', + sha512: '', + size: 0 + }], + path: '', + sha512: '', + releaseDate: '' + } ymlData.version = APP_VERSION ymlData.path = appReleaseFileName @@ -45,11 +56,12 @@ try { ymlData.files[0].sha512 = sha512 ymlData.files[0].size = size - const yamlStr = yaml.dump(ymlData) + delete ymlData.files[0].blockMapSize - console.log(yamlStr) + const yamlStr = yaml.dump(ymlData, { lineWidth: -1 }) fs.writeFileSync(ymlPath, yamlStr, 'utf8') + console.log('Successfully updated YAML file and configurations with blockmap') } catch (e) { console.log('Error in updating YAML file and configurations with blockmap', e) diff --git a/scripts/node/make-app-update-yml.js b/scripts/node/make-app-update-yml.js deleted file mode 100644 index 01beb89e..00000000 --- a/scripts/node/make-app-update-yml.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict' - -const path = require('path') -const fs = require('fs') -const yaml = require('js-yaml') - -const appDir = path.join( - path.dirname(require.main.filename), - '../..' -) -const { - build: { publish } -} = require(path.join(appDir, 'package.json')) -const unpackedFolder = process.argv[2] - -if ( - !publish || - typeof publish !== 'object' || - !unpackedFolder || - typeof unpackedFolder !== 'string' -) { - process.exit(1) -} - -const ymlName = 'app-update.yml' -const ymlPath = path.join( - unpackedFolder, - 'resources', - ymlName -) - -const yamlStr = yaml.dump(publish, { - lineWidth: 8000 -}) - -fs.writeFileSync(ymlPath, yamlStr) diff --git a/scripts/node/make-mac-app-update-yml.js b/scripts/node/make-mac-app-update-yml.js new file mode 100644 index 00000000..955a3a7d --- /dev/null +++ b/scripts/node/make-mac-app-update-yml.js @@ -0,0 +1,28 @@ +'use strict' + +const path = require('path') +const fs = require('fs') +const yaml = require('js-yaml') + +const cwd = process.cwd() +const { + publish +} = require(path.join(cwd, 'electron-builder-config')) + +if ( + !publish || + typeof publish !== 'object' +) { + process.exit(1) +} + +const ymlName = 'app-update.yml' +const ymlPath = path.join( + cwd, + 'dist/mac/Bitfinex Report.app/Contents/Resources', + ymlName +) + +const yamlStr = yaml.dump(publish, { lineWidth: -1 }) + +fs.writeFileSync(ymlPath, yamlStr) diff --git a/scripts/reinstall-deps.sh b/scripts/reinstall-deps.sh deleted file mode 100755 index 3c57b1c2..00000000 --- a/scripts/reinstall-deps.sh +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -set -x - -ROOT="$PWD" - -source $ROOT/scripts/get-conf-value.sh - -ARCH="x64" -ELECTRON_VER=$(getConfValue "electron" $ROOT) -DIST_URL=https://electronjs.org/headers - -unameOut="$(uname -s)" - -case "${unameOut}" in - Linux*) machine=linux;; - Darwin*) machine=darwin;; - CYGWIN*) machine=win32;; - MINGW*) machine=win32;; - *) machine="UNKNOWN:${unameOut}" -esac - -targetPlatform=$machine - -if [ $# -ge 1 ] -then - targetPlatform=$(echo $1 | sed -e 's/win$/win32/' -e 's/mac/darwin/') -fi - -backendFolder="$ROOT/bfx-reports-framework" -expressFolder="$ROOT/bfx-report-ui/bfx-report-express" - -cd $ROOT -rm -f ./package-lock.json -rm -rf ./node_modules -npm i --development --no-audit - -export npm_config_target_platform=$targetPlatform -export npm_config_platform=$targetPlatform -export npm_config_target=$ELECTRON_VER -export npm_config_runtime="electron" -export npm_config_target_arch=$ARCH -export npm_config_arch=$ARCH -export npm_config_dist_url=$DIST_URL -export npm_config_disturl=$DIST_URL - -rm -f ./package-lock.json -npm i --production --no-audit - -cd $expressFolder -rm -f ./package-lock.json -rm -rf ./node_modules -npm i --production --no-audit - -cd $backendFolder -rm -f ./package-lock.json -rm -rf ./node_modules -npm i --production --no-audit - -cd $ROOT -rm -rf "$ROOT/node_modules/ed25519-supercop/build" diff --git a/scripts/setup.sh b/scripts/setup.sh new file mode 100755 index 00000000..ae39a923 --- /dev/null +++ b/scripts/setup.sh @@ -0,0 +1,132 @@ +#!/bin/bash + +set -euo pipefail + +SCRIPTPATH="${SCRIPTPATH:-"$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"}" +ROOT="${ROOT:-"$(dirname "$SCRIPTPATH")"}" +SETUP_CURRDIR="$PWD" +DOT_ENV_FILE_PATH="$ROOT/.env" + +set -a +[ -f "$DOT_ENV_FILE_PATH" ] && . "$DOT_ENV_FILE_PATH" +set +a + +COLOR_RED=${COLOR_RED:-"\033[31m"} +COLOR_GREEN=${COLOR_GREEN:-"\033[32m"} +COLOR_YELLOW=${COLOR_YELLOW:-"\033[33m"} +COLOR_BLUE=${COLOR_BLUE:-"\033[34m"} +COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + +BFX_API_URL="https://api-pub.bitfinex.com" +STAGING_BFX_API_URL="https://api.staging.bitfinex.com" + +LAST_COMMIT_FILE_NAME="lastCommit.json" +ELECTRON_ENV_FILE_NAME="electronEnv.json" + +WORKER_FOLDER="$ROOT/bfx-reports-framework" +UI_FOLDER="$ROOT/bfx-report-ui" +EXPRESS_FOLDER="$UI_FOLDER/bfx-report-express" +UI_BUILD_FOLDER="$UI_FOLDER/build" + +source "$ROOT/scripts/helpers/make-last-commit-json.sh" +source "$ROOT/scripts/helpers/run-ui-watchdog.sh" +source "$ROOT/scripts/helpers/escape-string.sh" +source "$ROOT/scripts/helpers/install-backend-deps.sh" + +programname=$0 +bfxApiUrl="$BFX_API_URL" + +syncRepo=0 +syncSubModules=0 +isBfxApiStaging=${IS_BFX_API_STAGING:-0} +isDevEnv=${IS_DEV_ENV:-0} + +function usage { + echo -e "\ +\n${COLOR_GREEN}Usage: $programname [options] [-h]${COLOR_BLUE} +\nOptions: + -r Sync all repositories + -o Sync only sub-modules + -s Use staging BFX API + -d Set development environment + -h Display help\ +${COLOR_NORMAL}" 1>&2 +} + +while getopts "rosdh" opt; do + case "${opt}" in + r) syncRepo=1;; + o) syncSubModules=1;; + s) isBfxApiStaging=1;; + d) isDevEnv=1;; + h) + usage + exit 0 + ;; + *) + echo -e "\n${COLOR_RED}No reasonable options found!${COLOR_NORMAL}" >&2 + usage + exit 1 + ;; + esac +done + +if [ $isBfxApiStaging == 1 ]; then + bfxApiUrl="$STAGING_BFX_API_URL" +fi +if [ $isDevEnv == 1 ]; then + echo -e "\n${COLOR_YELLOW}Developer environment is turned on!${COLOR_NORMAL}" + + echo "{\"NODE_ENV\":\"development\"}" > "$ROOT/$ELECTRON_ENV_FILE_NAME" +else + rm -f "$ROOT/$ELECTRON_ENV_FILE_NAME" +fi + +if [ $syncRepo == 1 ]; then + echo -e "\n${COLOR_BLUE}Syncing all repositories...${COLOR_NORMAL}" + source "$ROOT/scripts/sync-repo.sh" "-a" +fi +if [ $syncSubModules == 1 ]; then + echo -e "\n${COLOR_BLUE}Syncing only all sub-modules...${COLOR_NORMAL}" + source "$ROOT/scripts/sync-repo.sh" "-wue" +fi + +makeLastCommitJson "$ROOT/$LAST_COMMIT_FILE_NAME" + +echo -e "\n${COLOR_BLUE}Making backend config files${COLOR_NORMAL}" + +cp "$WORKER_FOLDER/config/schedule.json.example" \ + "$WORKER_FOLDER/config/schedule.json" +cp "$WORKER_FOLDER/config/common.json.example" \ + "$WORKER_FOLDER/config/common.json" +cp "$WORKER_FOLDER/config/service.report.json.example" \ + "$WORKER_FOLDER/config/service.report.json" +cp "$WORKER_FOLDER/config/facs/grc.config.json.example" \ + "$WORKER_FOLDER/config/facs/grc.config.json" +cp "$WORKER_FOLDER/config/facs/grc-slack.config.json.example" \ + "$WORKER_FOLDER/config/facs/grc-slack.config.json" +cp "$EXPRESS_FOLDER/config/default.json.example" \ + "$EXPRESS_FOLDER/config/default.json" + +echo -e "\n${COLOR_BLUE}Setting backend configs${COLOR_NORMAL}" + +escapedBfxApiUrl=$(escapeString $bfxApiUrl) +sed -i -e \ + "s/\"restUrl\": \".*\"/\"restUrl\": \"$escapedBfxApiUrl\"/g" \ + "$WORKER_FOLDER/config/service.report.json" + +installBackendDeps + +echo -e "\n${COLOR_BLUE}Watching for UI build...${COLOR_NORMAL}" + +"$ROOT/scripts/build-ui.sh" + +if ! runUIWatchdog "$UI_BUILD_FOLDER" 10; then + echo -e "\n${COLOR_RED}The UI has not been built within the specified time!${COLOR_NORMAL}" >&2 + exit 1 +fi + +echo -e "\n${COLOR_GREEN}The UI has been built successful${COLOR_NORMAL}" +echo -e "\n${COLOR_GREEN}The electron app has been set up successful${COLOR_NORMAL}" + +cd "$SETUP_CURRDIR" diff --git a/scripts/sync-repo.sh b/scripts/sync-repo.sh new file mode 100755 index 00000000..a21418f3 --- /dev/null +++ b/scripts/sync-repo.sh @@ -0,0 +1,143 @@ +#!/bin/bash + +set -euo pipefail + +SCRIPTPATH="${SCRIPTPATH:-"$(cd -- "$(dirname "$0")" >/dev/null 2>&1; pwd -P)"}" +ROOT="${ROOT:-"$(dirname "$SCRIPTPATH")"}" +SYNC_REPO_CURRDIR="$PWD" +DOT_ENV_FILE_PATH="$ROOT/.env" + +set -a +[ -f "$DOT_ENV_FILE_PATH" ] && . "$DOT_ENV_FILE_PATH" +set +a + +COLOR_RED=${COLOR_RED:-"\033[31m"} +COLOR_GREEN=${COLOR_GREEN:-"\033[32m"} +COLOR_BLUE=${COLOR_BLUE:-"\033[34m"} +COLOR_NORMAL=${COLOR_NORMAL:-"\033[39m"} + +programname=$0 +workerSubmoduleName=bfx-reports-framework +uiSubmoduleName=bfx-report-ui +expressSubmoduleName=bfx-report-express +branch="${REPO_BRANCH:-"master"}" + +syncAll=0 +syncElectron=0 +syncWorker=0 +syncUI=0 +syncExpress=0 + +function usage { + echo -e "\ +\n${COLOR_GREEN}Usage: $programname [options] | [-h]${COLOR_BLUE} +\nOptions: + -a Sync all repositories + -m Sync bfx-report-electron only + -w Sync bfx-reports-framework only + -u Sync bfx-report-ui only + -e Sync bfx-report-express only + -h Display help\ +${COLOR_NORMAL}" 1>&2 +} + +if [ $# == 0 ]; then + echo -e "\n${COLOR_RED}Requires at least one option!${COLOR_NORMAL}" >&2 + usage + exit 1 +fi + +while getopts "amwueh" opt; do + case "${opt}" in + a) syncAll=1;; + m) syncElectron=1;; + w) syncWorker=1;; + u) syncUI=1;; + e) syncExpress=1;; + h) + usage + exit 0 + ;; + *) + echo -e "\n${COLOR_RED}No reasonable options found!${COLOR_NORMAL}" >&2 + usage + exit 1 + ;; + esac +done + +cd "$ROOT" + +if [ $syncElectron == 1 ] \ + && [ $syncWorker == 1 ] \ + && [ $syncUI == 1 ] \ + && [ $syncExpress == 1 ] +then + syncAll=1 + syncElectron=0 + syncWorker=0 + syncUI=0 + syncExpress=0 +fi + +if [ $syncAll == 1 ] \ + || [ $syncElectron == 1 ] \ + || [ $syncWorker == 1 ] \ + || [ $syncUI == 1 ] \ + || [ $syncExpress == 1 ] +then + git config url."https://github.com/".insteadOf git@github.com: + git fetch --recurse-submodules=on-demand + git submodule sync --recursive + git config --unset url."https://github.com/".insteadOf +fi + +if [ $syncAll == 1 ]; then + git clean -fd + git reset --hard "origin/$branch" + + git submodule foreach --recursive "git clean -fd; git reset --hard HEAD" + git submodule update --init --force --recursive + + cd "$SYNC_REPO_CURRDIR" + exit 0 +fi +if [ $syncElectron == 1 ]; then + git clean -fd + git reset --hard "origin/$branch" +fi +if [ $syncWorker == 1 ]; then + git submodule foreach ' + if [ "$sm_path" = "$workerSubmoduleName" ]; then + git clean -fd + git reset --hard HEAD + fi +' + + git submodule update --init --force $workerSubmoduleName +fi +if [ $syncUI == 1 ]; then + git submodule foreach ' + if [ "$sm_path" = "$uiSubmoduleName" ]; then + git clean -fd + git reset --hard HEAD + fi +' + + git submodule update --init --force $uiSubmoduleName +fi +if [ $syncExpress == 1 ]; then + git submodule foreach --recursive ' + if [ "$sm_path" = "$expressSubmoduleName" ]; then + git clean -fd + git reset --hard HEAD + fi +' + git submodule foreach ' + if [ "$sm_path" = "$uiSubmoduleName" ]; then + git submodule update --init --force $expressSubmoduleName + fi +' +fi + +cd "$SYNC_REPO_CURRDIR" diff --git a/scripts/update-submodules.sh b/scripts/update-submodules.sh deleted file mode 100755 index 679fe350..00000000 --- a/scripts/update-submodules.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -set -x - -function updateSubmodules { - local branch=master - - if [ $# -ge 1 ] - then - branch=$1 - else - exit 1 - fi - - git submodule sync --recursive - git submodule update --recursive - git config url."https://github.com/".insteadOf git@github.com: - git submodule update --recursive - git pull --recurse-submodules - - if [ $branch != "master" ] - then - git submodule foreach --recursive git checkout $branch - git submodule foreach --recursive git fetch origin - git submodule foreach --recursive git reset --hard origin/$branch - fi - - git config --unset url."https://github.com/".insteadOf -} - -if [ $# -ge 2 ] && [ $1 == "-b" ] && [ $2 != "" ] -then - updateSubmodules $2 -fi diff --git a/src/auto-updater/bfx.appimage.updater.js b/src/auto-updater/bfx.appimage.updater.js deleted file mode 100644 index b43e5f4e..00000000 --- a/src/auto-updater/bfx.appimage.updater.js +++ /dev/null @@ -1,51 +0,0 @@ -'use strict' - -const path = require('path') -const { spawn } = require('child_process') -const { - AppImageUpdater -} = require('electron-updater') - -const { - prepareInstall, - rmOldReleaseDir, - setAppImagePathIfZipRelease -} = require('./utils') - -setAppImagePathIfZipRelease() - -class BfxAppImageUpdater extends AppImageUpdater { - doInstall (opts) { - const root = prepareInstall() - const res = super.doInstall({ - ...opts, - isForceRunAfter: !root - }) - - if (!root) { - return res - } - - const cwd = path.join(root, '..') - const destination = path.join( - cwd, - path.basename(opts.installerPath) - ) - - rmOldReleaseDir(root) - spawn(destination, [], { - detached: true, - stdio: 'ignore', - env: { - ...process.env, - // string is required with AppImage - APPIMAGE_SILENT_INSTALL: 'true' - }, - cwd - }).unref() - - return res - } -} - -module.exports = BfxAppImageUpdater diff --git a/src/auto-updater/index.js b/src/auto-updater/index.js index 92530b30..c785c26a 100644 --- a/src/auto-updater/index.js +++ b/src/auto-updater/index.js @@ -4,6 +4,7 @@ const { ipcMain, Menu } = require('electron') const fs = require('fs') const path = require('path') const { + AppImageUpdater, NsisUpdater, AppUpdater } = require('electron-updater') @@ -11,7 +12,6 @@ const Alert = require('electron-alert') const yaml = require('js-yaml') const log = require('../error-manager/log') -const BfxAppImageUpdater = require('./bfx.appimage.updater') const BfxMacUpdater = require('./bfx.mac.updater') const wins = require('../windows') const { @@ -236,7 +236,7 @@ const _autoUpdaterFactory = () => { }) } if (process.platform === 'linux') { - autoUpdater = new BfxAppImageUpdater() + autoUpdater = new AppImageUpdater() } autoUpdater.on('error', async (err) => { diff --git a/src/auto-updater/utils.js b/src/auto-updater/utils.js deleted file mode 100644 index 1c3d643f..00000000 --- a/src/auto-updater/utils.js +++ /dev/null @@ -1,76 +0,0 @@ -'use strict' - -const path = require('path') -const fs = require('fs') -const { rootPath: appDir } = require('electron-root-path') - -const _root = path.join(appDir, '../..') -const { - version -} = require(path.join(appDir, 'package.json')) - -const isZipRelease = (root = _root) => { - const isZipReleaseFile = path.join(root, 'isZipRelease') - - return fs.existsSync(isZipReleaseFile) -} - -const getTempReleaseFilePath = (root = _root) => { - const fileName = `BitfinexReport-${version}-x64-linux.AppImage` - const filePath = path.join(root, '..', fileName) - - return filePath -} - -const setAppImagePath = ( - appImagePath = getTempReleaseFilePath() -) => { - process.env.APPIMAGE = appImagePath -} - -const setAppImagePathIfZipRelease = () => { - if (!isZipRelease()) return - - setAppImagePath() -} - -const makeTempReleaseFile = (filePath) => { - try { - fs.writeFileSync(filePath, '') - } catch (err) { - console.error(err) - } -} - -const rmOldReleaseDir = (root) => { - if (!root) { - return - } - - try { - fs.rmdirSync(root, { recursive: true }) - } catch (err) { - console.error(err) - } -} - -const prepareInstall = () => { - const root = path.join(appDir, '../..') - - if (!isZipRelease(root)) { - return - } - - const filePath = getTempReleaseFilePath(root) - makeTempReleaseFile(filePath) - setAppImagePath(filePath) - - return root -} - -module.exports = { - isZipRelease, - prepareInstall, - rmOldReleaseDir, - setAppImagePathIfZipRelease -} diff --git a/src/error-manager/index.js b/src/error-manager/index.js index 547b16f6..95bbc67b 100644 --- a/src/error-manager/index.js +++ b/src/error-manager/index.js @@ -80,7 +80,9 @@ const _isLogSkipped = (log) => { typeof str === 'string' && ( str.includes('contextIsolation is deprecated') || - str.includes('ERR_INTERNET_DISCONNECTED') + str.includes('ERR_INTERNET_DISCONNECTED') || + // Skip error when can't get code signature on mac + str.includes('Could not get code signature') ) ) } diff --git a/src/helpers/get-debug-info.js b/src/helpers/get-debug-info.js index d1f5e6af..1612d637 100644 --- a/src/helpers/get-debug-info.js +++ b/src/helpers/get-debug-info.js @@ -9,6 +9,11 @@ const { getAppUpdateConfigSync } = require('../auto-updater') const packageJson = require(path.join(appDir, 'package.json')) const productName = require('./product-name') +let electronBuilderConfig = {} + +try { + electronBuilderConfig = require(path.join(appDir, 'electron-builder-config')) +} catch (err) {} let lastCommit = { hash: '-', date: '-' } let appUpdateConfig = {} @@ -18,7 +23,8 @@ try { } catch (err) { console.debug(err) - appUpdateConfig = packageJson.build.publish + appUpdateConfig = electronBuilderConfig + ?.publish ?? {} } try { lastCommit = require(path.join(appDir, 'lastCommit.json')) diff --git a/src/helpers/is-main-win-available.js b/src/helpers/is-main-win-available.js index 0f430e41..d15444fd 100644 --- a/src/helpers/is-main-win-available.js +++ b/src/helpers/is-main-win-available.js @@ -2,10 +2,17 @@ const wins = require('../windows') -module.exports = (win = wins?.mainWindow) => { +module.exports = ( + win = wins?.mainWindow, + opts = {} +) => { return ( win && typeof win === 'object' && - !win.isDestroyed() + !win.isDestroyed() && + ( + !opts?.shouldCheckVisibility || + win.isVisible() + ) ) } diff --git a/src/helpers/product-name.js b/src/helpers/product-name.js index 0d2ece7d..b4912969 100644 --- a/src/helpers/product-name.js +++ b/src/helpers/product-name.js @@ -3,8 +3,13 @@ const path = require('path') const { rootPath: appDir } = require('electron-root-path') -const packageJson = require(path.join(appDir, 'package.json')) -const productName = packageJson?.build +let electronBuilderConfig = {} + +try { + electronBuilderConfig = require(path.join(appDir, 'electron-builder-config')) +} catch (err) {} + +const productName = electronBuilderConfig ?.productName ?? 'Bitfinex Report' module.exports = productName diff --git a/src/initialize-app.js b/src/initialize-app.js index 9b7a310f..55c68240 100644 --- a/src/initialize-app.js +++ b/src/initialize-app.js @@ -34,9 +34,6 @@ const { const { manageChangelog } = require('./changelog-manager') -const { - isZipRelease -} = require('./auto-updater/utils') const enforceMacOSAppLocation = require( './enforce-macos-app-location' ) @@ -167,16 +164,11 @@ const _manageConfigs = (params = {}) => { pathToUserDocuments } = params - const isZipReleaseRun = isZipRelease() - const isRelativeCsvPath = ( - isZipReleaseRun && - process.platform !== 'darwin' + const pathToUserCsv = path.join( + pathToUserDocuments, + 'bitfinex/reports' ) - const pathToUserCsv = isRelativeCsvPath - ? path.join('../../..', 'csv') - : path.join(pathToUserDocuments, 'bitfinex/reports') - const configsKeeper = configsKeeperFactory( { pathToUserData }, { @@ -189,7 +181,7 @@ const _manageConfigs = (params = {}) => { configsKeeper, { pathToUserCsv, - isRelativeCsvPath + isRelativeCsvPath: true } ) } diff --git a/src/manage-worker-messages.js b/src/manage-worker-messages.js index 84fc2d05..82bf707a 100644 --- a/src/manage-worker-messages.js +++ b/src/manage-worker-messages.js @@ -19,7 +19,10 @@ const PROCESS_STATES = require( ) module.exports = (ipc) => { - const win = isMainWinAvailable() + const win = isMainWinAvailable( + wins.mainWindow, + { shouldCheckVisibility: true } + ) ? wins.mainWindow : BrowserWindow.getFocusedWindow() diff --git a/src/relaunch.js b/src/relaunch.js index 75fbb978..e46561f0 100644 --- a/src/relaunch.js +++ b/src/relaunch.js @@ -2,10 +2,6 @@ const electron = require('electron') -const { - isZipRelease -} = require('./auto-updater/utils') - module.exports = () => { const app = electron.app || electron.remote.app @@ -13,10 +9,7 @@ module.exports = () => { args: process.argv.slice(1).concat(['--relaunch']) } - if ( - process.env.APPIMAGE && - !isZipRelease() - ) { + if (process.env.APPIMAGE) { options.execPath = process.env.APPIMAGE options.args.unshift('--appimage-extract-and-run') }