-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd-component-help.ps1
More file actions
51 lines (40 loc) · 2.06 KB
/
Copy pathadd-component-help.ps1
File metadata and controls
51 lines (40 loc) · 2.06 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
$distFolder = Resolve-Path -Path "./dist"
function Update-SvelteFiles {
param (
[string]$folder
)
$svelteFiles = Get-ChildItem -Path $folder -Filter *.svelte.d.ts
$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
# Extract component name from filename (e.g., "Link.svelte.d.ts" -> "Link")
$componentName = [System.IO.Path]::GetFileNameWithoutExtension($svelteFiles[0].Name) -replace '\.svelte.*$', ''
$readmeContent = Get-Content -Path $readmeFile -Raw -Encoding utf8
# Normalize line endings to Unix format
$readmeContent = $readmeContent -replace "`r`n", "`n" -replace "`r", "`n"
$svelteContent = Get-Content -Path $svelteFile -Raw -Encoding utf8
# Find JSDoc comment before the specific component's declare statement
$declarePattern = "declare const ${componentName}:"
if ($svelteContent -match "(/\*\*[\s\S]*?\*/)\s*$([regex]::Escape($declarePattern))") {
# Replace existing JSDoc comment for this specific component
$newJSDoc = "/**`n * $($readmeContent -replace "`n", "`n * ")`n */"
$svelteContent = $svelteContent -replace "/\*\*[\s\S]*?\*/\s*(?=$([regex]::Escape($declarePattern)))", "$newJSDoc`n"
} else {
# Add new JSDoc comment before the specific component's declare statement
$newJSDoc = "/**`n * $($readmeContent -replace "`n", "`n * ")`n */`n"
$svelteContent = $svelteContent -replace "($([regex]::Escape($declarePattern)))", "$newJSDoc`$1"
}
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