Skip to content

Commit e02fa86

Browse files
tianzhouclaude
andcommitted
fix: improve resource path resolution for demo mode
Now trying multiple possible locations to find the SQL files in both development and production environments. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c17661a commit e02fa86

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/config/demo-loader.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,30 @@ const __filename = fileURLToPath(import.meta.url);
1313
const __dirname = path.dirname(__filename);
1414

1515
// Path to sample data files - will be bundled with the package
16-
const DEMO_DATA_DIR = path.join(__dirname, '..', 'resources', 'employee-sqlite');
16+
// Try different paths to find the SQL files in development or production
17+
let DEMO_DATA_DIR: string;
18+
const projectRootPath = path.join(__dirname, '..', '..', '..');
19+
const projectResourcesPath = path.join(projectRootPath, 'resources', 'employee-sqlite');
20+
const distPath = path.join(__dirname, '..', 'resources', 'employee-sqlite');
21+
22+
// First try the project root resources directory (for development)
23+
if (fs.existsSync(projectResourcesPath)) {
24+
DEMO_DATA_DIR = projectResourcesPath;
25+
}
26+
// Then try dist directory (for production)
27+
else if (fs.existsSync(distPath)) {
28+
DEMO_DATA_DIR = distPath;
29+
}
30+
// Fallback to a relative path from the current directory
31+
else {
32+
DEMO_DATA_DIR = path.join(process.cwd(), 'resources', 'employee-sqlite');
33+
if (!fs.existsSync(DEMO_DATA_DIR)) {
34+
throw new Error(`Could not find employee-sqlite resources in any of the expected locations:
35+
- ${projectResourcesPath}
36+
- ${distPath}
37+
- ${DEMO_DATA_DIR}`);
38+
}
39+
}
1740

1841
/**
1942
* Load SQL file contents

0 commit comments

Comments
 (0)