UNPKG

1.17 kBJavaScriptView Raw
1/**
2 * Define a bud for LICENSE
3 * @memberof module:ape-tmpl/lib
4 * @function licenseBud
5 * @param {object} config - Configuration.
6 * @param {string} config.type - Type of license.
7 * @param {number} config.year - Copy right year.
8 * @param {string} config.holder - License holder name.
9 * @returns {object} - Bud object.
10 */
11
12'use strict'
13
14const assert = require('assert')
15const _tmpl = require('./_tmpl')
16
17/** @lends licenseBud */
18function 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
33function _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
48module.exports = licenseBud