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: Deprecate gatsby-recipes #34094

Merged
merged 17 commits into from
Dec 9, 2021
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Gatsby Recipes

**Please Note: Gatsby Recipes has been removed from `gatsby` with v4.5.0. If you want to use it you can install `gatsby-cli@4.4.0` to use it.**

Recipes is an “infrastructure as code” system that lets users automatically manage and provision the technology stack for their Gatsby site/app through code rather than manual processes.

It’s powered by React & MDX and a useful analogy is “React Native for Infrastructure”.
Expand Down
21 changes: 21 additions & 0 deletions deprecated-packages/gatsby-recipes/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = api => {
const isTest = api.env(`test`)

return {
presets: [
[
`@babel/env`,
{
// use ES modules for rollup and commonjs for jest
modules: isTest ? `commonjs` : false,
shippedProposals: true,
targets: {
node: `10.13.0`,
},
},
],
`@babel/preset-react`,
],
plugins: [`@babel/plugin-transform-runtime`],
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
const components = require(`./dist/web/components`)
module.exports = components
module.exports = components
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import path from "path"
function excludeDevTools() {
const re = /ink/
return {
name: "ignoreDevTools",

name: `ignoreDevTools`,
// eslint-disable-next-line
load(id) {
if (id.match(re)) {
if (path.parse(id).name === `devtools`) {
Expand All @@ -33,7 +33,7 @@ export default [
output: {
dir: `dist`,
entryFileNames: `[name].js`,
format: "cjs",
format: `cjs`,
sourcemap: true,
},
plugins: [
Expand Down Expand Up @@ -98,7 +98,7 @@ export default [
output: {
dir: `dist/web/`,
entryFileNames: `[name].js`,
format: "es",
format: `es`,
sourcemap: true,
},
plugins: [
Expand Down
1 change: 0 additions & 1 deletion docs/docs/adding-a-shopping-cart-with-snipcart.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,4 @@ The following quote is from the Snipcart [payment gateway page](https://app.snip
- [OneShopper Gatsby starter](/starters/rohitguptab/OneShopper/)
- Reference guide on [sourcing from Etsy](/docs/sourcing-from-etsy/)
- Reference guide on [processing payments with Stripe](/docs/how-to/adding-common-features/processing-payments-with-stripe/)
- From the Snipcart blog: [Gatsby E-Commerce Recipe: Integrate a Cart in a Few Steps](https://snipcart.com/blog/gatsby-recipes-ecommerce)
- [Snipcart documentation](https://docs.snipcart.com/v3/setup/installation)
25 changes: 25 additions & 0 deletions docs/docs/glossary/infrastructure-as-code.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
title: Infrastructure as Code
disableTableOfContents: true
---

Learn what <q>Infrastructure as Code</q> means, and how you can use code to standardize and automate things.

## What is <q>Infrastructure as Code?</q>

_Infrastructure as Code_, or IaC, is the practice of managing your development, testing, and production environments using configuration files or scripts. Provisioning and configuring environments individually can introduce errors or inconsistencies. You may, for example, find yourself running different versions of Node.js on your laptop and your production servers. Infrastructure as Code minimizes this kind of drift and lets you automate the process of provisioning environments.

Your configuration file describes what resources your project requires. If you're building an API, for example, you might create a configuration file that says, "Please install Node.js 12.16.2, npm 6.14.4, Express 4.17.1, and PostgreSQL 12.2 for Ubuntu Linux." For a Gatsby project, your configuration file may add plugins and themes.

Configuration files, like other code files, are text. That means you can use version control software to store them and track changes to the environment. In short, IaC:

- Creates consistent environments.
- Saves time that would otherwise be spent setting up environments.
- Reduces the risk of errors caused by mismatched environments.
- Lays the groundwork for automation.

## Automating Gatsby site development with Gatsby Recipes

[Gatsby Recipes](/blog/2020-04-15-announcing-gatsby-recipes/) applies the infrastructure as code concept to front-end development. With Gatsby Recipes, you can automate common site building tasks, such as adding a plugin or test suite.

We've discontinued this experiment and you can use Gatsby versions up to `4.4.0` to still use it. The old code still lives [on GitHub](https://github.com/gatsbyjs/gatsby/tree/master/deprecated-packages/gatsby-recipes).
84 changes: 0 additions & 84 deletions docs/docs/glossary/infrastructure-as-code/index.md

This file was deleted.

Binary file not shown.
32 changes: 19 additions & 13 deletions packages/create-gatsby/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# create-gatsby (alpha)
# create-gatsby

Create Gatsby apps in an interactive CLI experience that does the plumbing for you.

Expand All @@ -18,7 +18,7 @@ yarn create gatsby

It will ask you questions about what you're building, and set up a Gatsby project for you.

_Note: this package is different from the Gatsby CLI, it is intended solely to create new sites._
_Note: This package is different from `gatsby-cli`, it is intended solely to create new sites._

## Options

Expand All @@ -33,28 +33,34 @@ npm init gatsby -y <site-directory>
If you're making changes to the create-gatsby package, you can follow the steps below to test out your changes locally:

```sh
# Move into the create-gatsby package
cd packages/create-gatsby
# Move into the monorepo
cd <path-to-gatsby-monorepo>

# Install dependencies and build the package
yarn && yarn build
yarn bootstrap

# Run the create-gatsby script
node cli.js
node packages/create-gatsby/cli.js
```

Note that if you use the `build` script, you'll have to rebuild after each change. Alternatively, you can use the `watch` script to automatically rebuild after local changes. In that case, you'll need to run `cli.js` from the top-level directory of the `gatsby` repo:
Note that if you use the `bootstrap` script, you'll have to rebuild after each change. Alternatively, you can use the `watch` script to automatically rebuild after local changes:

```sh
# Move into the create-gatsby package
cd packages/create-gatsby
# Move into the monorepo
cd <path-to-gatsby-monorepo>

# Install dependencies and build the package
yarn && yarn watch
yarn bootstrap

# Open another terminal window and get back to the gatsby monorepo
cd <path-to-gatsby-monorepo>
# Watch changes
yarn watch --scope=create-gatsby
```

Open another terminal window and go to a folder where you can easily delete the test projects:

```
cd <path-to-playground>

# Run the create-gatsby script
node packages/create-gatsby/cli.js
node <some-path/packages/create-gatsby/cli.js
```
6 changes: 3 additions & 3 deletions packages/create-gatsby/src/site-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ export async function setSiteMetadata(
value: string
): Promise<void> {
try {
const recipesPath = require.resolve(`gatsby-recipes`, {
const coreUtilsPath = require.resolve(`gatsby-core-utils`, {
paths: [root],
})
const { GatsbySiteMetadata } = require(recipesPath)
await GatsbySiteMetadata?.create({ root }, { name, value })
const { addFieldToMinimalSiteMetadata } = require(coreUtilsPath)
await addFieldToMinimalSiteMetadata({ root }, { name, value })
} catch (e) {
// Silently fail, as it's fine if we don't add it to the config
}
Expand Down
1 change: 0 additions & 1 deletion packages/gatsby-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"fs-exists-cached": "^1.0.0",
"fs-extra": "^10.0.0",
"gatsby-core-utils": "^3.5.0-next.0",
"gatsby-recipes": "^1.5.0-next.0",
"gatsby-telemetry": "^3.5.0-next.0",
"hosted-git-info": "^3.0.8",
"is-valid-path": "^0.1.1",
Expand Down
41 changes: 5 additions & 36 deletions packages/gatsby-cli/src/create-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,46 +386,15 @@ function buildLocalCommands(cli: yargs.Argv, isLocalSite: boolean): void {
),
})

cli.command({
command: `recipes [recipe]`,
describe: `[EXPERIMENTAL] Run a recipe`,
builder: _ =>
_.option(`D`, {
alias: `develop`,
type: `boolean`,
default: false,
describe: `Start recipe in develop mode to live-develop your recipe (defaults to false)`,
}).option(`I`, {
alias: `install`,
type: `boolean`,
default: false,
describe: `Install recipe (defaults to plan mode)`,
}),
handler: handlerP(async ({ recipe, develop, install }: yargs.Arguments) => {
const { recipesHandler } = require(`./recipes`)
await recipesHandler(
siteInfo.directory,
recipe as string,
develop as boolean,
install as boolean
)
}),
})

cli.command({
command: `plugin <cmd> [plugins...]`,
describe: `Useful commands relating to Gatsby plugins`,
builder: yargs =>
yargs
.positional(`cmd`, {
choices: [`docs`, `ls`],
describe: "Valid commands include `docs`, `ls`.",
type: `string`,
})
.positional(`plugins`, {
describe: `The plugin names`,
type: `string`,
}),
yargs.positional(`cmd`, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The stub was added in #27725 but never used again. So plugins positional was never working, thus I removed this here + removed plugin-add.ts handler file

choices: [`docs`, `ls`],
describe: "Valid commands include `docs`, `ls`.",
type: `string`,
}),
handler: async ({
cmd,
}: yargs.Arguments<{
Expand Down