2024-01-22 01:50:35 +09:00
|
|
|
T := dev/make_virtual_target
|
|
|
|
|
2024-01-22 20:33:01 +09:00
|
|
|
recursive_wildcard=$(foreach d, $(wildcard $(1:=/*)), $(call recursive_wildcard, $d, $2) $(filter $(subst *, %, $2), $d))
|
|
|
|
|
2024-01-22 01:29:49 +09:00
|
|
|
PACKAGE_JSONS := package.json
|
|
|
|
PACKAGE_JSONS += packages/backend/package.json
|
2024-01-23 01:29:15 +09:00
|
|
|
PACKAGE_JSONS += packages/backend-rs/package.json
|
2024-01-22 01:29:49 +09:00
|
|
|
PACKAGE_JSONS += packages/client/package.json
|
|
|
|
PACKAGE_JSONS += packages/firefish-js/package.json
|
|
|
|
PACKAGE_JSONS += packages/megalodon/package.json
|
|
|
|
PACKAGE_JSONS += packages/sw/package.json
|
|
|
|
|
2024-01-31 19:32:56 +09:00
|
|
|
CARGO_TOMLS := Cargo.toml
|
|
|
|
CARGO_TOMLS += packages/backend-rs/Cargo.toml
|
|
|
|
|
|
|
|
RUST_BE_DIR := packages/backend-rs
|
|
|
|
RUST_BE_SRC := Cargo.toml
|
|
|
|
RUST_BE_SRC += $(RUST_BE_DIR)/Cargo.toml
|
|
|
|
RUST_BE_SRC += $(call recursive_wildcard, $(RUST_BE_DIR)/src, *)
|
2024-01-22 01:34:26 +09:00
|
|
|
|
2024-01-22 01:50:35 +09:00
|
|
|
MIGRATIONS := $(foreach dir, packages/backend/migration, $(wildcard $(dir)/*))
|
|
|
|
MIGRATIONS += $(foreach dir, packages/backend/migration-neko, $(wildcard $(dir)/*))
|
|
|
|
|
|
|
|
UPDATE_SCRIPTS := update.sh
|
|
|
|
UPDATE_SCRIPTS += $(foreach dir, neko/update, $(wildcard $(dir)/*))
|
|
|
|
|
2024-01-22 04:14:31 +09:00
|
|
|
POSTGRES_USER := firefish
|
|
|
|
POSTGRES_DB := firefish_db
|
|
|
|
POSTGRES_PASSWORD := password
|
|
|
|
POSTGRES_HOST_PORT := localhost:25432
|
|
|
|
|
2024-01-22 01:29:49 +09:00
|
|
|
|
2024-01-14 19:48:41 +09:00
|
|
|
.PHONY: pre-commit
|
2024-01-22 04:14:31 +09:00
|
|
|
pre-commit: test format shellcheck update-lockfiles regenerate-entities neko/index.js rust-lint
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: test
|
|
|
|
test: test-revert
|
|
|
|
|
|
|
|
|
|
|
|
.PHONY: test-revert
|
|
|
|
test-revert: $(T)/test-revert
|
|
|
|
|
|
|
|
$(T)/test-revert: neko/revert.sql $(MIGRATIONS)
|
|
|
|
cd dev && \
|
|
|
|
podman-compose exec db \
|
|
|
|
psql \
|
|
|
|
--echo-all \
|
|
|
|
--user=$(POSTGRES_USER) \
|
|
|
|
--dbname=$(POSTGRES_DB) \
|
|
|
|
--set='ON_ERROR_STOP=1' \
|
2024-01-22 07:22:29 +09:00
|
|
|
--command="$$(printf '%s\nROLLBACK;' "$$(cat ../neko/revert.sql | sed '$$ d')")"
|
2024-01-22 04:14:31 +09:00
|
|
|
touch $@
|
2024-01-22 01:50:35 +09:00
|
|
|
|
2024-01-22 01:29:49 +09:00
|
|
|
|
2024-01-22 01:50:35 +09:00
|
|
|
.PHONY: update-lockfiles
|
2024-01-31 19:32:56 +09:00
|
|
|
update-lockfiles: pnpm-lock.yaml Cargo.lock
|
2024-01-22 01:29:49 +09:00
|
|
|
|
|
|
|
pnpm-lock.yaml: pnpm-workspace.yaml $(PACKAGE_JSONS)
|
|
|
|
pnpm install
|
|
|
|
|
2024-01-31 19:32:56 +09:00
|
|
|
Cargo.lock: $(CARGO_TOMLS)
|
|
|
|
cargo update
|
2024-01-14 19:48:41 +09:00
|
|
|
|
|
|
|
|
2024-01-22 02:04:54 +09:00
|
|
|
.PHONY: run
|
|
|
|
run:
|
2024-01-14 19:48:41 +09:00
|
|
|
pnpm install
|
|
|
|
pnpm run build:debug
|
|
|
|
pnpm run migrate
|
|
|
|
pnpm run start
|
2024-01-10 12:08:13 +09:00
|
|
|
|
|
|
|
|
|
|
|
.PHONY: shellcheck
|
2024-01-22 01:50:35 +09:00
|
|
|
shellcheck: $(T)/shellcheck
|
|
|
|
|
|
|
|
$(T)/shellcheck: $(UPDATE_SCRIPTS)
|
|
|
|
shellcheck --external-sources $^
|
|
|
|
touch $@
|
2024-01-14 19:48:41 +09:00
|
|
|
|
|
|
|
|
2024-01-22 02:11:22 +09:00
|
|
|
.PHONY: format
|
|
|
|
format:
|
|
|
|
pnpm run format
|
|
|
|
|
|
|
|
|
2024-01-14 19:48:41 +09:00
|
|
|
.PHONY: rust-lint
|
2024-01-31 19:32:56 +09:00
|
|
|
rust-lint: $(T)/rust-be-lint
|
2024-01-22 01:50:35 +09:00
|
|
|
|
2024-01-31 19:32:56 +09:00
|
|
|
$(T)/rust-be-lint: $(RUST_BE_SRC)
|
2024-01-23 01:29:15 +09:00
|
|
|
pnpm --filter='backend-rs' run lint
|
2024-01-22 01:50:35 +09:00
|
|
|
touch $@
|
2024-01-14 19:48:41 +09:00
|
|
|
|
|
|
|
|
|
|
|
.PHONY: regenerate-entities
|
2024-01-22 01:50:35 +09:00
|
|
|
regenerate-entities: $(T)/regenerate-entities
|
|
|
|
|
|
|
|
$(T)/regenerate-entities: $(MIGRATIONS)
|
2024-01-19 00:16:13 +09:00
|
|
|
pnpm run migrate
|
2024-01-31 19:32:56 +09:00
|
|
|
cd $(RUST_BE_DIR) && \
|
2024-01-14 19:48:41 +09:00
|
|
|
sea-orm-cli generate entity \
|
|
|
|
--output-dir='src/model/entity' \
|
2024-01-22 04:14:31 +09:00
|
|
|
--database-url='postgres://$(POSTGRES_USER):$(POSTGRES_PASSWORD)@$(POSTGRES_HOST_PORT)/$(POSTGRES_DB)' \
|
2024-01-20 05:57:00 +09:00
|
|
|
--date-time-crate='chrono' \
|
2024-01-21 02:13:13 +09:00
|
|
|
--model-extra-attributes='NAPI_EXTRA_ATTR_PLACEHOLDER' && \
|
|
|
|
for file in src/model/entity/*; do \
|
|
|
|
base=$$(basename -- "$${file}"); \
|
|
|
|
jsname=$$(printf '%s\n' "$${base%.*}" | perl -pe 's/(^|_)./uc($$&)/ge;s/_//g'); \
|
|
|
|
attribute=$$(printf 'napi_derive::napi(object, js_name = "%s")' "$${jsname}"); \
|
|
|
|
sed -i "s/NAPI_EXTRA_ATTR_PLACEHOLDER/$${attribute}/" "$${file}"; \
|
|
|
|
done
|
2024-01-20 05:57:00 +09:00
|
|
|
sed -i 's/#\[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum)\]/#[derive(Debug, PartialEq, Eq, EnumIter, DeriveActiveEnum)]\n#[napi_derive::napi]/' \
|
2024-01-31 19:32:56 +09:00
|
|
|
$(RUST_BE_DIR)/src/model/entity/sea_orm_active_enums.rs
|
2024-01-22 01:50:35 +09:00
|
|
|
touch $@
|
2024-01-14 19:48:41 +09:00
|
|
|
|
2024-01-20 08:33:18 +09:00
|
|
|
|
2024-01-31 19:32:56 +09:00
|
|
|
neko/index.js: $(RUST_BE_SRC)
|
2024-01-23 01:29:15 +09:00
|
|
|
pnpm --filter='backend-rs' run build:debug
|
2024-01-31 19:32:56 +09:00
|
|
|
[ -f $(RUST_BE_DIR)/built/index.js ]
|
2024-01-14 20:15:05 +09:00
|
|
|
rm neko/index.js
|
2024-01-31 19:32:56 +09:00
|
|
|
cp $(RUST_BE_DIR)/built/index.js neko/index.js
|
2024-01-14 20:15:05 +09:00
|
|
|
|
|
|
|
|
|
|
|
.PHONY: build-image
|
2024-01-14 21:57:23 +09:00
|
|
|
build-image:
|
2024-01-07 07:02:43 +09:00
|
|
|
. neko/update/utils && \
|
|
|
|
buildah build \
|
|
|
|
--no-cache \
|
|
|
|
--platform linux/amd64 \
|
|
|
|
--build-arg "VERSION=$$(version_ci)" \
|
|
|
|
--tag registry.code.naskya.net/naskya/firefish \
|
|
|
|
.
|