Optimizing scripts

This commit is contained in:
Elitsa Marinovska
2019-04-28 21:14:32 +02:00
committed by GitHub
parent 56d7755487
commit 7e064cee83

View File

@@ -1,119 +1,44 @@
$PSScriptFilePath = (Get-Item $MyInvocation.MyCommand.Path);
$RepoRoot = (get-item $PSScriptFilePath).Directory.Parent.FullName;
$SolutionRoot = Join-Path -Path $RepoRoot "src";
$ToolsRoot = Join-Path -Path $RepoRoot "\build\temp";
$DocFx = Join-Path -Path $ToolsRoot "docfx\docfx.exe"
$DocFxFolder = (Join-Path -Path $ToolsRoot "docfx")
$DocFxJson = Join-Path -Path $SolutionRoot "ApiDocs\docfx.json"
$7Zip = Join-Path -Path $ToolsRoot "7za.exe"
$DocFxSiteOutput = Join-Path -Path $SolutionRoot "ApiDocs\_site\*.*"
#$NgDocsSiteOutput = Join-Path -Path $RepoRoot "src\Umbraco.Web.UI.Client\docs\api\*.*"
$ProgFiles86 = [Environment]::GetEnvironmentVariable("ProgramFiles(x86)");
$MSBuild = "$ProgFiles86\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe"
$uenv=build/build.ps1 -get
$src = "$($uenv.SolutionRoot)\src"
$tmp = $uenv.BuildTemp
$out = $uenv.BuildOutput
$DocFxJson = "$src\ApiDocs\docfx.json"
$DocFxSiteOutput = "$tmp\_site\*.*"
<#
################ Do the UI docs
$uenv.CompileBelle()
"Changing to Umbraco.Web.UI.Client folder"
cd ..
cd src\Umbraco.Web.UI.Client
Write-Host $(Get-Location)
"Moving to Umbraco.Web.UI.Client folder"
cd .\src\Umbraco.Web.UI.Client
"Creating build folder so MSBuild doesn't run the whole grunt build"
if (-Not (Test-Path "build")) {
md "build"
}
"Installing node"
# Check if Install-Product exists, should only exist on the build server
if (Get-Command Install-Product -errorAction SilentlyContinue)
{
Install-Product node ''
}
"Installing node modules"
& npm install
"Installing grunt"
& npm install -g grunt-cli
"Moving back to build folder"
cd ..
cd ..
cd build
Write-Host $(Get-Location)
& grunt --gruntfile ../src/umbraco.web.ui.client/gruntfile.js docs
"Generating the docs and waiting before executing the next commands"
& gulp docs | Out-Null
# change baseUrl
$BaseUrl = "https://our.umbraco.org/apidocs/ui/"
$IndexPath = "../src/umbraco.web.ui.client/docs/api/index.html"
$IndexPath = "./docs/api/index.html"
(Get-Content $IndexPath).replace('location.href.replace(rUrl, indexFile)', "`'" + $BaseUrl + "`'") | Set-Content $IndexPath
# zip it
& $uenv.BuildEnv.Zip a -tzip -r "$out\ui-docs.zip" "$src\Umbraco.Web.UI.Client\docs\api\*.*"
& $7Zip a -tzip ui-docs.zip $NgDocsSiteOutput -r
#>
################ Do the c# docs
# Build the solution in debug mode
$SolutionPath = Join-Path -Path $SolutionRoot -ChildPath "umbraco.sln"
# Go get nuget.exe if we don't have it
$NuGet = "$ToolsRoot\nuget.exe"
$FileExists = Test-Path $NuGet
If ($FileExists -eq $False) {
Write-Host "Retrieving nuget.exe..."
$SourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
Invoke-WebRequest $SourceNugetExe -OutFile $NuGet
}
$SolutionPath = Join-Path -Path $src -ChildPath "umbraco.sln"
#$uenv.CompileUmbraco()
#restore nuget packages
Write-Host "Restoring nuget packages..."
& $NuGet restore $SolutionPath
$uenv.RestoreNuGet()
& $MSBuild "$SolutionPath" /p:Configuration=Debug /maxcpucount /t:Clean
if (-not $?)
{
throw "The MSBuild process returned an error code."
}
& $MSBuild "$SolutionPath" /p:Configuration=Debug /maxcpucount
if (-not $?)
{
throw "The MSBuild process returned an error code."
}
# run DocFx
$DocFx = $uenv.BuildEnv.DocFx
# Go get docfx if we don't have it
$FileExists = Test-Path $DocFx
If ($FileExists -eq $False) {
If(!(Test-Path $DocFxFolder))
{
New-Item $DocFxFolder -type directory
}
Write-Host "Getting docfx..."
$DocFxZip = Join-Path -Path $ToolsRoot "docfx\docfx.zip"
$DocFxSource = "https://github.com/dotnet/docfx/releases/download/v2.41/docfx.zip"
# Create SSL/TLS secure channel to access GitHub API endpoint
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest $DocFxSource -OutFile $DocFxZip
#unzip it
& $7Zip e $DocFxZip "-o$DocFxFolder"
}
#clear site
If(Test-Path(Join-Path -Path $RepoRoot "ApiDocs\_site"))
{
Remove-Item $DocFxSiteOutput -recurse
}
# run it!
Write-Host "$DocFxJson"
& $DocFx metadata $DocFxJson
& $DocFx $DocFxJson --serve
& $DocFx build $DocFxJson
# zip it
& $7Zip a -tzip csharp-docs.zip $DocFxSiteOutput -r
& $uenv.BuildEnv.Zip a -tzip -r "$out\csharp-docs.zip" $DocFxSiteOutput