Skip to content

Commit 7befd0c

Browse files
committed
#22: Refactor Makefile for better organization and readability
1 parent b5e5fdb commit 7befd0c

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ src/test/
1212
bin/
1313
out/
1414
resources/
15-
LICENSES/
15+
LICENSES/

Makefile

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ ANTLR4TS := npx antlr4ts
88
ESLINT := npx eslint
99
JEST := npx jest
1010
NCC := npx ncc
11-
PKG := npx pkg
1211
CURL := curl
1312

1413
GRAMMAR_URL := https://raw.githubusercontent.com/objectionary/eo/master/eo-parser/src/main/antlr4/org/eolang/parser/Eo.g4
@@ -17,7 +16,6 @@ GRAMMAR_FILE := resources/Eo.g4
1716
SRC_DIR := src
1817
DIST_DIR := dist
1918
OUT_DIR := out
20-
BIN_DIR := bin
2119
PARSER_DIR := $(SRC_DIR)/parser
2220
RESOURCES_DIR := resources
2321

@@ -30,44 +28,36 @@ all: build test package
3028
build: get-grammar build-parser compile
3129

3230
.PHONY: compile
33-
compile: get-grammar build-parser
31+
compile: $(SRC_DIR)/parser
3432
$(TSC) -b
3533

3634
.PHONY: get-grammar
37-
get-grammar:
35+
resources/Eo.g4:
3836
@mkdir -p $(RESOURCES_DIR)
39-
$(CURL) -s $(GRAMMAR_URL) > $(GRAMMAR_FILE)
37+
$(CURL) -s $(GRAMMAR_URL) > $@
4038

4139
.PHONY: build-parser
42-
build-parser: $(GRAMMAR_FILE)
43-
$(ANTLR4TS) -visitor $(GRAMMAR_FILE)
40+
$(SRC_DIR)/parser: resources/Eo.g4
41+
$(ANTLR4TS) -visitor $<
4442
@mkdir -p $(PARSER_DIR)
4543
mv $(RESOURCES_DIR)/*.ts $(PARSER_DIR)/
4644

47-
.PHONY: fetch-and-build-grammar
48-
fetch-and-build-grammar: get-grammar build-parser
49-
5045
.PHONY: test
51-
test: get-grammar build-parser
46+
test: $(SRC_DIR)/parser
5247
$(JEST)
5348

5449
.PHONY: lint
5550
lint:
5651
$(ESLINT) $(SRC_DIR) --ext .ts,.tsx
5752

5853
.PHONY: package
59-
package: compile
60-
@if [ ! -f $(OUT_DIR)/server.js ]; then \
61-
echo "Build failed: server.js not found. Run 'make build' first"; \
62-
exit 1; \
63-
fi
54+
package: $(SRC_DIR)/parser
6455
$(NCC) build $(OUT_DIR)/server.js
6556
sed -i "1i\#!/usr/bin/env node\n" $(DIST_DIR)/index.js
66-
$(PKG) package.json
6757

6858
.PHONY: clean
6959
clean:
70-
rm -rf $(DIST_DIR) $(OUT_DIR) $(BIN_DIR) src/parser
60+
rm -rf $(DIST_DIR) $(OUT_DIR) src/parser
7161

7262
.PHONY: ci
7363
ci: install lint test build

0 commit comments

Comments
 (0)