Skip to content

Commit

Permalink
chore: add "Local Development" guide for @faustwp/core (#1934)
Browse files Browse the repository at this point in the history
* - re-order dependencies
- add guide for "Local Development" of @faustwp/core package

* - update Local Development guide for more clarity after walking through it with `@josephfusco`

* - update docs

* - move file
  • Loading branch information
jasonbahl authored Aug 21, 2024
1 parent 2b7949b commit 56dd90b
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 29 deletions.
2 changes: 1 addition & 1 deletion examples/next/faustwp-getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"node": ">=18",
"npm": ">=8"
}
}
}
2 changes: 1 addition & 1 deletion examples/next/getting-started/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
"rimraf": "^3.0.2",
"typescript": "^4.5.2"
}
}
}
16 changes: 8 additions & 8 deletions packages/block-editor-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
"react-dom": "^18.0.0"
},
"dependencies": {
"@wordpress/block-editor": "^12.11.1",
"@wordpress/blocks": "^12.20.1",
"@wordpress/components": "^25.9.1",
"@wordpress/block-editor": "^12.11.1",
"@wordpress/element": "5.20.0",
"@wordpress/hooks": "^3.43.0",
"@wordpress/i18n": "^4.43.0"
},
"devDependencies": {
"@react-spring/web": "9.7.3",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.0.0",
"jest-environment-jsdom": "29.7.0",
"@types/jest": "^29.5.5",
"@types/node": "^18.0.6",
"@types/react": "^18.2.28",
"@types/jest": "^29.5.5",
"rimraf": "^4.4.0",
"@wordpress/jest-preset-default": "^11.14.0",
"@types/wordpress__blocks": "12.5.6",
"@types/wordpress__block-editor": "11.5.5",
"ts-jest": "29.1.1",
"@types/wordpress__blocks": "12.5.6",
"@wordpress/jest-preset-default": "^11.14.0",
"jest": "29.7.0",
"@react-spring/web": "9.7.3"
"jest-environment-jsdom": "29.7.0",
"rimraf": "^4.4.0",
"ts-jest": "29.1.1"
},
"scripts": {
"prebuild": "npm run clean",
Expand Down
8 changes: 4 additions & 4 deletions packages/blocks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
"module": "dist/mjs/index.js",
"types": "dist/mjs/index.d.ts",
"peerDependencies": {
"@apollo/client": ">=3.6.6",
"@faustwp/core": ">=1.1.0",
"react": ">=17.0.2",
"react-dom": ">=17.0.2",
"@wordpress/style-engine": ">=1.18.0",
"@apollo/client": ">=3.6.6",
"next": ">=12.1.6"
"next": ">=12.1.6",
"react": ">=17.0.2",
"react-dom": ">=17.0.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.16.5",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@
"author": "WP Engine",
"license": "MIT",
"dependencies": {
"cookie": "^0.4.1",
"deepmerge": "^4.2.2",
"gqty": "^2.3.0",
"isomorphic-fetch": "^3.0.0",
"lodash": "^4.17.21",
"cookie": "^0.4.1"
"lodash": "^4.17.21"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.15.0",
Expand All @@ -79,11 +79,11 @@
"@types/node": "^17.0.17",
"@types/webpack-env": "^1.16.3",
"clean-webpack-plugin": "^4.0.0",
"fetch-mock": "9.11.0",
"jest": "^27.3.1",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.7",
"ts-loader": "^9.2.6",
"typescript": "^4.4.4",
"fetch-mock": "9.11.0"
"typescript": "^4.4.4"
}
}
4 changes: 2 additions & 2 deletions packages/faustwp-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"@types/jest": "^29.5.5",
"@types/node": "^18.15.11",
"@types/prompt": "1.1.2",
"fetch-mock-jest": "^1.5.1",
"jest-environment-jsdom": "29.6.4",
"rimraf": "5.0.5",
"ts-jest": "^29.1.1",
"typescript": "^4.9.5",
"fetch-mock-jest": "^1.5.1"
"typescript": "^4.9.5"
},
"dependencies": {
"archiver": "^6.0.1",
Expand Down
113 changes: 113 additions & 0 deletions packages/faustwp-core/LOCAL_DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Local Development

**_NOTE_**: This guide is a WIP and may be incomplete.

This guide will walk you through setting up a local development environment for `@faustwp/core`.

## Table of Contents
1. [Requirements](#requirements)
2. [Setup](#setup)
- [Link `@faustwp/core`](#link-faustwp-core)
- [Start the `@faustwp/core` development server](#start-the-faustwp-core-development-server)
- [Start the project site](#start-the-project-site)
3. [Troubleshooting](#troubleshooting)

## Requirements

- [Node.js](https://nodejs.org/en/) (v14 or higher)
- [Yarn](https://yarnpkg.com/) (v4.4 or higher)
- [Git](https://git-scm.com/) (v2.33 or higher)

> [!NOTE]
> We will be using both `yarn` and `npm` in this guide.
> The `faustjs` repo uses `npm` for installing dependencies and running scripts.
> The project using faust will use `yarn` to create a link to Faust for local development with "fast refresh" support.

## Project Site Setup

First, we'll need a site using Faust that we can work with. If you have an existing site using `@faustwp/core` you \_should\_ be able to use it. If you need a project site to test with, we recommend cloning the `acf.wpgraphql.com` repo, which this guide is based on.

> [!NOTE]
> If you clone `acf.wpgraphql.com` to use as an example, you will need to copy the `.env.local.example` file into `.env.local`
### Link `@faustwp/core`

From within the directory of the project using Faust (i.e. your site's directory, not the directory where you cloned Faust), run the following command to check the version of yarn being used:

```shell
yarn --version
```

If not using yarn v4.4 or higher, you will need to upgrade yarn to v4.4 or higher:

```shell
yarn set version berry
```

With Yarn v4.4 or higher, you can now link the local copy of `@faustwp/cli` and `@faustwp/core`:

```sh
yarn link "~/path/to/faustjs/packages/faustwp-cli"
yarn link "~/path/to/faustjs/packages/faustwp-core"
```

This will create a symlink in the `node_modules` directory of the project to the local copy of `@faustwp/cli` and `@faustwp/core`.

### Start the `@faustwp/core` development server

From within the directory where the Faust repo was cloned, run the following command to install dependencies, build the code and start the development server for `@faustwp/core`:

```sh
npm install --workspace=@faustwp/core
npm run build --workspace=@faustwp/core
npm run dev --workspace=@faustwp/core
```

Leave this terminal window open while you work on your project in another terminal window.

### Start the project site

From within the directory of the project site, run the following command to install dependencies and start the development server:

```sh
yarn install
yarn dev
```

You should be able to view the local site running at `localhost:3000` and see output in the terminal.

### Local Development of Faust

Now that we have both the project site running in `dev` mode and `@faustwp/core` running in `dev` mode, we can make changes to `@faustwp/core` and see them reflected in the project site.

In VS Code or your IDE of choice, open the `faustjs/packages/faustwp-core/src/getTemplate.ts` and add the following to the top of the `getPossibleTemplates` function:

```ts
console.log(`Hello from Faust!`);
```

Save the file, and you should see the message logged immediately in the terminal running your project site in dev mode.

You should now be able to work on Faust locally and see changes reflected in your project site.

## Clean Up

When you are done working on your project site, you can unlink the local copy of `@faustwp/core` and `@faustwp/cli`:

```sh
yarn unlink @faustwp/core
yarn unlink @faustwp/cli
```

This will remove the symlink from the `node_modules` directory of the project and cleanup the resolutions in the package.json.

## Troubleshooting

- **Issue:** `yarn link` command not working.
- **Solution:** Ensure the path to `@faustwp/core` and `@faustwp/cli` are correct and that you have the necessary permissions.
- **Issue:** Development server not starting.
- **Solution:** Check for any errors in the terminal and ensure all dependencies are installed correctly.
- **Issue:** Build errors when running `npm install`
- **Solution:** Make sure all `node_modules` directories within the repo have been removed before running `npm install`.

6 changes: 3 additions & 3 deletions packages/faustwp-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"@types/is-number": "^7.0.1",
"@types/isomorphic-fetch": "^0.0.35",
"@types/jest": "^27.0.2",
"@types/js-cookie": "^3.0.6",
"@types/lodash": "^4.14.176",
"@types/node": "^17.0.17",
"@types/js-cookie": "^3.0.6",
"@types/testing-library__react": "10.2.0",
"concurrently": "^7.6.0",
"fetch-mock": "9.11.0",
Expand All @@ -39,9 +39,9 @@
"deepmerge": "^4.2.2",
"fast-xml-parser": "^4.4.1",
"isomorphic-fetch": "^3.0.0",
"js-cookie": "^3.0.5",
"js-sha256": "^0.9.0",
"lodash": "^4.17.21",
"js-cookie": "^3.0.5"
"lodash": "^4.17.21"
},
"scripts": {
"dev": "concurrently \"npm:watch-*\" --prefix-colors \"auto\"",
Expand Down
6 changes: 3 additions & 3 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@
"author": "WP Engine",
"license": "MIT",
"peerDependencies": {
"@faustjs/core": ">=0.15.13",
"@faustjs/react": ">=0.15.13",
"next": ">=11.1.2",
"react": ">=17.0.2",
"react-dom": ">=17.0.2",
"@faustjs/core": ">=0.15.13",
"@faustjs/react": ">=0.15.13"
"react-dom": ">=17.0.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.15.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@
"author": "WP Engine",
"license": "MIT",
"peerDependencies": {
"@faustjs/core": ">=0.15.13",
"react": ">=17.0.2",
"react-dom": ">=17.0.2",
"@faustjs/core": ">=0.15.13"
"react-dom": ">=17.0.2"
},
"devDependencies": {
"@testing-library/jest-dom": "^5.15.0",
Expand All @@ -56,8 +56,8 @@
"@types/lodash": "^4.14.176",
"@types/node": "^17.0.17",
"@types/react": "^17.0.34",
"jest": "^27.3.1",
"bs-logger": "^0.2.6",
"jest": "^27.3.1",
"make-error": "^1.3.6",
"rimraf": "^3.0.2",
"ts-jest": "^27.0.7",
Expand Down

0 comments on commit 56dd90b

Please sign in to comment.