mirror of
https://github.com/primer/css.git
synced 2024-12-02 07:53:06 +03:00
36 lines
1.0 KiB
JavaScript
Executable File
36 lines
1.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
const fs = require('fs-extra')
|
|
const globby = require('globby')
|
|
const {join} = require('path')
|
|
|
|
const {packages} = require('../lerna.json')
|
|
const year = process.argv.slice(2)[0] || (new Date()).getFullYear()
|
|
const yearRegex = /Copyright \(c\) (20\d\d) GitHub/
|
|
|
|
if (module.parent) {
|
|
module.exports = happyNewYear
|
|
} else {
|
|
happyNewYear()
|
|
}
|
|
|
|
function happyNewYear() {
|
|
return getPackageGlobs('{LICENSE,*.scss,lib/**/*.scss}')
|
|
.then(paths => paths.map(path => {
|
|
return fs.readFile(path, 'utf8')
|
|
.then(source => {
|
|
const match = source.match(yearRegex)
|
|
if (match && match[1] != year) {
|
|
const replaced = source.replace(yearRegex, (substr, y) => {
|
|
console.warn(`updating year in ${path} from ${y} to ${year}`)
|
|
return substr.replace(y, year)
|
|
})
|
|
return fs.writeFile(path, replaced, 'utf8')
|
|
}
|
|
})
|
|
}))
|
|
}
|
|
|
|
function getPackageGlobs(glob) {
|
|
return globby(packages.map(pkg => join(pkg, glob)))
|
|
}
|