-
-
Notifications
You must be signed in to change notification settings - Fork 385
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from yamadashy/feature/repopackignore
Add support for .repopackignore and enhance ignore pattern documentation
- Loading branch information
Showing
9 changed files
with
149 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import * as fs from 'fs/promises'; | ||
import path from 'path'; | ||
import ignore from 'ignore'; | ||
import { logger } from './logger.js'; | ||
import { RepopackConfigMerged } from '../types/index.js'; | ||
import { defaultIgnoreList } from './defaultIgnore.js'; | ||
|
||
export async function getIgnorePatterns(filename: string, rootDir: string, fsModule = fs): Promise<string[]> { | ||
const ignorePath = path.join(rootDir, filename); | ||
try { | ||
const ignoreContent = await fsModule.readFile(ignorePath, 'utf-8'); | ||
return parseIgnoreContent(ignoreContent); | ||
} catch (error) { | ||
logger.debug(`No ${filename} file found or unable to read it.`); | ||
return []; | ||
} | ||
} | ||
|
||
export function parseIgnoreContent(content: string): string[] { | ||
return content | ||
.split('\n') | ||
.map((line) => line.trim()) | ||
.filter((line) => line && !line.startsWith('#')); | ||
} | ||
|
||
export type IgnoreFilter = (path: string) => boolean; | ||
|
||
export function createIgnoreFilter(patterns: string[]): IgnoreFilter { | ||
const ig = ignore.default().add(patterns); | ||
return ig.createFilter(); | ||
} | ||
|
||
export async function getAllIgnorePatterns(rootDir: string, config: RepopackConfigMerged): Promise<string[]> { | ||
let ignorePatterns: string[] = []; | ||
|
||
if (config.ignore.useDefaultPatterns) { | ||
ignorePatterns = [...ignorePatterns, ...defaultIgnoreList]; | ||
} | ||
|
||
const gitignorePatterns = await getIgnorePatterns('.gitignore', rootDir); | ||
if (config.ignore.useGitignore) { | ||
ignorePatterns = [...ignorePatterns, ...gitignorePatterns]; | ||
} | ||
|
||
const repopackIgnorePatterns = await getIgnorePatterns('.repopackignore', rootDir); | ||
ignorePatterns = [...ignorePatterns, ...repopackIgnorePatterns]; | ||
|
||
if (config.ignore.customPatterns) { | ||
ignorePatterns = [...ignorePatterns, ...config.ignore.customPatterns]; | ||
} | ||
|
||
return ignorePatterns; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.