aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar André Oliveira <oliveira.andrerodrigues95@gmail.com>2022-04-25 20:36:03 +0100
committerLibravatar Vijay Aravamudhan <vraravam@users.noreply.github.com>2022-04-30 05:23:58 -0500
commit5143d301a20d0fd2e8b3d6e969c0ed2748708483 (patch)
tree9eadd51ebb12e1f6f92770d39bccd21485d4e112
parentRegenerate '.gitignore' (diff)
downloadferdium-server-5143d301a20d0fd2e8b3d6e969c0ed2748708483.tar.gz
ferdium-server-5143d301a20d0fd2e8b3d6e969c0ed2748708483.tar.zst
ferdium-server-5143d301a20d0fd2e8b3d6e969c0ed2748708483.zip
Creates the build script for Windows based on Ferdium-App
-rw-r--r--scripts/build-windows.ps1175
1 files changed, 175 insertions, 0 deletions
diff --git a/scripts/build-windows.ps1 b/scripts/build-windows.ps1
new file mode 100644
index 0000000..e932da9
--- /dev/null
+++ b/scripts/build-windows.ps1
@@ -0,0 +1,175 @@
1# INTRO:
2# This file is used to build ferdium-server 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 and python (which are 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 independently
6# This file can live anywhere in your PATH
7
8$USERHOME = "${env:HOMEDRIVE}${env:HOMEPATH}"
9
10$env:CI = $true
11
12# -----------------------------------------------------------------------------
13# Utility functions
14
15Function fail_with_docs {Param ($1)
16 Write-Host "*************** FAILING ***************"
17 Write-Host "$1"
18 Write-Host ""
19 Write-Host "Please read the developer documentation in CONTRIBUTING.md"
20 exit 1
21}
22
23Function Test-CommandExists { Param ($command, $1)
24 $oldPreference = $ErrorActionPreference
25 $ErrorActionPreference = "stop"
26
27 try {
28 if(Get-Command $command){RETURN}
29 } Catch {
30 fail_with_docs $1
31 }
32 Finally {$ErrorActionPreference=$oldPreference}
33}
34
35# -----------------------------------------------------------------------------
36# Checking the developer environment
37# Check for installed programmes
38Test-CommandExists node "Node is not installed"
39Test-CommandExists npm "npm is not installed"
40Test-CommandExists python "Python is not installed"
41# NEEDS proper way to CHECK MSVS Tools
42
43# Check node version
44$EXPECTED_NODE_VERSION = (cat .nvmrc)
45$ACTUAL_NODE_VERSION = (node -v)
46if ("v$EXPECTED_NODE_VERSION" -ne $ACTUAL_NODE_VERSION) {
47 fail_with_docs "You are not running the expected version of node!
48 expected: [v$EXPECTED_NODE_VERSION]
49 actual : [$ACTUAL_NODE_VERSION]"
50}
51
52# Check if the 'recipes' folder is present either as a git submodule or a symbolic link
53if (-not (Test-Path -Path recipes\package.json -PathType Leaf)) {
54 fail_with_docs "'recipes' folder is missing or submodule has not been checked out"
55}
56
57# This log statement is only to remind me which 'recipes' folder I am using (symlink or git submodule)
58# TODO: Implement this
59
60# -----------------------------------------------------------------------------
61# If you are moving to a new version of node or any other system dependency, then cleaning is recommended
62# so that there's no irregular results due to cached modules
63if ($env:CLEAN -eq "true")
64{
65 $NPM_PATH = "$USERHOME\AppData\Roaming\npm\node_modules"
66 $NPM_CACHE1_PATH = "$USERHOME\AppData\Local\npm-cache"
67 $NPM_CACHE2_PATH = "$USERHOME\AppData\Roaming\npm-cache"
68 $NODE_GYP = "$USERHOME\AppData\Local\node-gyp"
69
70 Write-Host "Cleaning!"
71
72 if ( (Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm) )
73 {
74 $PNPM_STORE = "$USERHOME\.pnpm-store"
75 $PNPM_STATE = "$USERHOME\.pnpm-state"
76
77 pnpm store prune
78
79 Remove-Item -Path $PNPM_STORE -Recurse -ErrorAction SilentlyContinue
80 Remove-Item -Path $PNPM_STATE -Recurse -ErrorAction SilentlyContinue
81 }
82
83 npm cache clean --force
84 Remove-Item -Path $NPM_PATH -Recurse -ErrorAction SilentlyContinue
85 Remove-Item -Path $NPM_CACHE1_PATH -Recurse -ErrorAction SilentlyContinue
86 Remove-Item -Path $NPM_CACHE2_PATH -Recurse -ErrorAction SilentlyContinue
87 Remove-Item -Path $NODE_GYP -Recurse -ErrorAction SilentlyContinue
88
89 git -C recipes clean -fxd # Clean recipes folder/submodule
90 git clean -fxd # Note: This will blast away the 'recipes' folder if you have symlinked it
91}
92
93# -----------------------------------------------------------------------------
94# Ensure that the system dependencies are at the correct version - fail if not
95# Check python version
96$EXPECTED_PYTHON_VERSION = "3.10.4"
97$ACTUAL_PYTHON_VERSION = (python --version).trim("Python ")
98if ([System.Version]$ACTUAL_PYTHON_VERSION -ne [System.Version]$EXPECTED_PYTHON_VERSION) {
99 fail_with_docs "You are not running the expected version of Python!
100 expected: [$EXPECTED_PYTHON_VERSION]
101 actual : [$ACTUAL_PYTHON_VERSION]"
102}
103
104# TODO: Needs proper way to check MSVS Tools
105# Check MSVS Tools through MSVS_VERSION
106$EXPECTED_MSVST_VERSION = "2015"
107$ACTUAL_MSVST_VERSION = (npm config get msvs_version)
108if ([double]$ACTUAL_MSVST_VERSION -ne [double]$EXPECTED_MSVST_VERSION) {
109 fail_with_docs "You are not running the expected version of MSVS Tools!
110 expected: [$EXPECTED_MSVST_VERSION]
111 actual : [$ACTUAL_MSVST_VERSION]"
112}
113
114# -----------------------------------------------------------------------------
115# Ensure that the system dependencies are at the correct version - recover if not
116# Check npm version
117$EXPECTED_NPM_VERSION = (Get-Content package.json | ConvertFrom-Json).engines.npm
118$ACTUAL_NPM_VERSION = (npm -v)
119if ($EXPECTED_NPM_VERSION -ne $ACTUAL_NPM_VERSION) {
120 Write-Host "You are not running the expected version of npm!
121 expected: [$EXPECTED_NPM_VERSION]
122 actual : [$ACTUAL_NPM_VERSION]"
123 Write-Host "Changing version of npm to [$EXPECTED_NPM_VERSION]"
124 npm i -gf npm@$EXPECTED_NPM_VERSION
125}
126
127# Check pnpm version
128$EXPECTED_PNPM_VERSION = (Get-Content recipes\package.json | ConvertFrom-Json).engines.pnpm
129$ACTUAL_PNPM_VERSION = Get-Command pnpm --version -ErrorAction SilentlyContinue # in case the pnpm executable itself is not present
130if ($ACTUAL_PNPM_VERSION -ne $EXPECTED_PNPM_VERSION) {
131 npm i -gf pnpm@$EXPECTED_PNPM_VERSION
132}
133
134# -----------------------------------------------------------------------------
135# This is useful if we move from 'npm' to 'pnpm' for the main repo as well
136if ((Test-Path -Path ".\pnpm-lock.yaml") -and (Get-Command -ErrorAction Ignore -Type Application pnpm))
137{
138 $BASE_CMD="pnpm"
139 $env:EXEC_CMD="pnpm dlx"
140}
141else
142{
143 $BASE_CMD="npm"
144 $env:EXEC_CMD="npx"
145}
146
147$ENV_FILE = ".env"
148if (-not (Test-Path -Path $ENV_FILE)) {
149 Copy-Item .env.example -Destination $ENV_FILE
150 $APP_KEY = ("!@#$%^&*0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz".tochararray() | sort {Get-Random})[0..32] -join ''
151 # SAVE APP_KEY TO .env FILE
152 (Get-Content $ENV_FILE -Raw) -replace 'APP_KEY', "APP_KEY=$APP_KEY" | Set-Content $ENV_FILE
153}
154
155if (-not (Test-Path -Path "data")) {
156 mkdir data
157}
158
159# -----------------------------------------------------------------------------
160Write-Host "*************** Building recipes ***************"
161# Note: 'recipes' is already using only pnpm - can switch to $BASE_CMD AFTER both repos are using pnpm
162Push-Location recipes
163pnpm i
164pnpm package
165Pop-Location
166
167# Now the meat.....
168& $BASE_CMD i
169& node ace migration:refresh
170
171# -----------------------------------------------------------------------------
172Write-Host "*************** Starting app ***************"
173& $BASE_CMD start --dev
174
175Write-Host "*************** App successfully stopped! ***************"