From 45b4cb0fb83f83cef4caac0814cb6c478b3aecda Mon Sep 17 00:00:00 2001 From: Nicolas Gonzalez Date: Thu, 4 Nov 2021 23:41:58 -0300 Subject: [PATCH 1/2] feat: add a prompt to modify users .gitignore (closes netlify#2038) --- src/utils/gitignore.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/utils/gitignore.js b/src/utils/gitignore.js index 3e82ecf3bad..7cf82b091b1 100644 --- a/src/utils/gitignore.js +++ b/src/utils/gitignore.js @@ -1,5 +1,6 @@ const path = require('path') +const inquirer = require('inquirer') const parseIgnore = require('parse-gitignore') const { fileExistsAsync, readFileAsync, writeFileAsync } = require('../lib/fs') @@ -30,8 +31,27 @@ const ensureNetlifyIgnore = async function (dir) { } /* Not ignoring .netlify folder. Add to .gitignore */ if (!ignorePatterns || !ignorePatterns.patterns.some((pattern) => /(^|\/|\\)\.netlify($|\/|\\)/.test(pattern))) { - const newContents = `${gitIgnoreContents}\n${ignoreContent}` - await writeFileAsync(gitIgnorePath, newContents, 'utf8') + const EDIT_GITIGNORE = 'Add local netlify folder to .gitignore' + const LEAVE_GITIGNORE = 'Leave .gitignore as it is' + + const initializeOpts = [EDIT_GITIGNORE, LEAVE_GITIGNORE] + + const { initChoice } = await inquirer.prompt([ + { + type: 'list', + name: 'initChoice', + message: 'Would you like to add .netlify folder to .gitignore?', + choices: initializeOpts, + }, + ]) + // Edit .gitignore o ignore it + if (initChoice === EDIT_GITIGNORE) { + // edit .gitignore\ + const newContents = `${gitIgnoreContents}\n${ignoreContent}` + await writeFileAsync(gitIgnorePath, newContents, 'utf8') + } else if (initChoice === LEAVE_GITIGNORE) { + // leave .gitignore\ + } } } From 7ea5b3f05b75765036590c9b22fad9ca30626e2f Mon Sep 17 00:00:00 2001 From: Nicolas Gonzalez Date: Tue, 7 Dec 2021 16:33:40 -0300 Subject: [PATCH 2/2] feat: add a log message when modifies .gitignore file (closes netlify#2038) --- src/utils/gitignore.js | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/src/utils/gitignore.js b/src/utils/gitignore.js index 7cf82b091b1..947d880d1fe 100644 --- a/src/utils/gitignore.js +++ b/src/utils/gitignore.js @@ -1,10 +1,11 @@ const path = require('path') -const inquirer = require('inquirer') const parseIgnore = require('parse-gitignore') const { fileExistsAsync, readFileAsync, writeFileAsync } = require('../lib/fs') +const { log } = require('./command-helpers') + const hasGitIgnore = async function (dir) { const gitIgnorePath = path.join(dir, '.gitignore') const hasIgnore = await fileExistsAsync(gitIgnorePath) @@ -31,27 +32,10 @@ const ensureNetlifyIgnore = async function (dir) { } /* Not ignoring .netlify folder. Add to .gitignore */ if (!ignorePatterns || !ignorePatterns.patterns.some((pattern) => /(^|\/|\\)\.netlify($|\/|\\)/.test(pattern))) { - const EDIT_GITIGNORE = 'Add local netlify folder to .gitignore' - const LEAVE_GITIGNORE = 'Leave .gitignore as it is' - - const initializeOpts = [EDIT_GITIGNORE, LEAVE_GITIGNORE] - - const { initChoice } = await inquirer.prompt([ - { - type: 'list', - name: 'initChoice', - message: 'Would you like to add .netlify folder to .gitignore?', - choices: initializeOpts, - }, - ]) - // Edit .gitignore o ignore it - if (initChoice === EDIT_GITIGNORE) { - // edit .gitignore\ - const newContents = `${gitIgnoreContents}\n${ignoreContent}` - await writeFileAsync(gitIgnorePath, newContents, 'utf8') - } else if (initChoice === LEAVE_GITIGNORE) { - // leave .gitignore\ - } + log() + log('Adding local .netlify folder to .gitignore file...') + const newContents = `${gitIgnoreContents}\n${ignoreContent}` + await writeFileAsync(gitIgnorePath, newContents, 'utf8') } }