forked from transitive-bullshit/create-react-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget-default-library-params.js
54 lines (43 loc) · 1.4 KB
/
get-default-library-params.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
'use strict'
const getGitConfigPath = require('git-config-path')
const githubUsername = require('github-username')
const parseGitConfig = require('parse-git-config')
const which = require('which')
const config = require('./config')
module.exports = async () => {
const defaults = {
name: '',
description: 'Made with create-react-library',
author: config.get('author'),
repo: (info) => `${info.author}/${info.name}`,
license: config.get('license', 'MIT'),
manager: config.get('manager', 'npm'),
template: config.get('template', 'default')
}
try {
if (!config.get('author')) {
const gitConfigPath = getGitConfigPath('global')
if (gitConfigPath) {
const gitConfig = parseGitConfig.sync({ path: gitConfigPath })
if (gitConfig.github && gitConfig.github.user) {
defaults.author = gitConfig.github.user
} else if (gitConfig.user && gitConfig.user.email) {
defaults.author = await githubUsername(gitConfig.user.email)
}
}
if (defaults.author) {
config.set('author', defaults.author)
}
}
if (!config.get('manager')) {
if (which.sync('yarn', { nothrow: true })) {
defaults.manager = 'yarn'
}
config.set('manager', defaults.manager)
}
if (!config.get('template')) {
config.set('template', defaults.template)
}
} catch (err) {}
return defaults
}