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

Docs: Move DevEnv to own section for docs #23593

Merged
merged 12 commits into from
Jul 14, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ export default function Edit( { attributes, className, setAttributes } ) {
}
```

Next Section: [Finishing Touches](finishing.md)
Next Section: [Finishing Touches](/docs/designers-developers/developers/tutorials/create-block/finishing.md)
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ __( 'Gutenpride', 'create_block' );

This is an internationalization wrapper that allows for the string "Gutenpride" to be translated. The second parameter, "create_block" is called the text domain and gives context for where the string is from. The JavaScript internationalization, often abbreviated i18n, matches the core WordPress internationalization process. See the [I18n for WordPress documentation](https://codex.wordpress.org/I18n_for_WordPress_Developers) for more details.

Next Section: [Block Attributes](block-attributes.md)
Next Section: [Block Attributes](/docs/designers-developers/developers/tutorials/create-block/block-attributes.md)
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ export default function Save( { attributes, className } ) {

Rebuild the block using `npm run build`, reload the editor and add the block. Type a message in the editor, save, and view it in the post.

Next Section: [Code Implementation](block-code.md)
Next Section: [Code Implementation](/docs/designers-developers/developers/tutorials/create-block/block-code.md)
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ Update **gutenpride.php** to enqueue from generated file location:
$editor_css = "build/index.css";
```

Next Section: [Authoring Experience](author-experience.md)
Next Section: [Authoring Experience](/docs/designers-developers/developers/tutorials/create-block/author-experience.md)
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Let's get you started creating your first block for the WordPress Block Editor.

The tutorial includes setting up your development environment, tools, and getting comfortable with the new development model. If you are already comfortable, try the quick start below, otherwise step through whatever part of the tutorial you need.

## Prerequisities

The first thing you need is a development enviornment and tools. This includes setting up your WordPress environment, Node, NPM, and your code editor. If you need help, see the [setting up your development environment documentation](/docs/designers-developers/developers/tutorials/devenv/readme.md).

## Quick Start

The `@wordpress/create-block` package exists to create the necessary block scaffolding to get you started. See [create-block package documentation](https://www.npmjs.com/package/@wordpress/create-block) for additional features. This quick start assumes you have a development environment with node installed, and a WordPress site.
Expand All @@ -22,10 +26,12 @@ After activated, go to the block editor and use the inserter to search and add y

## Table of Contents

1. [Development Environment](devenv.md)
2. [WordPress Plugin](wp-plugin.md)
3. [Anatomy of a Block](block-anatomy.md)
4. [Block Attributes](block-attributes.md)
5. [Code Implementation](block-code.md)
6. [Authoring Experience](author-experience.md)
7. [Finishing Touches](finishing.md)
The create a block tutorials breaks down to the following sections.

1. [WordPress Plugin](/docs/designers-developers/developers/tutorials/create-block/wp-plugin.md)
2. [ESNext Syntax](/docs/designers-developers/developers/tutorials/create-block/esnext-js.md)
3. [Anatomy of a Gutenberg Block ](/docs/designers-developers/developers/tutorials/create-block/block-anatomy.md)
4. [Block Attributes](/docs/designers-developers/developers/tutorials/create-block/block-attributes.md)
5. [Code Implementation](/docs/designers-developers/developers/tutorials/create-block/block-code.md)
6. [Authoring Experience](/docs/designers-developers/developers/tutorials/create-block/author-experience.md)
7. [Finishing Touches](/docs/designers-developers/developers/tutorials/create-block/finishing.md)
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Let's confirm the plugin is loaded and working.

-or-

(3B) If you are using `wp-env`, see [Development Environment setup](devenv.md), then you should now run this command from inside the `gutenpride` directory:
(3B) If you are using `wp-env`, see [Development Environment setup](/docs/designers-developers/developers/tutorials/devenv/readme.md), then you should now run from inside the `gutenpride` directory:

```sh
wp-env start
Expand Down Expand Up @@ -156,4 +156,4 @@ For more info, see the build section of the [Getting Started with JavaScript tut

Hopefully, at this point, you have your plugin created and activated. We have the package.json with the `@wordpress/scripts` dependency, that defines the build and start scripts. The basic block is in place and can be added to the editor.

Next Section: [Anatomy of a Block](block-anatomy.md)
Next Section: [Anatomy of a Block](/docs/designers-developers/developers/tutorials/create-block/block-anatomy.md)
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Development Environment
gziolo marked this conversation as resolved.
Show resolved Hide resolved

We will need a place to work and tools for creating a block, this is often referred to as the development environment. The three main pieces needed for our development environment are:
The development environment setup guide is for setting up your local development environment for JavaScript development; creating plugins and tools for extending WordPress and the block editor.

A development environment is a catch-all term for the setup on your computer to work. The three main pieces needed for our development environment are:

1. Node/NPM Development Tools
2. WordPress Development Site
3. Code Editor

Copy link
Contributor

Choose a reason for hiding this comment

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

The short guide.

In terminal - Mac, Windows or Linux.
Install nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
Quit and restart terminal.
Install node:
nvm install --lts

Download and install Docker. Startup Docker (?) ...

In terminal.
npm -g install @wordpress/env
Check to see it has been installed:
wp-env --version

Do something (?)
Then in terminal:
wp-env start

You should now have a local development environment in place. If something does not work then check the uninstall guide to remove and start over. - @mkaz and @noahtallen it would be good to have a section for uninstalling all that we have installed. To start over if needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

The do something step is from the Create a Block tutorial, on generating the plugin directory see wp-plugin.md.

npx @wordpress/create-block gutenpride
cd gutenpride
wp-env start

The create block script creates a plugin directory, you run the wp-env start from within that directory.

Copy link
Member

Choose a reason for hiding this comment

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

you can uninstall wp-env like so:

  • run wp-env destroy to destroy the local environment data for a specific projest
  • run npm uninstall -g @wordpress/env will uninstall the npm package, but will not remove any environment data

Copy link
Contributor

Choose a reason for hiding this comment

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

The do something step is confusing as we are having nice and logical steps on what to do in terminal to setup a local WordPress development. I expect the do something step will then create the local WordPress development site which we can then easily access. I am saying the same thing just below. We should not refer to another tutorial as that information can come later.

Copy link
Contributor

@paaljoachim paaljoachim Jul 10, 2020

Choose a reason for hiding this comment

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

Thanks Noah! Btw how do we test to see that all of it is actually uninstalled?
Having uninstall information (as you added) and checking to see that it is uninstalled would be helpful.

Copy link
Member

Choose a reason for hiding this comment

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

If it is actually uninstalled, then wp-env start will result in an error like "command not found". Additionally, if you destroyed your environment, the command docker ps -a, which shows a list of local environments, will not display environments associated with the local environment that was deleted.

Verifying that the environment was properly uninstalled is kind of complicated because you have to understand how Docker works and how wp-env works under the hood, since several different things are cleaned up when you run wp-env destroy

Copy link
Contributor

@paaljoachim paaljoachim Jul 13, 2020

Choose a reason for hiding this comment

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

I am thinking as long as one gets the error messages one is supposed to get then that would be the confirmatation that it is uninstalled.

## Development Tools

The tools needed for development are **Node** and **NPM**. **Nodejs** is a runtime environment that allows running JavaScript outside of the browser. NPM is the Node Package Manager, it is used for installing dependencies and running scripts. The script `npx` is installed with `npm` and is used to run packages not yet installed, we will use this to bootstrap a block.
The tools needed for development are **Node** and **NPM**. **Nodejs** is a runtime environment that allows running JavaScript outside of the browser. NPM is the Node Package Manager, it is used for installing dependencies and running scripts. The script `npx` is also installed with Nodejs—this script is used to run packages not yet installedwe will use `npx` to bootstrap a block.

The tools are used to convert the JavaScript we are going to write into a format that browsers can run. This is called transpiling or the build step.

Expand All @@ -18,15 +20,36 @@ For Windows, or alternative installs, you can [download a Nodejs installer](http

Here are the quick instructions to install using nvm, see the [full installation instructions](https://github.com/nvm-sh/nvm#installing-and-updating) for additional details.

mkaz marked this conversation as resolved.
Show resolved Hide resolved
A tip for macOS Catalina, the default profile file may not be created, you can create the required file typing `touch ~/.zshrc` on the command-line. It is fine to run if the file already exists. Note, `~/` is a shortcut to your home directory.

Run the following on the command-line to install nvm:

```sh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
```

After installing nvm, you need to use it to install node, to install the latest version of node, run:
Note: On macOS, the required developer tools are not installed by default, if not already installed you may be prompted to download the install.

<img src="https://developer.wordpress.org/files/2020/07/git-install-prompt.png" alt="Mac git command requies command line developer tools" width="400" height="195"/>

After installing nvm, you need to use it to install node, to install the LTS version of node, run:

```sh
nvm install --lts
```

If there is an error running the above command, for example a common error that occurs is:

```sh
$ nvm install --lts
zsh: command not found: nvm
```

First, try quitting and restarting your terminal to pick up the installed config.

If restarting did not resolve the problem, you might need to create the default profile file.

On macOS Catalina, the default shell is zsh, to create the profile file type `touch ~/.zshrc` on the command-line. It is fine to run if the file already exists. Note, `~/` is a shortcut to your home directory. For Ubuntu, including WSL, the default profile is bash, use `touch ~/.bashrc` to create.

After creating the profile file, re-run the install command:

```sh
nvm install --lts
Expand All @@ -52,20 +75,32 @@ The WordPress [wp-env package](https://www.npmjs.com/package/@wordpress/env) let

The `wp-env` package requires Docker to be installed. There are instructions available for installing Docker on [Windows 10 Pro](https://docs.docker.com/docker-for-windows/install/), [all other versions of Windows](https://docs.docker.com/toolbox/toolbox_install_windows/), [macOS](https://docs.docker.com/docker-for-mac/install/), and [Linux](https://docs.docker.com/v17.12/install/linux/docker-ce/ubuntu/#install-using-the-convenience-script).

After confirming that the prerequisites are installed, install `wp-env` globally from the command-line using:
After you have installed Docker, go ahead and install `wp-env` globally from the command-line using:

```sh
npm -g install @wordpress/env
```

This will be used in the next [Plugin step](wp-plugin.ms). To confirm it is installed and available, run:
To confirm it is installed and available, run:

```sh
wp-env --version
> 1.4.0
> 1.6.0
```

The `wp-env` script is used to create a Docker WordPress environment, to use start from your plugin directory—if you are following the create block tutorial, this would be in the generated directory.

Copy link
Contributor

@paaljoachim paaljoachim Jul 9, 2020

Choose a reason for hiding this comment

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

It is confusing going from working in terminal to suddenly mentioning the plugin directory.
Where is the plugin directory? We need a step that goes from checking the wp-env to locating the plugin directory and then running wp-env start. This needs clarification.

"...if you are following the create block tutorial, this would be in the generated directory."
This seems out of context. As the context is setting up a local dev environment to be used with creating a plugin and/or contributing to Gutenberg.

(I added a similar comment in the below solved comment thread, but as it got hidden I am adding it again here.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure setting up a dev environment with no context makes much sense. There is a reason you are setting up an environment, the most likely is for developing a plugin or theme. If you are following the create a block tutorial it provides the context in that tutorial here.

Otherwise, you might of come to this page wanting to setup an environment to create a plugin, so you would have that in mind already.

Copy link
Contributor

Choose a reason for hiding this comment

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

We has this introduction:
"The development environment setup guide is for setting up your local development environment for JavaScript development; creating plugins and tools for extending WordPress and the block editor."

This is how I understand it:
Setup a local WordPress development site for creating own plugin and/or contributing to WordPress/Gutenberg. (That is the context.)

"If you are following the create a block tutorial it provides the context in that tutorial here."
As the doc we are working on right now is the very first tutorial for setting up a local dev site I find it confusing that someone would be following the next tutorial in the series so to speak. As the tutorial we have now would be a prerequisite for the block tutorial. Having a side path to tutorial 2 seems strange at this stage.

```sh
wp-env start
mkaz marked this conversation as resolved.
Show resolved Hide resolved
```

mkaz marked this conversation as resolved.
Show resolved Hide resolved
### Alternatives
You can access your environment in your browser at: [http://localhost:8888/](http://localhost:8888/), the default username is `admin` and default password is `password`. For more information controlling the Docker environment see the [@wordpress/env package readme](/packages/env/README.md).

If you are developing a single plugin, you should run `wp-env start` from that plugin working directory—it will mount and activate the plugin automatically. Note: This also works for themes, run from the directory you are developing the theme.

If you want a single environment for all your plugins/themes, you need to create a `.wp-env.json` in a working directory and add the plugins/themes to it. You then run `wp-env start` from the same directory as that config file. See the [@wordpress/env package for additional details](/packages/env/README.md#wp-envjson).

mkaz marked this conversation as resolved.
Show resolved Hide resolved
### Alternative to Docker

A block is just a plugin, so any WordPress environment can be used for development. A couple of alternatives that might be easier, since they do not require Docker install and setup.

Expand All @@ -84,5 +119,3 @@ The important part is having a WordPress site installed, and know where and how
Alternative editors include [Sublime Text](https://www.sublimetext.com/) that is also available across platforms, though is a commercial product; or other free alternatives include [Vim](https://www.vim.org/), [Atom](https://atom.io/), and [Notepad++](https://notepad-plus-plus.org/) all support standard JavaScript style development.

You can use any editor you're comfortable with, it is more a personal preference. The development setup for WordPress block editor is a common JavaScript environment and most editors have plugins and suppport. The key is having a way to open, edit, and save text files.

Next Section: [WordPress Plugin](wp-plugin.md)
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ First, you need to set up Node.js for your development environment. The steps re
- macOS: `brew install node`
- Windows: `choco install node`

If you are not using a package manager, see the [Node.js download page](https://nodejs.org/en/download/) for installers and binaries.
If you are not using a package manager, see the [developer environment setup documentation](/docs/designers-developers/developers/tutorials/devenv/readme.md) for setting up Node using nvm, or see the official [Node.js download page](https://nodejs.org/en/download/) for installers and binaries.

**Note:** The build tools and process occur on the command-line, so basic familiarity using a terminal application is required. Some text editors have a terminal built-in that is fine to use; Visual Studio Code and PhpStorm are two popular options.

### Node Package Manager (npm)

The Node Package Manager (npm) is a tool included with node. npm allows you to install and manage JavaScript packages. npm can also generate and process a special file called `package.json`, which contains some information about your project and the packages your project uses.
The Node Package Manager (npm) is a tool included with node. npm allows you to install and manage JavaScript packages. npm can also generate and process a special file called `package.json`, that contains information about your project and the packages your project uses.

To start a new node project, first create a directory to work in:

Expand Down Expand Up @@ -127,9 +127,7 @@ You can then run the build using: `npm run build`.

After the build finishes, you will see the built file created at `build/index.js`. Enqueue this file in the admin screen as you would any JavaScript in WordPress, see [loading JavaScript step in this tutorial](/docs/designers-developers/developers/tutorials/javascript/loading-javascript.md), and the block will load in the editor.

## Finishing Touches

### Development Mode
## Development Mode

The **build** command in `@wordpress/scripts` runs in "production" mode. This shrinks the code down so it downloads faster, but makes it difficult to read in the process. You can use the **start** command which runs in development mode that does not shrink the code, and additionally continues a running process to watch the source file for more changes and rebuilds as you develop.

Expand All @@ -146,13 +144,13 @@ Now, when you run `npm start` a watcher will run in the terminal. You can then e

**Note:** keep an eye on your terminal for any errors. If you make a typo or syntax error, the build will fail and the error will be in the terminal.

### Source Control
## Source Control

Because a typical `node_modules` folder will contain thousands of files that change with every software update, you should exclude `node_modules/` from your source control. If you ever start from a fresh clone, simply run `npm install` in the same folder your `package.json` is located to pull your required packages.

Likewise, you do not need to include `node_modules` or any of the above configuration files in your plugin because they will be bundled inside the file that webpack builds. **Be sure to enqueue the `build/index.js` file** in your plugin PHP. This is the main JavaScript file needed for your block to run.

### Dependency Management
## Dependency Management

Using `wp-scripts` ver 5.0.0+ build step will also produce an `index.asset.php` file that contains an array of dependencies and a version number for your block. For our simple example above, it is something like:
`array('dependencies' => array('wp-element', 'wp-polyfill'), 'version' => 'fc93c4a9675c108725227db345898bcc');`
Expand Down
16 changes: 9 additions & 7 deletions docs/designers-developers/developers/tutorials/readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Tutorials

* See the [Getting Started with JavaScript Tutorial](/docs/designers-developers/developers/tutorials/javascript/readme.md) to learn about how to use JavaScript within WordPress.
- First things first, see [setting up your development environment](/docs/designers-developers/developers/tutorials/devenv/readme.md) for the tools and setup you need to extend the block editor.

* The [Blocks Tutorial](/docs/designers-developers/developers/tutorials/block-tutorial/readme.md) is the best place to start to learn more about block creation.
- See the [Getting Started with JavaScript Tutorial](/docs/designers-developers/developers/tutorials/javascript/readme.md) to learn about how to use JavaScript within WordPress.

* See the [Meta Boxes Tutorial](/docs/designers-developers/developers/tutorials/metabox/readme.md) for new ways of extending the editor storing and using post meta data.
- The [Blocks Tutorial](/docs/designers-developers/developers/tutorials/block-tutorial/readme.md) is the best place to start to learn more about block creation.

* Check out the [Notices Tutorial](/docs/designers-developers/developers/tutorials/notices/README.md) to learn how to display informational UI at the top of the editor.
- See the [Meta Boxes Tutorial](/docs/designers-developers/developers/tutorials/metabox/readme.md) for new ways of extending the editor storing and using post meta data.
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to this PR, but can we move Meta Boxes Tutorial further? :)


* The [Sidebar Tutorial](/docs/designers-developers/developers/tutorials/sidebar-tutorial/plugin-sidebar-0.md) will walk you through the steps of creating a sidebar to update data from the `post_meta` table.
- Check out the [Notices Tutorial](/docs/designers-developers/developers/tutorials/notices/README.md) to learn how to display informational UI at the top of the editor.

* Learn how to add customized buttons to the toolbar with the [Format API tutorial](/docs/designers-developers/developers/tutorials/format-api/).
- The [Sidebar Tutorial](/docs/designers-developers/developers/tutorials/sidebar-tutorial/plugin-sidebar-0.md) will walk you through the steps of creating a sidebar to update data from the `post_meta` table.

* Build your own [custom block editor instance](/docs/designers-developers/developers/platform/custom-block-editor/) - this will walk you through building a standalone instance of the block editor within WP Admin.
- Learn how to add customized buttons to the toolbar with the [Format API tutorial](/docs/designers-developers/developers/tutorials/format-api/).

- Build your own [custom block editor instance](/docs/designers-developers/developers/platform/custom-block-editor/) - this will walk you through building a standalone instance of the block editor within WP Admin.
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,12 @@
"markdown_source": "../docs/designers-developers/developers/tutorials/readme.md",
"parent": null
},
{
"title": "Development Environment",
"slug": "devenv",
"markdown_source": "../docs/designers-developers/developers/tutorials/devenv/readme.md",
"parent": "tutorials"
},
{
"title": "Getting Started with JavaScript",
"slug": "javascript",
Expand Down
1 change: 1 addition & 0 deletions docs/toc.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
{ "docs/contributors/repository-management.md": [] }
] },
{ "docs/designers-developers/developers/tutorials/readme.md": [
{ "docs/designers-developers/developers/tutorials/devenv/readme.md": [] },
{ "docs/designers-developers/developers/tutorials/javascript/readme.md": [
{ "docs/designers-developers/developers/tutorials/javascript/plugins-background.md": [] },
{ "docs/designers-developers/developers/tutorials/javascript/loading-javascript.md": [] },
Expand Down