-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ignore): Add .repopackignore support
- Loading branch information
Showing
12 changed files
with
168 additions
and
106 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.useGitignorePatterns) { | ||
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { defaultConfig } from '../../src/config/defaultConfig.js'; | ||
import { RepopackConfigMerged } from '../../src/types/index.js'; | ||
|
||
export const createMockConfig = (config: Partial<RepopackConfigMerged> = {}): RepopackConfigMerged => { | ||
return { | ||
output: config.output || defaultConfig.output, | ||
ignore: config.ignore || defaultConfig.ignore, | ||
}; | ||
}; |
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.