Skip to content

Commit

Permalink
feat(gatsby-cli): add GATSBY_EXPERIMENTAL_GATSBY_NEW_FLOW flag to use…
Browse files Browse the repository at this point in the history
… create-gatsby when no options are provided (#27954)

* adjust gatsby new logic to use create-gatsby

* remove unused code

* udpate docs for changed behavior

* add basic test to verify create-gatsby is run

* add flag for the new interactive experience

* remove line break that doesnt need to be added

* add more explicit comment

* update create-gatsby version

Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
  • Loading branch information
gillkyle and gatsbybot committed Nov 13, 2020
1 parent 5fbda3c commit 55821db
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
2 changes: 2 additions & 0 deletions docs/docs/gatsby-cli.md
Expand Up @@ -66,6 +66,8 @@ gatsby new
(Use a different starter)
```
_Note: you can try out the experimental interactive experience from the `create-gatsby` package with the `GATSBY_EXPERIMENTAL_GATSBY_NEW_FLOW=true` flag, which will prompt you with questions about the kind of site you're building, and install the plugins you'll need automatically._
See the [Gatsby starters docs](/docs/gatsby-starters/) for more details.
### `develop`
Expand Down
19 changes: 16 additions & 3 deletions integration-tests/gatsby-cli/__tests__/new.js
Expand Up @@ -28,7 +28,7 @@ describe(`gatsby new`, () => {
await clean(dir)
})

it(`a default starter creates a gatsby site`, () => {
it(`creates a gatsby site with the default starter`, () => {
const [code, logs] = GatsbyCLI.from(cwd).invoke([`new`, `gatsby-default`])

logs.should.contain(
Expand All @@ -45,7 +45,7 @@ describe(`gatsby new`, () => {
expect(code).toBe(0)
})

it(`a theme starter creates a gatsby site`, () => {
it(`creates a gatsby site with the blog starter`, () => {
const [code, logs] = GatsbyCLI.from(cwd).invoke([
`new`,
`gatsby-blog`,
Expand All @@ -66,7 +66,7 @@ describe(`gatsby new`, () => {
expect(code).toBe(0)
})

it(`an invalid starter fails to create a gatsby site`, () => {
it(`fails to create a gatsby site with an invalid starter`, () => {
const [code, logs] = GatsbyCLI.from(cwd).invoke([
`new`,
`gatsby-invalid`,
Expand All @@ -78,4 +78,17 @@ describe(`gatsby new`, () => {

expect(code).toBe(1)
})

it(`runs the prompted starter selection process when no arguments are passed`, () => {
const [_, logs] = GatsbyCLI.from(cwd).invoke([`new`])

logs.should.contain(`What is your project called?`)
})

it(`runs create-gatsby when no arguments are provided to gatsby new with the GATSBY_EXPERIMENTAL_GATSBY_NEW_FLOW flag set`, () => {
process.env.GATSBY_EXPERIMENTAL_GATSBY_NEW_FLOW = true // when this flag is removed we can remove this line
const [_, logs] = GatsbyCLI.from(cwd).invoke([`new`])

logs.should.contain(`Welcome to Gatsby!`)
})
})
1 change: 1 addition & 0 deletions packages/gatsby-cli/package.json
Expand Up @@ -19,6 +19,7 @@
"common-tags": "^1.8.0",
"configstore": "^5.0.1",
"convert-hrtime": "^3.0.0",
"create-gatsby": "^0.0.0-9",
"envinfo": "^7.7.3",
"execa": "^3.4.0",
"fs-exists-cached": "^1.0.0",
Expand Down
20 changes: 15 additions & 5 deletions packages/gatsby-cli/src/create-cli.ts
@@ -1,9 +1,6 @@
import path from "path"
import resolveCwd from "resolve-cwd"
import yargs from "yargs"
import report from "./reporter"
import { setStore } from "./reporter/redux"
import { getLocalGatsbyVersion } from "./util/version"
import envinfo from "envinfo"
import { sync as existsSync } from "fs-exists-cached"
import clipboardy from "clipboardy"
Expand All @@ -13,9 +10,13 @@ import {
setTelemetryEnabled,
isTrackingEnabled,
} from "gatsby-telemetry"
import { startGraphQLServer } from "gatsby-recipes"
import { run as runCreateGatsby } from "create-gatsby"
import report from "./reporter"
import { setStore } from "./reporter/redux"
import { getLocalGatsbyVersion } from "./util/version"
import { initStarter } from "./init-starter"
import { recipesHandler } from "./recipes"
import { startGraphQLServer } from "gatsby-recipes"
import { getPackageManager, setPackageManager } from "./util/package-manager"
import reporter from "./reporter"

Expand Down Expand Up @@ -502,7 +503,16 @@ export const createCli = (argv: Array<string>): yargs.Arguments => {
const starterStr = starter ? String(starter) : undefined
const rootPathStr = rootPath ? String(rootPath) : undefined

await initStarter(starterStr, rootPathStr)
// We only run the interactive CLI when there are no arguments passed in
if (
process.env.GATSBY_EXPERIMENTAL_GATSBY_NEW_FLOW &&
!starterStr &&
!rootPathStr
) {
await runCreateGatsby()
} else {
await initStarter(starterStr, rootPathStr)
}
}),
})
.command({
Expand Down

0 comments on commit 55821db

Please sign in to comment.