aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Vijay A <vraravam@users.noreply.github.com>2022-04-30 05:15:02 -0500
committerLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-04-30 05:23:58 -0500
commit713614cb36c4ab22039720187835c69b18b88bbd (patch)
treef875fc4727969fa955e6462ef9dbc2f02be71e01
parentCreates the build script for Windows based on Ferdium-App (diff)
downloadferdium-server-713614cb36c4ab22039720187835c69b18b88bbd.tar.gz
ferdium-server-713614cb36c4ab22039720187835c69b18b88bbd.tar.zst
ferdium-server-713614cb36c4ab22039720187835c69b18b88bbd.zip
Added build script for unix OSes
-rwxr-xr-xscripts/build-unix.sh142
-rw-r--r--scripts/build-windows.ps14
2 files changed, 143 insertions, 3 deletions
diff --git a/scripts/build-unix.sh b/scripts/build-unix.sh
new file mode 100755
index 0000000..ff1ce0f
--- /dev/null
+++ b/scripts/build-unix.sh
@@ -0,0 +1,142 @@
1#!/bin/bash
2
3# INTRO:
4# This file is used to build ferdium-server 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 and python (which are 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 independently
8# This file can live anywhere in your PATH
9
10set -e
11
12export CI=true
13
14# -----------------------------------------------------------------------------
15# Utility functions
16fail_with_docs() {
17 printf "\n*************** FAILING ***************\n"
18 echo "$1"
19 echo ""
20 echo "Please read the developer documentation in CONTRIBUTING.md"
21 exit 1
22}
23
24command_exists() {
25 type "$1" &>/dev/null 2>&1
26}
27
28# -----------------------------------------------------------------------------
29# Checking the developer environment
30# Check for installed programmes
31command_exists node || fail_with_docs "Node is not installed"
32command_exists python || fail_with_docs "python is not installed"
33
34# Check node version
35EXPECTED_NODE_VERSION=$(cat .nvmrc)
36ACTUAL_NODE_VERSION=$(node -v)
37if [ "v$EXPECTED_NODE_VERSION" != "$ACTUAL_NODE_VERSION" ]; then
38 fail_with_docs "You are not running the expected version of node!
39 expected: [v$EXPECTED_NODE_VERSION]
40 actual : [$ACTUAL_NODE_VERSION]"
41fi
42
43# Check if the 'recipes' folder is present either as a git submodule or a symbolic link
44if ! [ -f "recipes/package.json" ]; then
45 fail_with_docs "'recipes' folder is missing or submodule has not been checked out"
46fi
47
48# This log statement is only to remind me which 'recipes' folder I am using (symlink or git submodule)
49if [[ -L recipes ]]; then
50 printf "\n*************** CONTINUING for 'recipes' symlinked ***************\n"
51else
52 printf "\n*************** CONTINUING for 'recipes' submodule ***************\n"
53fi
54
55# -----------------------------------------------------------------------------
56# If you are moving to a new version of node or any other system dependency, then cleaning is recommended
57# so that there's no irregular results due to cached modules
58if [ "$CLEAN" != "true" ]; then
59 printf "\n*************** SKIPPING Cleaning ***************\n"
60else
61 printf "\n*************** Cleaning!!!!!! ***************\n"
62
63 if [[ -s 'pnpm-lock.yaml' ]]; then
64 pnpm store prune || true # in case the pnpm executable itself is not present
65 rm -rf ~/.pnpm-store ~/.pnpm-state
66 fi
67
68 npm cache clean --force
69 rm -rf ~/.npm ~/.node-gyp ~/.asdf/installs/nodejs/*/.npm/
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# -----------------------------------------------------------------------------
76# Ensure that the system dependencies are at the correct version - fail if not
77# Check python version
78EXPECTED_PYTHON_VERSION="3.10.4"
79ACTUAL_PYTHON_VERSION=$(python --version | sed -e "s/Python //")
80if [[ "$ACTUAL_PYTHON_VERSION" != "$EXPECTED_PYTHON_VERSION" ]]; then
81 fail_with_docs "You are not running the expected version of Python!
82 expected: [$EXPECTED_PYTHON_VERSION]
83 actual : [$ACTUAL_PYTHON_VERSION]"
84fi
85
86# -----------------------------------------------------------------------------
87# Ensure that the system dependencies are at the correct version - recover if not
88# If 'asdf' is installed, reshim for new nodejs if necessary
89command_exists asdf && asdf reshim nodejs
90
91# Ensure that the system dependencies are at the correct version
92# Check npm version
93EXPECTED_NPM_VERSION=$(node -p 'require("./package.json").engines.npm')
94ACTUAL_NPM_VERSION=$(npm --version)
95if [[ "$ACTUAL_NPM_VERSION" != "$EXPECTED_NPM_VERSION" ]]; then
96 npm i -gf npm@$EXPECTED_NPM_VERSION
97fi
98
99# Check pnpm version
100EXPECTED_PNPM_VERSION=$(node -p 'require("./recipes/package.json").engines.pnpm')
101ACTUAL_PNPM_VERSION=$(pnpm --version || true) # in case the pnpm executable itself is not present
102if [[ "$ACTUAL_PNPM_VERSION" != "$EXPECTED_PNPM_VERSION" ]]; then
103 npm i -gf pnpm@$EXPECTED_PNPM_VERSION
104fi
105
106# If 'asdf' is installed, reshim for new nodejs if necessary
107command_exists asdf && asdf reshim nodejs
108
109# -----------------------------------------------------------------------------
110# This is useful if we move from 'npm' to 'pnpm' for the main repo as well
111if [[ -s 'pnpm-lock.yaml' ]]; then
112 BASE_CMD=pnpm
113else
114 BASE_CMD=npm
115fi
116
117ENV_FILE=".env"
118if [[ ! -s $ENV_FILE ]]; then
119 APP_KEY=`cat /dev/urandom | LC_ALL=C tr -dc "[:alnum:]" | fold -w ${1:-32} | head -n 1`
120 # SAVE APP_KEY TO .env FILE
121 sed "s/APP_KEY\=/APP_KEY=$APP_KEY/" .env.example > $ENV_FILE
122fi
123
124mkdir -p data
125
126# -----------------------------------------------------------------------------
127printf "\n*************** Building recipes ***************\n"
128# Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm
129pushd recipes
130pnpm i
131pnpm package
132popd
133
134# Now the meat.....
135$BASE_CMD i
136node ace migration:refresh
137
138# -----------------------------------------------------------------------------
139printf "\n*************** Building app ***************\n"
140$BASE_CMD start --dev
141
142printf "\n*************** App successfully stopped! ***************\n"
diff --git a/scripts/build-windows.ps1 b/scripts/build-windows.ps1
index e932da9..81187c6 100644
--- a/scripts/build-windows.ps1
+++ b/scripts/build-windows.ps1
@@ -136,12 +136,10 @@ if ($ACTUAL_PNPM_VERSION -ne $EXPECTED_PNPM_VERSION) {
136if ((Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm)) 136if ((Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm))
137{ 137{
138 $BASE_CMD="pnpm" 138 $BASE_CMD="pnpm"
139 $env:EXEC_CMD="pnpm dlx"
140} 139}
141else 140else
142{ 141{
143 $BASE_CMD="npm" 142 $BASE_CMD="npm"
144 $env:EXEC_CMD="npx"
145} 143}
146 144
147$ENV_FILE = ".env" 145$ENV_FILE = ".env"
@@ -149,7 +147,7 @@ if (-not (Test-Path -Path $ENV_FILE)) {
149 Copy-Item .env.example -Destination $ENV_FILE 147 Copy-Item .env.example -Destination $ENV_FILE
150 $APP_KEY = ("!@#$%^&*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".tochararray() | sort {Get-Random})[0..32] -join '' 148 $APP_KEY = ("!@#$%^&*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".tochararray() | sort {Get-Random})[0..32] -join ''
151 # SAVE APP_KEY TO .env FILE 149 # SAVE APP_KEY TO .env FILE
152 (Get-Content $ENV_FILE -Raw) -replace 'APP_KEY', "APP_KEY=$APP_KEY" | Set-Content $ENV_FILE 150 (Get-Content $ENV_FILE -Raw) -replace 'APP_KEY=', "APP_KEY=$APP_KEY" | Set-Content $ENV_FILE
153} 151}
154 152
155if (-not (Test-Path -Path "data")) { 153if (-not (Test-Path -Path "data")) {