1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | const path = require('path')
|
7 | const exists = require('fs').existsSync
|
8 | const getGitUser = require('./git')
|
9 |
|
10 | module.exports = dir => {
|
11 | const metajs = path.join(dir, 'meta.js')
|
12 | let opts = {}
|
13 |
|
14 | if (exists(metajs)) {
|
15 | const req = require(path.resolve(metajs))
|
16 | if (req !== Object(req)) {
|
17 | throw new Error('meta.js needs to expose an object')
|
18 | }
|
19 | opts = req
|
20 | }
|
21 |
|
22 | const author = getGitUser()
|
23 | if (author) {
|
24 | setDefault(opts, 'author', author)
|
25 | }
|
26 |
|
27 | return opts
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | function setDefault (opts, key, val) {
|
38 | const prompts = opts.prompts || (opts.prompts = {})
|
39 | if (!prompts[key] || typeof prompts[key] !== 'object') {
|
40 | prompts[key] = {
|
41 | 'type': 'string',
|
42 | 'default': val
|
43 | }
|
44 | } else {
|
45 | prompts[key].default = val
|
46 | }
|
47 | }
|