Code contributions, bug reports, and feature requests are welcome! The following sections provide guidelines for contributing to this project, as well as information about development processes and testing.
The monorepo is organized as follows:
Click to expand
│ # Repository files
├── .github/
│
│ # Verdaccio configuration for local package testing
├── .verdaccio/
│
│ # Global config files reused in multiple packages
├── config/
│ ├── .babelrc # Babel config for transpiling unit test files
│ ├── .prettierrc.js # Prettier config extending WordPress defaults
│ ├── jest.config.js # Unit tests config
│ ├── playwright.config.js # E2E tests config. Any file with the name *.spec.ts will be considered as an E2E test
│ └── tsconfig.base.json # A base Typescript config for all modules to inherit from
│
│ # Framework documentation
├── docs/
│
│ # Example implementations and starter templates
├── examples/
│ └── nextjs/starter/ # A basic Next.js starter template
│
│ # E2E tests using Playwright
├── e2e-tests/
│
│ # Contains all the modules (libraries and apps) for the project
├── packages/
│ ├── blocks # Consumable WordPress blocks for frontend use
│ ├── cli # CLI commands for `npx snapwp`
│ ├── codegen-config # GraphQL code generation configuration
│ ├── core # Core functionality shared by the SnapWP framework
│ ├── eslint-config # Shared ESLint configuration for all packages
│ ├── next # Utilities and frontend components for integrating with Next.js
│ ├── prettier-config # Shared Prettier configuration
│ └── query # GraphQL queries for WordPress data fetching
│
├── .env.example # Example .env file for local development. Copy this to .env and customize as needed
├── .eslintrc.json # Global ESLint configuration
├── DEVELOPMENT.md # 🎯 This file
├── package.json # Global package.json for the monorepo.
└── tsconfig.json # Global Typescript configuration
To set up locally, clone the repository and navigate to the frontend
subdirectory.
-
Copy the example environment file to
.env
and update the values as neededcp .env.example .env
-
Use the node version defined in .nvmrc.
nvm use
-
Install the NPM dependencies.
npm install
-
Build the packages locally.
npm run build
At this point the libraries should be ready to use in any of the projects in the
examples/
directory. -
(Optional) Start the packages in watch mode.
npm run dev
Alternatively, you can publish the packages locally using Verdaccio:
npm run publish:local
The develop
branch is used for active development, while main
contains the current stable release. Always create a new branch from develop
when working on a new feature or bug fix.
Branches should be prefixed with the type of change (e.g. feat
, chore
, tests
, fix
, etc.) followed by a short description of the change. For example, a branch for a new feature called "Add new feature" could be named feat/add-new-feature
.
This project uses several tools to ensure code quality and standards are maintained:
This project uses ESLint, which is a tool for identifying and reporting on patterns found in ECMAScript/JavaScript code.
You can run ESLint using the following command:
npm run lint
ESLint can automatically fix some issues. To fix issues automatically, run:
npm run lint:fix
This project uses Jest to run unit tests . Unit tests are located inside the /packages/**/test/ directory
To run the unit tests, run:
npm run test:unit
To generate coverage report, run:
npm run test:unit:coverage
To update the snapshot, run:
npm run test:unit:updatesnapshot
Note: Update snapshots when a test fails due to intentional changes in the code.
This project uses Playwright to run e2e tests.
Tests are located in the e2e-tests
directory.
To run the Playwright tests, run:
npm run test:e2e
You can run type check for all packages:
npm run typecheck
You can test these packages locally by linking them, or by using a local npm registry such as Verdaccio.
- Follow steps 1–3 in Setup.
- Run
npm link -w snapwp
to link the package into your global dependencies. - Verify the CLI by running
snapwp
. - Remove the global link with
npm r snapwp -g
.
- Follow steps 1–4 in Setup.
- Use
npm_config_registry=http://localhost:4873 npx snapwp
to run the local package. - Clear the npx cache if needed:
- Find your cache location using
npm config get cache
. - Remove the
_npx
directory in that cache folder.
- Find your cache location using
@todo
This project uses Changesets for versioning and generating changelogs across the packages in the monorepo.
To generate a Changeset (copied and modified from Changesets' docs):
-
Run
npm run changeset
in the root of the monorepo. -
Select the packages you want to include in the changeset.
- Use
↑
and↓
to navigate to packages. - Use
space
to select a package. - Hit
enter
when all desired packages are selected.
- Use
-
You will be prompted to select a bump type for each selected package. First you will flag all the packages that should receive a
major
bump, thenminor
. The remaining packages will receive apatch
bump.- Major: Any form of breaking change.
- Minor: New (non-breaking) features or changes.
- Patch: Bug fixes.
-
Your final prompt will be to provide a message to go along with the changeset. This message will be written to the changeset when the next release is made.
⚠️ ImportantRemember to follow Conventional Commits formatting and to use imperative language in your changeset message.
For example, "feat: Add new feature" instead of "Added new feature".
After this, a new changeset will be added which is a markdown file with YAML front matter.
-| .changeset/ -|-| UNIQUE_ID.md
The message you typed can be found in the markdown file. If you want to expand on it, you can write as much markdown as you want, which will all be added to the changelog on publish. If you want to add more packages or change the bump types of any packages, that's also fine.
-
Once you are happy with the changeset, commit the file to your branch.
This project uses Changesets to manage releases.
Once all the latest version of the packages are ready to be released and all the changesets are generated, the generated chore: Release packages 🏷️
PR should be reviewed and approved. Merging the PR will release the packages to NPM and tag + publish the corresponding GitHub releases.