This repository was archived by the owner on Mar 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.build-helpers.ps1
More file actions
103 lines (78 loc) · 2.96 KB
/
.build-helpers.ps1
File metadata and controls
103 lines (78 loc) · 2.96 KB
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
function Clean-Folder {
param(
$path
)
Remove-Item "$path/*" `
-Force `
-Recurse `
-ErrorAction SilentlyContinue
}
function New-Folder {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Scope="Function")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSUseShouldProcessForStateChangingFunctions", "", Scope="Function")]
param(
$folder
)
if(!(Test-Path $folder))
{
New-Item -ItemType Directory -Force -Path $folder | Out-Null
}
}
function Require-Variable($value, $description) {
if($value -eq $null) {
throw "Variable is null: $description"
}
}
function Edit-ValueInFile($path, $old, $new) {
(Get-Content $path).replace( $old, $new ) `
| Set-Content $path
}
function Copy-NetlifyConfig {
Copy-Item "$dirPath/netlify/*" "$buildFolder/" -Recurse -Force
}
function Set-NetlifyPreVariables() {
if($null -ne $env:APPVEYOR_REPO_BRANCH) {
Write-Build Green "Building under appveyor"
$netlifySiteIdEnvName = ("SPS_NETLIFY_PRE_SITE_ID_" + $env:APPVEYOR_REPO_BRANCH)
$netlifySiteId = (get-item env:$netlifySiteIdEnvName).Value;
$netlifyAuthToken = $env:SPS_NETLIFY_API_KEY
Require-Variable $netlifySiteId "Netlify site id"
Require-Variable $netlifyAuthToken "Netlify auth token"
$ENV:NETLIFY_SITE_ID = $netlifySiteId
$ENV:NETLIFY_AUTH_TOKEN = $netlifyAuthToken
} else {
Write-Build Green "Building locally"
Require-Variable $NETLIFY_PRE_SITE_ID "Netlify site id"
Require-Variable $NETLIFY_AUTH_TOKEN "Netlify auth token"
$ENV:NETLIFY_SITE_ID = $NETLIFY_PRE_SITE_ID
$ENV:NETLIFY_AUTH_TOKEN = $NETLIFY_AUTH_TOKEN
}
}
function Set-NetlifyVariables() {
if($null -ne $env:APPVEYOR_REPO_BRANCH) {
Write-Build Green "Building under appveyor"
$netlifySiteIdEnvName = ("SPS_NETLIFY_SITE_ID_" + $env:APPVEYOR_REPO_BRANCH)
$netlifySiteId = (get-item env:$netlifySiteIdEnvName).Value;
$netlifyAuthToken = $env:SPS_NETLIFY_API_KEY
Require-Variable $netlifySiteId "Netlify site id"
Require-Variable $netlifyAuthToken "Netlify auth token"
$ENV:NETLIFY_SITE_ID = $netlifySiteId
$ENV:NETLIFY_AUTH_TOKEN = $netlifyAuthToken
} else {
Write-Build Green "Building locally"
Require-Variable $NETLIFY_SITE_ID "Netlify site id"
Require-Variable $NETLIFY_AUTH_TOKEN "Netlify auth token"
$ENV:NETLIFY_SITE_ID = $NETLIFY_SITE_ID
$ENV:NETLIFY_AUTH_TOKEN = $NETLIFY_AUTH_TOKEN
}
}
function Copy-Assets() {
$imageFolders = Get-ChildItem "$dirPath/docs" -Recurse -Filter *assets*
foreach($imageFolder in $imageFolders) {
$path = $imageFolder.FullName
if($path.EndsWith("docs\assets") -eq $True) {
continue;
}
Copy-Item $path "$dirPath/docs" -Recurse -Force
}
}