8e0b928a80
Lint / lint (push) Waiting to run
- Use-Clasp.ps1: swap profil login global per akun clasp - scripts/clasp-env.ps1: wrapper satu pintu swap akun+project, guard PROD/BDN - package.json: script use:dev/prod/bdn - .gitignore: pola generik .clasp.*.json + package-lock.json (repo pakai yarn)
68 lines
2.2 KiB
PowerShell
68 lines
2.2 KiB
PowerShell
#Requires -Version 5.1
|
|
<#
|
|
.SYNOPSIS
|
|
Wrapper satu pintu untuk clasp tiga akun + tiga project (dev / prod / bdn).
|
|
.DESCRIPTION
|
|
Urutan kerja: swap akun (Use-Clasp.ps1) -> salin .clasp.<env>.json menjadi
|
|
.clasp.json -> guard khusus prod -> jalankan clasp. Jangan panggil
|
|
`clasp push` langsung; selalu lewat wrapper ini / npm script.
|
|
.EXAMPLE
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\clasp-env.ps1 -Env dev -Cmd use
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\clasp-env.ps1 -Env dev -Cmd push
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File .\scripts\clasp-env.ps1 -Env prod -Cmd push
|
|
#>
|
|
param(
|
|
[ValidateSet("dev", "prod", "bdn")]
|
|
[string]$Env = "dev",
|
|
[ValidateSet("use", "push")]
|
|
[string]$Cmd = "use"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
$repoRoot = Split-Path $PSScriptRoot -Parent
|
|
|
|
# 1. Aktifkan akun yang sesuai (berhenti bila profil/token bermasalah).
|
|
& powershell -NoProfile -ExecutionPolicy Bypass -File (Join-Path $repoRoot "Use-Clasp.ps1") $Env
|
|
if ($LASTEXITCODE -ne 0) { exit 1 }
|
|
|
|
# 2. Arahkan ke project script yang sesuai.
|
|
$projectFile = Join-Path $repoRoot ".clasp.$Env.json"
|
|
$activeFile = Join-Path $repoRoot ".clasp.json"
|
|
if (-not (Test-Path -LiteralPath $projectFile)) {
|
|
Write-Output "File project belum ada: $projectFile"
|
|
Write-Output "Cara buat: clasp create --type sheets --title ... --rootDir ./dist"
|
|
Write-Output "lalu isi scriptId project-$Env, atau copy dari .clasp.json.SAMPLE"
|
|
exit 1
|
|
}
|
|
Copy-Item -LiteralPath $projectFile -Destination $activeFile -Force
|
|
|
|
$scriptId = (Get-Content -LiteralPath $activeFile -Raw | ConvertFrom-Json).scriptId
|
|
Write-Output "Project aktif [$Env]: $scriptId"
|
|
|
|
if ($Cmd -eq "use") {
|
|
Write-Output "Siap. Perintah clasp berikutnya memakai akun-$Env + project-$Env."
|
|
exit 0
|
|
}
|
|
|
|
# 3. Guard prod/bdn: wajib konfirmasi eksplisit.
|
|
if ($Env -eq "prod" -or $Env -eq "bdn") {
|
|
$need = $Env.ToUpper()
|
|
$answer = Read-Host "Ketik $need untuk push ke PROYEK $need ($scriptId)"
|
|
if ($answer -cne $need) {
|
|
Write-Output "Dibatalkan. Tidak ada yang di-push."
|
|
exit 1
|
|
}
|
|
}
|
|
|
|
# 4. Push (build dulu agar dist/ selalu segar dari src/).
|
|
Push-Location $repoRoot
|
|
try {
|
|
& npm run build
|
|
if ($LASTEXITCODE -ne 0) { exit 1 }
|
|
& clasp push
|
|
exit $LASTEXITCODE
|
|
}
|
|
finally {
|
|
Pop-Location
|
|
}
|