diff --git a/.github/workflows/lint-test-build.yml b/.github/workflows/lint-test-build.yml index 736588b34..640691672 100644 --- a/.github/workflows/lint-test-build.yml +++ b/.github/workflows/lint-test-build.yml @@ -70,16 +70,16 @@ jobs: curl -L https://github.com/ScuffleTV/ci-binaries/releases/download/sqlx-cli/sqlx-cli.tar.gz | tar -xz -C $CARGO_HOME/bin - name: Install dependencies - run: just setup-deps + run: mask bootstrap --no-db --no-docker --no-env --no-js-tests --no-stack --no-rust - name: Run migrations - run: just db-migrate + run: mask db migrate - name: Run Lint - run: just lint + run: mask lint - name: Run Test Rust - run: just test-rust + run: mask test --no-js test-js: name: Run Tests JavaScript @@ -116,16 +116,17 @@ jobs: restore-keys: | gnu-rust-test-js- - - uses: taiki-e/install-action@just + - name: Install mask + run: | + curl -L https://github.com/jacobdeichert/mask/releases/download/v0.11.3/mask-v0.11.3-x86_64-unknown-linux-gnu.zip -o mask.zip + unzip mask.zip -d /tmp/mask + mv /tmp/mask/**/mask ~/.cargo/bin/mask - name: Install dependencies - run: just setup-deps - - - name: Setup tests - run: just setup-tests + run: mask bootstrap --no-db --no-docker --no-env --no-stack --no-rust - name: Run Test JavaScript - run: just test-js + run: mask test --no-rust build: name: Run Build @@ -167,7 +168,7 @@ jobs: musl-rust-target-build- - name: Install dependencies - run: just setup-deps + run: mask bootstrap --no-db --no-docker --no-env --no-js-tests --no-stack --no-rust - name: Run Build - run: just build + run: mask build diff --git a/.gitignore b/.gitignore index 0608c861b..f09bc0fc3 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ target/ !.vscode/extensions.json node_modules/ .env* -dev-stack/stack.docker-compose.yaml +dev-stack/docker-compose.yml +*.log +.DS_Store diff --git a/.husky/pre-commit b/.husky/pre-commit index 946349d66..c814f2328 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,4 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" -just lint +mask lint diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5b50e35e1..ef69c4184 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -30,7 +30,7 @@ You can find instructions on how to do that [here](https://devblogs.microsoft.co - [Docker](https://www.docker.com/) - [Docker Compose V2](https://docs.docker.com/compose/install) - [Rust](https://www.rust-lang.org/tools/install) -- [Just](https://just.systems/) +- [Mask](https://github.com/jacobdeichert/mask) - [Musl](https://musl.libc.org/) ### For Ubuntu @@ -75,10 +75,10 @@ source $HOME/.cargo/env export PATH="$HOME/.cargo/bin:$HOME/.yarn/bin:$PATH" ``` -Installing Just +Installing Mask ``` -cargo install just +cargo install mask ``` ## Setting up the project @@ -88,9 +88,18 @@ Once you have everything installed, you can clone the project and install the de ```bash git clone --recurse-submodules https://github.com/ScuffleTV/scuffle.git scuffle cd scuffle -just setup +mask bootstrap ``` +The boostrap command will setup the project for you. + +This includes: + +- Installing all the dependencies +- Setting up the database +- Setting up the local stack +- Setting up .env files + ## Development Database We use Postgres for our database. @@ -98,49 +107,39 @@ We use Postgres for our database. You can run a local instance of Postgres with the following command: ```bash -just db-up +mask db up ``` To shut down the local instance of Postgres you can run the following command: ```bash -just db-down +mask db down ``` ### Database Migrations We use sqlx-cli to manage our database migrations. -You can create a new migration with the following command: - -```bash -just db-migrate-create -``` - -Then you can find the SQL for the migration in the [migrations](./backend/migrations) folder. - You can run the migrations with the following command: ```bash -just db-migrate +mask db migrate ``` -### Creating Database Migrations - -To create a new migration, you can use the `just db-migrate-create` command. +You can create a new migration with the following command: ```bash -just db-migrate-create +mask db migrate add "migration name" ``` -This will create a new migration file in the [migrations](./backend/migrations) folder. +Then you can find the SQL for the migration in the [migrations](./backend/migrations) folder. You can then edit the up migration file to add your SQL. You must also provide a down migration file so we can rollback the migration. You will then be prompted to rerun the prepare command ```bash -just db-prepare +mask db prepare ``` This will run the migrations and generate the SQLx code for the database. So that compile time querying can be used. @@ -150,28 +149,28 @@ This will run the migrations and generate the SQLx code for the database. So tha You can setup a local stack with the following command: ```bash -just stack-init +mask stack init ``` You need to have fully built local environment before running this command. You can do that with the following command: ```bash -just build +mask build ``` Or if you want to build it inside a container you can run: ```bash -just build-container +mask build --container ``` Then to start it run ``` -just stack-up +mask stack up ``` -You can modify the stack by editing `./dev-stack/docker-compose.yaml` file generated by `just stack-init`. +You can modify the stack by editing `./dev-stack/docker-compose.yml` file generated by `mask stack init`. ## Monorepo diff --git a/Justfile b/Justfile deleted file mode 100644 index 70072c2ff..000000000 --- a/Justfile +++ /dev/null @@ -1,107 +0,0 @@ -set dotenv-load - -arch := `uname -m | sed 's/amd64/x86_64/' | sed 's/arm64/aarch64/'` - -build: - yarn workspace website build - cargo build --release - -build-container: env-backup - docker run --rm -v $(pwd):/pwd -w /pwd ghcr.io/scuffletv/base-build:1.66.1 just build - -env-backup: - test -f .env && (\ - mv .env .env.bak \ - ) || true - -format: - yarn format - yarn workspace website format - cargo fmt --all - cargo clippy --fix --allow-dirty --allow-staged - cargo clippy --fix --allow-dirty --allow-staged --package player --target wasm32-unknown-unknown - -lint: - yarn lint - yarn workspace website lint - cargo clippy - cargo clippy --package player --target wasm32-unknown-unknown - cargo fmt --all --check - cargo sqlx prepare --check --merged -- --all-targets --all-features - -test: test-rust test-js - -test-rust: - cargo test - -test-js: - yarn workspace website test - -audit: - cargo audit - yarn audit - -setup: setup-deps env - cargo install cargo-watch - cargo install sqlx-cli - cargo install cargo-audit --features=fix,vendored-openssl - rustup target add wasm32-unknown-unknown - rustup target add {{arch}}-unknown-linux-musl - -setup-deps: - yarn - -setup-tests: - yarn playwright install - -clean: - cargo clean - yarn workspace website clean - -db-migrate: - sqlx database create - sqlx migrate run --source ./backend/migrations - -db-prepare: - cargo sqlx prepare --merged -- --all-targets --all-features - yarn prettier --write sqlx-data.json - -db-migrate-create *ARGS: - sqlx migrate add "{{ ARGS }}" --source ./backend/migrations -r - -db-rollback: - sqlx migrate revert --source ./backend/migrations - -db-reset: - sqlx database reset --source ./backend/migrations - just db-migrate - -db-up: - docker network create --driver bridge scuffle-dev || true - docker compose --file ./dev-stack/db.docker-compose.yaml up -d - just db-migrate - -env: - test -f .env || (\ - test -f .env.bak && (\ - mv .env.bak .env \ - ) || (\ - echo "DATABASE_URL=postgres://postgres:postgres@localhost:5432/scuffle-dev" > .env \ - ) \ - ) - -db-down: - docker compose --file ./dev-stack/db.docker-compose.yaml down - -stack-init: - cp ./dev-stack/stack-example.docker-compose.yaml ./dev-stack/stack.docker-compose.yaml - -stack-up: - docker network create --driver bridge scuffle-dev || true - docker compose --file ./dev-stack/stack.docker-compose.yaml up -d --build - -stack-down: - docker compose --file ./dev-stack/stack.docker-compose.yaml down - -stack-logs *ARGS: - docker compose --file ./dev-stack/stack.docker-compose.yaml logs {{ ARGS }} diff --git a/dev-stack/db.docker-compose.yaml b/dev-stack/db.docker-compose.yml similarity index 95% rename from dev-stack/db.docker-compose.yaml rename to dev-stack/db.docker-compose.yml index 5ed3c6b37..9746fb770 100644 --- a/dev-stack/db.docker-compose.yaml +++ b/dev-stack/db.docker-compose.yml @@ -1,5 +1,7 @@ version: "3.1" +name: "db-scuffle-dev" + services: postgres: image: postgres:15.2 diff --git a/dev-stack/stack-example.docker-compose.yaml b/dev-stack/example.docker-compose.yml similarity index 96% rename from dev-stack/stack-example.docker-compose.yaml rename to dev-stack/example.docker-compose.yml index 688f41389..808b2d6b7 100644 --- a/dev-stack/stack-example.docker-compose.yaml +++ b/dev-stack/example.docker-compose.yml @@ -1,5 +1,7 @@ version: "3.1" +name: "stack-scuffle-dev" + services: api: build: diff --git a/docker/build.Dockerfile b/docker/build.Dockerfile index c88713157..1c10888df 100644 --- a/docker/build.Dockerfile +++ b/docker/build.Dockerfile @@ -2,6 +2,8 @@ FROM rust:1.67.1-alpine3.17 RUN < Build the project + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +cd $MASKFILE_DIR + +wasm-pack build --target web --out-name player --out-dir ./pkg --release +``` + +### dev + +> Run the project in development mode + +**OPTIONS** + +- watch + - flags: --watch + - desc: Watch for changes and rebuild + +```bash +cd $MASKFILE_DIR + +wasm-pack build --target web --out-name player --out-dir ./pkg --dev + +if [ "$watch" == "true" ]; then + while true; do + cargo-watch -q --postpone -s "wasm-pack build --target web --out-name player --out-dir ./pkg --dev" + done +fi +``` + +## clean + +> Clean the project + +```bash +cd $MASKFILE_DIR + +rm -rf pkg +``` diff --git a/frontend/website/package.json b/frontend/website/package.json index 360e432ac..007882179 100644 --- a/frontend/website/package.json +++ b/frontend/website/package.json @@ -3,19 +3,20 @@ "version": "0.0.1", "private": true, "scripts": { - "dev": "concurrently -P --kill-others \"yarn wasm:watch\" \"vite dev {@}\" --", + "dev": "yarn wasm:dev && vite dev", "build": "yarn wasm && vite build", "preview": "vite preview", "test": "playwright test", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "test:unit": "vitest", - "lint": "prettier --plugin-search-dir . --check . && eslint .", - "format": "prettier --plugin-search-dir . --write .", - "wasm": "just --justfile $(realpath ../player/Justfile) build", - "wasm:dev": "just --justfile $(realpath ../player/Justfile) dev", - "wasm:watch": "cargo-watch -w $(realpath ../player) -C $(pwd) -s \"yarn wasm:dev\"", - "clean": "rm -rf build .svelte-kit wasm.d.ts ../player/pkg" + "lint": "prettier --plugin-search-dir . --check \"**/*\" -u && eslint .", + "format": "prettier --plugin-search-dir . --write \"**/*\" -u", + "wasm": "mask --maskfile $(realpath ../player/maskfile.md) build", + "wasm:dev": "yarn wasm dev", + "wasm:watch": "yarn wasm:dev --watch", + "wasm:clean": "mask --maskfile $(realpath ../player/maskfile.md) clean", + "clean": "rm -rf build .svelte-kit wasm.d.ts && yarn wasm:clean" }, "devDependencies": { "@playwright/test": "^1.28.1", diff --git a/maskfile.md b/maskfile.md new file mode 100644 index 000000000..ee68b0b46 --- /dev/null +++ b/maskfile.md @@ -0,0 +1,573 @@ +# Scuffle Tasks + +## build + +> Build the project + + + +**OPTIONS** + +- container + - flags: --container + - desc: Build the project in a container + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ "$container" == "true" ]; then + $MASK env backup + + function cleanup { + $MASK env restore + docker stop $PID >> /dev/null + } + trap cleanup EXIT + + PID=$(docker run -d --stop-signal SIGKILL --rm -v "$(pwd)":/pwd -w /pwd ghcr.io/scuffletv/build:1.67.1 mask build) + docker logs -f $PID +else + $MASK build rust + $MASK build website +fi +``` + +### rust + +> Build all rust code + +**OPTIONS** + +- container + - flags: --container + - desc: Build the project in a container + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ "$container" == "true" ]; then + $MASK env backup + + function cleanup { + $MASK env restore + docker stop $PID >> /dev/null + } + trap cleanup EXIT + + PID=$(docker run -d --stop-signal SIGKILL --rm -v "$(pwd)":/pwd -w /pwd ghcr.io/scuffletv/build:1.67.1 cargo build --release) + docker logs -f $PID +else + cargo build --release +fi +``` + +### website + +> Build the frontend website + +**OPTIONS** + +- container + - flags: --container + - desc: Build the project in a container + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ "$container" == "true" ]; then + $MASK env backup + + function cleanup { + $MASK env restore + docker stop $PID >> /dev/null + } + trap cleanup EXIT + + PID=$(docker run -d --stop-signal SIGKILL --rm -v "$(pwd)":/pwd -w /pwd ghcr.io/scuffletv/build:1.67.1 yarn workspace website build) + docker logs -f $PID +else + yarn workspace website build +fi +``` + +## clean + +> Clean the project + +**OPTIONS** + +- all + + - flags: --all + - desc: Removes everything that isn't tracked by git (use with caution, this is irreversible) + +- node_modules + + - flags: --node-modules + - desc: Removes node_modules + +- env + - flags: --env + - desc: Removes .env + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [[ "$all" == "true" ]]; then + git clean -xfd +fi + +cargo clean +yarn workspace website clean + +if [ "$node_modules" == "true" ]; then + rm -rf node_modules +fi + +if [ "$env" == "true" ]; then + rm -rf .env +fi +``` + +## format + +> Format the project + +**OPTIONS** + +- no_rust + - flags: --no-rust + - type: bool + - desc: Disables Rust formatting +- no_js + - flags: --no-js + - type: bool + - desc: Disables JS formatting + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ "$no_rust" != "true" ]; then + cargo fmt --all + cargo clippy --fix --allow-dirty --allow-staged + cargo clippy --fix --allow-dirty --allow-staged --package player --target wasm32-unknown-unknown +fi + +if [ "$no_js" != "true" ]; then + yarn format + yarn workspace website format +fi +``` + +## lint + +> Lint the project + +**OPTIONS** + +- no_rust + - flags: --no-rust + - type: bool + - desc: Disables Rust linting +- no_js + - flags: --no-js + - type: bool + - desc: Disables JS linting + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ "$no_rust" != "true" ]; then + cargo clippy + cargo clippy --package player --target wasm32-unknown-unknown + cargo fmt --all --check + cargo sqlx prepare --check --merged -- --all-targets --all-features +fi + +if [ "$no_js" != "true" ]; then + yarn lint + yarn workspace website lint +fi +``` + +## audit + +> Audit the project + +**OPTIONS** + +- no_rust + - flags: --no-rust + - type: bool + - desc: Disables Rust linting +- no_js + - flags: --no-js + - type: bool + - desc: Disables JS linting + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ "$no_rust" != "true" ]; then + cargo audit +fi + +if [ "$no_js" != "true" ]; then + yarn audit +fi +``` + +## test + +> Test the project + +**OPTIONS** + +- no_rust + - flags: --no-rust + - type: bool + - desc: Disables Rust testing +- no_js + - flags: --no-js + - type: bool + - desc: Disables JS testing + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ "$no_rust" != "true" ]; then + cargo test +fi + +if [ "$no_js" != "true" ]; then + yarn workspace website test +fi +``` + +## db + +> Database tasks + +### migrate + +> Migrate the database + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +sqlx database create +sqlx migrate run --source ./backend/migrations +``` + +#### create (name) + +> Create a database migration + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +sqlx migrate add "$name" --source ./backend/migrations -r +``` + +### rollback + +> Rollback the database + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +sqlx migrate revert --source ./backend/migrations +``` + +### prepare + +> Prepare the database + +**OPTIONS** + +- no_format + - flags: --no-format + - type: bool + - desc: Disables formatting + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +cargo sqlx prepare --merged -- --all-targets --all-features + +if [ "$no_format" != "true" ]; then + yarn prettier --write sqlx-data.json +fi +``` + +### reset + +> Reset the database + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +sqlx database reset --source ./backend/migrations +``` + +### up + +> Starts the docker compose stack + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +docker compose --file ./dev-stack/db.docker-compose.yml up -d +``` + +### down + +> Stops the docker compose stack + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +docker compose --file ./dev-stack/db.docker-compose.yml down +``` + +## env + +> Environment tasks + +### generate + +> Generate the environment files + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ ! -f .env ]; then + echo "DATABASE_URL=postgres://postgres:postgres@localhost:5432/scuffle-dev" > .env +fi +``` + +### backup + +> Backup the environment files + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ -f .env ]; then + mv .env .env.bak +fi +``` + +### restore + +> Restore the environment files + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ -f .env.bak ]; then + mv .env.bak .env +fi +``` + +## stack + +> Development stack tasks + +### up + +> Starts the docker compose stack + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +docker compose --file ./dev-stack/docker-compose.yml up -d --build +``` + +### down + +> Stops the docker compose stack + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +docker compose --file ./dev-stack/docker-compose.yml down +``` + +### init + +> Initializes the development stack + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +cp ./dev-stack/example.docker-compose.yml ./dev-stack/docker-compose.yml +``` + +### logs (service) + +> Prints the logs of the given service +> You can show logs of multiple services by passing a single string with space separated service names + +**OPTIONS** + +- follow + - flags: -f, --follow + - type: bool + - desc: Follow log output + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +follow=${follow:-false} + +docker compose --file ./dev-stack/docker-compose.yml logs --follow=$follow $service +``` + +## bootstrap + +> Bootstrap the project + +**OPTIONS** + +- no_rust + - flags: --no-rust + - type: bool + - desc: Disables Rust bootstrapping +- no_js + - flags: --no-js + - type: bool + - desc: Disables JS bootstrapping +- no_js_tests + - flags: --no-js-tests + - type: bool + - desc: Disables JS tests bootstrapping +- no_env + - flags: --no-env + - type: bool + - desc: Disables environment bootstrapping +- no_docker + - flags: --no-docker + - type: bool + - desc: Disables docker bootstrapping +- no_stack + - flags: --no-stack + - type: bool + - desc: Disables stack bootstrapping +- no_db + - flags: --no-db + - type: bool + - desc: Disables database bootstrapping + +```bash +set -e +if [[ "$verbose" == "true" ]]; then + set -x +fi + +if [ "$no_rust" != "true" ]; then + rustup update + rustup target add wasm32-unknown-unknown + rustup target add x86_64-unknown-linux-musl + + rustup component add rustfmt + rustup component add clippy + rustup component add llvm-tools-preview + + cargo install cargo-watch + cargo install sqlx-cli + cargo install wasm-pack + cargo install cargo-audit --features=fix,vendored-openssl +fi + +if [ "$no_js" != "true" ]; then + yarn install + + if [ "$no_js_tests" != "true" ]; then + yarn playwright install + fi +fi + +if [ "$no_env" != "true" ]; then + $MASK env generate +fi + +if [ "$no_docker" != "true" ]; then + docker network create scuffle-dev || true + + if [ "$no_stack" != "true" ]; then + $MASK stack init + fi + + if [ "$no_db" != "true" ]; then + $MASK db up + $MASK db migrate + fi +fi +``` diff --git a/package.json b/package.json index 51f1eb705..443f5b644 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ ], "scripts": { "prepare": "husky install", - "lint": "prettier --check .", - "format": "prettier --write ." + "lint": "prettier --check \"**/*\" -u", + "format": "prettier --write \"**/*\" -u" } }