From 081fc7c99be89a2556ead47eeec9c45a8fc5c4d4 Mon Sep 17 00:00:00 2001 From: Luke Karrys Date: Wed, 27 Oct 2021 15:53:19 -0700 Subject: [PATCH] feat: delete other license files in target --- lib/content/index.js | 12 +++++++++--- test/content.js | 14 ++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/content/index.js b/lib/content/index.js index fe3cf9cb..8255c157 100644 --- a/lib/content/index.js +++ b/lib/content/index.js @@ -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)) } } diff --git a/test/content.js b/test/content.js index d50bf868..2e257280 100644 --- a/test/content.js +++ b/test/content.js @@ -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) @@ -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}`) } } })