aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLibravatar Nathanaël Houn <contact@nathanaelhoun.fr>2022-04-22 11:51:48 +0200
committerLibravatar GitHub <noreply@github.com>2022-04-22 09:51:48 +0000
commit81b4aae66515b6eec2ac98fda50b1a59bffd94e3 (patch)
treee61886514667101ff8169aa09daa375c9853eb35 /scripts
parentFix build for snapcraft: command not found (diff)
downloadferdium-app-81b4aae66515b6eec2ac98fda50b1a59bffd94e3.tar.gz
ferdium-app-81b4aae66515b6eec2ac98fda50b1a59bffd94e3.tar.zst
ferdium-app-81b4aae66515b6eec2ac98fda50b1a59bffd94e3.zip
Added build scripts for linux, macos and windows to help new contributors get setup quickly (#21)
Co-authored-by: Vijay A <vraravam@users.noreply.github.com> Co-authored-by: André Oliveira <oliveira.andrerodrigues95@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/build-unix.sh135
-rw-r--r--scripts/build-windows.ps1100
2 files changed, 235 insertions, 0 deletions
diff --git a/scripts/build-unix.sh b/scripts/build-unix.sh
new file mode 100755
index 000000000..e80c38059
--- /dev/null
+++ b/scripts/build-unix.sh
@@ -0,0 +1,135 @@
1#!/bin/bash
2
3# INTRO:
4# This file is used to build ferdium on both x64 and arm-based for macos and linux (not tested on arm for linux).
5# It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning)
6# It will install the system dependencies except for node (which is still verified)
7# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed
8# This file can live anywhere in your PATH
9
10set -e
11
12export ELECTRON_CACHE=$HOME/.cache/electron
13export ELECTRON_BUILDER_CACHE=$HOME/.cache/electron-builder
14export CSC_IDENTITY_AUTO_DISCOVERY=false
15export CI=true
16
17# -----------------------------------------------------------------------------
18# Utility functions
19fail_with_docs() {
20 printf "\n*************** FAILING ***************\n"
21 echo "$1"
22 echo ""
23 echo "Please read the developer documentation in CONTRIBUTING.md"
24 exit 1
25}
26
27command_exists() {
28 type "$1" &>/dev/null 2>&1
29}
30
31# -----------------------------------------------------------------------------
32# Checking the developer environment
33# checking for installed programmes
34command_exists node || fail_with_docs "Node is not installed"
35command_exists jq || fail_with_docs "jq is not installed"
36
37EXPECTED_NODE_VERSION=$(cat .nvmrc)
38ACTUAL_NODE_VERSION=$(node -v)
39if [ "v$EXPECTED_NODE_VERSION" != "$ACTUAL_NODE_VERSION" ]; then
40 fail_with_docs "You are not running the expected version of node!
41 expected: [v$EXPECTED_NODE_VERSION]
42 actual : [$ACTUAL_NODE_VERSION]"
43fi
44
45# Check if the 'recipes' folder is present either as a git submodule or a symbolic link
46if ! [ -f "recipes/package.json" ]; then
47 fail_with_docs "'recipes' folder is missing or submodule has not been checked out"
48fi
49
50# This log statement is only to remind me which 'recipes' folder I am using (symlink or git submodule)
51if [[ -L recipes ]]; then
52 printf "\n*************** CONTINUING for 'recipes' symlinked ***************\n"
53else
54 printf "\n*************** CONTINUING for 'recipes' submodule ***************\n"
55fi
56
57# -----------------------------------------------------------------------------
58# If you are moving to a new version of node or any other system dependency, then cleaning is recommended
59# so that there's no irregular results due to cached modules
60if [ "$CLEAN" != "true" ]; then
61 printf "\n*************** SKIPPING Cleaning ***************\n"
62else
63 printf "\n*************** Cleaning!!!!!! ***************\n"
64 npm cache clean --force
65 rm -rf ~/.npm ~/.node-gyp ~/.asdf/installs/nodejs/*/.npm/
66 if [[ -s 'pnpm-lock.yaml' ]]; then
67 pnpm store prune || true # in case the pnpm executable itself is not present
68 rm -rf ~/.pnpm-store ~/.pnpm-state
69 fi
70
71 git -C recipes clean -fxd # Clean recipes folder/submodule
72 git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it
73fi
74
75# -----------------------------------------------------------------------------
76printf "\n*************** Installing node dependencies ***************\n"
77# If 'asdf' is installed, reshim for new nodejs if necessary
78command_exists asdf && asdf reshim nodejs
79
80# Ensure that the system dependencies are at the correct version
81EXPECTED_NPM_VERSION=$(jq --raw-output .engines.npm <"package.json")
82EXPECTED_PNPM_VERSION=$(jq --raw-output .engines.pnpm <"./recipes/package.json")
83if [[ "$(npm --version)" != "$EXPECTED_NPM_VERSION" ]]; then
84 npm i -gf "npm@$EXPECTED_NPM_VERSION"
85fi
86if [[ "$(pnpm --version)" != "$EXPECTED_PNPM_VERSION" ]]; then
87 npm i -gf "pnpm@$EXPECTED_PNPM_VERSION"
88fi
89
90# If 'asdf' is installed, reshim for new nodejs if necessary
91command_exists asdf && asdf reshim nodejs
92
93# This is useful if we move from 'npm' to 'pnpm' for the main repo as well
94if [[ -s 'pnpm-lock.yaml' ]]; then
95 BASE_CMD=pnpm
96else
97 BASE_CMD=npm
98fi
99
100# Now the meat.....
101$BASE_CMD i
102$BASE_CMD run prepare-code
103
104# -----------------------------------------------------------------------------
105printf "\n*************** Building recipes ***************\n"
106# Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm
107pushd recipes
108pnpm i
109pnpm run package
110popd
111
112# -----------------------------------------------------------------------------
113printf "\n*************** Building app ***************\n"
114if [[ "$(uname -m)" =~ "arm" ]]; then
115 TARGET_ARCH=arm64
116else
117 TARGET_ARCH=x64
118fi
119
120if [[ "$(uname)" =~ "Darwin" ]]; then
121 TARGET_OS="mac"
122else
123 TARGET_OS="linux"
124fi
125
126$BASE_CMD run build -- "--$TARGET_ARCH" --"$TARGET_OS" --dir
127
128printf "\n*************** App successfully built! ***************\n"
129# Final check to ensure that the version built is the same as the latest commit
130cat build/buildInfo.json
131git --no-pager log -1
132if [[ $(git rev-parse --short HEAD) != $(jq --raw-output .gitHashShort <"build/buildInfo.json") ]]; then
133 echo "The built version is not on the latest commit"
134 exit 1
135fi
diff --git a/scripts/build-windows.ps1 b/scripts/build-windows.ps1
new file mode 100644
index 000000000..9d4219ffb
--- /dev/null
+++ b/scripts/build-windows.ps1
@@ -0,0 +1,100 @@
1# INTRO:
2# This file is used to build ferdium on windows.
3# It also handles any corrupted node modules with the 'CLEAN' env var (set it to 'true' for cleaning)
4# It will install the system dependencies except for node (which is still verified)
5# I sometimes symlink my 'recipes' folder so that any changes that I need to do in it can also be committed and pushed
6# This file can live anywhere in your PATH
7
8#CHECK PYTHON
9#CHECK NODE.JS
10#CHECK NPM
11#CHECK MSVS_VERSION and MSVS Tools
12
13$USERHOME = "${env:HOMEDRIVE}${env:HOMEPATH}"
14
15$env:ELECTRON_CACHE = $USERHOME + '/.cache/electron'
16$env:ELECTRON_BUILDER_CACHE = $USERHOME + '/.cache/electron-builder'
17$env:CSC_IDENTITY_AUTO_DISCOVERY = $false
18
19$env:CI = $true
20
21$EXPECTED_NODE_VERSION = (Get-Content .\.nvmrc)
22$ACTUAL_NODE_VERSION = (node -v)
23
24if ( "v$EXPECTED_NODE_VERSION" -ne $ACTUAL_NODE_VERSION)
25{
26 Write-Host "You are not running the expected version of node!"
27 Write-Host " expected: [v$EXPECTED_NODE_VERSION]"
28 Write-Host " actual : [$ACTUAL_NODE_VERSION]"
29 exit 1
30}
31
32if ( $env:CLEAN -eq "true" )
33{
34 $NPM_PATH = "$USERHOME\.npm"
35 $NODE_GYP = "$USERHOME\.node-gyp"
36
37 Write-Host "Cleaning!"
38 npm cache clean --force
39 Remove-Item -Path $NPM_PATH -Recurse
40 Remove-Item -Path $NODE_GYP -Recurse
41
42 if ( Test-Path -Path ".\pnpm-lock.yaml" -and (Get-Command -ErrorAction Ignore -Type Application pnpm) )
43 {
44 $PNPM_STORE = "$USERHOME\.pnpm-store"
45 $PNPM_STATE = "$USERHOME\.pnpm-state"
46
47 pnpm store prune
48
49 Remove-Item -Path $PNPM_STORE -Recurse
50 Remove-Item -Path $PNPM_STATE -Recurse
51 }
52
53 git -C recipes clean -fxd
54 git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it
55}
56
57# Ensure that the system dependencies are at the correct version
58npm i -gf npm@8.7.0
59npm i -gf pnpm@6.32.8
60
61# This is useful if we move from 'npm' to 'pnpm' for the main repo as well
62if ( (Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm) )
63{
64 $BASE_CMD="pnpm"
65 $env:EXEC_CMD="pnpm dlx"
66}
67else
68{
69 $BASE_CMD="npm"
70 $env:EXEC_CMD="npx"
71}
72
73# Now the meat.....
74& $BASE_CMD i
75& $BASE_CMD run prepare-code
76
77# Check if the 'recipes' folder is present either as a git submodule or a symbolic link
78if (-not (Test-Path -Path ".\recipes\package.json"))
79{
80 try {
81 git submodule update --init --recursive --remote --rebase --force
82 } catch {
83 Write-Host "FAILING since 'recipes' folder/submodule has not been checked out"
84 exit 1
85 }
86}
87
88# Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm
89Set-Location recipes
90pnpm i
91pnpm run package
92Set-Location ..
93
94$TARGET_ARCH="x64"
95& $BASE_CMD run build -- --$TARGET_ARCH --dir
96
97# Final check to ensure that the version built is the same as the latest commit
98# TODO: Need to make this an assertion similar to tthe unix-equivalent
99Get-Content "build/buildInfo.json" | ConvertFrom-Json
100git log -1