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

Commit 72e77cb

Browse files
committed
Merge branch 'release/0.0.1'
2 parents af2b08c + d36c7e9 commit 72e77cb

File tree

6 files changed

+3635
-81
lines changed

6 files changed

+3635
-81
lines changed

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@
22

33
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/).
44

5+
## [0.0.1] - 2018-11-08
6+
7+
### Added
8+
9+
- Add function `updateCopyrightHeader` with slightly different API as a replacement for `updateLicenseHeader`
10+
- Add tests
11+
12+
### Deprecated
13+
14+
- `updateLicenseHeader` will be removed with the next breaking change. Use the new `updateCopyrightHeader` instead
15+
16+
### Fixed
17+
18+
- Handle `language.after` (e.g. `?>` for PHTML) correctly when input already starts with `language.begin` (e.g. `<?php`)
19+
520
## [0.0.0] - 2018-11-08
621

722
### Added
823

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

11-
[unreleased]: https://github.com/splish-me/copyright-headers/compare/0.0.0...HEAD
26+
[unreleased]: https://github.com/splish-me/copyright-headers/compare/0.0.1...HEAD
27+
[0.0.1]: https://github.com/splish-me/copyright-headers/compare/0.0.0...0.0.1
1228
[0.0.0]: https://github.com/splish-me/copyright-headers/compare/df12fe2868efc66641034590c3ffd37e0896afbb...HEAD

__tests__/index.ts

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
import {
2+
CopyrightHeaderOptions,
3+
CopyrightHeaderStatus,
4+
getUpdatedCopyrightHeader,
5+
php,
6+
phtml
7+
} from '../src'
8+
9+
describe('php', () => {
10+
const options: CopyrightHeaderOptions = {
11+
lines: [
12+
'This file is part of @splish-me/copyright-headers',
13+
'',
14+
'Copyright (c) 2018 Splish UG (haftungsbeschränkt)'
15+
]
16+
}
17+
18+
test('does not start with <?php', () => {
19+
const input = ``
20+
const [status, output] = getUpdatedCopyrightHeader(input, php, options)
21+
22+
expect(status).toEqual(CopyrightHeaderStatus.Added)
23+
expect(output).toEqual(`<?php
24+
/**
25+
* This file is part of @splish-me/copyright-headers
26+
*
27+
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
28+
*/
29+
`)
30+
})
31+
32+
test('does start with <?php', () => {
33+
const input = `<?php
34+
echo "foo bar";
35+
`
36+
const [status, output] = getUpdatedCopyrightHeader(input, php, options)
37+
38+
expect(status).toEqual(CopyrightHeaderStatus.Added)
39+
expect(output).toEqual(`<?php
40+
/**
41+
* This file is part of @splish-me/copyright-headers
42+
*
43+
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
44+
*/
45+
echo "foo bar";
46+
`)
47+
})
48+
49+
test('existing copyright header', () => {
50+
const input = `<?php
51+
/**
52+
* Copyright (c) 2016 Splish UG (haftungsbeschränkt)
53+
*/
54+
echo "foo bar";
55+
`
56+
const [status, output] = getUpdatedCopyrightHeader(input, php, {
57+
...options,
58+
shouldUpdate: () => true
59+
})
60+
61+
expect(status).toEqual(CopyrightHeaderStatus.Changed)
62+
expect(output).toEqual(`<?php
63+
/**
64+
* This file is part of @splish-me/copyright-headers
65+
*
66+
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
67+
*/
68+
echo "foo bar";
69+
`)
70+
})
71+
72+
test('existing external copyright header', () => {
73+
const input = `<?php
74+
/**
75+
* Copyright (c) 2016 Max Mustermann Corporation
76+
*/
77+
echo "foo bar";
78+
`
79+
const [status, output] = getUpdatedCopyrightHeader(input, php, {
80+
...options,
81+
shouldUpdate: () => false
82+
})
83+
84+
expect(status).toEqual(CopyrightHeaderStatus.External)
85+
expect(output).toEqual(input)
86+
})
87+
88+
test('multiple copyright headers', () => {
89+
const input = `<?php
90+
/**
91+
* This file is part of @splish-me/copyright-headers
92+
*
93+
* Copyright (c) 2016 Splish UG (haftungsbeschränkt)
94+
*/
95+
96+
/**
97+
* Copyright (c) 2016 Max Mustermann Corporation
98+
*/
99+
echo "foo bar";
100+
`
101+
const [status, output] = getUpdatedCopyrightHeader(input, php, {
102+
...options,
103+
shouldUpdate: () => true
104+
})
105+
106+
expect(status).toEqual(CopyrightHeaderStatus.Changed)
107+
expect(output).toEqual(`<?php
108+
/**
109+
* This file is part of @splish-me/copyright-headers
110+
*
111+
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
112+
*/
113+
114+
/**
115+
* Copyright (c) 2016 Max Mustermann Corporation
116+
*/
117+
echo "foo bar";
118+
`)
119+
})
120+
})
121+
122+
describe('phtml', () => {
123+
const options: CopyrightHeaderOptions = {
124+
lines: [
125+
'This file is part of @splish-me/copyright-headers',
126+
'',
127+
'Copyright (c) 2018 Splish UG (haftungsbeschränkt)'
128+
]
129+
}
130+
131+
test('does not start with <?php', () => {
132+
const input = ``
133+
const [status, output] = getUpdatedCopyrightHeader(input, phtml, options)
134+
135+
expect(status).toEqual(CopyrightHeaderStatus.Added)
136+
expect(output).toEqual(`<?php
137+
/**
138+
* This file is part of @splish-me/copyright-headers
139+
*
140+
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
141+
*/
142+
?>
143+
`)
144+
})
145+
146+
test('does start with <?php', () => {
147+
const input = `<?php
148+
echo "foo bar";
149+
?>
150+
`
151+
const [status, output] = getUpdatedCopyrightHeader(input, phtml, options)
152+
153+
expect(status).toEqual(CopyrightHeaderStatus.Added)
154+
expect(output).toEqual(`<?php
155+
/**
156+
* This file is part of @splish-me/copyright-headers
157+
*
158+
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
159+
*/
160+
echo "foo bar";
161+
?>
162+
`)
163+
})
164+
165+
test('existing copyright header', () => {
166+
const input = `<?php
167+
/**
168+
* Copyright (c) 2016 Splish UG (haftungsbeschränkt)
169+
*/
170+
echo "foo bar";
171+
?>
172+
`
173+
const [status, output] = getUpdatedCopyrightHeader(input, phtml, {
174+
...options,
175+
shouldUpdate: () => true
176+
})
177+
178+
expect(status).toEqual(CopyrightHeaderStatus.Changed)
179+
expect(output).toEqual(`<?php
180+
/**
181+
* This file is part of @splish-me/copyright-headers
182+
*
183+
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
184+
*/
185+
echo "foo bar";
186+
?>
187+
`)
188+
})
189+
190+
test('existing external copyright header', () => {
191+
const input = `<?php
192+
/**
193+
* Copyright (c) 2016 Max Mustermann Corporation
194+
*/
195+
echo "foo bar";
196+
?>
197+
`
198+
const [status, output] = getUpdatedCopyrightHeader(input, phtml, {
199+
...options,
200+
shouldUpdate: () => false
201+
})
202+
203+
expect(status).toEqual(CopyrightHeaderStatus.External)
204+
expect(output).toEqual(input)
205+
})
206+
207+
test('multiple copyright headers', () => {
208+
const input = `<?php
209+
/**
210+
* This file is part of @splish-me/copyright-headers
211+
*
212+
* Copyright (c) 2016 Splish UG (haftungsbeschränkt)
213+
*/
214+
215+
/**
216+
* Copyright (c) 2016 Max Mustermann Corporation
217+
*/
218+
echo "foo bar";
219+
?>
220+
`
221+
const [status, output] = getUpdatedCopyrightHeader(input, php, {
222+
...options,
223+
shouldUpdate: () => true
224+
})
225+
226+
expect(status).toEqual(CopyrightHeaderStatus.Changed)
227+
expect(output).toEqual(`<?php
228+
/**
229+
* This file is part of @splish-me/copyright-headers
230+
*
231+
* Copyright (c) 2018 Splish UG (haftungsbeschränkt)
232+
*/
233+
234+
/**
235+
* Copyright (c) 2016 Max Mustermann Corporation
236+
*/
237+
echo "foo bar";
238+
?>
239+
`)
240+
})
241+
})

jest.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
preset: 'ts-jest',
3+
testEnvironment: 'node'
4+
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@splish-me/copyright-headers",
3-
"version": "0.0.0",
3+
"version": "0.0.1",
44
"homepage": "https://github.com/splish-me/copyright-headers",
55
"bugs": {
66
"url": "https://github.com/splish-me/copyright-headers/issues"
@@ -19,6 +19,7 @@
1919
"format": "npm-run-all format:*",
2020
"lint": "npm-run-all lint:*",
2121
"license": "ts-node scripts/license-headers",
22+
"test": "jest",
2223
"format:prettier": "yarn _prettier --write",
2324
"lint:prettier": "yarn _prettier --list-different",
2425
"_php-cs-fixer": "php php-cs-fixer.phar fix --config=php-cs-fixer.config.php",
@@ -29,12 +30,15 @@
2930
},
3031
"devDependencies": {
3132
"@types/glob": "^7.0.0",
33+
"@types/jest": "^23.3.9",
3234
"@types/node": "^10.0.0",
3335
"@types/signale": "^1.2.0",
3436
"glob": "^7.0.0",
37+
"jest": "^23.6.0",
3538
"npm-run-all": "^4.0.0",
3639
"prettier": "^1.0.0",
3740
"rimraf": "^2.6.2",
41+
"ts-jest": "^23.10.4",
3842
"ts-node": "^7.0.0",
3943
"typescript": "^3.0.0"
4044
},

0 commit comments

Comments
 (0)