mirror of
https://github.com/garrytan/gstack.git
synced 2026-05-05 05:05:08 +02:00
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:
@@ -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"
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user