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)
49 lines
1.7 KiB
PowerShell
49 lines
1.7 KiB
PowerShell
#Requires -Version 5.1
|
|
<#
|
|
.SYNOPSIS
|
|
Aktifkan salah satu akun clasp (dev / prod / bdn) dengan swap file kredensial global.
|
|
.DESCRIPTION
|
|
clasp hanya mengenal SATU login global (%USERPROFILE%\.clasprc.json) dan tidak
|
|
punya flag --local (terverifikasi di clasp 2.5.0). Skrip ini meng-copy profil
|
|
tersimpan (.clasp-accounts\<env>.clasprc.json) menjadi login aktif, lalu
|
|
verifikasi dengan `clasp login --status`.
|
|
.EXAMPLE
|
|
powershell -NoProfile -ExecutionPolicy Bypass -File .\Use-Clasp.ps1 dev
|
|
#>
|
|
param(
|
|
[ValidateSet("dev", "prod", "bdn")]
|
|
[string]$Account = "dev"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$profileDir = Join-Path $env:USERPROFILE ".clasp-accounts"
|
|
$src = Join-Path $profileDir ("$Account.clasprc.json")
|
|
$dst = Join-Path $env:USERPROFILE ".clasprc.json"
|
|
|
|
if (-not (Test-Path -LiteralPath $src)) {
|
|
Write-Output "Profil '$Account' belum ada: $src"
|
|
Write-Output "Cara buat (sekali per akun):"
|
|
Write-Output " 1. clasp login # login sebagai akun-$Account di browser"
|
|
Write-Output " 2. New-Item -ItemType Directory -Force '$profileDir'"
|
|
Write-Output " 3. Copy-Item '$dst' '$src'"
|
|
exit 1
|
|
}
|
|
|
|
Copy-Item -LiteralPath $src -Destination $dst -Force
|
|
Write-Output "Akun clasp aktif: $Account"
|
|
|
|
$claspCmd = Get-Command clasp -ErrorAction SilentlyContinue
|
|
if (-not $claspCmd) {
|
|
$localClasp = Join-Path $PSScriptRoot "node_modules/.bin/clasp.ps1"
|
|
if (Test-Path -LiteralPath $localClasp) { $claspCmd = $localClasp }
|
|
else { $claspCmd = "clasp" }
|
|
}
|
|
|
|
& $claspCmd login --status
|
|
if ($LASTEXITCODE -ne 0) {
|
|
Write-Output "Token profil '$Account' tidak valid/kadaluarsa."
|
|
Write-Output "Perbaiki: clasp login (sebagai akun-$Account), lalu Copy-Item '$dst' '$src' -Force"
|
|
exit 1
|
|
}
|