Skip to content

Commit

Permalink
Install dependencies if outdated before serve
Browse files Browse the repository at this point in the history
Also, remove collectstatic during dev
  • Loading branch information
theskumar committed Aug 25, 2024
1 parent 20c8d67 commit e1dd555
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 61 deletions.
100 changes: 41 additions & 59 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
DJANGO_PORT = 9001
DJANGO_SETTINGS_MODULE = hypha.settings.dev
JS_VENDOR_DIR = ./hypha/static_src/javascript/vendor
JS_ESM_DIR = ./hypha/static_src/javascript/esm

Expand All @@ -11,37 +12,19 @@ help: ## Show this help


.PHONY: serve
serve: .cache/tandem build ## Run Django and docs preview server, also watch and compile frontend changes
serve: .cache/tandem .cache/pip-packages .cache/dev-build ## Run Django and docs preview server, also watch and compile frontend changes
@.cache/tandem \
'python manage.py runserver 0.0.0.0:$(DJANGO_PORT) --settings=hypha.settings.dev' \
'python manage.py runserver 0.0.0.0:$(DJANGO_PORT) --settings=$(DJANGO_SETTINGS_MODULE)' \
'npm:watch:*' \
'mkdocs serve'


.PHONY: build
build: ## Build js and css resources for development
@echo "Build js and css resources for development."
npm run dev:build
.PHONY: test
test: lint py-test cov-html ## Run all tests and generate coverage report


.PHONY: fmt
fmt: ## Run code formatters on all code
@echo "run code formatters on all code."
python -m ruff check --fix .
python -m ruff format .
npx prettier . --write
djhtml hypha/

.PHONY: cov-html
cov-html: ## Generate html coverage report
ifneq ("$(wildcard .coverage)","")
@rm -rf htmlcov
@echo "Generate html coverage report…"
coverage html
@echo "Open 'htmlcov/index.html' in your browser to see the report."
else
$(error Unable to generate html coverage report, please run 'make test' or 'make py-test')
endif
@pre-commit run --all-files


.PHONY: lint
Expand All @@ -55,41 +38,27 @@ lint: ## Run all linters
npm run lint


.PHONY: lint-fix
lint-fix: ## Fix all possible linter issues
@echo "Try fixing plausible python linting issues."
ruff check --fix .


.PHONY: py-test
py-test: ## Run python tests
py-test: ## Run python tests
@echo "Running python tests"
pytest --reuse-db --cov --cov-report term:skip-covered


.PHONY: serve-django
serve-django: ## Run Django server
python manage.py runserver 0.0.0.0:$(DJANGO_PORT) --settings=hypha.settings.dev


.PHONY: clean-test-files
clean-test-files:
@echo "Removing test files generated during test"
find media/ -iname 'test_*.pdf' -delete
find media/ -iname 'test_image*' -delete
find media/ -iname '*.dat' -delete
find media/ -type d -empty -delete
rm -rf media/temp_uploads/*
@find media/ -iname 'test_*.pdf' -o -iname 'test_image*' -o -iname '*.dat' -delete
@find media/ -type d -empty -delete
@rm -rf media/temp_uploads/*


.PHONY: test
test: lint py-test cov-html clean-test-files ## Run all tests


.PHONY: watch
watch: build ## Watch js and css resources for development
@echo "Watch js and css resources for development."
npm run watch
.PHONY: cov-html
cov-html: ## Generate html coverage report
ifneq ("$(wildcard .coverage)","")
@rm -rf htmlcov
@echo "Generate html coverage report…"
coverage html
@echo "Open 'htmlcov/index.html' in your browser to see the report."
else
$(error Unable to generate html coverage report, please run 'make test' or 'make py-test')
endif


.PHONY: download-esm-modules
Expand All @@ -100,17 +69,30 @@ download-esm-modules: ## Download ESM modules
download-esm choices.js $(JS_ESM_DIR)


.PHONY: copy-npm-scripts
copy-npm-scripts: ## Copy npm scripts
# Used by "npm install"
.cache/tandem: ## Install tandem, a tool to run multiple commands in parallel
@mkdir -p $$(dirname $@)
@curl -fsSL https://raw.githubusercontent.com/rosszurowski/tandem/main/install.sh | bash -s -- --dest="$$(dirname $@)"


.cache/dev-build-fe: .cache/npm-packages $(shell find hypha/static_src) ## Build frontend resources for development
@mkdir -p $$(dirname $@)
@.cache/tandem 'npm:dev:build:*'
@touch $@


.cache/py-packages: requirements-dev.txt requirements-docs.txt ## Install python packages
@mkdir -p $$(dirname $@)
pip install -r requirements-dev.txt -r requirements-docs.txt
@touch $@


.cache/npm-packages: package.json ## Install node packages and copy javascript files to vendor directory
@mkdir -p $$(dirname $@)
NODE_ENV=developement npm install
cp node_modules/htmx.org/dist/htmx.min.js $(JS_VENDOR_DIR)/htmx.min.js
cp node_modules/htmx.org/dist/ext/multi-swap.js $(JS_VENDOR_DIR)/htmx-ext-multi-swap.min.js
cp node_modules/alpinejs/dist/cdn.min.js $(JS_VENDOR_DIR)/alpine.min.js
cp node_modules/@alpinejs/focus/dist/cdn.min.js $(JS_VENDOR_DIR)/alpine-focus.min.js
cp node_modules/daterangepicker/moment.min.js $(JS_VENDOR_DIR)/moment.min.js
cp node_modules/daterangepicker/daterangepicker.js $(JS_VENDOR_DIR)/daterangepicker.min.js


.cache/tandem:
@mkdir -p $$(dirname $@)
@curl -fsSL https://raw.githubusercontent.com/rosszurowski/tandem/main/install.sh | bash -s -- --dest="$$(dirname $@)"
@touch $@
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@
"watch:js": "babel --watch ./hypha/static_src/javascript --out-dir ./hypha/static_compiled/js",
"watch:sass": "sass --watch ./hypha/static_src/sass:./hypha/static_compiled/css --load-path ./hypha/static_src/sass",
"watch:tailwind": "tailwindcss -i ./hypha/static_src/tailwind/main.css -o ./hypha/static_compiled/css/tailwind-output.css --watch",
"watch:static": "nodemon --delay 3 --exec \"npm run collectstatic\" --watch ./hypha/static_compiled --ext css,js,json,png,svg",
"watch:lint": "nodemon --exec \"npm run lint\" --watch ./hypha/static_src/sass --watch ./hypha/static_src/javscript --ext scss,js",
"dev:build": "npm-run-all --print-label --serial clean --parallel dev:build:* --serial collectstatic",
"dev:build": "npm-run-all --print-label --serial clean --parallel dev:build:*",
"dev:build:js": "npm run build:js",
"dev:build:sass": "sass ./hypha/static_src/sass:./hypha/static_compiled/css --load-path ./hypha/static_src/sass",
"dev:build:lint": "npm run lint",
Expand Down

0 comments on commit e1dd555

Please sign in to comment.