Skip to content

Commit 08b3373

Browse files
committed
Adds install.ps1 to CLI installer templates.
1 parent 111fb88 commit 08b3373

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

templates/cli/install.ps1.twig

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Love open-source, dev-tooling and passionate about code as much as we do?
2+
# ---
3+
# We're always looking for awesome hackers like you to join our 100% remote team!
4+
# Check and see if you find any relevant position @ https://appwrite.io/company/careers
5+
# (and let us know you found this message...)
6+
7+
# This script contains hidden JS code to allow better readability and syntax highlighting
8+
# You can use "View source" of this page to see the full script.
9+
10+
# REPO
11+
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/{{ sdk.version }}/appwrite-cli-win-x64.exe"
12+
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/{{ sdk.version }}/appwrite-cli-win-arm64.exe"
13+
14+
# Appwrite download directory
15+
${{ spec.title | upper }}_DOWNLOAD_DIR = Join-Path -Path $env:TEMP -ChildPath "{{ language.params.executableName }}.exe"
16+
17+
# Appwrite CLI location
18+
${{ spec.title | upper }}_INSTALL_DIR = Join-Path -Path $env:LOCALAPPDATA -ChildPath "{{ spec.title | caseUcfirst }}"
19+
20+
$USER_PATH_ENV_VAR = [Environment]::GetEnvironmentVariable("PATH", "User")
21+
22+
function Greeting {
23+
Write-Host @"
24+
_ _ _ ___ __ _____
25+
/_\ _ __ _ ____ ___ __(_) |_ ___ / __\ / / \_ \
26+
//_\| '_ \| '_ \ \ /\ / / '__| | __/ _ \ / / / / / /\/
27+
/ _ \ |_) | |_) \ V V /| | | | || __/ / /___/ /___/\/ /_
28+
\_/ \_/ .__/| .__/ \_/\_/ |_| |_|\__\___| \____/\____/\____/
29+
|_| |_|
30+
31+
"@ -ForegroundColor red
32+
Write-Host "Welcome to the {{ spec.title | caseUcfirst }} CLI install shield."
33+
}
34+
35+
36+
function CheckSystemInfo {
37+
Write-Host "[1/4] Getting System Info ..."
38+
if ((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') {
39+
Write-Host "PowerShell requires an execution policy of 'RemoteSigned'."
40+
Write-Host "To make this change please run:"
41+
Write-Host "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'"
42+
break
43+
}
44+
}
45+
46+
function DownloadBinary {
47+
Write-Host "[2/4] Downloading {{ spec.title | caseUcfirst }} CLI binary ..."
48+
Write-Host "🚦 Fetching latest version ... " -ForegroundColor green
49+
50+
if((Get-CimInstance Win32_operatingsystem).OSArchitecture -like '*ARM*') {
51+
Invoke-WebRequest -Uri $GITHUB_arm64_URL -OutFile ${{ spec.title | upper }}_DOWNLOAD_DIR
52+
} else {
53+
Invoke-WebRequest -Uri $GITHUB_x64_URL -OutFile ${{ spec.title | upper }}_DOWNLOAD_DIR
54+
}
55+
56+
57+
Move-Item $APPWRITE_DOWNLOAD_DIR $APPWRITE_INSTALL_DIR
58+
}
59+
60+
61+
function Install {
62+
Write-Host "[3/4] Starting installation ..."
63+
64+
if ($USER_PATH_ENV_VAR -like '*Appwrite*') {
65+
Write-Host "Skipping to add {{ spec.title | caseUcfirst }} to User Path."
66+
} else {
67+
[System.Environment]::SetEnvironmentVariable("PATH", $USER_PATH_ENV_VAR + ";$APPWRITE_INSTALL_DIR", "User")
68+
}
69+
}
70+
71+
function CleanUp {
72+
Write-Host "Cleaning up mess ..."
73+
}
74+
75+
function InstallCompleted {
76+
Write-Host "[4/4] Finishing Installation ... "
77+
cleanup
78+
Write-Host "🤘 May the force be with you."
79+
Write-Host "To get started with {{ spec.title | caseUcfirst }} CLI, please visit {{ sdk.url }}/docs/command-line"
80+
}
81+
82+
83+
Greeting
84+
CheckSystemInfo
85+
DownloadBinary
86+
Install
87+
CleanUp
88+
InstallCompleted

0 commit comments

Comments
 (0)