Add auto-reload for frontend and backend
Also adds more just commands and improves the README docs.
This commit is contained in:
parent
76cc87631f
commit
3f744c0c50
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
|||||||
.env
|
.env
|
||||||
/static/js/**.js
|
/static/js/**.js
|
||||||
/static/js/js_bundles.txt
|
/static/js/js_bundles.txt
|
||||||
|
.frontend-built
|
||||||
|
101
README.md
101
README.md
@ -3,52 +3,87 @@
|
|||||||
My personalized news and blog aggregator. Taking back control over the
|
My personalized news and blog aggregator. Taking back control over the
|
||||||
algorithm. Pining for the days of Google Reader. An excuse to write more Rust.
|
algorithm. Pining for the days of Google Reader. An excuse to write more Rust.
|
||||||
|
|
||||||
## Development Install
|
## Development Instructions
|
||||||
|
|
||||||
1. Install and run postgres.
|
### Prerequisites
|
||||||
2. Create postgres user and database:
|
|
||||||
|
|
||||||
```
|
Install these requirements to get started developing crawlnicle.
|
||||||
createuser crawlnicle
|
|
||||||
createdb crawlnicle
|
|
||||||
sudo -u postgres -i psql
|
|
||||||
postgres=# ALTER DATABASE crawlnicle OWNER TO crawlnicle;
|
|
||||||
\password crawlnicle
|
|
||||||
|
|
||||||
# Or, on Windows in PowerShell:
|
* [rust](https://www.rust-lang.org/)
|
||||||
|
* [postgres](https://www.postgresql.org/)
|
||||||
|
* [sqlx-cli](https://crates.io/crates/sqlx-cli)
|
||||||
|
* Only postgres needed. Install with:
|
||||||
|
|
||||||
& 'C:\Program Files\PostgreSQL\13\bin\createuser.exe' -U postgres crawlnicle
|
```bash
|
||||||
& 'C:\Program Files\PostgreSQL\13\bin\createdb.exe' -U postgres crawlnicle
|
cargo install sqlx-cli --no-default-features --features native-tls,postgres
|
||||||
& 'C:\Program Files\PostgreSQL\13\bin\psql.exe' -U postgres
|
```
|
||||||
postgres=# ALTER DATABASE crawlnicle OWNER TO crawlnicle;
|
|
||||||
\password crawlnicle
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Save password somewhere safe and then and add a `.env` file to the project
|
* [just](https://github.com/casey/just#installation)
|
||||||
|
* (optional) [cargo-watch](https://github.com/watchexec/cargo-watch#install) for
|
||||||
|
auto-recompiling the server in development
|
||||||
|
* (optional) [mold](https://github.com/rui314/mold#installation) for faster
|
||||||
|
builds
|
||||||
|
|
||||||
|
### First-time setup
|
||||||
|
|
||||||
|
1. Create postgres user and database:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
createuser crawlnicle
|
||||||
|
createdb crawlnicle
|
||||||
|
sudo -u postgres -i psql
|
||||||
|
postgres=# ALTER DATABASE crawlnicle OWNER TO crawlnicle;
|
||||||
|
\password crawlnicle
|
||||||
|
|
||||||
|
# Or, on Windows in PowerShell:
|
||||||
|
|
||||||
|
& 'C:\Program Files\PostgreSQL\13\bin\createuser.exe' -U postgres crawlnicle
|
||||||
|
& 'C:\Program Files\PostgreSQL\13\bin\createdb.exe' -U postgres crawlnicle
|
||||||
|
& 'C:\Program Files\PostgreSQL\13\bin\psql.exe' -U postgres
|
||||||
|
postgres=# ALTER DATABASE crawlnicle OWNER TO crawlnicle;
|
||||||
|
\password crawlnicle
|
||||||
|
```
|
||||||
|
|
||||||
|
1. Save password somewhere safe and then and add a `.env` file to the project
|
||||||
directory with the contents:
|
directory with the contents:
|
||||||
|
|
||||||
```
|
```env
|
||||||
RUST_LOG=crawlnicle=debug,cli=debug,lib=debug,tower_http=debug,sqlx=debug
|
RUST_LOG=crawlnicle=debug,cli=debug,lib=debug,tower_http=debug,sqlx=debug
|
||||||
HOST=127.0.0.1
|
HOST=127.0.0.1
|
||||||
PORT=3000
|
PORT=3000
|
||||||
DATABASE_URL=postgresql://crawlnicle:<password>@localhost/crawlnicle
|
DATABASE_URL=postgresql://crawlnicle:<password>@localhost/crawlnicle
|
||||||
DATABASE_MAX_CONNECTIONS=5
|
DATABASE_MAX_CONNECTIONS=5
|
||||||
TITLE=crawlnicle
|
TITLE=crawlnicle
|
||||||
MAX_MEM_LOG_SIZE=1000000
|
MAX_MEM_LOG_SIZE=1000000
|
||||||
```
|
```
|
||||||
|
|
||||||
4. Install
|
1. Run `just migrate` (or `sqlx migrate run`) which will run all the database
|
||||||
[`sqlx_cli`](https://github.com/launchbadge/sqlx/tree/master/sqlx-cli) with
|
migrations.
|
||||||
`cargo install sqlx-cli --no-default-features --features native-tls,postgres`
|
|
||||||
5. Run `sqlx migrate run` which will run all the database migrations.
|
### Running in Development
|
||||||
6. Build the release binary by running `cargo build --release`.
|
|
||||||
7. Run `./target/build/crawlnicle` to start the server.
|
Run `just watch` to build and run the server while watching the source-files for
|
||||||
|
changes and triggering a recompilation when modifications are made.
|
||||||
|
|
||||||
|
The server also triggers the browser to reload the page when the server binary
|
||||||
|
is updated and the server is restarted.
|
||||||
|
|
||||||
|
It also separately watches the files in `frontend/` which will trigger a
|
||||||
|
transpilation with `bun` and then rebuild the server binary so that it includes
|
||||||
|
the new JS bundle names.
|
||||||
|
|
||||||
|
Alternatively, you can just run `cargo run`.
|
||||||
|
|
||||||
|
### Building for Production
|
||||||
|
|
||||||
|
You can also build the binary in release mode for running in production with the
|
||||||
|
`just build` command (or `cargo build --release`).
|
||||||
|
|
||||||
## Using the CLI
|
## Using the CLI
|
||||||
|
|
||||||
This project also comes with a CLI binary which allows you to manipulate the
|
This project also comes with a CLI binary which allows you to manipulate the
|
||||||
database directly without needing to go through the REST API server. Run
|
database directly without needing to go through the REST API server. Run
|
||||||
`./target/build/cli --help` to see all of the available commands.
|
`cli --help` to see all of the available commands.
|
||||||
|
|
||||||
## Running jobs
|
## Running jobs
|
||||||
|
|
||||||
|
1
build.rs
1
build.rs
@ -4,6 +4,7 @@ use std::path::Path;
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
println!("cargo:rerun-if-changed=migrations");
|
println!("cargo:rerun-if-changed=migrations");
|
||||||
|
println!("cargo:rerun-if-changed=.frontend-built");
|
||||||
|
|
||||||
let root_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
let root_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
||||||
let root_dir = Path::new(&root_dir);
|
let root_dir = Path::new(&root_dir);
|
||||||
|
36
justfile
36
justfile
@ -1,4 +1,36 @@
|
|||||||
#!/usr/bin/env just --justfile
|
#!/usr/bin/env just --justfile
|
||||||
|
|
||||||
build-frontend:
|
build: build-frontend
|
||||||
bun build frontend/index.ts --outdir ./static/js --entry-naming [name]-[hash].[ext]
|
cargo build --release
|
||||||
|
|
||||||
|
install-frontend:
|
||||||
|
bun install --cwd frontend
|
||||||
|
|
||||||
|
clean-frontend:
|
||||||
|
rm -rf ./static/js/*
|
||||||
|
|
||||||
|
build-frontend: install-frontend clean-frontend
|
||||||
|
bun build frontend/index.ts \
|
||||||
|
--outdir ./static/js \
|
||||||
|
--entry-naming [name]-[hash].[ext]
|
||||||
|
|
||||||
|
watch-frontend: install-frontend
|
||||||
|
cargo watch -w frontend \
|
||||||
|
-s 'rm -rf ./static/js/*' \
|
||||||
|
-s 'bun build frontend/index.ts \
|
||||||
|
--outdir ./static/js \
|
||||||
|
--entry-naming [name]-[hash].[ext]' \
|
||||||
|
-s 'touch .frontend-built'
|
||||||
|
|
||||||
|
watch-backend:
|
||||||
|
mold -run cargo watch \
|
||||||
|
--ignore 'logs/*' \
|
||||||
|
--ignore 'static/*' \
|
||||||
|
--ignore 'frontend/*' \
|
||||||
|
-x run
|
||||||
|
|
||||||
|
watch:
|
||||||
|
./watch.sh
|
||||||
|
|
||||||
|
migrate:
|
||||||
|
sqlx migrate run
|
||||||
|
Loading…
Reference in New Issue
Block a user