1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | 'use strict'
|
13 |
|
14 | const assert = require('assert')
|
15 | const _tmpl = require('./_tmpl')
|
16 |
|
17 |
|
18 | function licenseBud (config) {
|
19 | assert.ok(config.type, 'config.type is required.')
|
20 | assert.ok(config.holder, 'config.holder is required.')
|
21 | return {
|
22 | force: true,
|
23 | mode: '444',
|
24 | path: 'LICENSE',
|
25 | tmpl: _tmplForType(String(config.type).trim()),
|
26 | data: {
|
27 | holder: config.holder,
|
28 | year: config.year || new Date().getFullYear()
|
29 | }
|
30 | }
|
31 | }
|
32 |
|
33 | function _tmplForType (type) {
|
34 | switch (type) {
|
35 | case 'mit':
|
36 | case 'MIT':
|
37 | return _tmpl('hbs/LICENSE_MIT.md.hbs')
|
38 | case 'Apache-2.0':
|
39 | case 'Apache2':
|
40 | case 'APACHE-2.0':
|
41 | case 'APACHE2':
|
42 | return _tmpl('hbs/LICENSE_Apache-2.0.md.hbs')
|
43 | default:
|
44 | throw new Error(`Unknown license type: ${type}`)
|
45 | }
|
46 | }
|
47 |
|
48 | module.exports = licenseBud
|