better CLI usage
This commit is contained in:
parent
de7c5a1acf
commit
740062db7c
7 changed files with 151 additions and 165 deletions
|
@ -0,0 +1,49 @@
|
|||
'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: '',
|
||||
author: config.get('author'),
|
||||
repo: (info) => `${info.author}/${info.name}`,
|
||||
license: config.get('license', 'MIT'),
|
||||
manager: config.get('manager', 'npm')
|
||||
}
|
||||
|
||||
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 || 'npm')
|
||||
}
|
||||
} catch (err) { }
|
||||
|
||||
return defaults
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue