-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRename-Project.ps1
56 lines (48 loc) · 3.43 KB
/
Rename-Project.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
function Rename-Project {
param (
[string]
$SourceRootPath,
[string]
$ComponentName
)
$ComponentName = $ComponentName.Replace('-', '_').ToLower()
$ComponentNameUpper = $ComponentName.ToUpper();
$TextReplacements = New-Object System.Collections.ArrayList
$TextReplacements.AddRange((
[Tuple]::Create("$($SourceRootPath)/components/component_name/include/component_name/component_name.h", 'COMPONENT_NAME', $ComponentNameUpper),
[Tuple]::Create("$($SourceRootPath)/components/component_name/include/component_name/component_name.h", 'component_name', $ComponentName),
[Tuple]::Create("$($SourceRootPath)/components/component_name/private_include/assertion.h", 'COMPONENT_NAME', $ComponentNameUpper),
[Tuple]::Create("$($SourceRootPath)/components/component_name/private_include/config.h", 'COMPONENT_NAME', $ComponentNameUpper),
[Tuple]::Create("$($SourceRootPath)/components/component_name/private_include/log.h", 'COMPONENT_NAME', $ComponentNameUpper),
[Tuple]::Create("$($SourceRootPath)/components/component_name/src/component_name.c", 'COMPONENT_NAME', $ComponentNameUpper),
[Tuple]::Create("$($SourceRootPath)/components/component_name/src/component_name.c", 'component_name', $ComponentName),
[Tuple]::Create("$($SourceRootPath)/components/component_name/test/CMakeLists.txt", 'component_name', $ComponentName),
[Tuple]::Create("$($SourceRootPath)/components/component_name/Kconfig", 'Component_Name', $ComponentName),
[Tuple]::Create("$($SourceRootPath)/components/component_name/Kconfig", 'COMPONENT_NAME', $ComponentNameUpper),
[Tuple]::Create("$($SourceRootPath)/main/CMakeLists.txt", 'component_name', $ComponentName),
[Tuple]::Create("$($SourceRootPath)/main/main.c", 'component_name', $ComponentName),
[Tuple]::Create("$($SourceRootPath)/test/CMakeLists.txt", 'component_name', $ComponentName),
[Tuple]::Create("$($SourceRootPath)/CMakeLists.txt", 'component_name', $ComponentName),
[Tuple]::Create("$($SourceRootPath)/sonar-project.properties", 'component_name', $ComponentName)
))
$FileRenamings = New-Object System.Collections.ArrayList
$FileRenamings.AddRange((
[Tuple]::Create("$($SourceRootPath)/components/component_name/include/component_name/component_name.h", "$($ComponentName).h"),
[Tuple]::Create("$($SourceRootPath)/components/component_name/src/component_name.c", "$($ComponentName).c")
))
$DirectoryRenamings = New-Object System.Collections.ArrayList
$DirectoryRenamings.AddRange((
[Tuple]::Create("$($SourceRootPath)/components/component_name/include/component_name", $ComponentName),
[Tuple]::Create("$($SourceRootPath)/components/component_name", $ComponentName)
))
foreach ($TextReplacement in $TextReplacements) {
((Get-Content -Path $TextReplacement.Item1 -Raw) -creplace $TextReplacement.Item2, $TextReplacement.Item3) | Set-Content -Path $TextReplacement.Item1
}
foreach ($FileRenaming in $FileRenamings) {
Rename-Item $FileRenaming.Item1 $FileRenaming.Item2
}
foreach ($DirectoryRenaming in $DirectoryRenamings) {
Rename-Item $DirectoryRenaming.Item1 $DirectoryRenaming.Item2
}
}
Rename-Project -SourceRootPath $args[0] -ComponentName $args[1]