1
0
Fork 0
freesewing/packages/create-freesewing-pattern/lib/get-default-library-params.js

55 lines
1.4 KiB
JavaScript
Raw Normal View History

"use strict";
2018-03-04 15:43:18 -05:00
const getGitConfigPath = require("git-config-path");
const githubUsername = require("github-username");
const parseGitConfig = require("parse-git-config");
const which = require("which");
2018-03-04 15:43:18 -05:00
const config = require("./config");
2018-03-15 23:54:41 -04:00
2018-03-04 15:43:18 -05:00
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"),
template: config.get("template", "freesewing")
};
2018-03-04 15:43:18 -05:00
try {
if (!config.get("author")) {
const gitConfigPath = getGitConfigPath("global");
2018-03-15 23:54:41 -04:00
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;
2018-03-15 23:54:41 -04:00
} else if (gitConfig.user && gitConfig.user.email) {
defaults.author = await githubUsername(gitConfig.user.email);
2018-03-15 23:54:41 -04:00
}
}
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
}
}
if (!config.get("manager")) {
if (which.sync("yarn", { nothrow: true })) {
defaults.manager = "yarn";
2018-03-15 23:54:41 -04:00
}
config.set("manager", defaults.manager);
}
if (!config.get("template")) {
config.set("template", defaults.template);
2018-03-04 15:43:18 -05:00
}
} catch (err) {}
2018-03-04 15:43:18 -05:00
return defaults;
};