forked from stdlib-js/stdlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelated.mk
More file actions
183 lines (159 loc) · 6.03 KB
/
related.mk
File metadata and controls
183 lines (159 loc) · 6.03 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#/
# @license Apache-2.0
#
# Copyright (c) 2021 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/
# VARIABLES #
# Define the path to the remark configuration file:
REMARK_RELATED_CONF ?= $(CONFIG_DIR)/remark/.remarkrc.empty.js
# Define the path to the remark ignore file:
# REMARK_RELATED_IGNORE ?= $(CONFIG_DIR)/remark/.remarkignore FIXME
REMARK_RELATED_IGNORE ?= $(ROOT_DIR)/.remarkignore
# Define the path to a plugin which inserts a "See Also" section of related `stdlib` packages:
REMARK_RELATED_PLUGIN ?= $(TOOLS_PKGS_DIR)/remark/plugins/remark-stdlib-related
REMARK_RELATED_PLUGIN_SETTINGS ?=
REMARK_RELATED_PLUGIN_FLAGS ?= --use $(REMARK_RELATED_PLUGIN)=$(REMARK_RELATED_PLUGIN_SETTINGS)
# Define command-line options when invoking the remark executable:
REMARK_RELATED_FLAGS ?= \
--ext $(MARKDOWN_FILENAME_EXT) \
--rc-path $(REMARK_RELATED_CONF) \
--ignore-path $(REMARK_RELATED_IGNORE)
# Define the remark output option:
REMARK_RELATED_OUTPUT_FLAG ?= --output
# Define a directory for writing temporary files:
REMARK_RELATED_TMP_DIR ?= $(TMP_DIR)
# Define a temporary file for writing a list of files to be processed:
REMARK_RELATED_TMP_FILE_LIST ?= $(TMP_DIR)/remark_related_tmp_file_list.txt
# Define a temporary file for writing a list of files which have been processed:
REMARK_RELATED_TMP_FILE_LIST_PROGRESS ?= $(TMP_DIR)/remark_related_tmp_file_list_progress.txt
# RULES #
#/
# Creates a directory for writing temporary files.
#
# @private
#/
$(REMARK_RELATED_TMP_DIR):
$(QUIET) $(MKDIR_RECURSIVE) $(REMARK_RELATED_TMP_DIR)
#/
# Creates a file containing a list of files to be processed.
#
# @private
#/
$(REMARK_RELATED_TMP_FILE_LIST): | $(REMARK_RELATED_TMP_DIR)
$(QUIET) $(TOUCH) $(REMARK_RELATED_TMP_FILE_LIST)
$(QUIET) $(FIND_MARKDOWN_CMD) > $(REMARK_RELATED_TMP_FILE_LIST)
#/
# Creates a file for writing the list of files which have been processed.
#
# @private
#/
$(REMARK_RELATED_TMP_FILE_LIST_PROGRESS): | $(REMARK_RELATED_TMP_DIR)
$(QUIET) $(TOUCH) $(REMARK_RELATED_TMP_FILE_LIST_PROGRESS)
#/
# Updates the related packages section of Markdown files.
#
# ## Notes
#
# - This rule is useful when wanting to glob for Markdown files (e.g., process all Markdown files for a particular package).
# - In order to insert a list of related `stdlib` packages, a Markdown file must contain a "related" section tag (i.e., `<section class="related"></section>`).
#
# @param {string} [MARKDOWN_FILTER] - file path pattern (e.g., `.*/math/base/special/.*`)
# @param {string} [MARKDOWN_PATTERN] - filename pattern (e.g., `*.md`)
#
# @example
# make markdown-related
#
# @example
# make markdown-related MARKDOWN_PATTERN='README.md' MARKDOWN_FILTER='.*/math/base/special/.*'
#/
markdown-related: $(NODE_MODULES) clean-markdown-related markdown-related-init
$(QUIET) $(FIND_MARKDOWN_CMD) | tee $(REMARK_RELATED_TMP_FILE_LIST) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ""; \
echo "Processing file: $$file"; \
"$(REMARK)" \
$$file \
$(REMARK_RELATED_FLAGS) \
$(REMARK_RELATED_PLUGIN_FLAGS) \
$(REMARK_RELATED_OUTPUT_FLAG) || exit 1; \
echo "$$file" >> $(REMARK_RELATED_TMP_FILE_LIST_PROGRESS); \
done
.PHONY: markdown-related
#/
# Updates the related packages section of a specified list of Markdown files.
#
# ## Notes
#
# - This rule is useful when wanting to process a list of Markdown files generated by some other command (e.g., a list of changed Markdown files obtained via `git diff`).
# - In order to insert a list of related `stdlib` packages, a Markdown file must contain a "related" section tag (i.e., `<section class="related"></section>`).
#
# @param {string} FILES - list of files
#
# @example
# make markdown-related-files FILES='/foo/foo.md /foo/bar.md'
#/
markdown-related-files: $(NODE_MODULES)
$(QUIET) for file in $(FILES); do \
echo ""; \
echo "Processing file: $$file"; \
"$(REMARK)" \
$$file \
$(REMARK_RELATED_FLAGS) \
$(REMARK_RELATED_PLUGIN_FLAGS) \
$(REMARK_RELATED_OUTPUT_FLAG) || exit 1; \
done
.PHONY: markdown-related-files
#/
# Resumes processing for updating the related packages section of Markdown files.
#
# ## Notes
#
# - The environment variables are **only** applicable when processing has not already begun. To apply the environment variables, be sure to first run `make clean-markdown-related`.
#
# @param {string} [MARKDOWN_FILTER] - file path pattern (e.g., `.*/math/base/special/.*`)
# @param {string} [MARKDOWN_PATTERN] - filename pattern (e.g., `*.md`)
#
# @example
# make markdown-related-resume
#/
markdown-related-resume: $(NODE_MODULES) $(REMARK_RELATED_TMP_FILE_LIST) $(REMARK_RELATED_TMP_FILE_LIST_PROGRESS)
$(QUIET) $(UNIQUE_LINES) $(REMARK_RELATED_TMP_FILE_LIST) $(REMARK_RELATED_TMP_FILE_LIST_PROGRESS) | grep '^[\/]\|^[a-zA-Z]:[/\]' | while read -r file; do \
echo ""; \
echo "Processing file: $$file"; \
"$(REMARK)" \
$$file \
$(REMARK_RELATED_FLAGS) \
$(REMARK_RELATED_PLUGIN_FLAGS) \
$(REMARK_RELATED_OUTPUT_FLAG) || exit 1; \
echo "$$file" >> $(REMARK_RELATED_TMP_FILE_LIST_PROGRESS); \
done
.PHONY: markdown-related-resume
#/
# Performs initialization tasks associated with processing Markdown files.
#
# @example
# make markdown-related-init
#/
markdown-related-init: $(REMARK_RELATED_TMP_DIR) $(REMARK_RELATED_TMP_FILE_LIST_PROGRESS)
$(QUIET) $(TOUCH) $(REMARK_RELATED_TMP_FILE_LIST)
.PHONY: markdown-related-init
#/
# Runs clean-up tasks associated with processing Markdown files.
#
# @example
# make clean-markdown-related
#/
clean-markdown-related:
$(QUIET) $(DELETE) $(DELETE_FLAGS) $(REMARK_RELATED_TMP_FILE_LIST_PROGRESS)
.PHONY: clean-markdown-related