Skip to content

Commit ebba57f

Browse files
committed
feat: implement diagnostic error messages in findConfig
- Added specific checks for .mex/ directory, git init, and scaffold completeness. - Note: Existing tests in test/config.test.ts are currently failing due to the message change. Waiting for confirmation to update test expectations.
1 parent f6f0f6c commit ebba57f

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/config.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,29 @@ import type { MexConfig } from "./types.js";
99
export function findConfig(startDir?: string): MexConfig {
1010
const dir = startDir ?? process.cwd();
1111

12+
if (dir.split(/[\\/]/).includes(".mex")) {
13+
throw new Error(
14+
"You're inside the .mex/ directory. Run mex commands from your project root instead."
15+
);
16+
}
17+
1218
// Try git root first, fall back to cwd if no git repo
13-
const projectRoot = findProjectRoot(dir) ?? dir;
19+
const gitRoot = findProjectRoot(dir);
20+
const projectRoot = gitRoot ?? dir;
1421

1522
const scaffoldRoot = findScaffoldRoot(projectRoot);
1623
if (!scaffoldRoot) {
24+
if (!gitRoot) {
25+
throw new Error("No git repository found. Initialize one first: git init");
26+
}
27+
28+
const mexDir = resolve(projectRoot, ".mex");
29+
if (existsSync(mexDir)) {
30+
throw new Error("Scaffold directory exists but looks incomplete. Run: bash .mex/setup.sh");
31+
}
32+
1733
throw new Error(
18-
`No scaffold found. Expected .mex/ directory or context/ directory in ${projectRoot}`
34+
"No .mex/ scaffold found. Run: git clone https://github.com/theDakshJaitly/mex.git .mex && bash .mex/setup.sh"
1935
);
2036
}
2137

@@ -37,7 +53,10 @@ function findProjectRoot(dir: string): string | null {
3753
function findScaffoldRoot(projectRoot: string): string | null {
3854
// Prefer .mex/ directory
3955
const mexDir = resolve(projectRoot, ".mex");
40-
if (existsSync(mexDir)) return mexDir;
56+
// Check if .mex exists and has the required setup file to consider it complete
57+
if (existsSync(mexDir) && existsSync(resolve(mexDir, "setup.sh"))) {
58+
return mexDir;
59+
}
4160

4261
// Fall back to context/ directory (current mex layout)
4362
const contextDir = resolve(projectRoot, "context");

0 commit comments

Comments
 (0)