diff --git a/src/cli.js b/src/cli.js index 796df0e..164958c 100644 --- a/src/cli.js +++ b/src/cli.js @@ -2,7 +2,7 @@ const ejs = require('ejs') const path = require('path') const inquirer = require('inquirer') const getYear = require('date-fns/get_year') -const { getPackageJson } = require('./utils') +const { getProjectInfos } = require('./utils') const { getTemplate, createReadme } = require('./utils') const { @@ -19,16 +19,16 @@ const { * Ask user questions and return context to generate a README */ const askQuestions = async () => { - const packageJson = await getPackageJson() + const projectInfos = await getProjectInfos() const questions = [ - askProjectName(), - askProjectDescription(packageJson), - askAuhtorName(packageJson), + askProjectName(projectInfos), + askProjectDescription(projectInfos), + askAuhtorName(projectInfos), askAuhtorGithub(), askAuhtorTwitter(), - askLicenseUrl(), - await askContributing(packageJson) + askLicenseUrl(projectInfos), + askContributing(projectInfos) ] return inquirer.prompt(questions) diff --git a/src/questions/author-name.js b/src/questions/author-name.js index d4b7ae7..26fcd1f 100644 --- a/src/questions/author-name.js +++ b/src/questions/author-name.js @@ -1,8 +1,6 @@ -const get = require('lodash/get') - -module.exports = packageJson => ({ +module.exports = projectInfos => ({ type: 'input', message: 'Enter your name', name: 'authorName', - default: get(packageJson, 'author', undefined) + default: projectInfos.author }) diff --git a/src/questions/contributing.js b/src/questions/contributing.js index 8455645..80505b1 100644 --- a/src/questions/contributing.js +++ b/src/questions/contributing.js @@ -1,8 +1,6 @@ -const { getReposIssuesUrl } = require('../utils') - -module.exports = async packageJson => ({ +module.exports = packageJson => ({ type: 'input', message: 'Enter the url of your issues (use empty value to skip)', name: 'contributingUrl', - default: await getReposIssuesUrl(packageJson) + default: packageJson.contributingUrl }) diff --git a/src/questions/project-description.js b/src/questions/project-description.js index ff88a21..78ff7a4 100644 --- a/src/questions/project-description.js +++ b/src/questions/project-description.js @@ -1,8 +1,6 @@ -const get = require('lodash/get') - -module.exports = packageJson => ({ +module.exports = projectInfos => ({ type: 'input', message: 'Enter your project description', name: 'projectDescription', - default: get(packageJson, 'description', undefined) + default: projectInfos.description }) diff --git a/src/questions/project-name.js b/src/questions/project-name.js index abb3a4c..206304d 100644 --- a/src/questions/project-name.js +++ b/src/questions/project-name.js @@ -1,8 +1,6 @@ -const getProjectName = require('project-name') - -module.exports = () => ({ +module.exports = projectInfos => ({ type: 'input', message: 'Enter your project name', name: 'projectName', - default: getProjectName() || undefined + default: projectInfos.name }) diff --git a/src/utils/index.js b/src/utils/index.js index 6477450..7f2dcd1 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -5,6 +5,7 @@ const loadJsonFile = require('load-json-file') const get = require('lodash/get') const isNil = require('lodash/isNil') const exec = util.promisify(require('child_process').exec) +const getProjectName = require('project-name') /** * Clean repository url by removing '.git' and 'git+' @@ -12,7 +13,10 @@ const exec = util.promisify(require('child_process').exec) * @param {string} cleanReposUrl */ const cleanReposUrl = reposUrl => { - return reposUrl.replace('git+', '').replace('.git', '') + return reposUrl + .replace('\n', '') + .replace('git+', '') + .replace('.git', '') } /** @@ -93,12 +97,25 @@ const getReposIssuesUrl = async packageJson => { return reposIssuesUrl } +const getProjectInfos = async () => { + const packageJson = await getPackageJson() + const name = getProjectName() || undefined + const description = get(packageJson, 'description', undefined) + const author = get(packageJson, 'author', undefined) + const repositoryUrl = await getReposUrl(packageJson) + const contributingUrl = await getReposIssuesUrl(packageJson) + + return { + name, + description, + author, + repositoryUrl, + contributingUrl + } +} + module.exports = { - getPackageJson, getTemplate, createReadme, - getReposUrlFromPackageJson, - getReposUrlFromGit, - getReposUrl, - getReposIssuesUrl + getProjectInfos } diff --git a/templates/default.md b/templates/default.md index 41a558d..5166d70 100644 --- a/templates/default.md +++ b/templates/default.md @@ -46,7 +46,7 @@ Contributions, issues and feature requests are welcome. Feel free to check [issu Please ⭐️ this repository if you like it. <% if (licenseUrl) { -%> -## License +## License <% if (authorName && authorGithubUsername) { -%> Copyright © <%= currentYear %> [<%= authorName %>](https://github.com/<%= authorGithubUsername %>).