add conf to remember preferred config
This commit is contained in:
parent
e180e34ee5
commit
288d18f616
6 changed files with 59 additions and 13 deletions
5
packages/create-freesewing-pattern/lib/config.js
Normal file
5
packages/create-freesewing-pattern/lib/config.js
Normal file
|
@ -0,0 +1,5 @@
|
|||
'use strict'
|
||||
|
||||
const Conf = require('conf')
|
||||
|
||||
module.exports = new Conf()
|
|
@ -5,27 +5,40 @@ const githubUsername = require('github-username')
|
|||
const parseGitConfig = require('parse-git-config')
|
||||
const which = require('which')
|
||||
|
||||
const config = require('./config')
|
||||
|
||||
module.exports = async () => {
|
||||
const defaults = {
|
||||
author: undefined,
|
||||
manager: 'npm'
|
||||
author: config.get('author'),
|
||||
manager: config.get('manager', 'npm'),
|
||||
license: config.get('license', 'MIT')
|
||||
}
|
||||
|
||||
try {
|
||||
const gitConfigPath = getGitConfigPath('global')
|
||||
if (!config.get('author')) {
|
||||
const gitConfigPath = getGitConfigPath('global')
|
||||
|
||||
if (gitConfigPath) {
|
||||
const gitConfig = parseGitConfig.sync({ path: gitConfigPath })
|
||||
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 (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 (which.sync('yarn', { nothrow: true })) {
|
||||
defaults.manager = 'yarn'
|
||||
if (!config.get('manager')) {
|
||||
if (which.sync('yarn', { nothrow: true })) {
|
||||
defaults.manager = 'yarn'
|
||||
}
|
||||
|
||||
config.set('manager', defaults.manager)
|
||||
}
|
||||
} catch (err) { }
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
const inquirer = require('inquirer')
|
||||
const isValidNpmName = require('is-valid-npm-name')
|
||||
|
||||
const config = require('./config')
|
||||
|
||||
module.exports = async (defaults) => {
|
||||
const info = await inquirer.prompt([
|
||||
{
|
||||
|
@ -35,7 +37,7 @@ module.exports = async (defaults) => {
|
|||
type: 'input',
|
||||
name: 'license',
|
||||
message: 'License',
|
||||
default: 'MIT'
|
||||
default: defaults.license
|
||||
},
|
||||
{
|
||||
type: 'list',
|
||||
|
@ -46,5 +48,9 @@ module.exports = async (defaults) => {
|
|||
}
|
||||
])
|
||||
|
||||
config.set('author', info.author)
|
||||
config.set('manager', info.manager)
|
||||
config.set('license', info.license)
|
||||
|
||||
return info
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue