|
| 1 | +# Contributing |
| 2 | + |
| 3 | +Thanks for your interest in contributing to WooCommerce Blocks! Below are some developer docs for working with the project. |
| 4 | + |
| 5 | +To get started, first run `npm install` and `composer install`. |
| 6 | + |
| 7 | +## npm scripts |
| 8 | + |
| 9 | +We have a set of scripts in npm to handle repeated developer tasks. |
| 10 | + |
| 11 | +### `build` & `start` |
| 12 | + |
| 13 | +These scripts compile the code using `webpack`. Run `build` to build the production build, `start` to build the development build and then keep watching for changes. You can also run `npx webpack` to run the development build and not keep watching. |
| 14 | + |
| 15 | +### `lint` |
| 16 | + |
| 17 | +This script runs 3 sub-commands: `lint:php`, `lint:css`, `lint:js`. Use these to run linters across the codebase. |
| 18 | + |
| 19 | +- `lint:php` runs phpcs via composer, which uses the [phpcs.xml](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/master/phpcs.xml) ruleset. |
| 20 | +- `lint:css` runs stylelint over all the scss code in `assets/css`, using the rules in [.stylelintrc.json.](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/master/.stylelintrc.json) |
| 21 | +- `lint:js` runs eslint over all the JavaScript, using the rules in [.eslintrc.js.](https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/master/.eslintrc.js) |
| 22 | + |
| 23 | +### `test` |
| 24 | + |
| 25 | +The test scripts use [wp-scripts](https://github.com/WordPress/gutenberg/tree/master/packages/scripts) to run jest for component and unit testing. |
| 26 | + |
| 27 | +- `test:update` updates the snapshot tests for components, used if you change a component that has tests attached. |
| 28 | +- Use `test:watch` to keep watch of files and automatically re-run tests. |
| 29 | + |
| 30 | +### `prepack` |
| 31 | + |
| 32 | +This script is run automatically when `npm pack` or `npm publish` is run. It installs packages, runs the linters, runs the tests, and then builds the files from the source once more. |
| 33 | + |
| 34 | +## Publishing @woocommerce/block-library |
| 35 | + |
| 36 | +We publish the blocks to npm at [@woocommerce/block-library,](https://www.npmjs.com/package/@woocommerce/block-library) and then import them into WooCommerce core via [a grunt script.](https://github.com/woocommerce/woocommerce/blob/741bd5ba6d193e21893ef3af3d4f3f030a79c099/Gruntfile.js#L347) |
| 37 | + |
| 38 | +To release a new version, there are 3 basic steps. Prepare and test the release, publish the version, then import into WooCommerce core. |
| 39 | + |
| 40 | +### Prepare and test the release |
| 41 | + |
| 42 | +- Manually change the versions in `package.json` and `woocommerce-gutenberg-products-block.php` (once in the plugin header, and `WGPB_VERSION`). [See an example PR with these changes.](https://github.com/woocommerce/woocommerce-gutenberg-products-block/pull/478/commits/725c43fe0362044c953728cb3391095a43e66bb5) |
| 43 | +- Run `npm pack` to prep a `.tgz` file. |
| 44 | +- Optionally test the package by uploading this onto a test site. |
| 45 | + |
| 46 | +### Publish this version |
| 47 | + |
| 48 | +On GitHub… |
| 49 | + |
| 50 | +- go to [Releases](https://github.com/woocommerce/woocommerce-gutenberg-products-block/releases) and click "Draft a new release" |
| 51 | +- The Tag version should start with `v`, and use [semver](https://semver.org/) formatting, ex `v2.0.0-rc`, or `v1.4.1` |
| 52 | +- The Release title should be the human-readable version, ex "2.0.0 Release Candidate" or "2.0.0 alpha release" |
| 53 | +- Add the changelog to the description (TBD, maybe not for every release?) |
| 54 | +- Upload the `.tgz` from `npm pack` in the previous step as an attached binary |
| 55 | + |
| 56 | +On npm… |
| 57 | + |
| 58 | +- Run `npm publish --access public`, which will push the version up to npm. |
| 59 | +- Check [@woocommerce/block-library](https://www.npmjs.com/package/@woocommerce/block-library) for your update |
| 60 | + |
| 61 | +### Pull into WooCommerce core |
| 62 | + |
| 63 | +- Manually update the @woocommerce/block-library version in `package.json` |
| 64 | +- In the woocommerce folder, run `npm install` to download the version you just specified |
| 65 | +- Run the copy command, `npx grunt blocks`, to copy the build files from node_modules into their destinations in WC core |
| 66 | +- Check that the changes imported look correct |
| 67 | +- Make a PR on WooCommerce to import the new version |
| 68 | + |
| 69 | +## Publishing the WooCommerce Blocks plugin |
| 70 | + |
| 71 | +TBD |
0 commit comments