1 | /**
|
2 | * Load template options
|
3 | * TODO:
|
4 | * - template validate
|
5 | * - docs tips
|
6 | * @param {String} src source path
|
7 | */
|
8 | module.exports = async src => {
|
9 | try {
|
10 | const options = require(src)
|
11 |
|
12 | if (Object.prototype.toString.call(options) !== '[object Object]') {
|
13 | throw new TypeError('template needs to expose an object.')
|
14 | }
|
15 |
|
16 | return options
|
17 | } catch (e) {
|
18 | if (e.code !== 'MODULE_NOT_FOUND' || e.message !== `Cannot find module '${src}'`) {
|
19 | e.message = `This template is invalid: ${e.message}`
|
20 | throw e
|
21 | }
|
22 |
|
23 | // return default template options
|
24 | return {}
|
25 | }
|
26 | }
|