From 3410722e419728661b069d94eeac1a22fcc197c4 Mon Sep 17 00:00:00 2001 From: naskya Date: Mon, 22 Jan 2024 01:50:35 +0900 Subject: [PATCH] dev: run make recipes only when needed --- Makefile | 33 +++++++++++++++++++++++------- dev/make_virtual_target/.gitignore | 4 ++++ 2 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 dev/make_virtual_target/.gitignore diff --git a/Makefile b/Makefile index fbb3398e0..709ce0b9c 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +T := dev/make_virtual_target + PACKAGE_JSONS := package.json PACKAGE_JSONS += packages/backend/package.json PACKAGE_JSONS += packages/client/package.json @@ -13,19 +15,28 @@ RUSTY_STUFF := $(foreach dir, $(RUST_DIR)/src, $(wildcard $(dir)/*)) RUSTY_STUFF += $(foreach dir, $(RUST_DIR)/migration/src, $(wildcard $(dir)/*)) RUSTY_STUFF += $(CARGO_TOMLS) +MIGRATIONS := $(foreach dir, packages/backend/migration, $(wildcard $(dir)/*)) +MIGRATIONS += $(foreach dir, packages/backend/migration-neko, $(wildcard $(dir)/*)) +MIGRATIONS += $(foreach dir, $(RUST_DIR)/migration/src, $(wildcard $(dir)/*)) + +UPDATE_SCRIPTS := update.sh +UPDATE_SCRIPTS += $(foreach dir, neko/update, $(wildcard $(dir)/*)) + .PHONY: build build: build-image .PHONY: pre-commit -pre-commit: shellcheck pnpm-lock.yaml $(RUST_DIR)/Cargo.lock regenerate-entities neko/index.js rust-lint +pre-commit: shellcheck update-lockfiles regenerate-entities neko/index.js rust-lint +.PHONY: update-lockfiles +update-lockfiles: pnpm-lock.yaml $(RUST_DIR)/Cargo.lock + pnpm-lock.yaml: pnpm-workspace.yaml $(PACKAGE_JSONS) pnpm install - $(RUST_DIR)/Cargo.lock: $(CARGO_TOMLS) cd $(RUST_DIR) && cargo update @@ -39,18 +50,25 @@ debug: .PHONY: shellcheck -shellcheck: - shellcheck --external-sources update.sh - shellcheck --external-sources neko/update/* +shellcheck: $(T)/shellcheck + +$(T)/shellcheck: $(UPDATE_SCRIPTS) + shellcheck --external-sources $^ + touch $@ .PHONY: rust-lint -rust-lint: +rust-lint: $(T)/rust-lint + +$(T)/rust-lint: cd $(RUST_DIR) && pnpm run lint + touch $@ .PHONY: regenerate-entities -regenerate-entities: +regenerate-entities: $(T)/regenerate-entities + +$(T)/regenerate-entities: $(MIGRATIONS) pnpm run migrate cd $(RUST_DIR) && \ sea-orm-cli generate entity \ @@ -66,6 +84,7 @@ regenerate-entities: done sed -i 's/#\[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)\]/#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]\n#[napi_derive::napi]/' \ $(RUST_DIR)/src/model/entity/sea_orm_active_enums.rs + touch $@ neko/index.js: $(RUSTY_STUFF) diff --git a/dev/make_virtual_target/.gitignore b/dev/make_virtual_target/.gitignore new file mode 100644 index 000000000..5e7d2734c --- /dev/null +++ b/dev/make_virtual_target/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore