2019-05-02 12:40:03 +02:00
|
|
|
"use strict";
|
2018-03-04 15:43:18 -05:00
|
|
|
|
2019-05-02 12:40:03 +02: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
|
|
|
|
2019-05-02 12:40:03 +02: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 = {
|
2019-05-02 12:40:03 +02:00
|
|
|
name: "",
|
|
|
|
description: "",
|
|
|
|
author: config.get("author"),
|
|
|
|
repo: info => `${info.author}/${info.name}`,
|
|
|
|
license: config.get("license", "MIT"),
|
|
|
|
manager: config.get("manager", "npm"),
|
2021-05-22 17:58:52 +02:00
|
|
|
template: config.get("template", "freesewing")
|
2019-05-02 12:40:03 +02:00
|
|
|
};
|
2018-03-04 15:43:18 -05:00
|
|
|
|
|
|
|
try {
|
2019-05-02 12:40:03 +02:00
|
|
|
if (!config.get("author")) {
|
|
|
|
const gitConfigPath = getGitConfigPath("global");
|
2018-03-15 23:54:41 -04:00
|
|
|
|
|
|
|
if (gitConfigPath) {
|
2019-05-02 12:40:03 +02:00
|
|
|
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) {
|
2019-05-02 12:40:03 +02:00
|
|
|
defaults.author = gitConfig.github.user;
|
2018-03-15 23:54:41 -04:00
|
|
|
} else if (gitConfig.user && gitConfig.user.email) {
|
2019-05-02 12:40:03 +02:00
|
|
|
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) {
|
2019-05-02 12:40:03 +02:00
|
|
|
config.set("author", defaults.author);
|
2018-03-04 15:43:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-02 12:40:03 +02:00
|
|
|
if (!config.get("manager")) {
|
|
|
|
if (which.sync("yarn", { nothrow: true })) {
|
|
|
|
defaults.manager = "yarn";
|
2018-03-15 23:54:41 -04:00
|
|
|
}
|
|
|
|
|
2019-05-02 12:40:03 +02:00
|
|
|
config.set("manager", defaults.manager);
|
2018-07-11 12:27:58 -04:00
|
|
|
}
|
|
|
|
|
2019-05-02 12:40:03 +02:00
|
|
|
if (!config.get("template")) {
|
|
|
|
config.set("template", defaults.template);
|
2018-03-04 15:43:18 -05:00
|
|
|
}
|
2019-05-02 12:40:03 +02:00
|
|
|
} catch (err) {}
|
2018-03-04 15:43:18 -05:00
|
|
|
|
2019-05-02 12:40:03 +02:00
|
|
|
return defaults;
|
|
|
|
};
|