-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathClean.ps1
More file actions
114 lines (96 loc) · 3.31 KB
/
Clean.ps1
File metadata and controls
114 lines (96 loc) · 3.31 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
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
<#
.SYNOPSIS
将 Android 项目的核心内容导出到新目录,排除构建产物、测试代码和本地配置。
#>
param(
[Parameter(Mandatory = $true, Position = 0, HelpMessage = "Android 项目根目录")]
[string]$SourcePath,
[Parameter(Mandatory = $true, Position = 1, HelpMessage = "导出的目标目录")]
[string]$TargetPath
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
# 定义需要排除的目录名称(匹配任意层级)
# 新增: release, test, androidTest
$excludeDirs = @(
'.git',
'.gradle',
'.idea',
'build',
'.cxx',
'.externalNativeBuild',
'captures',
'kotlin',
'release', # 排除 release 目录
'test', # 排除单元测试目录 (src/test)
'androidTest' # 排除仪器测试目录 (src/androidTest)
)
# 定义需要排除的文件名称(精确匹配或通配符)
$excludeFiles = @(
'local.properties',
'.DS_Store',
'Thumbs.db',
'*.iml',
'*.hprof'
)
function Copy-FilteredItem {
param(
[string]$CurrentSource,
[string]$CurrentTarget
)
# 确保目标目录存在
if (-not (Test-Path -Path $CurrentTarget)) {
[void](New-Item -ItemType Directory -Path $CurrentTarget)
}
# 获取当前目录下的所有项
$items = Get-ChildItem -Path $CurrentSource -Force
foreach ($item in $items) {
$targetItemPath = Join-Path -Path $CurrentTarget -ChildPath $item.Name
if ($item.PSIsContainer) {
# 如果是目录,检查是否在排除列表中
if ($excludeDirs -contains $item.Name) {
Write-Host "排除目录: $($item.FullName)" -ForegroundColor Gray
continue
}
# 递归处理子目录
Copy-FilteredItem -CurrentSource $item.FullName -CurrentTarget $targetItemPath
}
else {
# 如果是文件,检查是否在排除列表中
$shouldExclude = $false
foreach ($pattern in $excludeFiles) {
if ($item.Name -like $pattern) {
$shouldExclude = $true
break
}
}
if ($shouldExclude) {
Write-Host "排除文件: $($item.FullName)" -ForegroundColor Gray
continue
}
# 复制文件
Copy-Item -Path $item.FullName -Destination $targetItemPath -Force
}
}
}
# --- 主程序开始 ---
$absSource = Convert-Path -Path $SourcePath
if (-not (Test-Path -Path $absSource -PathType Container)) {
Throw "源目录不存在: $absSource"
}
Write-Host "=== 开始导出 Android 核心内容 (无测试/Release) ===" -ForegroundColor Cyan
Write-Host "源目录: $absSource"
Write-Host "目标目录: $TargetPath"
Write-Host "已排除目录: $($excludeDirs -join ', ')" -ForegroundColor Gray
Write-Host "-----------------------------------"
try {
$sw = [System.Diagnostics.Stopwatch]::StartNew()
Copy-FilteredItem -CurrentSource $absSource -CurrentTarget $TargetPath
$sw.Stop()
Write-Host "-----------------------------------"
Write-Host "导出完成!" -ForegroundColor Green
Write-Host "耗时: $($sw.Elapsed.ToString('hh\:mm\:ss\.fff'))" -ForegroundColor Green
}
catch {
Write-Error "导出过程中发生错误: $_"
}