2018-03-04 15:43:18 -05:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
const getGitConfigPath = require('git-config-path')
|
|
|
|
const githubUsername = require('github-username')
|
|
|
|
const parseGitConfig = require('parse-git-config')
|
|
|
|
const which = require('which')
|
|
|
|
|
2018-03-15 23:54:41 -04:00
|
|
|
const config = require('./config')
|
|
|
|
|
2018-03-04 15:43:18 -05:00
|
|
|
module.exports = async () => {
|
|
|
|
const defaults = {
|
2018-03-15 23:54:41 -04:00
|
|
|
author: config.get('author'),
|
|
|
|
manager: config.get('manager', 'npm'),
|
|
|
|
license: config.get('license', 'MIT')
|
2018-03-04 15:43:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2018-03-15 23:54:41 -04:00
|
|
|
if (!config.get('author')) {
|
|
|
|
const gitConfigPath = getGitConfigPath('global')
|
|
|
|
|
|
|
|
if (gitConfigPath) {
|
|
|
|
const gitConfig = parseGitConfig.sync({ path: gitConfigPath })
|
2018-03-04 15:43:18 -05:00
|
|
|
|
2018-03-15 23:54:41 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2018-03-04 15:43:18 -05:00
|
|
|
|
2018-03-15 23:54:41 -04:00
|
|
|
if (defaults.author) {
|
|
|
|
config.set('author', defaults.author)
|
2018-03-04 15:43:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-15 23:54:41 -04:00
|
|
|
if (!config.get('manager')) {
|
|
|
|
if (which.sync('yarn', { nothrow: true })) {
|
|
|
|
defaults.manager = 'yarn'
|
|
|
|
}
|
|
|
|
|
|
|
|
config.set('manager', defaults.manager)
|
2018-03-04 15:43:18 -05:00
|
|
|
}
|
|
|
|
} catch (err) { }
|
|
|
|
|
|
|
|
return defaults
|
|
|
|
}
|