blaketarter / web-synth

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crema App - Web 🌐

Build Status codecov License: MIT

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
  • Loki for visual testing
  • Prettier for code formatting (🚨 DO NOT enable the VS Code Prettier pluginβ€”ESLint runs it for you under the hood. πŸŽ‰)
  • Storybook for component playground (and used by Loki)
  • TypeScript for Static Typing in JavaScript (Learn)

πŸ— Setup

Run these commands from project root.

  1. Install NVM (Node Version Manager)
  2. nvm install (in new sessions run nvm use to load version specified in .nvmrc unless aliased to default)
  3. npm i -g npm@latest (npm@v7+ required)
  4. npm i (install project dependencies)
  5. Install the ESLint plugin for your editor VS Code and enable "Fix on Save" in settings.json:
    {
      "editor.codeActionsOnSave": {
        "source.fixAll.eslint": true
      }
    }

    Go to settings (⌘ + ,), search codeActionsOnSave and click "Edit in settings.json", then add "editor.codeActionsOnSave": {...} within the existing JSON object.

    "But I don't use VS Code." That's fine but you're on your own. πŸ˜…

    🚨 DO NOT enable the VS Code Prettier plugin for this projectβ€”ESLint runs it for you under the hood. πŸŽ‰

  6. Install Docker Desktop
    1. Used by Loki which runs on git pre-push hook via Husky

πŸ‘Ÿ Run

Run the following scripts with npm run <SCRIPT_HERE>:

  • start - start app
  • new:component - generate a new component
  • new:util - generate a new util(ity)
  • new:type - generate a new type
  • test:analyze - run bundle analyzer
  • test:deps - run dependency validation tests
  • test:e2e - run end-to-end tests
  • test:lint:fix - run linter and fix if possible
  • test:lint - run linter
  • test:playground - run component playground (storybook)
  • test:unit:coverage - run unit tests with coverage
  • test:unit - run unit tests
  • test:visual:approve - approve visual changes
  • test:visual:update - update or create visual references
  • test:visual - run visual tests (loki)
  • deps:graph - run dependency validation and generate an SVG representing the dependency graph (requires graphviz to be installed on your device)
  • deps:report - run dependency validation and generate an HTML report

These scripts are located in package.json and do not represent the entirety of available scripts, but are the most commonly used.

πŸ› Structure

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
β”œβ”€β”€ .loki # πŸ‘ˆ Loki provides visual regression testing of Storybook files
β”‚   β”œβ”€β”€ current # πŸ‘ˆ Images from current test run
β”‚   β”‚   └── chrome_App_Example.png
β”‚   β”œβ”€β”€ difference # πŸ‘ˆ Differences from current test run
β”‚   β”œβ”€β”€ reference # πŸ‘ˆ Approved reference images
β”‚   β”‚   └── chrome_App_Example.png
β”‚   └── .gitignore # πŸ‘ˆ `./current` and `./difference` are not tracked
β”œβ”€β”€ .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

πŸ₯‡ Best Practices

  • Use the code generators:
    • npm run new:component
    • npm run new:type
    • npm run new:util
  • Fill out the README.md to describe what your code does
  • Run your unit tests npm run test:unit while working to see immediate feedback
  • If you get stuck at any point, just log an issue and we'll figure it out together πŸ‘­.

About

License:MIT License


Languages

Language:TypeScript 70.6%Language:SCSS 21.1%Language:HTML 6.1%Language:CSS 1.7%Language:Shell 0.5%