-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
59 lines (43 loc) · 1.4 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
YEAR = $(shell date '+%Y')
DAY = $(shell date '+%d')
META_TITLE = YOUR TITLE GOES HERE
META_YEAR = $(YEAR)
META_DAY = $(subst S,,$(subst S0,,S$(DAY)))
META_URL = https://adventofcode.com/$(META_YEAR)/day/$(META_DAY)
FILE_PART_ONE = part-1.js
FILE_PART_TWO = part-2.js
FILE_README = README.md
TEMPLATE_DIRECTORY = _templates/
TEMPLATE_FILE_README = $(TEMPLATE_DIRECTORY)$(FILE_README)
TEMPLATE_FILE_PART_ONE = $(TEMPLATE_DIRECTORY)$(FILE_PART_ONE)
TEMPLATE_FILE_PART_TWO = $(TEMPLATE_DIRECTORY)$(FILE_PART_TWO)
OUTPUT_DIRECTORY = $(YEAR)/$(DAY)/
OUTPUT_FILE_README = $(OUTPUT_DIRECTORY)$(FILE_README)
OUTPUT_FILE_PART_ONE = $(OUTPUT_DIRECTORY)$(FILE_PART_ONE)
OUTPUT_FILE_PART_TWO = $(OUTPUT_DIRECTORY)$(FILE_PART_TWO)
IDE = code
GITHUB_URL = $(subst git@,https://,$(subst :,/,$(shell git remote get-url origin)))
all: $(OUTPUT_FILE_README) $(OUTPUT_FILE_PART_ONE) $(OUTPUT_FILE_PART_TWO)
$(OUTPUT_FILE_README): $(TEMPLATE_FILE_README)
mkdir -p $(OUTPUT_DIRECTORY)
cp $^ $@
sed -i -e 's/{YEAR}/$(META_YEAR)/g' -e 's/{DAY}/$(META_DAY)/g' -e 's/{TITLE}/$(META_TITLE)/g' -e 's$${URL}$$$(META_URL)$$g' $@
$(OUTPUT_FILE_PART_ONE): $(TEMPLATE_FILE_PART_ONE)
cp $^ $@;
$(OUTPUT_FILE_PART_TWO): $(TEMPLATE_FILE_PART_TWO)
cp $^ $@;
.PHONY: url
url:
@echo $(META_URL)
.PHONY: open
open:
open $(META_URL)
.PHONY: clean
clean:
rm -rf $(OUTPUT_DIRECTORY)
.PHONY: ide
ide:
$(IDE) . &
.PHONY: gh
gh:
open $(GITHUB_URL)