Skip to content
This repository has been archived by the owner on May 1, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/0.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
inyono committed Nov 8, 2018
2 parents af2b08c + d36c7e9 commit 72e77cb
Show file tree
Hide file tree
Showing 6 changed files with 3,635 additions and 81 deletions.
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@

All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [0.0.1] - 2018-11-08

### Added

- Add function `updateCopyrightHeader` with slightly different API as a replacement for `updateLicenseHeader`
- Add tests

### Deprecated

- `updateLicenseHeader` will be removed with the next breaking change. Use the new `updateCopyrightHeader` instead

### Fixed

- Handle `language.after` (e.g. `?>` for PHTML) correctly when input already starts with `language.begin` (e.g. `<?php`)

## [0.0.0] - 2018-11-08

### Added

- Add initial `updateLicenseHeader` function supporting JavaScript, TypeScript, PHP, PHTML and Twig.

[unreleased]: https://github.com/splish-me/copyright-headers/compare/0.0.0...HEAD
[unreleased]: https://github.com/splish-me/copyright-headers/compare/0.0.1...HEAD
[0.0.1]: https://github.com/splish-me/copyright-headers/compare/0.0.0...0.0.1
[0.0.0]: https://github.com/splish-me/copyright-headers/compare/df12fe2868efc66641034590c3ffd37e0896afbb...HEAD
241 changes: 241 additions & 0 deletions __tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
import {
CopyrightHeaderOptions,
CopyrightHeaderStatus,
getUpdatedCopyrightHeader,
php,
phtml
} from '../src'

describe('php', () => {
const options: CopyrightHeaderOptions = {
lines: [
'This file is part of @splish-me/copyright-headers',
'',
'Copyright (c) 2018 Splish UG (haftungsbeschränkt)'
]
}

test('does not start with <?php', () => {
const input = ``
const [status, output] = getUpdatedCopyrightHeader(input, php, options)

expect(status).toEqual(CopyrightHeaderStatus.Added)
expect(output).toEqual(`<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
*/
`)
})

test('does start with <?php', () => {
const input = `<?php
echo "foo bar";
`
const [status, output] = getUpdatedCopyrightHeader(input, php, options)

expect(status).toEqual(CopyrightHeaderStatus.Added)
expect(output).toEqual(`<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
*/
echo "foo bar";
`)
})

test('existing copyright header', () => {
const input = `<?php
/**
* Copyright (c) 2016 Splish UG (haftungsbeschränkt)
*/
echo "foo bar";
`
const [status, output] = getUpdatedCopyrightHeader(input, php, {
...options,
shouldUpdate: () => true
})

expect(status).toEqual(CopyrightHeaderStatus.Changed)
expect(output).toEqual(`<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
*/
echo "foo bar";
`)
})

test('existing external copyright header', () => {
const input = `<?php
/**
* Copyright (c) 2016 Max Mustermann Corporation
*/
echo "foo bar";
`
const [status, output] = getUpdatedCopyrightHeader(input, php, {
...options,
shouldUpdate: () => false
})

expect(status).toEqual(CopyrightHeaderStatus.External)
expect(output).toEqual(input)
})

test('multiple copyright headers', () => {
const input = `<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2016 Splish UG (haftungsbeschränkt)
*/
/**
* Copyright (c) 2016 Max Mustermann Corporation
*/
echo "foo bar";
`
const [status, output] = getUpdatedCopyrightHeader(input, php, {
...options,
shouldUpdate: () => true
})

expect(status).toEqual(CopyrightHeaderStatus.Changed)
expect(output).toEqual(`<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
*/
/**
* Copyright (c) 2016 Max Mustermann Corporation
*/
echo "foo bar";
`)
})
})

describe('phtml', () => {
const options: CopyrightHeaderOptions = {
lines: [
'This file is part of @splish-me/copyright-headers',
'',
'Copyright (c) 2018 Splish UG (haftungsbeschränkt)'
]
}

test('does not start with <?php', () => {
const input = ``
const [status, output] = getUpdatedCopyrightHeader(input, phtml, options)

expect(status).toEqual(CopyrightHeaderStatus.Added)
expect(output).toEqual(`<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
*/
?>
`)
})

test('does start with <?php', () => {
const input = `<?php
echo "foo bar";
?>
`
const [status, output] = getUpdatedCopyrightHeader(input, phtml, options)

expect(status).toEqual(CopyrightHeaderStatus.Added)
expect(output).toEqual(`<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
*/
echo "foo bar";
?>
`)
})

test('existing copyright header', () => {
const input = `<?php
/**
* Copyright (c) 2016 Splish UG (haftungsbeschränkt)
*/
echo "foo bar";
?>
`
const [status, output] = getUpdatedCopyrightHeader(input, phtml, {
...options,
shouldUpdate: () => true
})

expect(status).toEqual(CopyrightHeaderStatus.Changed)
expect(output).toEqual(`<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
*/
echo "foo bar";
?>
`)
})

test('existing external copyright header', () => {
const input = `<?php
/**
* Copyright (c) 2016 Max Mustermann Corporation
*/
echo "foo bar";
?>
`
const [status, output] = getUpdatedCopyrightHeader(input, phtml, {
...options,
shouldUpdate: () => false
})

expect(status).toEqual(CopyrightHeaderStatus.External)
expect(output).toEqual(input)
})

test('multiple copyright headers', () => {
const input = `<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2016 Splish UG (haftungsbeschränkt)
*/
/**
* Copyright (c) 2016 Max Mustermann Corporation
*/
echo "foo bar";
?>
`
const [status, output] = getUpdatedCopyrightHeader(input, php, {
...options,
shouldUpdate: () => true
})

expect(status).toEqual(CopyrightHeaderStatus.Changed)
expect(output).toEqual(`<?php
/**
* This file is part of @splish-me/copyright-headers
*
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
*/
/**
* Copyright (c) 2016 Max Mustermann Corporation
*/
echo "foo bar";
?>
`)
})
})
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node'
}
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@splish-me/copyright-headers",
"version": "0.0.0",
"version": "0.0.1",
"homepage": "https://github.com/splish-me/copyright-headers",
"bugs": {
"url": "https://github.com/splish-me/copyright-headers/issues"
Expand All @@ -19,6 +19,7 @@
"format": "npm-run-all format:*",
"lint": "npm-run-all lint:*",
"license": "ts-node scripts/license-headers",
"test": "jest",
"format:prettier": "yarn _prettier --write",
"lint:prettier": "yarn _prettier --list-different",
"_php-cs-fixer": "php php-cs-fixer.phar fix --config=php-cs-fixer.config.php",
Expand All @@ -29,12 +30,15 @@
},
"devDependencies": {
"@types/glob": "^7.0.0",
"@types/jest": "^23.3.9",
"@types/node": "^10.0.0",
"@types/signale": "^1.2.0",
"glob": "^7.0.0",
"jest": "^23.6.0",
"npm-run-all": "^4.0.0",
"prettier": "^1.0.0",
"rimraf": "^2.6.2",
"ts-jest": "^23.10.4",
"ts-node": "^7.0.0",
"typescript": "^3.0.0"
},
Expand Down
Loading

0 comments on commit 72e77cb

Please sign in to comment.