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 GATSBY_EXPERIMENTAL_GATSBY_NEW_FLOW flag to use create-gatsby when no options are provided #27954

Merged
merged 12 commits into from Nov 13, 2020
Merged
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-6",
"envinfo": "^7.7.3",
"execa": "^3.4.0",
"fs-exists-cached": "^1.0.0",
Expand Down
19 changes: 14 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,15 @@ export const createCli = (argv: Array<string>): yargs.Arguments => {
const starterStr = starter ? String(starter) : undefined
const rootPathStr = rootPath ? String(rootPath) : undefined

await initStarter(starterStr, rootPathStr)
if (
process.env.GATSBY_EXPERIMENTAL_GATSBY_NEW_FLOW &&
!starterStr &&
!rootPathStr
) {
gillkyle marked this conversation as resolved.
Show resolved Hide resolved
await runCreateGatsby()
} else {
await initStarter(starterStr, rootPathStr)
}
}),
})
.command({
Expand Down