Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.

Commit 6bd3a54

Browse files
authored
Merge pull request #549 from 4ydan/makefile-devcon
Makefile
2 parents 1d19fb5 + 17e1d93 commit 6bd3a54

File tree

6 files changed

+187
-23
lines changed

6 files changed

+187
-23
lines changed

Makefile

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
.PHONY: all
2+
all: build
3+
4+
.PHONY: help
5+
help: ## Show help for each of the Makefile recipes.
6+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9_-]+:.*?## / {gsub("\\\\n",sprintf("\n%22c",""), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
7+
8+
.PHONY: run-frontend
9+
run-frontend: build-frontend ## Starts the frontend server.
10+
cd frontend && npm run dev
11+
12+
.PHONY: run-backend
13+
run-backend: build-backend ## Starts the backend server.
14+
cd backend && make run
15+
16+
.PHONY: run-mdbook
17+
run-mdbook: build-mdbook ## Starts the mdbook server.
18+
mdbook serve --open
19+
20+
.PHONY: run-storybook
21+
run-storybook: build-storybook ## Starts the storybook server.
22+
cd frontend && npm run storybook
23+
24+
# TEST
25+
26+
.PHONY: test
27+
test: test-frontend test-backend test-mdbook ## Tests everything + pre-commit
28+
pre-commit
29+
30+
.PHONY: test-frontend
31+
test-frontend: build-frontend ## Tests the frontend.
32+
cd frontend && npm install && npm run format:check && npm run lint && npm run test
33+
34+
.PHONY: test-backend
35+
test-backend: build-backend ## Tests the backend.
36+
cd backend && make test
37+
38+
.PHONY: test-mdbook
39+
test-mdbook: build-mdbook ## Tests the mdbook.
40+
mdbook test
41+
42+
.PHONY: test-storybook
43+
test-storybook:
44+
@echo "\033[0;31m Not supported \033[0m" && exit 1
45+
46+
# BUILD
47+
48+
.PHONY: build
49+
build: install generate-api-types build-frontend build-backend build-storybook build-mdbook # Builds everything.
50+
51+
.PHONY: build-frontend
52+
build-frontend: install generate-api-types ## Builds the frontend.
53+
cd frontend && npm install && npm run generate-api-types && npm run build
54+
55+
.PHONY: build-backend
56+
build-backend: install generate-api-types ## Builds the backend.
57+
cd backend && make build
58+
59+
.PHONY: build-mdbook
60+
build-mdbook: install ## Builds the mdbook.
61+
mdbook build
62+
63+
.PHONY: build-storybook
64+
build-storybook: install generate-api-types ## Builds the storybook.
65+
cd frontend && npm install && npm run build-storybook
66+
67+
# MISC
68+
69+
.PHONY: generate-type-doc
70+
generate-type-doc: ## Generates typedoc.
71+
cd frontend && npm install && npm run doc
72+
73+
.PHONY: generate-api-types
74+
generate-api-types: ## Generates typescript types.
75+
cd frontend && npm run generate-api-types
76+
77+
.PHONY: psql-r
78+
psql-r: ## Remote connect to postgis, uses $POSTGRES_USER and $POSTGRES_DB
79+
psql -h db -p 5432 -U $(POSTGRES_USER) $(POSTGRES_DB)
80+
81+
.PHONY: pre-commit-all
82+
pre-commit-all: ## Check all files with pre-commit.
83+
pre-commit run --all-files
84+
85+
.PHONY: distclean
86+
distclean: clean uninstall ## Cleans everything and uninstalls.
87+
88+
.PHONY: clean
89+
clean: clean-frontend clean-backend clean-mdbook clean-storybook ## Cleans everything.
90+
91+
.PHONY: clean-frontend
92+
clean-frontend: ## Removes node modules.
93+
cd frontend && rm -rf node_modules
94+
95+
.PHONY: clean-backend
96+
clean-backend: ## Cleans the backend.
97+
cd backend && make clean
98+
99+
.PHONY: clean-mdbook
100+
clean-mdbook: ## Removes the mdbook folder.
101+
mdbook clean
102+
103+
.PHONY: clean-storybook
104+
clean-storybook: ## Removes the storybook static folder.
105+
cd frontend && rm -rf storybook-static
106+
107+
.PHONY: install
108+
install: ## Install necessary packages within the source repo.
109+
cd backend && make install
110+
cargo install mdbook mdbook-mermaid
111+
cargo install --git https://github.com/ElektraInitiative/mdbook-generate-summary mdbook-generate-summary
112+
113+
.PHONY: uninstall
114+
uninstall: ## Uninstalls dependencies within the source repo.
115+
cd backend && make uninstall
116+
cargo uninstall mdbook mdbook-mermaid
117+
cargo uninstall mdbook-generate-summary

README.md

+19-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,33 @@
88
- Web: Firefox, Chromium
99
- Larger mobile devices like tablets: Progressive Web App (PWA) Android 9+
1010

11+
## Documentation
12+
1113
Start reading in [/doc/architecture/README.md](/doc/architecture/README.md).
1214
The documentation is best viewed by running the following commands in the projects root folder:
1315

1416
```sh
15-
cargo install mdbook mdbook-mermaid
16-
cargo install --git https://github.com/ElektraInitiative/mdbook-generate-summary mdbook-generate-summary
17-
mdbook serve --open
17+
make run-mdbook
1818
```
1919

2020
Which will open [/doc/architecture/README.md](/doc/architecture/README.md) as first page.
2121

22+
## Makefile commands
23+
24+
Following commands exists:
25+
26+
`run, test, build, clean`
27+
28+
Following entities exist:
29+
30+
`frontend, backend, mdbook, storybook`
31+
32+
You can construct your commands now, e.g `run-backend`, `test-mdbook`, `build-storybook` or `clean-backend`
33+
34+
Type `make help` to see all commands`
35+
36+
**SOME OF THESE COMMANDS REQUIRE ENV VARIABLES TO WORK, LOOK AT [backend env variables](./doc/backend/01setup.md) or [frontend env variables](./frontend/README.md)**
37+
2238
Important links:
2339

2440
- [Web API Documentation](https://www.permaplant.net/doc/api/swagger/ui/)

backend/Makefile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.PHONY: run
2+
run:
3+
cargo run
4+
5+
.PHONY: test
6+
test: build
7+
cargo test && cargo check && cargo clippy && cargo doc
8+
9+
.PHONY: build
10+
build: install migrate
11+
cargo build
12+
13+
# Diesel setup, this makes sure that diesel will create the database if it doesn't exist yet and will run all migrations.
14+
# Diesel migrations, to bring the database up to date with the current schema.
15+
.PHONY: migrate
16+
migrate: install
17+
LC_ALL=C diesel setup && LC_ALL=C diesel migration run
18+
19+
.PHONY: clean
20+
clean:
21+
cargo clean
22+
23+
.PHONY: install
24+
install:
25+
rustup component add rustfmt clippy
26+
cargo install [email protected] --no-default-features --features postgres && cargo install typeshare-cli
27+
28+
.PHONY: uninstall
29+
uninstall:
30+
rustup component remove rustfmt clippy
31+
cargo uninstall [email protected] --no-default-features --features postgres && cargo install typeshare-cli

backend/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# PermaplanT Backend
22

3-
Documentation about the backend including setup instructions can be found in `doc/backend/`.
3+
Documentation about the backend including setup instructions can be found [here](../doc/backend/01setup.md).

doc/CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Syntax: `- short text describing the change _(Your Name)_`
3333
- _()_
3434
- _()_
3535
- Improved user visible texts in map editor _(Thorben)_
36-
- _()_
36+
- DEV: Makefile added #549 _(4ydan)_
3737

3838
## 0.2.1 - UNRELEASED
3939

doc/backend/01setup.md

+18-18
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,29 @@ sudo -u postgres psql
2020
CREATE USER permaplant WITH CREATEDB PASSWORD 'permaplant';
2121
```
2222

23-
2. Install Diesel CLI:
23+
2. Install
2424

25-
```shell
26-
cargo install diesel_cli --no-default-features --features postgres
27-
```
25+
To install dependencies.
2826

29-
3. Run the diesel setup, this makes sure that diesel will create the database if it doesn't exist yet and will run all migrations.
30-
31-
```shell
32-
LC_ALL=C diesel setup
27+
```sh
28+
make install
3329
```
3430

35-
4. Run diesel migrations, to bring the database up to date with the current schema.
31+
3. migrate
3632

37-
```shell
38-
LC_ALL=C diesel migration run
33+
To update the database.
34+
35+
```sh
36+
make migrate
3937
```
4038

41-
5. Install the typeshare cli to enable type safety between Rust and TypeScript:
39+
4. build
4240

43-
```shell
44-
cargo install typeshare-cli
41+
```sh
42+
make build
4543
```
4644

47-
6. Start Keycloak
45+
5. Start Keycloak
4846

4947
You can do one of the following two steps, the first one being the simpler one, but with less configuration options.
5048

@@ -54,10 +52,12 @@ You can do one of the following two steps, the first one being the simpler one,
5452
- `AUTH_DISCOVERY_URI=http://localhost:8081/realms/PermaplanT/.well-known/openid-configuration`
5553
- `AUTH_CLIENT_ID=PermaplanT`
5654

57-
7. Run the backend
55+
6. run
56+
57+
To start the server
5858

59-
```bash
60-
cargo run
59+
```sh
60+
make run
6161
```
6262

6363
## Test server using Swagger

0 commit comments

Comments
 (0)