diff --git a/README.md b/README.md index 9d468973..2a886eea 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Install hooks: pnpm prepare ``` -## Getting Started +## Setup Follow the directions [here](https://nx.dev/nx-cloud/intro/what-is-nx-cloud) to set up an nx account and access token. @@ -32,7 +32,9 @@ Set up your `NPM_TOKEN` and `NX_CLOUD_ACCESS_TOKEN` via `Settings` -> `Secrets` Enable read and write workflow permissions in your repo via `Settings` -> `Actions` -> `General` -> `Workflow permissions` -> `read and write permissions`. -## Commands +## Getting Started + +**Note**: Append `--skip-nx-cache` at the end of cached commands to disable nx cloud caching Run local development servers: @@ -42,8 +44,6 @@ pnpm dev Lint files: -**Note**: Since `vite-project` depends on linked packages, a linting error will occur if `pnpm build` has not run at least once first. - ```bash pnpm lint ``` @@ -60,19 +60,21 @@ Run tests in watch mode: pnpm test:watch ``` -Clean up bundle artifacts: +Compile files and build bundle: + +**Note**: It is recommended to run `pnpm clean` before `pnpm build` ```bash -pnpm clean +pnpm build ``` -Compile files and build bundle: +Clean up bundle artifacts: ```bash -pnpm build +pnpm clean ``` -Starts local servers that serves the `build` outputs from their respective from `dist/` folders: +Starts local servers that serves the `build` outputs from their respective output folders: **Note**: Run `pnpm build` first. @@ -86,80 +88,6 @@ Stub `dist` for project linking without needing to watch and rebuild: pnpm stub ``` -### Workspace Commands - -Install dependecies to the root of the workspace: - -```bash -pnpm add -w [package-name] -``` - -Add a local package as a dependency for another local package: - -```bash -pnpm add -D eslint-config-custom --filter vite-project --workspace -``` - -Remove a local package from another local package: - -```bash -pnpm remove eslint-config-custom --filter vite-project -``` - -Install / run commands for a specific sub-package: - -```bash -pnpm --filter vite-project dev -``` - -### Other Commands - -Commit changes using conventional changelog: - -```bash -pnpm commit -``` - -Delete workspace root `node_modules` and `pnpm-lock.yaml` files: - -**Note**: Install `rimraf` globally and make sure it is not installed in the workspace root so errors aren't thrown. - -```bash -pnpm delete -``` - -Lint root and `configs/` `js/cjs` files, check for secrets, lint dependency versions, validate published packages, and verify monorepo best practices: - -```bash -pnpm lint:mr -``` - -Visualize the project structure/dependencies: - -```bash -pnpm nx:graph -``` - -Format all files in the monorepo: - -```bash -pnpm format -``` - -Preview the output result of the `version` command without actually executing it: - -**Note**: Set your personal access token as an environment variable in your operating system as `GH_TOKEN` with the token unique identifier as the value. - -```bash -pnpm preview:version -``` - -Preview the output result of the `publish` command without actually executing it: - -```bash -pnpm preview:publish -``` - ## NX Distributed Caching To enable nx distributed caching, refactor the `.github/workflows/release.yml` file via the directions [here](https://nx.dev/recipes/ci/monorepo-ci-github-actions#distributed-ci-with-nx-cloud). diff --git a/docs/repo/ARCHITECTURE.md b/docs/repo/ARCHITECTURE.md new file mode 100644 index 00000000..9be2d6ca --- /dev/null +++ b/docs/repo/ARCHITECTURE.md @@ -0,0 +1,36 @@ +# Architecture + +## Introduction + +The repository setup and folder structure is heavily inspired by the turborepo [kitchen sink starter monorepo templates](https://github.com/vercel/turbo/tree/main/examples/kitchen-sink) and the [design system monorepo template](https://github.com/vercel/turbo/tree/main/examples/design-system). + +## Folder Structure + +```bash +apps/ +configs/ +docs/ +packages/ +... +package.json +pnpm-workspace.yaml +``` + +**`apps`** - Contains standalone applications / SPAs that can consume modules in `packages` + +**`configs`** - Contains linters / configurations such as `eslint` / `tsconfig` shared across the monorepo + +**`docs`** - Contains documentation for ui components and other documentation + +**`packages`** - Contains utilities and tools published to `npm` that are used across the monorepo + +## Turborepo Differences + +- Tooling and configurations such as `eslint` and `tsconfig` are included in their own `config` folder. This is a personal preference to separate from the `packages` folder where reusable packages and utilities shared across projects are stored. +- Configurations such as `eslint` and `tsconfig` in the `config` folder do not reference other shareable configurations, for example, my own personal `eslint` config I use across projects. This is a personal preference so that configuration complexity and inheritence is kept to a minimum. This keeps configuration code more readable and self contained to the monorepo. +- Package naming for public packages published to `npm` have the `@` alias scoping while private packages do not have an alias. This is a personal preference to maintain the distinction between published and non-published packages more easily. +- The `apps` and `docs` folders remain separate and both are top-level folders. This is a personal preference to make the distinction between SPA and UI component documentation code / other documentation. I opt for more top-level folders. + +## Turborepo Similarities + +- Under `docs` is where `storybook` component code is stored, however it is common to house this along with the UI component for simplicity. If kept together, you would need to update the project to ignore `storybook` files when building and publishing the UI components to `npm`. diff --git a/docs/repo/COMMANDS.md b/docs/repo/COMMANDS.md new file mode 100644 index 00000000..2ed032e7 --- /dev/null +++ b/docs/repo/COMMANDS.md @@ -0,0 +1,47 @@ +# Additional Commands + +Commit changes using conventional changelog: + +```bash +pnpm commit +``` + +Delete workspace root `node_modules` and `pnpm-lock.yaml` files: + +**Note**: Install `rimraf` globally and make sure it is not installed in the workspace root so errors aren't thrown. + +```bash +pnpm delete +``` + +Lint root and `configs/` `js/cjs` files, check for secrets, lint dependency versions, validate published packages, and verify monorepo best practices: + +```bash +pnpm lint:mr +``` + +Visualize the project structure/dependencies: + +```bash +pnpm nx:graph +``` + +Format all files in the monorepo: + +```bash +pnpm format +``` + +Preview the output result of the `version` command without actually executing it: + +**Note**: Set your personal access token as an environment variable in your operating system as `GH_TOKEN` with the token unique identifier as the value. + +```bash +pnpm preview:version +``` + +Preview the output result of the `publish` command without actually executing it: + +```bash +pnpm preview:publish +``` diff --git a/docs/repo/LICENSE b/docs/repo/LICENSE new file mode 100644 index 00000000..f4c942e0 --- /dev/null +++ b/docs/repo/LICENSE @@ -0,0 +1,7 @@ +Copyright 2023 Matthew Waldron + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/docs/repo/README.md b/docs/repo/README.md new file mode 100644 index 00000000..e89482b6 --- /dev/null +++ b/docs/repo/README.md @@ -0,0 +1,7 @@ +# Monorepo Documentation + +[Architecture](ARCHTIECTURE.md) + +[Additional Commands](COMMANDS.md) + +[Workspace Commands](WORKSPACE.md) diff --git a/docs/repo/WORKSPACE.md b/docs/repo/WORKSPACE.md new file mode 100644 index 00000000..4261314b --- /dev/null +++ b/docs/repo/WORKSPACE.md @@ -0,0 +1,39 @@ +# Workspace Commands + +pnpm workspace commands + +## Add Packages + +Install dependecies to the root of the workspace: + +```bash +pnpm add -w [package-name] +``` + +Add a package as a dependency for another local package: + +```bash +pnpm add react --filter vite-project --workspace +``` + +Add a **local** package as a development dependency for another local package: + +```bash +pnpm add -D eslint-config-custom --filter vite-project --workspace +``` + +## Remove Packages + +Remove a local package from another local package: + +```bash +pnpm remove eslint-config-custom --filter vite-project +``` + +## Run Commands + +Install / run commands for a specific sub-package: + +```bash +pnpm dev --filter vite-project +``` diff --git a/docs/repo/package.json b/docs/repo/package.json new file mode 100644 index 00000000..e948612e --- /dev/null +++ b/docs/repo/package.json @@ -0,0 +1,6 @@ +{ + "name": "monorepo-docs", + "version": "1.0.0", + "private": true, + "license": "MIT" +}