1
0
Fork 0

add conf to remember preferred config

This commit is contained in:
Travis Fischer 2018-03-15 23:54:41 -04:00 committed by Joost De Cock
parent e180e34ee5
commit 288d18f616
6 changed files with 59 additions and 13 deletions

View file

@ -0,0 +1,5 @@
'use strict'
const Conf = require('conf')
module.exports = new Conf()

View file

@ -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) { }

View file

@ -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
}

View file

@ -28,6 +28,7 @@
"publish"
],
"dependencies": {
"conf": "^1.4.0",
"consolidate": "^0.15.0",
"cp-file": "^5.0.0",
"execa": "^0.9.0",

View file

@ -10,6 +10,7 @@
"jsnext:main": "dist/index.es.js",
"scripts": {
"test": "CI=1 react-scripts test --env=jsdom",
"test:watch": "react-scripts test --env=jsdom",
"build": "rollup -c",
"start": "rollup -c -w",
"prepare": "{{manager}} run build",

View file

@ -1051,6 +1051,16 @@ concordance@^3.0.0:
semver "^5.3.0"
well-known-symbols "^1.0.0"
conf@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/conf/-/conf-1.4.0.tgz#1ea66c9d7a9b601674a5bb9d2b8dc3c726625e67"
dependencies:
dot-prop "^4.1.0"
env-paths "^1.0.0"
make-dir "^1.0.0"
pkg-up "^2.0.0"
write-file-atomic "^2.3.0"
configstore@^3.0.0:
version "3.1.1"
resolved "https://registry.yarnpkg.com/configstore/-/configstore-3.1.1.tgz#094ee662ab83fad9917678de114faaea8fcdca90"
@ -1338,6 +1348,10 @@ encoding@^0.1.11:
dependencies:
iconv-lite "~0.4.13"
env-paths@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/env-paths/-/env-paths-1.0.0.tgz#4168133b42bb05c38a35b1ae4397c8298ab369e0"
equal-length@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/equal-length/-/equal-length-1.0.1.tgz#21ca112d48ab24b4e1e7ffc0e5339d31fdfc274c"
@ -3436,6 +3450,12 @@ pkg-dir@^2.0.0:
dependencies:
find-up "^2.1.0"
pkg-up@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/pkg-up/-/pkg-up-2.0.0.tgz#c819ac728059a461cab1c3889a2be3c49a004d7f"
dependencies:
find-up "^2.1.0"
plur@^2.0.0, plur@^2.1.2:
version "2.1.2"
resolved "https://registry.yarnpkg.com/plur/-/plur-2.1.2.tgz#7482452c1a0f508e3e344eaec312c91c29dc655a"
@ -4494,7 +4514,7 @@ write-file-atomic@^1.1.4:
imurmurhash "^0.1.4"
slide "^1.1.5"
write-file-atomic@^2.0.0:
write-file-atomic@^2.0.0, write-file-atomic@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.3.0.tgz#1ff61575c2e2a4e8e510d6fa4e243cce183999ab"
dependencies: