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

Commit 5ab8d9d

Browse files
authored
Merge release-v2.8.1 into master
2 parents 5cd9210 + 2af8f40 commit 5ab8d9d

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## v2.8.1 (May 8, 2017)
2+
- Fixes whitespace / newline management in copyright tool
3+
- Fix to additional space added when --update flag passed into copyright tool
4+
15
## v2.8.0 (May 5, 2017)
26
- Adds new copyright-header management tool
37

copyright/copyright.js

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env node
2-
32
/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
43
/* Copyright (c) 2017 Mobify Research & Development Inc. All rights reserved. */
54
/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -63,6 +62,19 @@ const buildSupportedExtensions = () => {
6362
})
6463
}
6564

65+
/**
66+
* Removes extra \n characters from the top of any files
67+
* to ensure more consistent spacing between copyright headers
68+
* @param {String} content original file to edit
69+
* @return {String} new file with no leading \n
70+
*/
71+
const removeLeadingNewlines = (content) => {
72+
if (content[0] !== '') {
73+
return content
74+
}
75+
content.shift()
76+
return removeLeadingNewlines(content)
77+
}
6678

6779
if (args.length === 0 || args.indexOf('--help') >= 0) {
6880

@@ -105,13 +117,15 @@ args
105117
const content = fs.readFileSync(file)
106118
const hasCopyrightHeader = content.includes('Copyright (c)')
107119
const ext = file.match(/\.[0-9a-z]+$/i)[0]
108-
109120
let newData = ''
110121

111122
if (hasCopyrightHeader && updateMode) {
112-
newData = content.toString().replace(/(\(c\)\s)(\d{4})/, `$1 ${currentYear}`)
113-
fs.writeFileSync(file, newData)
114-
console.log(`${green}Copyright header succesfully updated to ${currentYear} in ${magenta}${file}`)
123+
let previousHeaderYear = content.toString().match(/(?:\(c\))(?:\s)(\d{4})/)[1]
124+
if (previousHeaderYear !== currentYear.toString()) {
125+
newData = content.toString().replace(`(c) ${previousHeaderYear}`, `(c) ${currentYear}`)
126+
fs.writeFileSync(file, newData)
127+
console.log(`${green}Copyright header succesfully updated from ${previousHeaderYear} to ${currentYear} in ${magenta}${file}`)
128+
}
115129
}
116130

117131
if (!hasCopyrightHeader) {
@@ -124,10 +138,11 @@ args
124138
// accomodate for shebang and insert before header
125139
if (contentStr[0].indexOf('#!') >= 0) {
126140
const shebang = contentStr.shift()
127-
contentStr = contentStr.join('\n')
128-
newData = shebang + '\n\n' + getHeaderText(ext) + '\n' + contentStr // eslint-disable-line prefer-template
141+
contentStr = removeLeadingNewlines(contentStr).join('\n')
142+
newData = shebang + '\n' + getHeaderText(ext) + '\n' + contentStr // eslint-disable-line prefer-template
129143
} else {
130-
newData = getHeaderText(ext) + `\n${content}` // eslint-disable-line prefer-template
144+
contentStr = removeLeadingNewlines(contentStr).join('\n')
145+
newData = getHeaderText(ext) + `\n${contentStr}` // eslint-disable-line prefer-template
131146
}
132147

133148
fs.writeFileSync(file, newData)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mobify-code-style",
3-
"version": "2.8.0",
3+
"version": "2.8.1",
44
"description": "Code style guide and linting tools for Mobify",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)