From 912c602c9022ebcfd84f66ffce96ab814f424cd7 Mon Sep 17 00:00:00 2001 From: Franck Date: Sat, 8 Jun 2019 20:40:47 +0200 Subject: [PATCH] :sparkles: Add log infos during process --- package-lock.json | 141 ++++++++++++++++++++++++++++++++++++++++++++- package.json | 2 + src/cli.js | 31 +++++++++- src/utils/index.js | 18 +++++- 4 files changed, 187 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 19ee847..f87f235 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "readme-md-generator", - "version": "0.1.0", + "version": "0.1.3", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -30,6 +30,26 @@ "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.4.0.tgz", "integrity": "sha512-aUjdRFISbuFOl0EIZc+9e4FfZp0bDZgAdOOf30bJmw8VM9v84SHyVyxDfbWxpGYbdZD/9XoKxfHVNmxPkhwyGw==" }, + "ansi-align": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/ansi-align/-/ansi-align-3.0.0.tgz", + "integrity": "sha512-ZpClVKqXN3RGBmKibdfWzqCY4lnjEuoNzU5T0oEFpfd/z5qJHVarukridD4juLO2FXMiwUQxr9WqQtaYa8XRYw==", + "requires": { + "string-width": "^3.0.0" + }, + "dependencies": { + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + } + } + }, "ansi-escapes": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.2.0.tgz", @@ -117,6 +137,38 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, + "boxen": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/boxen/-/boxen-4.0.0.tgz", + "integrity": "sha512-gBklgJ9hxaEG8AvEq6JmHns0qQh7JS0uRQtpk4r0OW9AJFKfvP0PVoltH0xzZt/OIio2Iy48xkiV3OaIun7GUw==", + "requires": { + "ansi-align": "^3.0.0", + "camelcase": "^5.3.1", + "chalk": "^2.4.2", + "cli-boxes": "^2.2.0", + "string-width": "^3.1.0", + "term-size": "^2.1.0", + "type-fest": "^0.5.2", + "widest-line": "^3.1.0" + }, + "dependencies": { + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "type-fest": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.5.2.tgz", + "integrity": "sha512-DWkS49EQKVX//Tbupb9TFa19c7+MK1XmzkrZUR8TAktmE/DizXoaoJV6TZ/tSIPXipqNiRI6CyAe7x69Jb6RSw==" + } + } + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -164,6 +216,11 @@ "resolved": "https://registry.npmjs.org/circular-json/-/circular-json-0.3.3.tgz", "integrity": "sha512-UZK3NBx2Mca+b5LsG7bY183pHWt5Y1xts4P3Pz7ENTwGVnJOUWbRb3ocjvX7hx9tq/yTAdclXm9sZ38gNuem4A==" }, + "cli-boxes": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/cli-boxes/-/cli-boxes-2.2.0.tgz", + "integrity": "sha512-gpaBrMAizVEANOpfZp/EEUixTXDyGt7DFzdK5hU+UbWt/J0lB0w20ncZj59Z9a93xHb9u12zF5BS6i9RKbtg4w==" + }, "cli-cursor": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-2.1.0.tgz", @@ -172,6 +229,11 @@ "restore-cursor": "^2.0.0" } }, + "cli-spinners": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.1.0.tgz", + "integrity": "sha512-8B00fJOEh1HPrx4fo5eW16XmE1PcL1tGpGrxy63CXGP9nHdPBN63X75hA1zhvQuhVztJWLqV58Roj2qlNM7cAA==" + }, "cli-width": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", @@ -199,6 +261,11 @@ } } }, + "clone": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", + "integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=" + }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -257,6 +324,14 @@ "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", "integrity": "sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ=" }, + "defaults": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz", + "integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=", + "requires": { + "clone": "^1.0.2" + } + }, "define-properties": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", @@ -962,6 +1037,14 @@ "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.11.tgz", "integrity": "sha512-cQKh8igo5QUhZ7lg38DYWAxMvjSAKG0A8wGSVimP07SIUEK2UO+arSRKbRZWtelMtN5V0Hkwh5ryOto/SshYIg==" }, + "log-symbols": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-2.2.0.tgz", + "integrity": "sha512-VeIAFslyIerEJLXHziedo2basKbMKtTw3vfn5IzG0XTjhAVEJyNHnL2p7vc+wBDSdQuUpNw3M2u6xb9QsAY5Eg==", + "requires": { + "chalk": "^2.0.1" + } + }, "map-age-cleaner": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/map-age-cleaner/-/map-age-cleaner-0.1.3.tgz", @@ -1113,6 +1196,19 @@ "wordwrap": "~1.0.0" } }, + "ora": { + "version": "3.4.0", + "resolved": "https://registry.npmjs.org/ora/-/ora-3.4.0.tgz", + "integrity": "sha512-eNwHudNbO1folBP3JsZ19v9azXWtQZjICdr3Q0TDPIaeBQ3mXLrh54wM+er0+hSp+dWKf+Z8KM58CYzEyIYxYg==", + "requires": { + "chalk": "^2.4.2", + "cli-cursor": "^2.1.0", + "cli-spinners": "^2.0.0", + "log-symbols": "^2.2.0", + "strip-ansi": "^5.2.0", + "wcwidth": "^1.0.1" + } + }, "os-locale": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/os-locale/-/os-locale-3.1.0.tgz", @@ -1557,6 +1653,11 @@ "string-width": "^2.1.1" } }, + "term-size": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/term-size/-/term-size-2.1.0.tgz", + "integrity": "sha512-I42EWhJ+2aeNQawGx1VtpO0DFI9YcfuvAMNIdKyf/6sRbHJ4P+ZQ/zIT87tE+ln1ymAGcCJds4dolfSAS0AcNg==" + }, "text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -1610,6 +1711,14 @@ "spdx-expression-parse": "^3.0.0" } }, + "wcwidth": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", + "integrity": "sha1-8LDc+RW8X/FSivrbLA4XtTLaL+g=", + "requires": { + "defaults": "^1.0.3" + } + }, "which": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", @@ -1623,6 +1732,36 @@ "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" }, + "widest-line": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/widest-line/-/widest-line-3.1.0.tgz", + "integrity": "sha512-NsmoXalsWVDMGupxZ5R08ka9flZjjiLvHVAWYOKtiKM8ujtZWr9cRffak+uSE48+Ob8ObalXpwyeUiyDD6QFgg==", + "requires": { + "string-width": "^4.0.0" + }, + "dependencies": { + "emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==" + }, + "string-width": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.1.0.tgz", + "integrity": "sha512-NrX+1dVVh+6Y9dnQ19pR0pP4FiEIlUvdTGn8pw6CKTNq5sgib2nIhmUNT5TAmhWmvKr3WcxBcP3E8nWezuipuQ==", + "requires": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^5.2.0" + } + } + } + }, "wordwrap": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", diff --git a/package.json b/package.json index 5683008..f3eb5cc 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "readme": "src/index.js" }, "dependencies": { + "boxen": "^4.0.0", "date-fns": "^1.30.1", "ejs": "^2.6.1", "eslint": "^5.3.0", @@ -15,6 +16,7 @@ "inquirer": "^6.3.1", "load-json-file": "^6.0.0", "lodash": "^4.17.11", + "ora": "^3.4.0", "prettier": "^1.17.1", "project-name": "^1.0.0", "yargs": "^13.2.4" diff --git a/src/cli.js b/src/cli.js index d8e9915..4cb799c 100644 --- a/src/cli.js +++ b/src/cli.js @@ -3,6 +3,7 @@ const path = require('path') const inquirer = require('inquirer') const { isNil } = require('lodash') const getYear = require('date-fns/get_year') +const boxen = require('boxen') const { getProjectInfos } = require('./utils') const { getTemplate, createReadme } = require('./utils') @@ -23,8 +24,7 @@ const { /** * Ask user questions and return context to generate a README */ -const askQuestions = async () => { - const projectInfos = await getProjectInfos() +const askQuestions = async projectInfos => { let answersContext = { isGithubRepos: projectInfos.isGithubRepos, repositoryUrl: projectInfos.repositoryUrl, @@ -60,13 +60,36 @@ const askQuestions = async () => { return answersContext } +/** + * Display end message + */ +const displayEndMessage = () => { + process.stdout.write( + boxen( + ` +README.md was successfully generated. +Thanks for using readme-md-generator ! +`, + { + padding: 1, + margin: { top: 2, bottom: 3 }, + borderColor: 'cyan', + align: 'center', + borderStyle: 'double' + } + ) + ) +} + module.exports = async args => { const templatePath = path.resolve( __dirname, `../templates/${args.template}.md` ) + const template = await getTemplate(templatePath) - const context = await askQuestions() + const projectInfos = await getProjectInfos() + const context = await askQuestions(projectInfos) const currentYear = getYear(new Date()) const readmeContent = ejs.render(template, { @@ -76,4 +99,6 @@ module.exports = async args => { }) await createReadme(readmeContent) + + displayEndMessage() } diff --git a/src/utils/index.js b/src/utils/index.js index 3a96e2c..e140a34 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -6,6 +6,7 @@ const get = require('lodash/get') const isNil = require('lodash/isNil') const exec = util.promisify(require('child_process').exec) const getProjectName = require('project-name') +const ora = require('ora') const GITHUB_URL = 'https://github.com/' @@ -33,7 +34,18 @@ const createReadme = async readmeContent => * * @param {string} templatePath */ -const getTemplate = async templatePath => await readFile(templatePath, 'utf8') +const getTemplate = async templatePath => { + const spinner = ora('Loading README template').start() + + try { + const template = await readFile(templatePath, 'utf8') + spinner.succeed('README template loaded') + return template + } catch (err) { + spinner.fail('README template loading fail') + throw err + } +} /** * Get package.json content @@ -119,6 +131,8 @@ const getLicenseUrlFromGithubRepositoryUrl = repositoryUrl => * Get project informations from git and package.json */ const getProjectInfos = async () => { + const spinner = ora('Gathering project infos').start() + const packageJson = await getPackageJson() const name = getProjectName() || undefined const description = get(packageJson, 'description', undefined) @@ -137,6 +151,8 @@ const getProjectInfos = async () => { ? getLicenseUrlFromGithubRepositoryUrl(repositoryUrl) : undefined + spinner.succeed('Project infos gathered') + return { name, description,