MCPcopy Create free account
hub / github.com/observablehq/framework / validateRootPath

Function validateRootPath

src/create.ts:155–163  ·  view source on GitHub ↗
(rootPath: string, defaultError?: string)

Source from the content-addressed store, hash-verified

153}
154
155function validateRootPath(rootPath: string, defaultError?: string): string | undefined {
156 if (rootPath === "") return defaultError; // accept default value
157 rootPath = normalize(rootPath);
158 if (!canWriteRecursive(rootPath)) return "Path is not writable.";
159 if (!existsSync(rootPath)) return;
160 if (!statSync(rootPath).isDirectory()) return "File already exists.";
161 if (!canWrite(rootPath)) return "Directory is not writable.";
162 if (readdirSync(rootPath).length !== 0) return "Directory is not empty.";
163}
164
165function inferTitle(rootPath = "."): string {
166 return basename(join(process.cwd(), rootPath))

Callers 1

createFunction · 0.85

Calls 3

canWriteRecursiveFunction · 0.85
existsSyncFunction · 0.85
canWriteFunction · 0.85

Tested by

no test coverage detected