forked from xthezealot/npmprune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
npmprunewin.ps1
117 lines (108 loc) · 2.12 KB
/
npmprunewin.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
$targetDir = "node_modules"
# Check if node_modules exists
if (-Not (Test-Path -Path $targetDir -PathType Container)) {
Write-Host "$targetDir does not exist"
exit 1
}
# Patterns
$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*",
"jsconfig.json",
"karma.conf*",
"licence",
"LICENSE",
"licence.txt",
"makefile",
"npm-debug.log",
"powered-test",
"prettier.*",
"test",
"tests",
"tsconfig.json",
"tsconfig.json"
)
# Production patterns
$prodPatterns = @(
"*.map",
"*.ts"
)
# Include production patterns if '-p' is passed
if ($args -Contains "-p") {
$patterns = $patterns + $prodPatterns
$host.UI.RawUI.ForegroundColor = "Blue"
Write-Host "Prod mode"
}
else {
$host.UI.RawUI.ForegroundColor = "Green"
Write-Host "Dev mode"
}
function Get-DirectorySize {
Param ([string]$path)
$bytes = (Get-ChildItem -Path $path -Recurse -Force | Measure-Object -Property Length -Sum).Sum
[math]::Round($bytes / 1024, 2)
}
# Display size before cleanup
$sizeBefore = Get-DirectorySize -path $targetDir
Write-Host "$targetDir size before: $sizeBefore KB"
# Cleanup
foreach ($pattern in $patterns) {
Get-ChildItem -Path $targetDir -Recurse -Force -Include $pattern |
Remove-Item -Force -Recurse
}
# Display size after cleanup
$sizeAfter = Get-DirectorySize -path $targetDir
Write-Host "$targetDir size after: $sizeAfter KB"
$host.UI.RawUI.ForegroundColor = "White"