forked from hawkerm/monaco-editor-uwp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-dependencies.ps1
91 lines (63 loc) · 3.85 KB
/
install-dependencies.ps1
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
# Run this script using PowerShell to download and
# install dependencies into the project directory before building.
# Reference to Monaco Version to Use in the Package
$monaco_version = "0.21.3"
# Reference to @webcomponents/webcomponents.js polyfills (for Shadow DOM for Code Action feature)
$webcomponentsjs_version = "2.5.0"
# ------------------------
$monaco_tgz_url = "https://registry.npmjs.org/monaco-editor/-/monaco-editor-$monaco_version.tgz"
$webcomponentsjs_tgz_url = "https://registry.npmjs.org/@webcomponents/webcomponentsjs/-/webcomponentsjs-$webcomponentsjs_version.tgz"
$sharp_zip_lib_url = "https://github.com/icsharpcode/SharpZipLib/releases/download/0.86.0.518/ICSharpCode.SharpZipLib.dll"
$temp_dir_name = ".temp"
# Make download faster by not showing progress
$ProgressPreference = 'SilentlyContinue'
function Get-ScriptDirectory {
Split-Path -parent $PSCommandPath
}
$script_dir = Get-ScriptDirectory
Push-Location $script_dir
function Extract-TGZ {
Param([string]$gzArchiveName, [string] $destFolder)
$inStream = [System.IO.File]::OpenRead($gzArchiveName)
$gzipStream = New-Object ICSharpCode.SharpZipLib.GZip.GZipInputStream -ArgumentList $inStream
$tarArchive = [ICSharpCode.SharpZipLib.Tar.TarArchive]::CreateInputTarArchive($gzipStream);
$tarArchive.ExtractContents($destFolder);
$tarArchive.Close()
$gzipStream.Close()
$inStream.Close()
}
$message = "Erase monaco-editor directory and download Monaco dependency?"
$question = "Are you sure you want to proceed?"
$choices = New-Object Collections.ObjectModel.Collection[Management.Automation.Host.ChoiceDescription]
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&Yes', "Proceed with clean-up and download."))
$choices.Add((New-Object Management.Automation.Host.ChoiceDescription -ArgumentList '&No', "Abort."))
$decision = $Host.UI.PromptForChoice($message, $question, $choices, 1)
if ($decision -eq 0) {
# Remove Old Dependencies
Remove-Item ".\MonacoEditorComponent\monaco-editor" -Force -Recurse -ErrorAction SilentlyContinue
Remove-Item ".\MonacoEditorComponent\webcomponents-js" -Force -Recurse -ErrorAction SilentlyContinue
# Create Temp Directory and Output
New-Item -Name $temp_dir_name -ItemType Directory | Out-Null
New-Item -Name ".\MonacoEditorComponent\monaco-editor" -ItemType Directory | Out-Null
New-Item -Name ".\MonacoEditorComponent\webcomponents-js" -ItemType Directory | Out-Null
Write-Host "Downloading SharpZipLib"
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
Invoke-WebRequest -Uri $sharp_zip_lib_url -OutFile ".\$temp_dir_name\SharpZipLib.dll"
Write-Host "Downloading Monaco"
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
Invoke-WebRequest -Uri $monaco_tgz_url -OutFile ".\$temp_dir_name\monaco.tgz"
Write-Host "Downloading webcomponents.js"
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
Invoke-WebRequest -Uri $webcomponentsjs_tgz_url -OutFile ".\$temp_dir_name\webcomponentsjs.tgz"
Write-Host "Extracting..."
# Load Sharp Zip Lib so we can unpack Monaco
# Load in memory so we can delete the dll after.
[System.Reflection.Assembly]::Load([IO.File]::ReadAllBytes("$script_dir\$temp_dir_name\SharpZipLib.dll")) | Out-Null
Extract-TGZ "$script_dir\$temp_dir_name\monaco.tgz" "$script_dir\$temp_dir_name\monaco"
Copy-Item -Path ".\$temp_dir_name\monaco\package\*" -Destination ".\MonacoEditorComponent\monaco-editor" -Recurse
Extract-TGZ "$script_dir\$temp_dir_name\webcomponentsjs.tgz" "$script_dir\$temp_dir_name\webcomponentsjs"
Copy-Item -Path ".\$temp_dir_name\webcomponentsjs\package\*" -Destination ".\MonacoEditorComponent\webcomponents-js" -Recurse
# Clean-up Temp Dir
Remove-Item $temp_dir_name -Force -Recurse -ErrorAction SilentlyContinue
}
Pop-Location