Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-cli): Add success message after installing gatsby #17241

Merged
merged 8 commits into from
Sep 24, 2019

Conversation

anamritraj
Copy link
Contributor

Description

Show custom message when a user does npm install gatsby-cli to install gatsby-cli.

Adds a nice looking success message and point users to the Gatsby documentation website.
Also, shows the commands available to the cli users (default help prompt).

Screenshot from 2019-08-30 15-55-48

Related Issues

Fixes #13511

@anamritraj anamritraj requested a review from a team as a code owner August 30, 2019 10:26
@anamritraj
Copy link
Contributor Author

Apparently I was only cleaning up the gatsby-cli/node_modules folder after each install, and not gatsby-cli/lib folder. And that is the reason it worked in my local.

I don't want to hardcode all the stuff from cli help into postinstall.js.

I tried importing the gatsby-cli/src/create-cli file, but that has some import statements (in one of the imported files) which node doesn't like.

Any help?

@lannonbr lannonbr changed the title Add success message after installing gastsby-cli. feat(gatsby-cli): Add success message after installing gastsby-cli. Aug 30, 2019
@lannonbr lannonbr added the topic: cli Related to the Gatsby CLI label Aug 30, 2019
@pieh
Copy link
Contributor

pieh commented Sep 2, 2019

Hmm, kind of chicken and egg problem here. We don't really want to run this script when installing dependencies in our monorepo or when building gatsby-cli package - but rather when user installs it (and also when user explicitely installs gatsby-cli, and not when it's installed together with gatsby as dependency) - not sure if we can distinguish those things

@pieh
Copy link
Contributor

pieh commented Sep 2, 2019

Also few notes:

  • please don't hardcode color formatting with their codes - let's use chalk (which is already dependency of gatsby-cli) - it will also handle case when user doesn't want to see colors (FORCE_COLOR env var) or terminal doesn't support them
  • we will need to add scripts dir to package.json -> files to make sure that post install script is packaged when publishing to npm registry

@sidharthachatterjee sidharthachatterjee added the status: awaiting author response Additional information has been requested from the author label Sep 2, 2019
@wardpeet
Copy link
Contributor

wardpeet commented Sep 3, 2019

One benefit here is that yarn doesn't show postinstall logs of dependant packages 😛. Npm does so we still have to find a workaround for this.

@pieh
Copy link
Contributor

pieh commented Sep 3, 2019

One benefit here is that yarn doesn't show postinstall logs of dependant packages 😛. Npm does so we still have to find a workaround for this.

I was just testing, and yarn doesn't output things even if you directly install package with postInstall script (it doesn't seem to be related to package not being direct dependency). One way to make it output is for postInstall script to return non-zero exit code, but then it would look like this:

➜  throw yarn
yarn install v1.17.3
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
error /Users/misiek/test/throw/node_modules/@pieh/package-c: Command failed.
Exit code: 1
Command: node hello.js
Arguments:
Directory: /Users/misiek/test/throw/node_modules/@pieh/package-c
Output:
hello

I'm thinking what we could do is in install script we could import from lib and wrap everything in try/catch so it fails silently - this way we can at least show message for npm users - but worth checking how things would look like when npx gatsby <command> is used (we probably don't want to show welcome message in that case?)

@anamritraj
Copy link
Contributor Author

Hmm, kind of chicken and egg problem here. We don't really want to run this script when installing dependencies in our monorepo or when building gatsby-cli package - but rather when user installs it (and also when user explicitely installs gatsby-cli, and not when it's installed together with gatsby as dependency) - not sure if we can distinguish those things.

@pieh Is there maybe an environment variable which we can use when we are installing things in the monorepo or when building the gatsby-cli package?

  • please don't hardcode color formatting with their codes - let's use chalk (which is already dependency of gatsby-cli) - it will also handle case when user doesn't want to see colors
  • (FORCE_COLOR env var) or terminal doesn't support them
    we will need to add scripts dir to package.json -> files to make sure that post install script is packaged when publishing to npm registry

I will make these changes. Thank you for the suggestions!

I'm thinking what we could do is in install script we could import from lib and wrap everything in try/catch so it fails silently - this way we can at least show message for npm users - but worth checking how things would look like when npx gatsby is used (we probably don't want to show welcome message in that case?)

Let me try this and a couple of ideas that I have in mind and get back to you guys. Thanks a lot for all the suggestions and comments.

Cheers!

@anamritraj
Copy link
Contributor Author

Can anyone please help me out here. I am not sure why the tests are failing. Seems like some dependencies are missing.

Did I break it in my changes? I don't think I touched any of the dependencies in package.json. 🤒

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I tested all platforms and only npm show it while installing it globally and regularly. I feel like we can move forward with this. A local npm install is a bit unfortunate but 🤷‍♂.

npm install -g
image

Yarn global install
image

npx gatsby-cli
image

Regular npm install
image

regular yarn install
image

I've added a few comments about the postinstall code.

packages/gatsby-cli/package.json Outdated Show resolved Hide resolved
packages/gatsby-cli/package.json Outdated Show resolved Hide resolved
@wardpeet
Copy link
Contributor

wardpeet commented Sep 24, 2019

Regular npm install on a project doesn't show anything which is 👌

npm install gatsby@cli-postinstall

image

npm install -g gatsby-cli@cli-postinstall

image

yarn add gatsby@cli-postinstall

image

yarn global add gatsby-cli@cli-postinstall

image

npx gatsby-cli@cli-postinstall

image

@wardpeet wardpeet removed the status: awaiting author response Additional information has been requested from the author label Sep 24, 2019
@LekoArts LekoArts changed the title feat(gatsby-cli): Add success message after installing gastsby-cli. feat(gatsby-cli): Add success message after installing gatsby-cli Sep 24, 2019
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me ;)

@wardpeet wardpeet changed the title feat(gatsby-cli): Add success message after installing gatsby-cli feat(gatsby-cli): Add success message after installing gatsby Sep 24, 2019
@wardpeet wardpeet merged commit 073e1a0 into gatsbyjs:master Sep 24, 2019
@gatsbot
Copy link

gatsbot bot commented Sep 24, 2019

Holy buckets, @anamritraj — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. We’ve got Gatsby t-shirts, stickers, hats, scrunchies, and much more. (You can also unlock even more free swag with 5 contributions — wink wink nudge nudge.) See gatsby.dev/swag for details.
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@wardpeet
Copy link
Contributor

Published in gatsby-cli@2.7.50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: cli Related to the Gatsby CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Welcome message in the Gatsby CLI
5 participants