From 3ee385d78ce826a2dd4fa19036770efd268ecfb3 Mon Sep 17 00:00:00 2001 From: David Bushong Date: Thu, 28 Oct 2021 16:09:47 -0700 Subject: [PATCH 1/2] feat: add license header support for more files ts, mjs, tsx, jsx --- lib/license/index.js | 8 ++++++-- test/fixtures/merge-commit | 4 ++-- test/license/index.test.js | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/lib/license/index.js b/lib/license/index.js index 3cf9eb1..f6958ad 100644 --- a/lib/license/index.js +++ b/lib/license/index.js @@ -58,7 +58,7 @@ const COMMENT_TYPES = { return ` ${`* ${line}`.trim()}`; }) .join('\n'); - return `/*\n${body}\n */`; + return `/*\n${body}\n */\n`; }, }, '.coffee': { @@ -74,7 +74,7 @@ function collectFiles(cwd, whitelist, optionalExclude) { ); function scanDirectory(directory) { - return globAsync(`${directory}/**/*.{js,coffee}`, { + return globAsync(`${directory}/**/*.{js,jsx,mjs,ts,tsx,coffee}`, { ignore: exclude, nodir: true, cwd, @@ -115,6 +115,10 @@ function addLicenseHeader(entry) { function addMissingLicenseHeaders(licenseText, files) { const licenseHeaders = { '.js': COMMENT_TYPES['.js'].getLicenseHeader(licenseText), + '.jsx': COMMENT_TYPES['.js'].getLicenseHeader(licenseText), + '.mjs': COMMENT_TYPES['.js'].getLicenseHeader(licenseText), + '.ts': COMMENT_TYPES['.js'].getLicenseHeader(licenseText), + '.tsx': COMMENT_TYPES['.js'].getLicenseHeader(licenseText), '.coffee': COMMENT_TYPES['.coffee'].getLicenseHeader(licenseText), }; return files diff --git a/test/fixtures/merge-commit b/test/fixtures/merge-commit index df41431..16ed0ea 100755 --- a/test/fixtures/merge-commit +++ b/test/fixtures/merge-commit @@ -2,6 +2,6 @@ set -e git init -echo "console.log('do stuff');" > merge.js -git add merge.js +echo "import { mittens } from 'kittens';" > merge.ts +git add merge.ts git commit -m 'Merge pull request #119 from theowner/some/branch' diff --git a/test/license/index.test.js b/test/license/index.test.js index 2936b03..6d94bc4 100644 --- a/test/license/index.test.js +++ b/test/license/index.test.js @@ -87,4 +87,26 @@ describe('addLicenseHeaders', () => { ); }); }); + + describe('with a ts file w/o a license header', () => { + const dirname = withFixture('merge-commit'); + const filename = `${dirname}/merge.ts`; + + it('adds the header', async () => { + fs.writeFileSync(`${dirname}/LICENSE`, 'SIMPLE'); + + const changedFiles = await addLicenseHeaders(dirname); + assert.deepStrictEqual(changedFiles, [filename]); + assert.strictEqual( + fs.readFileSync(filename, 'utf8'), + `\ +/* + * SIMPLE + */ + +import { mittens } from 'kittens'; +` + ); + }); + }); }); From a7ee4ad0bb173afbc0ea74173b6247a9bb5e1477 Mon Sep 17 00:00:00 2001 From: David Bushong Date: Thu, 28 Oct 2021 19:25:45 -0700 Subject: [PATCH 2/2] fix: revert extra license newline --- lib/license/index.js | 2 +- test/license/index.test.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/license/index.js b/lib/license/index.js index f6958ad..19e9c3d 100644 --- a/lib/license/index.js +++ b/lib/license/index.js @@ -58,7 +58,7 @@ const COMMENT_TYPES = { return ` ${`* ${line}`.trim()}`; }) .join('\n'); - return `/*\n${body}\n */\n`; + return `/*\n${body}\n */`; }, }, '.coffee': { diff --git a/test/license/index.test.js b/test/license/index.test.js index 6d94bc4..ba80d59 100644 --- a/test/license/index.test.js +++ b/test/license/index.test.js @@ -103,7 +103,6 @@ describe('addLicenseHeaders', () => { /* * SIMPLE */ - import { mittens } from 'kittens'; ` );