@getmikk/core 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/utils/fs.ts +64 -0
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -8,7 +8,7 @@ export * from './hash/index.js'
|
|
|
8
8
|
export * from './search/index.js'
|
|
9
9
|
export * from './utils/errors.js'
|
|
10
10
|
export * from './utils/logger.js'
|
|
11
|
-
export { discoverFiles, discoverContextFiles, readFileContent, writeFileContent, fileExists, setupMikkDirectory, readMikkIgnore, parseMikkIgnore, detectProjectLanguage, getDiscoveryPatterns, generateMikkIgnore } from './utils/fs.js'
|
|
11
|
+
export { discoverFiles, discoverContextFiles, readFileContent, writeFileContent, fileExists, setupMikkDirectory, readMikkIgnore, parseMikkIgnore, detectProjectLanguage, getDiscoveryPatterns, generateMikkIgnore, updateGitIgnore, cleanupGitIgnore } from './utils/fs.js'
|
|
12
12
|
export type { ContextFile, ContextFileType, ProjectLanguage } from './utils/fs.js'
|
|
13
13
|
export { minimatch } from './utils/minimatch.js'
|
|
14
14
|
export { scoreFunctions, findFuzzyMatches, levenshtein, splitCamelCase, extractKeywords } from './utils/fuzzy-match.js'
|
package/src/utils/fs.ts
CHANGED
|
@@ -655,3 +655,67 @@ export async function generateMikkIgnore(projectRoot: string, language: ProjectL
|
|
|
655
655
|
await fs.writeFile(ignorePath, lines.join('\n'), 'utf-8')
|
|
656
656
|
return true
|
|
657
657
|
}
|
|
658
|
+
|
|
659
|
+
/**
|
|
660
|
+
* Automatically add .mikk/ to the project's .gitignore file if it exists.
|
|
661
|
+
* Returns true if the file was modified, false otherwise.
|
|
662
|
+
*/
|
|
663
|
+
export async function updateGitIgnore(projectRoot: string): Promise<boolean> {
|
|
664
|
+
const gitIgnorePath = path.join(projectRoot, '.gitignore')
|
|
665
|
+
|
|
666
|
+
// If no .gitignore, we don't create one (don't assume the project uses Git)
|
|
667
|
+
if (!await fileExists(gitIgnorePath)) return false
|
|
668
|
+
|
|
669
|
+
try {
|
|
670
|
+
const content = await fs.readFile(gitIgnorePath, 'utf-8')
|
|
671
|
+
const lines = content.split('\n')
|
|
672
|
+
|
|
673
|
+
// Check if already ignored
|
|
674
|
+
const alreadyIgnored = lines.some(line => {
|
|
675
|
+
const trimmed = line.trim()
|
|
676
|
+
return trimmed === '.mikk' || trimmed === '.mikk/' || trimmed === '**/.mikk/**'
|
|
677
|
+
})
|
|
678
|
+
|
|
679
|
+
if (alreadyIgnored) return false
|
|
680
|
+
|
|
681
|
+
// Append to .gitignore
|
|
682
|
+
const newContent = content.endsWith('\n')
|
|
683
|
+
? `${content}\n# Mikk internal\n.mikk/\n`
|
|
684
|
+
: `${content}\n\n# Mikk internal\n.mikk/\n`
|
|
685
|
+
|
|
686
|
+
await fs.writeFile(gitIgnorePath, newContent, 'utf-8')
|
|
687
|
+
return true
|
|
688
|
+
} catch {
|
|
689
|
+
return false
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* Remove Mikk entries from .gitignore.
|
|
695
|
+
*/
|
|
696
|
+
export async function cleanupGitIgnore(projectRoot: string): Promise<boolean> {
|
|
697
|
+
const gitIgnorePath = path.join(projectRoot, '.gitignore')
|
|
698
|
+
if (!await fileExists(gitIgnorePath)) return false
|
|
699
|
+
|
|
700
|
+
try {
|
|
701
|
+
const content = await fs.readFile(gitIgnorePath, 'utf-8')
|
|
702
|
+
const lines = content.split('\n')
|
|
703
|
+
|
|
704
|
+
let modified = false
|
|
705
|
+
const filtered = lines.filter(line => {
|
|
706
|
+
const trimmed = line.trim()
|
|
707
|
+
const isMikkEntry = trimmed === '.mikk' || trimmed === '.mikk/' || trimmed === '**/.mikk/**' || trimmed === '# Mikk internal'
|
|
708
|
+
if (isMikkEntry) modified = true
|
|
709
|
+
return !isMikkEntry
|
|
710
|
+
})
|
|
711
|
+
|
|
712
|
+
if (!modified) return false
|
|
713
|
+
|
|
714
|
+
// Joins lines and trim trailing newlines to avoid growing whitespace
|
|
715
|
+
const newContent = filtered.join('\n').trim() + '\n'
|
|
716
|
+
await fs.writeFile(gitIgnorePath, newContent, 'utf-8')
|
|
717
|
+
return true
|
|
718
|
+
} catch {
|
|
719
|
+
return false
|
|
720
|
+
}
|
|
721
|
+
}
|