Last active
June 30, 2022 18:49
-
-
Save SMoni/7b3a3564a5cb69b1d1c2726877b77e96 to your computer and use it in GitHub Desktop.
Copy all npm-packages for production into the dist-folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Clear-Host | |
Set-Location $PSScriptRoot | |
$main = { | |
npm list --prod | | |
Select-Object -Skip 1 | # First line is the project itself | |
Get-Dependency | | |
Sort-Object | | |
Get-Unique | | |
Copy-Dependency | |
} | |
function Get-Dependency() { | |
process { | |
if([string]::IsNullOrWhiteSpace($_)) { | |
return | |
} | |
$result = [regex]::Matches($_, '--\s(?<file>.+)@')[0].groups['file'].Value | |
if([string]::IsNullOrWhiteSpace($result)) { | |
return | |
} | |
$result. ` | |
Replace(' deduped', ''). ` | |
Replace('/', '\'). ` | |
Trim() | |
} | |
} | |
function Copy-Dependency() { | |
begin { | |
$sourceFolder = '.\node_modules' | |
$destinationFolder = '.\dist\node_modules' | |
if(Test-Path $destinationFolder) { | |
Remove-Item $destinationFolder -Force -Recurse | |
} | |
} | |
process { | |
Write-Host $_ | |
$source = "$sourceFolder\$_" | |
$destination = "$destinationFolder\$_" | |
Copy-Item -Path $source -Destination $destination -Recurse | |
} | |
} | |
&$main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment