Skip to content

Commit

Permalink
feat(local-build): initial config
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Sep 16, 2023
1 parent 5fe32c6 commit 3507009
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/playbook/local-build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,41 @@ $configPath = "$env:appdata\local-build\config.json"
# config system #
# ------------- #

$shortcut = "$env:LOCALAPPDATA\Microsoft\WindowsApps\ame-lb-conf.lnk"

function New-ConfigPathShortcut {
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($shortcut)
$Shortcut.TargetPath = $configPath
$Shortcut.Save()
}

function CreateConfig($conf) {
New-Item -Type Directory -Force -Path $(Split-Path $configPath) -ErrorAction SilentlyContinue | Out-Null
$conf | ConvertTo-Json -Depth 100 | Out-File $configPath
}
if (!(Test-Path $configPath)) { CreateConfig $defaultConfig }

if (!(Test-Path $configPath)) {
Remove-Item -Force -Path $shortcut -EA SilentlyContinue

Write-Host "It seems like this is your first time using AME Local Build.`n" -ForegroundColor Yellow
Write-Host "Setup`n---------------------------------" -ForegroundColor Green
Write-Host "Adding config to path would allow you to type 'ame-lb-conf' into Run (Win + R) or any other shell and open the config." -ForegroundColor Blue
choice /c:yn /n /m "Would you like to add a shortcut to %PATH% for the configuration file? [Y/N]"
if ($LASTEXITCODE -eq 1) { New-ConfigPathShortcut}

Write-Host ""
choice /c:yn /n /m "Would you like to open the config file now? [Y/N]"
CreateConfig $defaultConfig
if ($LASTEXITCODE -eq 1) {
Start-Process -FilePath "notepad.exe" -ArgumentList $configPath -Wait
}
}

# check if path shortcut matches config path
if (Test-Path $shortcut) {
if ($configPath -ne $(New-Object -ComObject WScript.Shell).CreateShortcut($shortcut).TargetPath) { New-ConfigPathShortcut }
}

try {
$configNotHashtable = Get-Content $configPath | ConvertFrom-Json
Expand Down

0 comments on commit 3507009

Please sign in to comment.