Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify project structure #117

Merged
merged 6 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ on:

jobs:

# server:
# can we run the server, is the API alright?
#
# Priority is to fail fast, so first can we compile and build
# the server binary, then tests, and linting.
server:
app:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -33,5 +28,5 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: cashapp/activate-hermit@v1
- name: shellcheck ./dev
run: shellcheck ./prod
- name: shellcheck
run: shellcheck bin/prmectl
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,13 @@ to generate something that can be, well, presented!

## Development

This project uses [hermit](https://cashapp.github.io/hermit/) for dependency management.
This project uses [hermit](https://cashapp.github.io/hermit/) for dependency management,
if you have the shell hooks this will automatically work, otherwise you can use `bin/prmectl`.

### Bootstrap

```sh
# for go packages
go mod download

# for tailwindcss
bun install
bin/prmectl boostrap
```

Make sure you've run this before anything else!
Expand Down Expand Up @@ -93,7 +90,7 @@ Commands:
#### Development

```bash
dev
bin/prmectl dev
```

- <http://localhost:8080>
File renamed without changes.
1 change: 0 additions & 1 deletion bin/[email protected]

This file was deleted.

2 changes: 1 addition & 1 deletion bin/bun
1 change: 0 additions & 1 deletion bin/corepack

This file was deleted.

1 change: 0 additions & 1 deletion bin/node

This file was deleted.

1 change: 0 additions & 1 deletion bin/npm

This file was deleted.

1 change: 0 additions & 1 deletion bin/npx

This file was deleted.

106 changes: 48 additions & 58 deletions bin/prmectl
Original file line number Diff line number Diff line change
@@ -1,65 +1,55 @@
#!/bin/bash
set -euo pipefail

# We ensure that we're running in the project directory
# assuming that this script is in a single level sudirectory
# out from the PROJECT base...
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
PROJECT_DIR="$SCRIPT_DIR/../"
cd "$PROJECT_DIR"
cd "$(dirname "${BASH_SOURCE[@]}")/../"

usage() {
echo "Commands: "
rg '^\s+([^)]+)\)$' "${BASH_SOURCE[0]}" -r '- prmectl $1' -N | grep -v '\*'
}
# shellcheck disable=SC1091
. bin/activate-hermit || true

case "$1" in
bootstrap)
# 1. Hermit has dependencies in this directory.
hermit install
# 2. Corepack installs yarn, then we get all of our frontend/ deps
corepack enable
pushd frontend
yarn
popd
# 3. Get all of our server/ deps
pushd server
go mod download
popd
;;
dev)
_run_dev() {
trap 'trap " " SIGTERM; kill 0; wait' SIGINT SIGTERM
prmectl start-frontend &
prmectl start-server &
_run_go-dev &
_run_tw-dev &
wait
;;
local-prod)
cd frontend
yarn generate
cd ../server
(rm static || true) && ln -s ../frontend/.output/public static
# shellcheck disable=SC2046,SC2002
exec env $(cat .env | xargs) \
go run ./cmd/server
;;
start-frontend)
cd frontend
exec yarn run dev
;;
start-server)
cd server
# shellcheck disable=SC2046,SC2002
exec env $(cat .env | xargs) \
go run github.com/cespare/reflex -d none -s -- \
go run ./cmd/server --serve=proxy
;;
help)
usage
;;
*)
echo "invalid option: $1"
echo
usage
exit 1
;;
esac
exit 0
}

_run_prod() {
_run_tw-minify && _run_go-prod
}

_run_tw-minify() {
bun run tailwindcss --minify \
-i static/input.css \
-o static/styles.css
}

_run_go-prod() {
# shellcheck disable=SC2046,SC2002
exec env $(cat .env | xargs) \
go run ./cmd/veun serve --environment=prod
}

_run_go-dev() {
# shellcheck disable=SC2046,SC2002
exec env $(cat .env | xargs) \
go run github.com/cespare/reflex -d none -s -- go run ./cmd/veun serve
}

_run_tw-dev() {
exec bun run tailwindcss -w \
-i static/input.css \
-o static/styles.dev.css
}

_run_bootstrap() {
hermit install
go mod download
bun install --frozen-lockfile
}

_run_shellcheck() {
shellcheck "${BASH_SOURCE[@]}"
}

"_run_$1"
Binary file modified bun.lockb
Binary file not shown.
13 changes: 13 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package presentme

import (
"context"
"time"

"github.com/pkg/errors"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -38,3 +39,15 @@ func (c *Config) Logger(ctx context.Context) (context.Context, zerolog.Logger) {
func (c *Config) Cache(ctx context.Context) *cache.Cache {
return cache.NewCache(ctx, c.DiskCache)
}

type ServeConfig struct {
// Port describes the port this server runs on.
Port string `default:"8080" env:"PORT"`
Hostname string `default:"localhost" env:"HOSTNAME"`
ServerReadTimeout time.Duration `default:"5s"`
ServerWriteTimeout time.Duration `default:"10s"`
}

func (c *ServeConfig) Address() string {
return c.Hostname + ":" + c.Port
}
26 changes: 0 additions & 26 deletions dev

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "dependencies": { "tailwindcss": "^3.4.3" } }
{ "dependencies": { "tailwindcss": "^3.4.4" } }
7 changes: 0 additions & 7 deletions prod

This file was deleted.

17 changes: 0 additions & 17 deletions serve_config.go

This file was deleted.

Loading