2019-01-03 08:51:14 +03:00
|
|
|
const test = require('ava')
|
|
|
|
const fs = require('fs-extra')
|
|
|
|
const globby = require('globby')
|
|
|
|
const {join} = require('path')
|
2017-10-27 21:25:09 +03:00
|
|
|
|
2019-01-03 08:51:14 +03:00
|
|
|
const {packages} = require('../lerna.json')
|
2017-10-27 21:25:09 +03:00
|
|
|
const year = (new Date()).getFullYear()
|
2017-10-27 21:28:00 +03:00
|
|
|
const yearRegex = new RegExp(`Copyright \\(c\\) ${year} GitHub Inc\\.`)
|
2017-10-27 21:25:09 +03:00
|
|
|
|
|
|
|
test(`LICENSE files have the current year ${year}`, t => {
|
2019-01-03 08:51:14 +03:00
|
|
|
return getPackageGlobs('LICENSE')
|
2017-10-27 21:25:09 +03:00
|
|
|
.then(paths => {
|
|
|
|
t.plan(paths.length)
|
|
|
|
return paths.map(path => {
|
2019-01-03 08:51:14 +03:00
|
|
|
const license = fs.readFileSync(path, 'utf8')
|
2017-10-27 21:28:00 +03:00
|
|
|
return t.regex(license, yearRegex, `The license "${path}" does not include the current year ${year}`)
|
2017-10-27 21:25:09 +03:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
test(`Source header copyrights have the current year ${year}`, t => {
|
2019-01-03 08:51:14 +03:00
|
|
|
return getPackageGlobs('{*.scss,lib/**/*.scss}')
|
2017-10-27 21:25:09 +03:00
|
|
|
.then(paths => {
|
|
|
|
t.plan(paths.length)
|
|
|
|
return paths.map(path => {
|
2019-01-03 08:51:14 +03:00
|
|
|
const source = fs.readFileSync(path, 'utf8')
|
2017-10-27 21:25:09 +03:00
|
|
|
if (source.match(/Copyright \(c\)/)) {
|
2017-10-27 21:28:00 +03:00
|
|
|
return t.regex(source, yearRegex, `The source's header "${path}" does not include the current year ${year}`)
|
2017-10-27 21:25:09 +03:00
|
|
|
} else {
|
|
|
|
return t.true(true)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2019-01-03 08:51:14 +03:00
|
|
|
|
|
|
|
function getPackageGlobs(glob) {
|
|
|
|
return globby(packages.map(pkg => join(pkg, glob)))
|
|
|
|
}
|