-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-svelte-files.ps1
36 lines (28 loc) · 1.07 KB
/
update-svelte-files.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
$distFolder = Resolve-Path -Path "./dist"
function Update-SvelteFiles {
param (
[string]$folder
)
$svelteFiles = Get-ChildItem -Path $folder -Filter *.svelte
$readmeFiles = Get-ChildItem -Path $folder -Filter README.md
if ($svelteFiles.Count -eq 1 -and $readmeFiles.Count -eq 1) {
$svelteFile = $svelteFiles[0].FullName
$readmeFile = $readmeFiles[0].FullName
$readmeContent = Get-Content -Path $readmeFile -Raw -Encoding utf8
$componentTagStart = "<!--`r`n@component"
$componentTagEnd = "-->"
$svelteContent = Get-Content -Path $svelteFile -Raw -Encoding utf8
$svelteContent += "`r`n$componentTagStart`r`n$readmeContent`r`n$componentTagEnd"
Set-Content -Path $svelteFile -Value $svelteContent -Encoding utf8NoBOM
}
}
function Traverse-Folders {
param (
[string]$rootFolder
)
$folders = Get-ChildItem -Path $rootFolder -Directory -Recurse
foreach ($folder in $folders) {
Update-SvelteFiles -folder $folder.FullName
}
}
Traverse-Folders -rootFolder $distFolder