npmprune icon indicating copy to clipboard operation
npmprune copied to clipboard

Windows ?

Open huqedato opened this issue 1 year ago • 3 comments

Hi,

Great to have a Windows version... Powershell.

Thanks.

huqedato avatar Nov 30 '23 12:11 huqedato

Contributions are welcome.

iamandrewluca avatar Dec 05 '23 22:12 iamandrewluca

Exactly!

And you can use this code as a foundation (made by GTP-4, not tested):

$TARGET_DIR = "node_modules"

if (-Not (Test-Path $TARGET_DIR)) {
    Write-Host "$TARGET_DIR does not exist"
    exit 1
}

$PATTERNS = @(
    "__tests__", "_config.yml", ".*ignore", ".babel*", ".circle*", ".documentup*", ".ds_store", ".editorconfig",
    ".env*", ".git*", ".idea", ".lint*", ".npm*", ".nyc*", ".prettier*", ".tern-project", ".yarn-integrity",
    ".yarn-metadata.json", ".yarnclean", ".yo-*", "*.coffee", "*.flow*", "*.jst", "*.markdown", "*.md", "*.mkd", "*.swp", 
    "*.tgz", "*appveyor*", "*coveralls*", "*eslint*", "*htmllint*", "*jshint*", "*readme*", "*stylelint*", "*travis*", 
    "*tslint*", "*vscode*", "*wallaby*", "authors", "changelog", "changes", "circle.yml", "component.json", "contributors", 
    "coverage", "doc", "docs", "example", "examples", "grunt*", "gulp*", "jenkins*", "jest.config.*", "jsconfig.json", 
    "karma.conf*", "licence", "licence.txt", "license", "license.txt", "makefile", "npm-debug.log", "powered-test", 
    "prettier.*", "test", "tests", "tsconfig.json"
)

$PROD_PATTERNS = @(
    "*.map", "*.mts", "*.ts"
)

if ($env:NODE_ENV -eq "production") {
    $PATTERNS += $PROD_PATTERNS
}

if ($env:NODE_ENV -ne "production") {
    Write-Host "$TARGET_DIR size before: $(Get-ChildItem $TARGET_DIR -Recurse | Measure-Object -Property Length -Sum | % { '{0:N2} MB' -f ($_.Sum / 1MB) })"
}

foreach ($pattern in $PATTERNS) {
    Get-ChildItem $TARGET_DIR -Recurse -Include $pattern | Remove-Item -Recurse -Force
}

if ($env:NODE_ENV -ne "production") {
    Write-Host "$TARGET_DIR size after: $(Get-ChildItem $TARGET_DIR -Recurse | Measure-Object -Property Length -Sum | % { '{0:N2} MB' -f ($_.Sum / 1MB) })"
}

xthezealot avatar Dec 05 '23 22:12 xthezealot

Forked: https://github.com/huqedato/npmprunewin

huqedato avatar Dec 07 '23 10:12 huqedato