This repository has been archived by the owner on Jun 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paltry-js.cmd
189 lines (173 loc) · 6.83 KB
/
paltry-js.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
@echo off
title Paltry JS
set SSH_REPO_URL=" "
set HTTPS_REPO_URL="https://github.com/skidding/flatris.git"
set REPO_FOLDER="test-repo"
set PROJECT_FOLDER="."
set CONFIG_XML_FILE="pom.xml"
set CONFIG_XML_XPATH="//*[name()='nodeVersion']"
set TMP_SCRIPT="%TMP%\%~n0.ps1"
for /f "delims=:" %%a in ('findstr -n "^___" %0') do set "Line=%%a"
(for /f "skip=%Line% tokens=* eol=_" %%a in ('type %0') do echo(%%a) > %TMP_SCRIPT%
powershell -ExecutionPolicy RemoteSigned -File %TMP_SCRIPT% ^
-SshRepoUrl "%SSH_REPO_URL%" -HttpsRepoUrl "%HTTPS_REPO_URL%" ^
-RepoFolder "%REPO_FOLDER%" -ProjectFolder "%PROJECT_FOLDER%" ^
-ConfigXmlFile "%CONFIG_XML_FILE%" -ConfigXmlXpath "%CONFIG_XML_XPATH%"
exit
___SCRIPT___
Param(
[string]$SshRepoUrl,
[string]$HttpsRepoUrl,
[string]$RepoFolder,
[string]$ProjectFolder,
[string]$ConfigXmlFile,
[string]$ConfigXmlXpath
)
Add-Type -Assembly "System.IO.Compression.FileSystem"
$CurrentFolder = $PWD
$UserProfile = $Env:USERPROFILE
$DownloadsFolder = "$UserProfile\Downloads"
$TempFolder = "$UserProfile\Temp"
$ToolsFolder = "$CurrentFolder\tools"
$VsCodeDataFolder = "$CurrentFolder\vscode"
$FullRepoFolder = "$CurrentFolder\$RepoFolder"
$WebClient = New-Object System.Net.WebClient
$WebClient.Headers.Add("User-Agent", "PowerShell")
$Online = Test-Connection -ComputerName 8.8.8.8 -Quiet -ErrorAction Ignore
New-Item -ItemType Directory -Force -Path $DownloadsFolder | Out-Null
New-Item -ItemType Directory -Force -Path $TempFolder | Out-Null
New-Item -ItemType Directory -Force -Path $ToolsFolder | Out-Null
Function Log-Info($Message) {
Write-Host -ForegroundColor "Green" $Message
}
Function Log-Warn($Message) {
Write-Host -ForegroundColor "Yellow" $Message
}
Function Require-Online {
if(!$Online) {
$ErrorMessage = "Required files not downloaded and you are offline"
(New-Object -ComObject Wscript.Shell).Popup($ErrorMessage, 0, "ERROR!", 16)
exit 1
}
}
Function Get-WebClient {
$WebClient = New-Object System.Net.WebClient
$WebClient.Headers.Add("User-Agent", "PowerShell")
return $WebClient
}
Function DownloadString($Url) {
$WebClient = Get-WebClient
return $WebClient.DownloadString($Url)
}
Function DownloadFile($Url, $Path) {
$WebClient = Get-WebClient
return $WebClient.DownloadFile($Url, $Path)
}
Function Install7Zip {
$7ZipUrl = "http://www.7-zip.org/a/7z1604-x64.msi"
$7ZipFile = $7ZipUrl.Split("/") | Select-Object -Last 1
$7ZipFolder = [io.path]::GetFileNameWithoutExtension($7ZipFile)
$7ZipInstallerFile = "$DownloadsFolder\$7ZipFile"
$7ZipInstallerFolder = "$TempFolder\$7ZipFolder"
$7ZipInstalledFolder = "$ToolsFolder\$7ZipFolder"
if(!(Test-Path $7ZipInstalledFolder)) {
if(!(Test-Path $7ZipInstallerFile)) {
Require-Online
Log-Info "Downloading 7-Zip..."
DownloadFile $7ZipUrl $7ZipInstallerFile
}
Log-Info "Extracting 7-Zip..."
msiexec /a "$7ZipInstallerFile" TARGETDIR="$7ZipInstallerFolder" /qn | Out-Null
Move-Item "$7ZipInstallerFolder\Files\7-Zip" $7ZipInstalledFolder -Force
Remove-Item -Recurse -Force -ErrorAction Ignore $7ZipInstallerFolder
}
$Env:Path = "$7ZipInstalledFolder;$Env:Path"
}
Function InstallTool($Name, $Url, $Prefix) {
if($Online) {
$ToolFile = $Url.Split("/") | Select-Object -Last 1
$ToolFolder = [io.path]::GetFileNameWithoutExtension($ToolFile)
if(!($ToolFolder.Contains("."))) {
$Url = [System.Net.WebRequest]::Create($Url).GetResponse().ResponseUri.AbsoluteUri
$ToolFile = $Url.Split("/") | Select-Object -Last 1
$ToolFolder = [io.path]::GetFileNameWithoutExtension($ToolFile)
}
$DownloadedFile = "$DownloadsFolder\$ToolFile"
$ExtractedFolder = "$TempFolder\$Name"
$InstalledFolder = "$ToolsFolder\$ToolFolder"
} else {
$InstalledFolder = Get-ChildItem $ToolsFolder -Filter $Prefix |
Sort-Object Name -Descending | Select-Object -First 1 | %{ $_.FullName }
if(!$InstalledFolder) {
Require-Online
}
}
if(!(Test-Path $InstalledFolder)) {
if(!(Test-Path $DownloadedFile)) {
Require-Online
Log-Info "Downloading $Name..."
DownloadFile $Url $DownloadedFile
}
Log-Info "Extracting $Name..."
Remove-Item -Recurse -ErrorAction Ignore $ExtractedFolder
7z x "$DownloadedFile" -o"$ExtractedFolder" | Out-Null
$ExtractedContents = Get-ChildItem $ExtractedFolder
if($ExtractedContents.Length -eq 1 -And $ExtractedContents[0].PSIsContainer) {
Move-Item $ExtractedContents[0].FullName $InstalledFolder
Remove-Item $ExtractedFolder
} else {
Move-Item $ExtractedFolder $InstalledFolder
}
}
$ToolBinFolder = Get-ChildItem -Recurse $InstalledFolder -Filter *.exe | Select-Object -First 1 | %{ $_.Directory.FullName }
$Env:Path = "$ToolBinFolder;$Env:Path"
}
Install7Zip
$GitReleaseApiUrl = "https://api.github.com/repos/git-for-windows/git/releases/latest"
if($Online) {
$MinGitRelease = DownloadString $GitReleaseApiUrl | ConvertFrom-Json |
Select -Expand assets | Where-Object { $_.name -Match "MinGit.*64-bit.zip" }
}
$MinGitUrl = $MinGitRelease.browser_download_url -Split " " | Select-Object -First 1
InstallTool -Name "Git" -Url $MinGitUrl -Prefix MinGit*
if(!(Test-Path $FullRepoFolder)) {
Require-Online
Log-Info "Cloning Repo..."
if((Test-Path "$UserProfile\.ssh") -And $SshRepoUrl) {
git clone $SshRepoUrl $RepoFolder
}
if(!(Test-Path $FullRepoFolder)) {
git clone $HttpsRepoUrl $RepoFolder
}
}
$ConfigXmlPath = "$FullRepoFolder\$ConfigXmlFile"
if((Test-Path $ConfigXmlPath) -And $ConfigXmlXpath) {
$NodeVersion = Select-Xml -Path $ConfigXmlPath -XPath $ConfigXmlXpath | %{ $_.Node.'#text' }
}
if(!$NodeVersion) {
$NodeVersion = $Env:NODE_VERSION
}
if(!$NodeVersion -And $Online) {
$LatestNodeHashesUrl = "https://nodejs.org/dist/latest/SHASUMS256.txt"
$NodeVersionRegEx = "^node-v([\d\.]+)-win-x64.zip$"
$NodeVersion = $WebClient.DownloadString($LatestNodeHashesUrl) -Split "\n" |
%{ $_ -Split "\s+" | Select-Object -Last 1 } | ?{ $_ -Match $NodeVersionRegEx } |
%{ $_ -Replace $NodeVersionRegEx, '$1' }
}
$NodeUrl = "https://nodejs.org/dist/v$NodeVersion/node-v$NodeVersion-win-x64.zip"
InstallTool -Name "Node.js" -Url $NodeUrl -Prefix node*
cd "$FullRepoFolder\$ProjectFolder"
if($Online) {
if(!(Test-Path node_modules)) {
Log-Info "Installing JavaScript Dependencies..."
Log-Warn "Please be patient, this will take a moment..."
} else {
Log-Info "Updating JavaScript Dependencies..."
}
npm install
}
$VsCodeUrl = "https://vscode-update.azurewebsites.net/latest/win32-x64-archive/stable"
InstallTool -Name "VS Code" -Url $VsCodeUrl -Prefix VSCode*
Log-Info "Launching VS Code..."
code --user-data-dir $VsCodeDataFolder --extensions-dir "$VsCodeDataFolder\extensions" .
powershell