/
get-banner.js
35 lines (26 loc) · 893 Bytes
/
get-banner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import stringifyAuthor from 'stringify-author'
export default (banner, pkg) => {
if (!banner || typeof banner === 'string') {
return banner
}
pkg = typeof banner === 'object' ? { ...pkg, ...banner } : pkg
const name = pkg.name
if (typeof name !== 'string') {
throw new TypeError(`Expect "name" in package.json to be a string but got ${typeof name}.`)
}
const version = pkg.version ? `v${pkg.version}` : ''
const year = pkg.year || new Date().getFullYear()
let author =
typeof pkg.author === 'string' ?
pkg.author :
typeof pkg.author === 'object' ? stringifyAuthor(pkg.author) : ''
author = author ? author : ''
const license = pkg.license || ''
banner =
'/*!\n' +
` * ${name} ${version}\n` +
` * (c) ${year}-present ${author}\n` +
(license && ` * Released under the ${license} License.\n`) +
' */'
return banner
}