Skip to content

Commit c76c884

Browse files
Merge pull request #391 from appwrite/feat-win-install-for-0.13
Adds install.ps1 to CLI installer templates.
2 parents 0eb7bb2 + 26f44f0 commit c76c884

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+
## <script src="/dist/scripts/cli-bash.js"></script>
2+
## <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/themes/prism-okaidia.min.css" rel="stylesheet" />
3+
## <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/components/prism-core.min.js" data-manual></script>
4+
## <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.16.0/components/prism-powershell.min.js"></script>
5+
## <style>body {color: #272822; background-color: #272822; font-size: 0.8em;} </style>
6+
# Love open-source, dev-tooling and passionate about code as much as we do?
7+
# ---
8+
# We're always looking for awesome hackers like you to join our 100% remote team!
9+
# Check and see if you find any relevant position @ https://{{ spec.title | lower }}.io/company/careers 👩‍💻 😎
10+
# (and let us know you found this message...)
11+
12+
# This script contains hidden JS code to allow better readability and syntax highlighting
13+
# You can use "View source" of this page to see the full script.
14+
15+
# REPO
16+
$GITHUB_x64_URL = "https://github.com/{{ sdk.gitUserName }}/{{ sdk.gitRepoName | caseDash }}/releases/download/{{ sdk.version }}/{{ language.params.executableName }}-cli-win-x64.exe"
17+
$GITHUB_arm64_URL = "https://github.com/{{ sdk.gitUserName }}/{{ sdk.gitRepoName | caseDash }}/releases/download/{{ sdk.version }}/{{ language.params.executableName }}-cli-win-arm64.exe"
18+
19+
# {{ spec.title | caseUcfirst }} download directory
20+
${{ spec.title | upper }}_DOWNLOAD_DIR = Join-Path -Path $env:TEMP -ChildPath "{{ language.params.executableName }}.exe"
21+
22+
# {{ spec.title | caseUcfirst }} CLI location
23+
${{ spec.title | upper }}_INSTALL_DIR = Join-Path -Path $env:LOCALAPPDATA -ChildPath "{{ spec.title | caseUcfirst }}"
24+
25+
$USER_PATH_ENV_VAR = [Environment]::GetEnvironmentVariable("PATH", "User")
26+
27+
function Greeting {
28+
Write-Host @"
29+
{{ language.params.logoUnescaped | raw }}
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 ${{ spec.title | upper }}_DOWNLOAD_DIR ${{ spec.title | upper }}_INSTALL_DIR
58+
}
59+
60+
61+
function Install {
62+
Write-Host "[3/4] Starting installation ..."
63+
64+
if ($USER_PATH_ENV_VAR -like '*{{ spec.title | caseUcfirst }}*') {
65+
Write-Host "Skipping to add {{ spec.title | caseUcfirst }} to User Path."
66+
} else {
67+
[System.Environment]::SetEnvironmentVariable("PATH", $USER_PATH_ENV_VAR + ";${{ spec.title | upper }}_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)