Skip to content

Commit

Permalink
Adding detailed README and cleanup (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
devinmatte authored Mar 19, 2024
1 parent 7c0e118 commit 154cd87
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 66 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = E501,E731,W503
exclude =
.chalice
.venv
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Set up Node ${{ matrix.node-version }}.x
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Set up CI Cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.npm
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: lint

on:
pull_request:
push:
branches:
- main

jobs:
frontend:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['20']
python-version: ['3.11']
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Node ${{ matrix.node-version }}.x
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Check if package-lock.json is up to date
run: |
npx --yes [email protected]
- name: Lint frontend code with ESLint
run: |
curl -sSL https://install.python-poetry.org | python3 -
npm ci
npm run lint-frontend
backend:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['20']
python-version: ['3.11']
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Set up Node ${{ matrix.node-version }}.x
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Check if package-lock.json is up to date
run: |
npx --yes [email protected]
- name: Lint backend code with Flake8
run: |
curl -sSL https://install.python-poetry.org | python3 -
npm ci
npm run lint-backend
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ server/cfn/*
server/.chalice/deployments/*

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
Expand Down
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"bradlc.vscode-tailwindcss"
]
}
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"eslint.enable": true,
"eslint.format.enable": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
"typescript.enablePromptUseWorkspaceTsdk": true,
"editor.formatOnSave": true,
"python.analysis.typeCheckingMode": "off",
"python.formatting.provider": "black",
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
}
}
65 changes: 43 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,51 @@
# React + TypeScript + Vite
# TransitMatters Shutdown Tracker

This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
This is the repository for the TransitMatters Shutdown Tracker. Client code is written in Typescript with React and vite, and the minimal backend is written in Python with Chalice.

Currently, two official plugins are available:
## Requirements to develop locally

- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
- node 20.x and npm 10+ required
- With `nvm` installed, use `nvm install && nvm use`
- verify with `node -v`
- Python 3.11 with recent poetry (1.6.0 or later)
- Verify with `python --version && poetry --version`
- `poetry self update` to update poetry
- If using `pyenv`, `pyenv install 3.11.7`

## Expanding the ESLint configuration
## Development Instructions

If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
1. In the root directory, run `npm install` to install all frontend and backend dependencies
2. Run `npm start` to start both the Vite development server and the Python backend at the same time.
1. `npm run dev` to just run the Vite development server
2. `npm run start-python` to just run the Chalice backend server
3. Navigate to [http://localhost:3000](http://localhost:3000) (or the url provided after running `npm start`)

- Configure the top-level `parserOptions` property like this:
## Deployment Instructions

```js
export default {
// other rules...
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
}
```
1. Configure AWS CLI 1.x or 2.x with your AWS access key ID and secret under the profile name `transitmatters`.
2. Configure shell environment variables for AWS ACM domain certificates.
- `TM_LABS_WILDCARD_CERT_ARN`
- (You may also need to set `AWS_DEFAULT_REGION` in your shell to `us-east-1`. Maybe not! We're not sure.)
- `DD_API_KEY` (Datadog API key, needed to deploy to TransitMatters stack in prod)
3. Execute `./deploy.sh`.

- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
#### Additional notes:

- If you're on a platform with a non-GNU `sed`, deploy.sh might fail. On macOS, this is fixed by `brew install gnu-sed` and adding it to your PATH.
- If you get an unexplained error, check the CloudFormation stack status in AWS Console. Good luck!

### Linting

To lint frontend and backend code, run `npm run lint` in the root directory

To lint just frontend code, run `npm run lint-frontend`

To lint just backend code, run `npm run lint-backend`

#### VSCode

If you're using VSCode, `.vscode` contains a based default workspace setup. It also includes recommended extentions that will improve the dev experience. This config is meant to be as small as possible to enable an "out of the box" easy experience for handling eslint.

## Support TransitMatters

If you've found this app helpful or interesting, please consider [donating](https://transitmatters.org/donate) to TransitMatters to help support our mission to provide data-driven advocacy for a more reliable, sustainable, and equitable transit system in Metropolitan Boston.
19 changes: 10 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
"start-python": "cd server && poetry run chalice local --port=5000",
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"lint-frontend": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 10",
"lint-backend": "cd server && poetry run flake8 && poetry run black . --check",
"lint": "concurrently npm:lint-frontend npm:lint-backend",
"postinstall": "cd server && poetry install",
"preview": "vite preview"
},
"engines": {
"node": ">=20.10.0",
"npm": ">=9.0.0"
"npm": ">=10.0.0"
},
"proxy": "http://localhost:5000",
"dependencies": {
"concurrently": "^8.2.0",
"concurrently": "^8.2.2",
"@headlessui/react": "^1.7.18",
"@heroicons/react": "^2.1.1",
"@tanstack/react-query": "^5.18.1",
Expand All @@ -36,7 +39,7 @@
"react-router-dom": "^6.22.0",
"react-scroll": "^1.9.0",
"react-toggle-dark-mode": "^1.1.1",
"zustand": "^4.5.0"
"zustand": "^4.5.1"
},
"devDependencies": {
"@types/bezier-js": "^4.1.3",
Expand Down
32 changes: 16 additions & 16 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 154cd87

Please sign in to comment.