1
0
Fork 1
mirror of https://example.com synced 2024-11-25 07:16:39 +09:00
firefish/Makefile

104 lines
3 KiB
Makefile

T := dev/make_virtual_target
PACKAGE_JSONS := package.json
PACKAGE_JSONS += packages/backend/package.json
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
RUST_DIR := packages/backend/native-utils
CARGO_TOMLS := $(RUST_DIR)/Cargo.toml
CARGO_TOMLS += $(RUST_DIR)/migration/Cargo.toml
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: pre-commit
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
.PHONY: run
run:
pnpm install
pnpm run build:debug
pnpm run migrate
pnpm run start
.PHONY: shellcheck
shellcheck: $(T)/shellcheck
$(T)/shellcheck: $(UPDATE_SCRIPTS)
shellcheck --external-sources $^
touch $@
.PHONY: rust-lint
rust-lint: $(T)/rust-lint
$(T)/rust-lint:
cd $(RUST_DIR) && pnpm run lint
touch $@
.PHONY: regenerate-entities
regenerate-entities: $(T)/regenerate-entities
$(T)/regenerate-entities: $(MIGRATIONS)
pnpm run migrate
cd $(RUST_DIR) && \
sea-orm-cli generate entity \
--output-dir='src/model/entity' \
--database-url='postgres://firefish:password@localhost:25432/firefish_db' \
--date-time-crate='chrono' \
--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
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)
pnpm --filter='native-utils' run build:debug
[ -f $(RUST_DIR)/built/index.js ]
pnpm run format
rm neko/index.js
cp $(RUST_DIR)/built/index.js neko/index.js
.PHONY: build-image
build-image:
. neko/update/utils && \
buildah build \
--no-cache \
--platform linux/amd64 \
--build-arg "VERSION=$$(version_ci)" \
--tag docker.io/naskya/firefish \
--tag registry.code.naskya.net/naskya/firefish \
--tag "registry.code.naskya.net/naskya/firefish:$$(version_ci | cut -d':' -f2)" \
.