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

Commit 65cb0be

Browse files
author
Cdok
committed
updates newline additions + year update check
This commit makes the addition of newlins more consistent, and also checks the current year vs previous year in the headers, to ensure that are only overridden if necessary. Also fixes an extra \s character being added when years are updated
1 parent 8f3c08c commit 65cb0be

1 file changed

Lines changed: 8 additions & 7 deletions

File tree

copyright/copyright.js

Lines changed: 8 additions & 7 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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -17,7 +16,7 @@ const blackBG = '\x1b[40m'
1716
const defaultBG = '\x1b[49m'
1817
const defaultFG = '\x1b[39m'
1918

20-
const currentYear = new Date().getFullYear()
19+
const currentYear = 2018 // new Date().getFullYear()
2120
const langs = {}
2221

2322
let lintMode = true
@@ -105,13 +104,15 @@ args
105104
const content = fs.readFileSync(file)
106105
const hasCopyrightHeader = content.includes('Copyright (c)')
107106
const ext = file.match(/\.[0-9a-z]+$/i)[0]
108-
109107
let newData = ''
110108

111109
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}`)
110+
let previousHeaderYear = content.toString().match(/(?:\(c\))(?:\s)(\d{4})/)[1]
111+
if (previousHeaderYear !== currentYear.toString()) {
112+
newData = content.toString().replace(`(c) ${previousHeaderYear}`, `(c) ${currentYear}`)
113+
fs.writeFileSync(file, newData)
114+
console.log(`${green}Copyright header succesfully updated from ${previousHeaderYear} to ${currentYear} in ${magenta}${file}`)
115+
}
115116
}
116117

117118
if (!hasCopyrightHeader) {
@@ -125,7 +126,7 @@ args
125126
if (contentStr[0].indexOf('#!') >= 0) {
126127
const shebang = contentStr.shift()
127128
contentStr = contentStr.join('\n')
128-
newData = shebang + '\n\n' + getHeaderText(ext) + '\n' + contentStr // eslint-disable-line prefer-template
129+
newData = shebang + '\n' + getHeaderText(ext) + '\n' + contentStr // eslint-disable-line prefer-template
129130
} else {
130131
newData = getHeaderText(ext) + `\n${content}` // eslint-disable-line prefer-template
131132
}

0 commit comments

Comments
 (0)