Skip to content

Commit 2485b6b

Browse files
committed
consolidate scripts and function
1 parent a628cbe commit 2485b6b

5 files changed

Lines changed: 60 additions & 48 deletions

File tree

.azure-pipelines/common-templates/install-tools.yml

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,33 +78,9 @@ steps:
7878
- task: PowerShell@2
7979
displayName: Pre-populate autorest extension cache
8080
inputs:
81-
targetType: inline
81+
targetType: filePath
8282
pwsh: true
83-
script: |
84-
# Autorest resolves extensions from ~/.autorest/<pkg>/<version>/node_modules/.
85-
# Pre-install every extension referenced by autorest-configuration.md so autorest
86-
# makes zero npm network calls during module generation.
87-
# Registry and auth are read from ~/.npmrc (copied from the authenticated .npmrc above).
88-
$extensions = @(
89-
"@autorest/core@3.10.4",
90-
"@autorest/modelerfour@4.24.3"
91-
)
92-
foreach ($ext in $extensions) {
93-
$parts = $ext -split '@(?=[^@]+$)' # split on last @
94-
$pkg = $parts[0]
95-
$ver = $parts[1]
96-
$cacheDir = Join-Path $env:USERPROFILE ".autorest\$($pkg.Replace('/','\'))\$ver"
97-
$nodeModules = Join-Path $cacheDir "node_modules\$($pkg.Replace('/','\'))"
98-
if (Test-Path $nodeModules) {
99-
Write-Host "Cache already present: $ext"
100-
continue
101-
}
102-
New-Item -ItemType Directory -Force -Path $cacheDir | Out-Null
103-
Write-Host "Pre-installing $ext into $cacheDir"
104-
npm install $ext --prefix $cacheDir
105-
if ($LASTEXITCODE -ne 0) { throw "Failed to pre-install $ext (exit $LASTEXITCODE)" }
106-
Write-Host "Done: $ext"
107-
}
83+
filePath: $(Build.SourcesDirectory)/tools/utilities/PrePopulateAutorestCache.ps1
10884

10985
- task: Npm@1
11086
displayName: Install Rush

tools/ReadModuleReadMe.ps1

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,7 @@ param(
66
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string] $FieldToRead
77
)
88
$ErrorActionPreference = "Stop"
9-
10-
function ConvertFrom-SimpleYaml {
11-
param([string]$Yaml)
12-
$result = @{}
13-
$Yaml -split "`n" | ForEach-Object {
14-
if ($_.Trim() -match '^([^:]+):\s*(.*)$') {
15-
$result[$Matches[1].Trim()] = $Matches[2].Trim()
16-
}
17-
}
18-
return $result
19-
}
9+
. "$PSScriptRoot\utilities\utils.ps1"
2010

2111
$FieldValue = $null
2212
# Read readme.md.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
<#
5+
.SYNOPSIS
6+
Pre-populates the autorest extension cache so that autorest makes zero npm
7+
network calls during module generation.
8+
9+
.DESCRIPTION
10+
Autorest resolves extensions from ~/.autorest/<pkg>/<version>/node_modules/.
11+
This script pre-installs every extension referenced by
12+
autorest-configuration.md into that cache layout.
13+
Registry and auth are read from ~/.npmrc (copied from the authenticated
14+
.npmrc earlier in the pipeline).
15+
#>
16+
17+
[CmdletBinding()]
18+
param()
19+
20+
$extensions = @(
21+
"@autorest/core@3.10.4",
22+
"@autorest/modelerfour@4.24.3"
23+
)
24+
25+
foreach ($ext in $extensions) {
26+
$parts = $ext -split '@(?=[^@]+$)' # split on last @
27+
$pkg = $parts[0]
28+
$ver = $parts[1]
29+
$cacheDir = Join-Path $env:USERPROFILE ".autorest\$($pkg.Replace('/','\'))\$ver"
30+
$nodeModules = Join-Path $cacheDir "node_modules\$($pkg.Replace('/','\'))"
31+
32+
if (Test-Path $nodeModules) {
33+
Write-Host "Cache already present: $ext"
34+
continue
35+
}
36+
37+
New-Item -ItemType Directory -Force -Path $cacheDir | Out-Null
38+
Write-Host "Pre-installing $ext into $cacheDir"
39+
npm install $ext --prefix $cacheDir
40+
if ($LASTEXITCODE -ne 0) { throw "Failed to pre-install $ext (exit $LASTEXITCODE)" }
41+
Write-Host "Done: $ext"
42+
}

tools/Utilities/utils.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,18 @@ Function Get-LocalCertificate {
2424
$global:DefaultCertificate = $pfxCertificate
2525
}
2626
return $global:DefaultCertificate
27+
}
28+
29+
<#
30+
Converts a simple single-level YAML string into a hashtable.
31+
#>
32+
Function ConvertFrom-SimpleYaml {
33+
param([string]$Yaml)
34+
$result = @{}
35+
$Yaml -split "`n" | ForEach-Object {
36+
if ($_.Trim() -match '^([^:]+):\s*(.*)$') {
37+
$result[$Matches[1].Trim()] = $Matches[2].Trim()
38+
}
39+
}
40+
return $result
2741
}

tools/WriteToModuleReadMe.ps1

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@ param(
77
[Parameter(Mandatory = $true)][ValidateNotNullOrEmpty()][string] $NewFieldValue
88
)
99
$ErrorActionPreference = "Stop"
10-
11-
function ConvertFrom-SimpleYaml {
12-
param([string]$Yaml)
13-
$result = @{}
14-
$Yaml -split "`n" | ForEach-Object {
15-
if ($_.Trim() -match '^([^:]+):\s*(.*)$') {
16-
$result[$Matches[1].Trim()] = $Matches[2].Trim()
17-
}
18-
}
19-
return $result
20-
}
10+
. "$PSScriptRoot\utilities\utils.ps1"
2111

2212
# Read readme.md.
2313
$ReadMeContent = Get-Content $ReadMePath -Delimiter "### Versioning"

0 commit comments

Comments
 (0)