forked from stackwiseai/stackwise
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
24 lines (21 loc) · 757 Bytes
/
index.ts
File metadata and controls
24 lines (21 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import path from 'path';
import * as fs from 'fs';
export default function ensureDirectoryExistence(filePath) {
const dir = path.dirname(filePath);
if (!fs.existsSync(dir)) {
// Using `recursive: true` to create all necessary parent directories
fs.mkdirSync(dir, { recursive: true });
createGitIgnore(dir);
}
}
// Create a .gitignore file if it does not exist
function createGitIgnore(dir) {
const gitIgnorePath = path.join(dir, '.gitignore');
if (!fs.existsSync(gitIgnorePath)) {
fs.writeFileSync(gitIgnorePath, 'llmCache.json\n');
}
const llmCachePath = path.join(dir, 'llmCache.json');
if (!fs.existsSync(llmCachePath)) {
fs.writeFileSync(llmCachePath, '{}\n');
}
}