(dirArg: string | undefined)
| 24 | } |
| 25 | |
| 26 | export function resolveProjectOrThrow(dirArg: string | undefined): ProjectDir { |
| 27 | const trimmed = dirArg?.trim(); |
| 28 | if (trimmed === "#") { |
| 29 | throw new InvalidProjectError( |
| 30 | "Invalid project directory: #", |
| 31 | "# is a URL fragment, not a project path.", |
| 32 | "Run hyperframes preview . from your project directory.", |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | const dir = resolve(dirArg ?? "."); |
| 37 | const name = basename(dir); |
| 38 | const indexPath = resolve(dir, "index.html"); |
| 39 | |
| 40 | if (!existsSync(dir) || !statSync(dir).isDirectory()) { |
| 41 | throw new InvalidProjectError("Not a directory: " + dir); |
| 42 | } |
| 43 | if (!existsSync(indexPath)) { |
| 44 | throw new InvalidProjectError( |
| 45 | "No composition found in " + dir, |
| 46 | "No index.html file found.", |
| 47 | "Run npx hyperframes init to create a new composition.", |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | return { dir, name, indexPath }; |
| 52 | } |
| 53 | |
| 54 | export function resolveProject(dirArg: string | undefined): ProjectDir { |
| 55 | try { |
no test coverage detected