diff --git a/docs/docs/gatsby-cli.md b/docs/docs/gatsby-cli.md index 5ebe3c90c9848..f2e1010501b99 100644 --- a/docs/docs/gatsby-cli.md +++ b/docs/docs/gatsby-cli.md @@ -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` diff --git a/integration-tests/gatsby-cli/__tests__/new.js b/integration-tests/gatsby-cli/__tests__/new.js index 4465bd805d3a6..3373763b0dbbd 100644 --- a/integration-tests/gatsby-cli/__tests__/new.js +++ b/integration-tests/gatsby-cli/__tests__/new.js @@ -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( @@ -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`, @@ -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`, @@ -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!`) + }) }) diff --git a/packages/gatsby-cli/package.json b/packages/gatsby-cli/package.json index 929999dd9988e..e1d10ba794329 100644 --- a/packages/gatsby-cli/package.json +++ b/packages/gatsby-cli/package.json @@ -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", diff --git a/packages/gatsby-cli/src/create-cli.ts b/packages/gatsby-cli/src/create-cli.ts index 6d9938245d143..a478cda279693 100644 --- a/packages/gatsby-cli/src/create-cli.ts +++ b/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" @@ -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" @@ -502,7 +503,16 @@ export const createCli = (argv: Array): 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({