Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support .ts .mjs .tsx .jsx extensions for license headers #96

Merged
merged 2 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions lib/license/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const COMMENT_TYPES = {
return ` ${`* ${line}`.trim()}`;
})
.join('\n');
return `/*\n${body}\n */`;
return `/*\n${body}\n */\n`;
},
},
'.coffee': {
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/merge-commit
Original file line number Diff line number Diff line change
Expand Up @@ -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'
22 changes: 22 additions & 0 deletions test/license/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
`
);
});
});
});