1 <# 2 .SYNOPSIS 3 Run this PowerShell script to enable dev mode and/or a custom script for the TypeScript language service, e.g. 4 5 PS C:\> .\scripts\VSDevMode.ps1 -enableDevMode -tsScript C:\src\TypeScript\built\local\ 6 7 Note: If you get security errors, try running powershell as an Administrator and with the "-executionPolicy remoteSigned" switch 8 9 .PARAMETER vsVersion 10 Set to "12" for Dev12 (VS2013) or "14" (the default) for Dev14 (VS2015) 11 12 .PARAMETER enableDevMode 13 Pass this switch to enable attaching a debugger to the language service 14 15 .PARAMETER tsScript 16 The path to a directory containing a custom language service script to use (typescriptServices.js), e.g. "C:\src\TypeScript\built\local\" 17 #> 18 Param( 19 [int]$vsVersion = 14, 20 [switch]$enableDevMode, 21 [string]$tsScript 22 ) 23 24 $vsRegKey = "HKCU:\Software\Microsoft\VisualStudio\${vsVersion}.0" 25 $tsRegKey = "${vsRegKey}\TypeScriptLanguageService" 26 27 if($enableDevMode -ne $true -and $tsScript -eq ""){ 28 Throw "You must either enable language service debugging (-enableDevMode), set a custom script (-tsScript), or both" 29 } 30 31 if(!(Test-Path $vsRegKey)){ 32 Throw "Visual Studio ${vsVersion} is not installed" 33 } 34 if(!(Test-Path $tsRegKey)){ 35 # Create the TypeScript subkey if it doesn't exist 36 New-Item -path $tsRegKey 37 } 38 39 if($tsScript -ne ""){ 40 $tsScriptServices = "${tsScript}\typescriptServices.js" 41 $tsScriptlib = "${tsScript}\lib.d.ts" 42 $tsES6Scriptlib = "${tsScript}\lib.es6.d.ts" 43 44 if(!(Test-Path $tsScriptServices)){ 45 Throw "Could not locate the TypeScript language service script at ${tsScriptServices}" 46 } 47 else { 48 $path = resolve-path ${tsScriptServices} 49 Set-ItemProperty -path $tsRegKey -name CustomTypeScriptServicesFileLocation -value "${path}" 50 Write-Host "Enabled custom TypeScript language service at ${path} for Dev${vsVersion}" 51 } 52 53 if(!(Test-Path $tsScriptlib)){ 54 Throw "Could not locate the TypeScript default library at ${tsScriptlib}" 55 } 56 else { 57 $path = resolve-path ${tsScriptlib} 58 Set-ItemProperty -path $tsRegKey -name CustomDefaultLibraryLocation -value "${path}" 59 Write-Host "Enabled custom TypeScript default library at ${path} for Dev${vsVersion}" 60 } 61 62 if(!(Test-Path $tsES6Scriptlib)){ 63 Throw "Could not locate the TypeScript default ES6 library at ${tsES6Scriptlib}" 64 } 65 else { 66 $path = resolve-path ${tsES6Scriptlib} 67 Set-ItemProperty -path $tsRegKey -name CustomDefaultES6LibraryLocation -value "${path}" 68 Write-Host "Enabled custom TypeScript default ES6 library at ${path} for Dev${vsVersion}" 69 } 70 } 71 72 if($enableDevMode){ 73 Set-ItemProperty -path $tsRegKey -name EnableDevMode -value 1 74 Write-Host "Enabled developer mode for Dev${vsVersion}" 75 } 76