Skip to content

Commit 2160ef9

Browse files
committed
Fix non-minified file being added to new bower package
1 parent fa654f2 commit 2160ef9

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

JsLibraryPackaging.psm1

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ function New-BowerLibrary ($name) {
5656

5757
$allPaths = (bower list --paths --json) -join "`n" | ConvertFrom-Json
5858
$paths = @($allPaths.$folderName)
59-
$jsPaths = @($paths | ? { $_ -match '\.js$' })
59+
$jsPaths = @($paths |
60+
? { $_ -match '\.js$' } |
61+
% { MakeMinifiedPath($_) })
6062

6163
if ($jsPaths.Count -eq 0) {
6264
$jsPaths = @(ls $paths *.js -Recurse)
@@ -66,18 +68,13 @@ function New-BowerLibrary ($name) {
6668
}
6769

6870
$jsFile = $jsPaths[0]
69-
$jsFolder = [System.IO.Path]::GetDirectoryName($jsFile)
70-
$jsFileName = [System.IO.Path]::GetFileNameWithoutExtension($jsFile)
71-
$minJsFile = [System.IO.Path]::Combine($jsFolder, $jsFileName + '.min.js')
72-
if (Test-Path $minJsFile) {
73-
$jsFile = $minJsFile
74-
}
75-
7671
$fileName = Split-Path $jsFile -Leaf
7772

7873
$versionedFolder = New-JavaScriptLibrary $name $version $fileName
7974

80-
$filePaths = @($paths | ? { -not (Test-Path $_ -PathType Container) })
75+
$filePaths = @($paths |
76+
? { -not (Test-Path $_ -PathType Container) } |
77+
% { MakeMinifiedPath($_) })
8178
if ($filePaths.Count -eq 0) {
8279
$jsPaths | % { cp $_.FullName $versionedFolder }
8380
} else {
@@ -209,7 +206,18 @@ function ReplaceTokens($file, $name, $friendlyName, $version, $fileName) {
209206
(Get-Content $file) |
210207
% { $_ -replace '\[name\]', $name -replace '\[friendlyName\]', $friendlyName -replace '\[version\]', $version -replace '\[file\]', $fileName } |
211208
Set-Content $file
212-
}
209+
}
210+
211+
function MakeMinifiedPath($path) {
212+
$folder = [System.IO.Path]::GetDirectoryName($path)
213+
$fileName = [System.IO.Path]::GetFileNameWithoutExtension($path)
214+
$minifiedPath = [System.IO.Path]::Combine($folder, $fileName + '.min.js')
215+
if (Test-Path $minifiedPath) {
216+
return $minifiedPath
217+
} else {
218+
return $path
219+
}
220+
}
213221

214222
Export-ModuleMember New-JavaScriptLibrary
215223
Export-ModuleMember New-BowerLibrary

0 commit comments

Comments
 (0)