mirror of
https://github.com/coder/coder.git
synced 2026-06-05 14:08:20 +00:00
ec077c6191
Fix for #348 - migrate our NextJS project to a pure webpack project w/ a single bundle - [x] Switch from `next/link` to `react-router-dom`'s link > This part was easy - just change the import to `import { Link } from "react-router-dom"` and `<Link href={...} />` to `<Link to={...} />` - [x] Switch from `next/router` to `react-router-dom`'s paradigms (`useNavigation`, `useLocation`, and `useParams`) > `router.push` can be converted to `navigate(...)` (provided by the `useNavigate` hook) > `router.replace` can be converted `navigate(..., {replace: true})` > Query parameters (`const { query } = useRouter`) can be converted to `const query = useParams()`) - [x] Implement client-side routing with `react-router-dom` > Parameterized routes in NextJS like `projects/[organization]/[project]` would look like: > ``` > <Route path="projects"> > <Route path=":organization/:project"> > <Route index element={<ProjectPage />} /> > </Route> > </Route> > ``` I've hooked up a `build:analyze` command that spins up a server to show the bundle size: <img width="1303" alt="image" src="https://user-images.githubusercontent.com/88213859/157496889-87c5fdcd-fad1-4f2e-b7b6-437aebf99641.png"> The bundle looks OK, but there are some opportunities for improvement - the heavy-weight dependencies, like React, ReactDOM, Material-UI, and lodash could be brought in via a CDN: https://stackoverflow.com/questions/50645796/how-to-import-reactjs-material-ui-using-a-cdn-through-webpacks-externals
94 lines
2.5 KiB
Makefile
94 lines
2.5 KiB
Makefile
INSTALL_DIR=$(shell go env GOPATH)/bin
|
|
GOOS=$(shell go env GOOS)
|
|
GOARCH=$(shell go env GOARCH)
|
|
|
|
bin:
|
|
goreleaser build --single-target --snapshot --rm-dist
|
|
.PHONY: bin
|
|
|
|
build: site/out bin
|
|
.PHONY: build
|
|
|
|
# Runs migrations to output a dump of the database.
|
|
database/dump.sql: $(wildcard database/migrations/*.sql)
|
|
go run database/dump/main.go
|
|
|
|
# Generates Go code for querying the database.
|
|
database/generate: fmt/sql database/dump.sql database/query.sql
|
|
cd database && sqlc generate && rm db_tmp.go
|
|
cd database && gofmt -w -r 'Querier -> querier' *.go
|
|
cd database && gofmt -w -r 'Queries -> sqlQuerier' *.go
|
|
.PHONY: database/generate
|
|
|
|
docker/image/coder: build
|
|
cp ./images/coder/run.sh ./dist/coder_$(GOOS)_$(GOARCH)
|
|
docker build --network=host -t us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest -f images/coder/Dockerfile ./dist/coder_$(GOOS)_$(GOARCH)
|
|
.PHONY: docker/build
|
|
|
|
fmt/prettier:
|
|
@echo "--- prettier"
|
|
# Avoid writing files in CI to reduce file write activity
|
|
ifdef CI
|
|
cd site && yarn run format:check
|
|
else
|
|
cd site && yarn run format:write
|
|
endif
|
|
.PHONY: fmt/prettier
|
|
|
|
fmt/sql: ./database/query.sql
|
|
npx sql-formatter \
|
|
--language postgresql \
|
|
--lines-between-queries 2 \
|
|
./database/query.sql \
|
|
--output ./database/query.sql
|
|
sed -i 's/@ /@/g' ./database/query.sql
|
|
|
|
fmt: fmt/prettier fmt/sql
|
|
.PHONY: fmt
|
|
|
|
gen: database/generate peerbroker/proto provisionersdk/proto provisionerd/proto
|
|
.PHONY: gen
|
|
|
|
install: bin
|
|
@echo "--- Copying from bin to $(INSTALL_DIR)"
|
|
cp -r ./dist/coder_$(GOOS)_$(GOARCH) $(INSTALL_DIR)
|
|
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
|
|
.PHONY: install
|
|
|
|
peerbroker/proto: peerbroker/proto/peerbroker.proto
|
|
protoc \
|
|
--go_out=. \
|
|
--go_opt=paths=source_relative \
|
|
--go-drpc_out=. \
|
|
--go-drpc_opt=paths=source_relative \
|
|
./peerbroker/proto/peerbroker.proto
|
|
.PHONY: peerbroker/proto
|
|
|
|
provisionerd/proto: provisionerd/proto/provisionerd.proto
|
|
protoc \
|
|
--go_out=. \
|
|
--go_opt=paths=source_relative \
|
|
--go-drpc_out=. \
|
|
--go-drpc_opt=paths=source_relative \
|
|
./provisionerd/proto/provisionerd.proto
|
|
.PHONY: provisionerd/proto
|
|
|
|
provisionersdk/proto: provisionersdk/proto/provisioner.proto
|
|
protoc \
|
|
--go_out=. \
|
|
--go_opt=paths=source_relative \
|
|
--go-drpc_out=. \
|
|
--go-drpc_opt=paths=source_relative \
|
|
./provisionersdk/proto/provisioner.proto
|
|
.PHONY: provisionersdk/proto
|
|
|
|
site/out:
|
|
./scripts/yarn_install.sh
|
|
cd site && yarn build
|
|
# Restores GITKEEP files!
|
|
git checkout HEAD site/out
|
|
.PHONY: site/out
|
|
|
|
snapshot:
|
|
goreleaser release --snapshot --rm-dist
|
|
.PHONY: snapshot |