Skip to content

Commit

Permalink
feat: initial boilerplate setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonpraful committed Feb 5, 2024
0 parents commit 891defd
Show file tree
Hide file tree
Showing 26 changed files with 5,027 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:react/jsx-runtime',
'plugin:react-hooks/recommended',
'plugin:@tanstack/eslint-plugin-query/recommended',
],
ignorePatterns: [
'dist',
'.eslintrc.cjs',
'postcss.config.js',
'tailwind.config.js',
],
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaFeatures: { jsx: true },
ecmaVersion: 2020,
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.browser.json'],
tsconfigRootDir: __dirname,
},
overrides: [
{
files: ['**/*.cjs'],
env: {
node: true,
},
},
],
plugins: ['@tanstack/query', 'react-refresh', 'simple-import-sort'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
'simple-import-sort/exports': 2,
'simple-import-sort/imports': 2,
},
}
36 changes: 36 additions & 0 deletions .github/workflows/pre-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Pre-merge checks
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 18
- name: Install dependencies
run: npm install -g yarn && yarn

- name: Install Playwright Browsers
run: yarn playwright install --with-deps

- name: Run Lint
run: yarn lint

- name: Run Unit Tests
run: yarn test:unit

- name: Run E2E Tests
run: yarn test:e2e

- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/

node_modules
.DS_Store
dist
dist-ssr
*.local
2 changes: 2 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
2 changes: 2 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
6 changes: 6 additions & 0 deletions commitlint.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'subject-case': [0, 'always'],
},
}
7 changes: 7 additions & 0 deletions e2e/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, test } from '@playwright/test'

test('has Hello World', async ({ page }) => {
await page.goto('http://localhost:4173')
const text = await page.textContent('h1')
expect(text).toBe('Hello, world!👋')
})
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite Boilerplate</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
67 changes: 67 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "vite-boilerplate",
"version": "1.0.0",
"type": "module",
"private": true,
"author": "Jason Praful <jason.praful@gmail.com>",
"license": "UNLICENSED",
"scripts": {
"dev": "vite",
"build": "vite build",
"format": "prettier --write .",
"lint": "eslint . --ext ts,tsx",
"lint:fix": "eslint . --ext ts,tsx --fix",
"preview": "vite preview",
"test:unit": "vitest",
"test:unit:coverage": "vitest run --coverage",
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test:e2e:debug": "playwright test --debug",
"test:e2e:codegen": "playwright codegen",
"playwright:setup": "playwright install --with-deps",
"commitlint": "commitlint --edit"
},
"dependencies": {
"@tanstack/react-query": "^5.18.1",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"@playwright/test": "^1.41.2",
"@tanstack/eslint-plugin-query": "^5.18.1",
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^14.2.1",
"@testing-library/user-event": "^14.5.2",
"@tsconfig/node18": "18.2.2",
"@tsconfig/vite-react": "^3.0.0",
"@types/node": "18.13.0",
"@types/react": "^18.2.43",
"@types/react-dom": "^18.2.17",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@vitejs/plugin-react": "^4.2.1",
"@vitest/coverage-istanbul": "^1.2.2",
"@vitest/ui": "^1.2.2",
"autoprefixer": "^10.4.17",
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^8.55.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.5",
"eslint-plugin-simple-import-sort": "^10.0.0",
"husky": "^9.0.10",
"jsdom": "^24.0.0",
"postcss": "^8.4.34",
"prettier": "^3.1.1",
"prettier-plugin-tailwindcss": "^0.5.11",
"tailwindcss": "^3.4.1",
"typescript": "^5.2.2",
"vite": "^5.0.8",
"vite-tsconfig-paths": "^4.3.1",
"vitest": "^1.2.2"
},
"engines": {
"node": ">=18.0.0"
}
}
67 changes: 67 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { defineConfig, devices } from '@playwright/test'

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
testDir: './e2e',
fullyParallel: true,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: process.env.CI ? 1 : undefined,
reporter: 'html',
use: {
baseURL: 'http://127.0.0.1:4173',
trace: 'on-first-retry',
},

projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
},

{
name: 'firefox',
use: { ...devices['Desktop Firefox'] },
},

{
name: 'webkit',
use: { ...devices['Desktop Safari'] },
},

/* Test against mobile viewports. */
// {
// name: 'Mobile Chrome',
// use: { ...devices['Pixel 5'] },
// },
// {
// name: 'Mobile Safari',
// use: { ...devices['iPhone 12'] },
// },

/* Test against branded browsers. */
// {
// name: 'Microsoft Edge',
// use: { ...devices['Desktop Edge'], channel: 'msedge' },
// },
// {
// name: 'Google Chrome',
// use: { ...devices['Desktop Chrome'], channel: 'chrome' },
// },
],

/* Run your local dev server before starting the tests */
webServer: {
command: 'yarn build && yarn preview',
url: 'http://localhost:4173',
reuseExistingServer: !process.env.CI,
},
})
6 changes: 6 additions & 0 deletions postcss.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
16 changes: 16 additions & 0 deletions prettier.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/** @type {import("prettier").Config} */
module.exports = {
jsxSingleQuote: false,
proseWrap: 'always',
quoteProps: 'as-needed',
requirePragma: false,
semi: false,
singleQuote: true,
tabWidth: 2,
trailingComma: 'all',
useTabs: true,
endOfLine: 'lf',
printWidth: 80,
tailwindConfig: './tailwind.config.ts',
plugins: ['prettier-plugin-tailwindcss'],
}
1 change: 1 addition & 0 deletions public/vite.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { render } from '@testing-library/react'
import { describe, expect, it } from 'vitest'

import App from './App'

describe('App', () => {
it('renders hello world', () => {
const { getByText } = render(<App />)
expect(getByText('Hello, world!👋')).toBeInTheDocument()
})
})
15 changes: 15 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function App() {
return (
<div className="h-dvh bg-slate-400 antialiased">
<div className="relative flex h-screen items-center justify-center ">
<div className="relative flex animate-bounce">
<div className="rounded-md border border-black bg-slate-900 px-10 py-2 text-white">
<h1 className="text-4xl font-bold">Hello, world!👋</h1>
</div>
</div>
</div>
</div>
)
}

export default App
1 change: 1 addition & 0 deletions src/assets/react.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@tailwind base;
@tailwind components;
@tailwind utilities;
12 changes: 12 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import './index.css'

import React from 'react'
import ReactDOM from 'react-dom/client'

import App from './App.tsx'

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
</React.StrictMode>,
)
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="vite/client" />
8 changes: 8 additions & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('tailwindcss').Config} */
export default {
content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'],
theme: {
extend: {},
},
plugins: [],
}
4 changes: 4 additions & 0 deletions tsconfig.browser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@tsconfig/vite-react/tsconfig.json",
"exclude": ["node_modules", "dist"]
}
8 changes: 8 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.browser.json",
"compilerOptions": {
"composite": true,
"moduleResolution": "Bundler",
"module": "ESNext"
}
}
11 changes: 11 additions & 0 deletions tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"module": "es2015",
"lib": ["es2020"]
},
"exclude": ["node_modules", "dist"]
}
21 changes: 21 additions & 0 deletions vite.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="vitest" />
import react from '@vitejs/plugin-react'
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'

// https://vitejs.dev/config/
export default defineConfig({
test: {
globals: true,
setupFiles: './vitest.setup.ts',
environment: 'jsdom',
css: true,
include: ['**/*.test.tsx', '**/*.test.ts'],
coverage: {
provider: 'istanbul',

reporter: ['html'],
},
},
plugins: [react(), tsconfigPaths()],
})
Loading

0 comments on commit 891defd

Please sign in to comment.