From 44d2f187602154fb75c7247e63514b42ecfe0ea4 Mon Sep 17 00:00:00 2001 From: Philippe Serhal Date: Wed, 30 Apr 2025 13:07:46 -0400 Subject: [PATCH 1/2] refactor: simplify and type-check postinstall script --- scripts/postinstall.js | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/scripts/postinstall.js b/scripts/postinstall.js index 5121f48f31a..a926f542856 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -12,25 +12,6 @@ import chalk from 'chalk' const __dirname = path.dirname(fileURLToPath(import.meta.url)) -const identity = (message) => message - -/** - * - * @param {string} message - * @param {Array} styles - * @returns - */ -const format = (message, styles) => { - let func = identity - try { - func = chalk - styles.forEach((style) => { - func = func[style] - }) - } catch {} - return func(message) -} - const postInstall = async () => { const { createMainCommand } = await import('../dist/commands/index.js') const { generateAutocompletion } = await import('../dist/lib/completion/index.js') @@ -45,24 +26,21 @@ const postInstall = async () => { } console.log('') - console.log(await format('Success! Netlify CLI has been installed!', ['greenBright', 'bold', 'underline'])) + console.log(chalk.greenBright.bold.underline('Success! Netlify CLI has been installed!')) console.log('') console.log('Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.') console.log('') console.log('Next steps:') console.log('') console.log( - ` ${await format('netlify init', [ - 'cyanBright', - 'bold', - ])} Connect or create a Netlify site from current directory`, + ` ${chalk.cyanBright.bold('netlify init')} Connect or create a Netlify site from current directory`, ) console.log( - ` ${await format('netlify deploy', ['cyanBright', 'bold'])} Deploy the latest changes to your Netlify site`, + ` ${chalk.cyanBright.bold('netlify deploy')} Deploy the latest changes to your Netlify site`, ) console.log('') - console.log(`For more information on the CLI run ${await format('netlify help', ['cyanBright', 'bold'])}`) - console.log(`Or visit the docs at ${await format('https://cli.netlify.com', ['cyanBright', 'bold'])}`) + console.log(`For more information on the CLI run ${chalk.cyanBright.bold('netlify help')}`) + console.log(`Or visit the docs at ${chalk.cyanBright.bold('https://cli.netlify.com')}`) console.log('') } @@ -73,7 +51,7 @@ const main = async () => { try { await fs.stat(path.resolve(__dirname, '../.git')) } catch (err) { - if (err.code === 'ENOENT') { + if (err instanceof Error && 'code' in err && err.code === 'ENOENT') { isEndUserInstall = true } } From 7f271166bcc56c70fe71debbb15bd7983654a9a6 Mon Sep 17 00:00:00 2001 From: Philippe Serhal Date: Thu, 1 May 2025 07:47:41 -0400 Subject: [PATCH 2/2] fix: polish postinstall script - Use a pretty cyan box with the Netlify diamond icon - Mention `ntl login` as a likely first step - Link to better CLI entrypoint URL - Link to main Netlify docs --- bin/run.js | 1 + scripts/postinstall.js | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/bin/run.js b/bin/run.js index c0f75c7962b..58fced931fc 100755 --- a/bin/run.js +++ b/bin/run.js @@ -14,6 +14,7 @@ const UPDATE_BOXEN_OPTIONS = { borderStyle: 'round', borderColor: NETLIFY_CYAN_HEX, float: 'center', + // This is an intentional half-width space to work around a unicode padding math bug in boxen title: '⬥ ', titleAlignment: 'center', } diff --git a/scripts/postinstall.js b/scripts/postinstall.js index a926f542856..6353bef33cd 100644 --- a/scripts/postinstall.js +++ b/scripts/postinstall.js @@ -9,9 +9,12 @@ import { fileURLToPath } from 'node:url' import process from 'node:process' // eslint-disable-next-line no-restricted-imports import chalk from 'chalk' +import boxen from 'boxen' const __dirname = path.dirname(fileURLToPath(import.meta.url)) +const NETLIFY_CYAN_HEX = '#28b5ac' + const postInstall = async () => { const { createMainCommand } = await import('../dist/commands/index.js') const { generateAutocompletion } = await import('../dist/lib/completion/index.js') @@ -25,22 +28,37 @@ const postInstall = async () => { generateAutocompletion(program) } - console.log('') - console.log(chalk.greenBright.bold.underline('Success! Netlify CLI has been installed!')) - console.log('') - console.log('Your device is now configured to use Netlify CLI to deploy and manage your Netlify sites.') - console.log('') - console.log('Next steps:') console.log('') console.log( - ` ${chalk.cyanBright.bold('netlify init')} Connect or create a Netlify site from current directory`, + boxen( + `Success! Netlify CLI has been installed! + + You can now use Netlify CLI to develop, deploy, and manage your Netlify sites. + + 🚀 Now get building!`, + { + padding: 1, + margin: 1, + textAlignment: 'center', + borderStyle: 'round', + borderColor: NETLIFY_CYAN_HEX, + // This is an intentional half-width space to work around a unicode padding math bug in boxen + title: '⬥ ', + titleAlignment: 'center', + }, + ), ) + console.log('Next steps:') + console.log(` ${chalk.cyanBright.bold('netlify login')} Log in to your Netlify account`) console.log( - ` ${chalk.cyanBright.bold('netlify deploy')} Deploy the latest changes to your Netlify site`, + ` ${chalk.cyanBright.bold('netlify init')} Connect or create a Netlify site from the current directory`, ) + console.log(` ${chalk.cyanBright.bold('netlify deploy')} Deploy the latest changes to your Netlify site`) + console.log(` ${chalk.cyanBright.bold('netlify help')} Find out what else you can do 👀`) + console.log('') + console.log(`For more help with the CLI, visit ${chalk.cyanBright.bold('https://developers.netlify.com/cli')}`) console.log('') - console.log(`For more information on the CLI run ${chalk.cyanBright.bold('netlify help')}`) - console.log(`Or visit the docs at ${chalk.cyanBright.bold('https://cli.netlify.com')}`) + console.log(`For help with Netlify, visit ${chalk.cyanBright.bold('https://docs.netlify.com')}`) console.log('') }