-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
103 lines (92 loc) · 3.71 KB
/
setup.ps1
File metadata and controls
103 lines (92 loc) · 3.71 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
# 引数を取得
param (
[string]$inputArgument,
[string]$name
)
# ヘルプメッセージを表示する関数
function Show-Help {
Write-Host "使い方: スクリプト名 [オプション]"
Write-Host ""
Write-Host "オプション:"
Write-Host " --name 名前を設定します"
Write-Host " --help ヘルプを表示します"
Write-Host " --version バージョン情報を表示します"
}
function Update-FileContent {
param (
[string]$filePath,
[string]$oldValue,
[string]$newValue
)
$content = Get-Content -Path $filePath -Raw
$content = $content -replace $oldValue, $newValue
$content = $content.TrimEnd()
Set-Content -Path $filePath -Value $content -NoNewline
Write-Host "$filePath 内の参照を更新しました"
}
function Rename-App {
param (
[string]$name
)
$oldName = ""
# README.mdファイルを読み込む
$content = Get-Content -Path 'README.md'
# 最初の行を取得
$firstLine = $content[0]
# 正規表現で文字列を抽出
if ($firstLine -match '^#\s*(.+)$') {
$oldName = $matches[1]
}
# 削除
if (Test-Path -Path .\$oldName\bin) {
Remove-Item -Path .\$oldName\bin -Recurse -Force
}
if (Test-Path -Path .\$oldName\obj) {
Remove-Item -Path .\$oldName\obj -Recurse -Force
}
if (Test-Path -Path .\$oldName\publish) {
Remove-Item -Path .\$oldName\publish -Recurse -Force
}
# Write-Host "アプリケーションの名前を '$newName' に変更しました"
if (Test-Path -Path $name) {
Write-Host "指定された名前 '$name' は既に存在します。別の名前を指定してください"
return
}
if (Test-Path -Path $oldName) {
Move-Item -Path $oldName -Destination $name
Write-Host "アプリケーションの名前を '$name' に変更しました"
} else {
Write-Host "アプリケーション '$oldName' が見つかりません"
return
}
if (Test-Path -Path "$name\$oldName.csproj") {
Move-Item -Path "$name\$oldName.csproj" -Destination "$name\$name.csproj"
Write-Host "プロジェクトファイルの名前を '$name.csproj' に変更しました"
} else {
Write-Host "プロジェクトファイル '$name\$name.csproj' が見つかりません"
return
}
Update-FileContent -filePath "README.md" -oldValue $oldName -newValue $name
Update-FileContent -filePath "README.en.md" -oldValue $oldName -newValue $name
Update-FileContent -filePath "dev.ps1" -oldValue $oldName -newValue $name
Update-FileContent -filePath "$name\App.xaml" -oldValue $oldName -newValue $name
Update-FileContent -filePath "$name\App.xaml.cs" -oldValue $oldName -newValue $name
Update-FileContent -filePath "$name\MainWindow.xaml" -oldValue $oldName -newValue $name
Update-FileContent -filePath "$name\MainWindow.xaml.cs" -oldValue $oldName -newValue $name
Update-FileContent -filePath "$name\Package.appxmanifest" -oldValue $oldName -newValue $name
Update-FileContent -filePath "$name\$name.csproj" -oldValue $oldName -newValue $name
}
# 引数が '--help' であればヘルプを表示
if ($inputArgument -eq '--help') {
Show-Help
} elseif ($inputArgument -eq '--version') {
Write-Host "バージョン 1.0.0"
} elseif ($inputArgument -eq '--name') {
if ($name -cmatch '^[A-Z][a-zA-Z0-9]*$') {
Rename-App $name
} else {
Write-Host "不正な名前の形式です。名前は大文字で始まり、英数字のみを含む必要があります"
}
}else {
Write-Host "無効な引数です。'--help' を入力して使用法を確認してください。"
}