35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
/**
|
|
* CI·테스트처럼 실제 사용자 설치 기록과 분리해야 하는 실행은 전용 상태 디렉터리를 쓴다.
|
|
* 사용자 설치 경로의 기준 홈은 바꾸지 않고, designpaca 자체 상태만 격리한다.
|
|
*/
|
|
function isolatedStateDir(): string | undefined {
|
|
const dir = process.env["DESIGNPACA_STATE_DIR"]?.trim();
|
|
return dir ? path.resolve(dir) : undefined;
|
|
}
|
|
|
|
/** designpaca 자체 상태 디렉터리 (~/.designpaca) */
|
|
export function stateDir(home?: string): string {
|
|
if (home) return path.join(home, ".designpaca");
|
|
return isolatedStateDir() ?? path.join(os.homedir(), ".designpaca");
|
|
}
|
|
|
|
export function manifestPath(home?: string): string {
|
|
return path.join(stateDir(home), "manifest.json");
|
|
}
|
|
|
|
/** 업데이트 확인 캐시 */
|
|
export function updateCachePath(home?: string): string {
|
|
return path.join(stateDir(home), "update-check.json");
|
|
}
|
|
|
|
/** 홈 경로를 ~ 로 줄여 표시한다 */
|
|
export function tildify(p: string, home = os.homedir()): string {
|
|
const rel = path.relative(home, p);
|
|
if (!rel.startsWith("..") && !path.isAbsolute(rel)) {
|
|
return path.posix.join("~", rel.split(path.sep).join("/"));
|
|
}
|
|
return p;
|
|
}
|