Skip to content

Commit

Permalink
DRY up Makefile using automatic variables
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhonas committed Jan 5, 2024
1 parent b2a2122 commit 0cc7e7a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
.PHONY: lint check_dupes install

sources :=$(wildcard ./exercises/**.json)

lint:
check-jsonschema --schemafile ./schema.json ./exercises/**.json
check-jsonschema --schemafile ./schema.json $(sources)
check_dupes:
# check for duplicate id's, if there's ID's listed here
# we've got duplicate id's that need to be resolved
jq -s ".[]" exercises/**.json | jq '.id' | sort | uniq -d
jq -s ".[]" $(sources) | jq '.id' | sort | uniq -d
install:
pip install check-jsonschema
dist/exercises.json: ./exercises/**.json
dist/exercises.json: $(sources)
# requires jq
# brew install jq (for macos)
jq -s '.' ./exercises/**.json > ./dist/exercises.json
dist/exercises.nd.json: ./exercises/**.json
jq -s '.' $^ > $@
dist/exercises.nd.json: $(sources)
# output to new line delimited JSON
# for use to import into PostgreSQL via the COPY command
#
# https://konbert.com/blog/import-json-into-postgres-using-copy
# https://www.postgresql.org/docs/current/sql-copy.html
jq -s '.[]' ./exercises/**.json > ./dist/exercises.nd.json
jq -s '.[]' $^ > $@
dist/exercises.csv: dist/exercises.json
# output to csv format
# requires in2csv which is part of
# https://csvkit.readthedocs.io/
in2csv ./dist/exercises.json > ./dist/exercises.csv
in2csv ./dist/exercises.json > $@

0 comments on commit 0cc7e7a

Please sign in to comment.