Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: delete other license files in target #13

Merged
merged 1 commit into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/content/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ const content = {
'SECURITY.md': './SECURITY.md',
}

const filesToDelete = [
// remove any other license files
/^LICENSE*/,
// remove any eslint config files that aren't local to the project
/^\.eslintrc\.(?!(local\.)).*/,
]

// given a root directory, copy all files in the content map
// after purging any non-local .eslintrc config files
// after purging any files we need to delete
const copyContent = async (root) => {
const contents = await fs.readdir(root)

for (const file of contents) {
// remove any eslint config files that aren't local to the project
if (file.startsWith('.eslintrc.') && !file.startsWith('.eslintrc.local.')) {
if (filesToDelete.some((p) => p.test(file))) {
await fs.rm(join(root, file))
}
}
Expand Down
14 changes: 10 additions & 4 deletions test/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@ t.test('copies content', async (t) => {
}
})

t.test('removes eslint configs', async (t) => {
t.test('removes files', async (t) => {
const content = {
'.eslintrc.json': '{}',
'.eslintrc.yml': '',
'.eslintrc.local.json': '{}',
'something.txt': '',
LICENSE: '',
'LICENSE.txt': '',
}
const keepContent = [
'.eslintrc.local.json',
'something.txt',
]
const root = t.testdir(content)

await copyContent(root)
Expand All @@ -31,10 +37,10 @@ t.test('removes eslint configs', async (t) => {

for (const target in content) {
const fullTarget = join(root, target)
if (target.startsWith('.eslintrc.') && !target.startsWith('.eslintrc.local.')) {
await t.rejects(fs.stat(fullTarget), { code: 'ENOENT' }, `removed ${target}`)
} else {
if (keepContent.find((f) => f === target)) {
await t.resolves(fs.stat(fullTarget), `left existing ${target}`)
} else {
await t.rejects(fs.stat(fullTarget), { code: 'ENOENT' }, `removed ${target}`)
}
}
})