This project includes configuration and tooling that conforms to Crema's baseline best-practices for a Web Application.
π§° Tools Used
- Create React App for simple configuration π
- Cypress for end-to-end testing
- ESLint for code linting
- Husky for running tasks via git hooks
- Hygen for component and util generators
- Jest for unit tests
- Prettier for code formatting
- Storybook for component playground
- TypeScript for Static Typing in JavaScript (Learn)
Run these commands from project root.
- Install NVM (Node Version Manager)
nvm install(in new sessions runnvm useto load version specified in.nvmrcunless aliased to default)npm i -g npm@latest(npm@v7+ required)npm i(install project dependencies)- Install the ESLint and Prettier plugins for
your editorVS Code and enable "Fix on Save" insettings.json:{ "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true }To access
settings.jsonin VS Code, typeshift + β + P) then search "Open Settings (JSON)"βadd the above settings within the existing JSON object."But I don't use VS Code." That's fine but you're on your own. π
Run the following scripts with npm run <SCRIPT_HERE>:
start- start appnew:component- generate a new componentnew:util- generate a new util(ity)new:type- generate a new typetest:analyze- run bundle analyzertest:deps- run dependency validation teststest:e2e- run end-to-end teststest:lint:fix- run linter and fix if possibletest:lint- run lintertest:playground- run component playground (storybook)test:unit:coverage- run unit tests with coveragetest:unit- run unit testsdeps:graph- run dependency validation and generate an SVG representing the dependency graph (requiresgraphvizto be installed on your device)deps:report- run dependency validation and generate an HTML report
These scripts are located in
package.jsonand do not represent the entirety of available scripts, but are the most commonly used.
Below is the project's file-tree with notes added as inline comments.
Uninteresting info is denoted by
...
.
βββ .github # π PR/Issue Templates, workflows, and Renovate config
βββ .storybook # π Storybook config
βββ cypress # π Cypress integration testing
βΒ Β βββ fixtures # π Test data
βΒ Β βΒ Β βββ example.json
βΒ Β βββ integration # π Tests go here
βΒ Β βΒ Β βββ sample_spec.ts
βΒ Β βββ ...
βββ public # π Static files
βββ src
βΒ Β βββ assets # π fonts, images, etc.
βΒ Β βΒ Β βββ logo.svg
βΒ Β βββ components # π Use `npm run new:component` to generate
βΒ Β βΒ Β βββ App
βΒ Β βΒ Β βΒ Β βββ README.md # π Every component has a README
βΒ Β βΒ Β βΒ Β βββ index.tsx # π Contains main implementation
βΒ Β βΒ Β βΒ Β βββ stories.tsx # π Component stories; use `npm run test:playground` to run
βΒ Β βΒ Β βΒ Β βββ styles.css # π Component styles (not included in generated code)
βΒ Β βΒ Β βΒ Β βββ test.tsx # π Component tests; use `npm run test:unit` to run
βΒ Β βΒ Β βββ README.md # π Every top-level directory in `src` has a README.md
βΒ Β βββ types # π Type definitions go here; use `npm run new:type` to generate
βΒ Β βΒ Β βββ README.md
βΒ Β βββ utils # π Utilities go here; use `npm run new:util` to generate
βΒ Β βΒ Β βββ README.md
βΒ Β βββ index.css # π Root styles
βΒ Β βββ index.tsx # π Root application file
βΒ Β βββ react-app-env.d.ts # π Extends react-scripts TypeScript definitions
βΒ Β βββ reportWebVitals.ts # π Useful, but not required
βΒ Β βββ serviceWorker.ts # π Useful, but not required
βΒ Β βββ setupTests.ts # π Top-level setup for Jest test runs
βββ .dependency-cruiser.js # π Dependency Cruiser config
βββ .eslintrc.js # π ESLint - Run Commands
βββ .gitattributes # π Git meta information
βββ .gitignore # π Git ignore patterns
βββ .nvmrc # π Node Version Manager - Run Commands
βββ .prettierrc.js # π Prettier - Run Commands
βββ LICENSE # π LICENSE π
βββ README.md # π π π YOU ARE HERE
βββ cypress.json # π Cypress config
βββ package-lock.json
βββ package.json
βββ tsconfig.json # π TypeScript config and extends- Use the code generators:
npm run new:componentnpm run new:typenpm run new:util
- Fill out the
README.mdto describe what your code does - Run your unit tests
npm run test:unitwhile working to see immediate feedback - If you get stuck at any point, just log an issue and we'll figure it out together π.