From 0829e0f03fb21f28ff9c1cce97e7959d0255bd48 Mon Sep 17 00:00:00 2001 From: Azizul Karim Date: Thu, 30 Jan 2025 23:39:22 +0600 Subject: [PATCH] initial setup --- Makefile | 9 +++------ flake.nix | 13 +++++++++++++ frontend/Makefile | 14 ++++++++++++-- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 3ae287b..dbfb669 100644 --- a/Makefile +++ b/Makefile @@ -40,12 +40,9 @@ backend: serve: frontend backend ifeq ($(DEBUG),1) - RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml + $(MAKE) -C $(FRONTEND_DIR) serve DEBUG=1 & \ + RUST_LOG=info,actix_web=debug $(CARGO_RUN) --manifest-path=$(BACKEND_DIR)/Cargo.toml; \ + kill %1 else ifeq ($(RELEASE),1) $(CARGO_RUN) --release --manifest-path=$(BACKEND_DIR)/Cargo.toml endif - -clean: - rm -rf $(PUBLIC_DIR)/* - rm -rf $(BACKEND_DIR)/target - make -C $(FRONTEND_DIR) clean diff --git a/flake.nix b/flake.nix index aa446c5..51399a4 100644 --- a/flake.nix +++ b/flake.nix @@ -113,6 +113,19 @@ with pkgs; mkShell { inputsFrom = [ example-spa-elm-app ]; + buildInputs = [ + nodejs_22 + ]; + + shellHook = '' + if [ ! -d "$PWD/frontend/node_modules/elm-go" ]; then + echo "Installing elm-go..." + cd "$PWD/frontend" + ${nodejs_22}/bin/npm install elm-go + cd .. + fi + export PATH="$PWD/frontend/node_modules/.bin:$PATH" + ''; }; } ); diff --git a/frontend/Makefile b/frontend/Makefile index 31d4a7f..20a5341 100644 --- a/frontend/Makefile +++ b/frontend/Makefile @@ -2,7 +2,7 @@ SRC_FILES := $(shell find src -name "*.elm") all: elm.min.js -.PHONY: elm.min.js +.PHONY: elm.min.js serve ifeq ($(DEBUG)$(RELEASE),) # Both are empty $(error You must set exactly one of DEBUG=1 or RELEASE=1) @@ -12,7 +12,6 @@ ifeq ($(DEBUG)$(RELEASE),11) # Both are set $(error Both DEBUG and RELEASE cannot be set at the same time) endif - elm.min.js: ifeq ($(DEBUG),1) ./build.sh --debug src/Main.elm @@ -20,5 +19,16 @@ else ifeq ($(RELEASE),1) ./build.sh --optimize src/Main.elm endif +serve: +ifeq ($(DEBUG),1) + elm-go src/Main.elm \ + --dir=../public \ + --start-page=index.html \ + --host=localhost \ + -- --debug +else ifeq ($(RELEASE),1) + $(error Cannot use serve target with RELEASE=1) +endif + clean: rm elm.js elm.min.js