@@ -39,7 +39,7 @@ COMMITLINT_FLAGS ?= \
3939# RULES #
4040
4141# /
42- # Lints a commit .
42+ # Performs linting initialization tasks .
4343#
4444# ## Notes
4545#
@@ -48,41 +48,61 @@ COMMITLINT_FLAGS ?= \
4848# @private
4949#
5050# @example
51- # make commitlint
51+ # make commitlint-init
5252# /
53- commitlint : $(NODE_MODULES )
53+ commitlint-init :
54+ ifneq ("$(wildcard $(ROOT_DIR ) /tsconfig.json) ", "")
5455 $(QUIET) mv $(ROOT_DIR)/tsconfig.json $(ROOT_DIR)/tsconfig.json.tmp
55- $(QUIET ) " $( COMMITLINT) " $(COMMITLINT_FLAGS ) --edit || ( mv $( ROOT_DIR) /tsconfig.json.tmp $( ROOT_DIR) /tsconfig.json && exit 1 )
56+ endif
57+
58+ .PHONY : commitlint-init
59+
60+ # /
61+ # Performs linting clean-up tasks.
62+ #
63+ # @private
64+ #
65+ # @example
66+ # make commitlint-cleanup
67+ # /
68+ commitlint-cleanup :
69+ ifneq ("$(wildcard $(ROOT_DIR ) /tsconfig.json.tmp) ", "")
5670 $(QUIET) mv $(ROOT_DIR)/tsconfig.json.tmp $(ROOT_DIR)/tsconfig.json
71+ endif
5772
58- .PHONY : commitlint
73+ .PHONY : commitlint-cleanup
5974
6075# /
61- # Lints a commit message .
76+ # Lints a commit.
6277#
63- # ## Notes
78+ # @private
6479#
65- # - We have to temporarily move the `tsconfig` file, as `commitlint` (erroneously) attempts to use the file for compiling TypeScript.
80+ # @example
81+ # make commitlint
82+ # /
83+ commitlint : $(NODE_MODULES ) commitlint-init
84+ $(QUIET ) " $( COMMITLINT) " $(COMMITLINT_FLAGS ) --edit || ( $( MAKE) -f $( this_file) commitlint-cleanup && exit 1 )
85+ $(QUIET ) $(MAKE ) -f $(this_file ) commitlint-cleanup
86+
87+ .PHONY : commitlint
88+
89+ # /
90+ # Lints a commit message.
6691#
6792# @private
6893#
6994# @example
7095# make commitlint-message
7196# /
72- commitlint-message : $(NODE_MODULES )
73- $(QUIET ) mv $(ROOT_DIR ) /tsconfig.json $(ROOT_DIR ) /tsconfig.json.tmp
74- $(QUIET ) ( printf " $( GIT_COMMIT_MESSAGE) " | " $( COMMITLINT) " $( COMMITLINT_FLAGS) ) || ( mv $( ROOT_DIR) /tsconfig.json.tmp $( ROOT_DIR) /tsconfig.json && exit 1 )
75- $(QUIET ) mv $(ROOT_DIR ) /tsconfig.json.tmp $(ROOT_DIR ) /tsconfig.json
97+ commitlint-message : $(NODE_MODULES ) commitlint-init
98+ $(QUIET ) ( printf " $( GIT_COMMIT_MESSAGE) " | " $( COMMITLINT) " $( COMMITLINT_FLAGS) ) || ( $( MAKE) -f $( this_file) commitlint-cleanup && exit 1 )
99+ $(QUIET ) $(MAKE ) -f $(this_file ) commitlint-cleanup
76100
77101.PHONY : commitlint-message
78102
79103# /
80104# Lints a list of files, each containing a commit message.
81105#
82- # ## Notes
83- #
84- # - We have to temporarily move the `tsconfig` file, as `commitlint` (erroneously) attempts to use the file for compiling TypeScript.
85- #
86106# @private
87107#
88108# @param {string} FILES - list of file paths
@@ -91,13 +111,12 @@ commitlint-message: $(NODE_MODULES)
91111# @example
92112# make commitlint-files FILES='/foo/commit.txt'
93113# /
94- commitlint-files : $(NODE_MODULES )
95- $(QUIET ) mv $(ROOT_DIR ) /tsconfig.json $(ROOT_DIR ) /tsconfig.json.tmp
114+ commitlint-files : $(NODE_MODULES ) commitlint-init
96115ifeq ($(FAIL_FAST ) , true)
97116 $(QUIET) for file in $(FILES); do \
98117 echo ''; \
99118 echo "Linting commit message:"; \
100- ( cat $$file | grep -v '^# ' | "$(COMMITLINT)" $(COMMITLINT_FLAGS) ) || ( mv $(ROOT_DIR)/tsconfig.json.tmp $(ROOT_DIR)/tsconfig.json && exit 1 ); \
119+ ( cat $$file | grep -v '^# ' | "$(COMMITLINT)" $(COMMITLINT_FLAGS) ) || ( $(MAKE) -f $(this_file) commitlint-cleanup && exit 1 ); \
101120 done
102121else
103122 $(QUIET) for file in $(FILES); do \
106125 ( cat $$file | grep -v '^# ' | "$(COMMITLINT)" $(COMMITLINT_FLAGS) ) || echo 'Linting failed.'; \
107126 done
108127endif
109- $(QUIET) mv $(ROOT_DIR)/tsconfig.json.tmp $(ROOT_DIR)/tsconfig.json
128+ $(QUIET) $(MAKE) -f $(this_file) commitlint-cleanup
110129
111130.PHONY : commitlint-files
0 commit comments