refactor: add PROJECTS_DIR to gstack-slug and getProjectsDir() to util.ts

gstack-slug now outputs PROJECTS_DIR (respecting GSTACK_STATE_DIR env var).
lib/util.ts gets getProjectsDir(slug?) as single source of truth for
TypeScript consumers.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-03-18 23:45:27 -07:00
parent 07aad3562f
commit b332364b43
2 changed files with 9 additions and 0 deletions
+3
View File
@@ -5,5 +5,8 @@
set -euo pipefail
SLUG=$(git remote get-url origin 2>/dev/null | sed 's|.*[:/]\([^/]*/[^/]*\)\.git$|\1|;s|.*[:/]\([^/]*/[^/]*\)$|\1|' | tr '/' '-' | tr '[:upper:]' '[:lower:]')
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null | tr '/' '-')
STATE_DIR="${GSTACK_STATE_DIR:-$HOME/.gstack}"
PROJECTS_DIR="${STATE_DIR}/projects"
echo "SLUG=$SLUG"
echo "BRANCH=$BRANCH"
echo "PROJECTS_DIR=$PROJECTS_DIR"
+6
View File
@@ -15,6 +15,12 @@ import { spawnSync } from 'child_process';
export const GSTACK_STATE_DIR = process.env.GSTACK_STATE_DIR || path.join(os.homedir(), '.gstack');
export const GSTACK_DEV_DIR = path.join(os.homedir(), '.gstack-dev');
/** Get the projects directory, optionally scoped to a specific project slug. */
export function getProjectsDir(slug?: string): string {
const base = path.join(GSTACK_STATE_DIR, 'projects');
return slug ? path.join(base, slug) : base;
}
// --- File I/O ---
/** Atomic write: write to .tmp then rename. Non-fatal on error. */