Skip to content

Commit

Permalink
chore(scripts): update
Browse files Browse the repository at this point in the history
  • Loading branch information
abgox committed Aug 20, 2024
1 parent c9d927a commit f45df7f
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 115 deletions.
47 changes: 47 additions & 0 deletions scripts/create-completion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
param([string]$completion_name)

if (!$PSCompletions) {
Write-Host "You should install PSCompletions module and import it." -ForegroundColor Red
return
}
$path_guide = "$($PSScriptRoot)/template/guide/$($PSCompletions.language).json"

if (Test-Path $path_guide) {
$guide = Get-Content -Path $path_guide -Encoding utf8 | ConvertFrom-Json
}
else {
$guide = Get-Content -Path "$($PSScriptRoot)/template/guide/en-US.json" -Encoding utf8 | ConvertFrom-Json
}

if (!$completion_name.Trim()) {
$PSCompletions.write_with_color("<@Red>You should enter an available completion name.`ne.g. <@Magenta>.\scripts\create-completion.ps1 test")
return
}

$config = @{
language = @('en-US', 'zh-CN')
}

$root_dir = Split-Path $PSScriptRoot -Parent
$completion_dir = $PSCompletions.join_path($root_dir, "completions", $completion_name)
if (Test-Path $completion_dir) {
$PSCompletions.write_with_color($guide.exist)
return
}

# create new completion
$PSCompletions.ensure_dir($completion_dir)
$PSCompletions.ensure_dir("$completion_dir/language")

[System.Guid]::NewGuid().Guid | Out-File "$completion_dir\guid.txt" -Encoding utf8 -Force

Copy-Item "$($PSScriptRoot)/template/config.json" "$completion_dir/config.json" -Force

Copy-Item "$($PSScriptRoot)/template/language/en-US.json" "$completion_dir/language/en-US.json" -Force
Copy-Item "$($PSScriptRoot)/template/language/zh-CN.json" "$completion_dir/language/zh-CN.json" -Force


$test_dir = Join-Path $PSCompletions.path.completions $completion_name
Remove-Item $test_dir -Recurse -Force -ErrorAction SilentlyContinue
New-Item -ItemType SymbolicLink -Path $test_dir -Target $completion_dir > $null
$PSCompletions.write_with_color($PSCompletions.replace_content($guide.success))
107 changes: 0 additions & 107 deletions scripts/create.ps1

This file was deleted.

20 changes: 20 additions & 0 deletions scripts/link-completion.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
param([string]$completion_name)

if (!$PSCompletions) {
Write-Host "You should install PSCompletions module and import it." -ForegroundColor Red
return
}
if (!$completion_name.Trim()) {
$PSCompletions.write_with_color("<@Red>You should enter an available completion name.`ne.g. <@Magenta>.\scripts\link-completion.ps1 git")
return
}
$root_dir = Split-Path $PSScriptRoot -Parent
$completion_dir = $PSCompletions.join_path($root_dir, "completions", $completion_name)
if (!(Test-Path $completion_dir)) {
$PSCompletions.write_with_color("<@Red><@Magenta>$completion_name<@Red> isn't exist.")
return
}

$completion_dir = "$($PSCompletions.path.completions)\$completion_name"
Remove-Item $completion_dir -Force -Recurse -ErrorAction SilentlyContinue
New-Item -ItemType SymbolicLink -Path $completion_dir -Target "$PSScriptRoot\..\completions\$completion_name" -Force
22 changes: 14 additions & 8 deletions scripts/update-guid.ps1
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
param([string]$path)
param([array]$completion_list)

if (Test-Path $path) {
if ((Get-Item $path).Extension -eq ".txt") {
(New-Guid).Guid | Out-File $path -Force

$root_dir = Split-Path $PSScriptRoot -Parent
$path_list = $completion_list | ForEach-Object {
$completion_dir = $root_dir + "/completions/" + $_
if (Test-Path $completion_dir) {
$completion_dir
}
else {
Get-ChildItem $path -Recurse -Filter "guid.txt" | ForEach-Object {
(New-Guid).Guid | Out-File $_.FullName -Force
}
}
if ($path_list) {
foreach ($path in $path_list) {
Write-Host "Updating Guid.txt file of " -NoNewline
Write-Host $(Split-Path $path -Leaf) -ForegroundColor Magenta -NoNewline
Write-Host "."
(New-Guid).Guid | Out-File "$path/guid.txt" -Force
}
return
}
Expand Down

0 comments on commit f45df7f

Please sign in to comment.