mirror of
https://github.com/Smaug123/KaTeX
synced 2025-10-05 11:18:39 +00:00
* Let git ignore .npm-install.stamp and dist The former is created for most makefile targets after dependencies have been retrieved. The latter is created by typical operations like “make” without arguments or “npm install”. Having these around is to be expected. Adding this to .gitignore should NOT affect npm packaging, since that is based on a whitelist in package.json which does mention dist. * Allow installing dependencies without actually building KaTeX We have been using “npm install” to install dependencies, but since that also does build KaTeX itself, it may fail if e.g. there are any style guide violations. Now we only fetch dependencies but do not build KaTeX itself. The make conditionals used here are not part of POSIX make but a GNU extension. But we already use functionality not mandated by POSIX (namely many of the functions like “wildcard”), so this should not make portability any worse than it already is.
114 lines
3.4 KiB
Makefile
114 lines
3.4 KiB
Makefile
.PHONY: build dist lint setup copy serve clean metrics test zip contrib
|
|
build: lint build/katex.min.js build/katex.min.css contrib zip compress
|
|
|
|
ifeq ($(KATEX_DIST),skip)
|
|
|
|
dist:
|
|
|
|
else
|
|
|
|
dist: build
|
|
rm -rf dist/
|
|
cp -R build/katex/ dist/
|
|
|
|
endif
|
|
|
|
# Export these variables for use in contrib Makefiles
|
|
export BUILDDIR = $(realpath build)
|
|
export BROWSERIFY = $(realpath ./node_modules/.bin/browserify)
|
|
export UGLIFYJS = $(realpath ./node_modules/.bin/uglifyjs) \
|
|
--mangle \
|
|
--beautify \
|
|
ascii_only=true,beautify=false
|
|
|
|
# The prepublish script in package.json will override the following variable,
|
|
# setting it to the empty string and thereby avoiding an infinite recursion
|
|
NIS = .npm-install.stamp
|
|
|
|
$(NIS) setup: package.json
|
|
KATEX_DIST=skip npm install # dependencies only, don't build
|
|
@touch $(NIS)
|
|
|
|
lint: $(NIS) katex.js server.js cli.js $(wildcard src/*.js) $(wildcard test/*.js) $(wildcard contrib/*/*.js) $(wildcard dockers/*/*.js)
|
|
./node_modules/.bin/eslint $(filter-out *.stamp,$^)
|
|
|
|
build/katex.js: katex.js $(wildcard src/*.js) $(NIS)
|
|
$(BROWSERIFY) $< --standalone katex > $@
|
|
|
|
build/katex.min.js: build/katex.js
|
|
$(UGLIFYJS) < $< > $@
|
|
|
|
build/katex.css: static/katex.less $(wildcard static/*.less) $(NIS)
|
|
./node_modules/.bin/lessc $< $@
|
|
|
|
build/katex.min.css: build/katex.css
|
|
./node_modules/.bin/cleancss -o $@ $<
|
|
|
|
.PHONY: build/fonts
|
|
build/fonts:
|
|
rm -rf $@
|
|
mkdir $@
|
|
for font in $(shell grep "font" static/katex.less | grep -o "KaTeX_\w\+" | cut -d" " -f 2 | sort | uniq); do \
|
|
cp static/fonts/$$font* $@; \
|
|
done
|
|
|
|
test/screenshotter/unicode-fonts:
|
|
git clone https://github.com/Khan/KaTeX-test-fonts test/screenshotter/unicode-fonts
|
|
cd test/screenshotter/unicode-fonts && \
|
|
git checkout 99fa66a2da643218754c8236b9f9151cac71ba7c && \
|
|
cd ../../../
|
|
|
|
contrib: build/contrib
|
|
|
|
.PHONY: build/contrib
|
|
build/contrib:
|
|
mkdir -p build/contrib
|
|
@# Since everything in build/contrib is put in the built files, make sure
|
|
@# there's nothing in there we don't want.
|
|
rm -rf build/contrib/*
|
|
$(MAKE) -C contrib/auto-render
|
|
|
|
.PHONY: build/katex
|
|
build/katex: build/katex.js build/katex.min.js build/katex.css build/katex.min.css build/fonts README.md build/contrib
|
|
mkdir -p build/katex
|
|
rm -rf build/katex/*
|
|
cp -r $^ build/katex
|
|
|
|
build/katex.tar.gz: build/katex
|
|
cd build && tar czf katex.tar.gz katex/
|
|
|
|
build/katex.zip: build/katex
|
|
rm -f $@
|
|
cd build && zip -rq katex.zip katex/
|
|
|
|
zip: build/katex.tar.gz build/katex.zip
|
|
|
|
compress: build/katex.min.js build/katex.min.css
|
|
@$(eval JSSIZE!=gzip -c build/katex.min.js | wc -c)
|
|
@$(eval CSSSIZE!=gzip -c build/katex.min.css | wc -c)
|
|
@$(eval TOTAL!=echo ${JSSIZE}+${CSSSIZE} | bc)
|
|
@printf "Minified, gzipped js: %6d\n" "${JSSIZE}"
|
|
@printf "Minified, gzipped css: %6d\n" "${CSSSIZE}"
|
|
@printf "Total: %6d\n" "${TOTAL}"
|
|
|
|
serve: $(NIS)
|
|
node server.js
|
|
|
|
test: $(NIS)
|
|
JASMINE_CONFIG_PATH=test/jasmine.json node_modules/.bin/jasmine
|
|
|
|
PERL=perl
|
|
PYTHON=$(shell python2 --version >/dev/null 2>&1 && echo python2 || echo python)
|
|
|
|
metrics:
|
|
cd metrics && $(PERL) ./mapping.pl | $(PYTHON) ./extract_tfms.py | $(PYTHON) ./extract_ttfs.py | $(PYTHON) ./format_json.py > ../src/fontMetricsData.js
|
|
|
|
extended_metrics:
|
|
cd metrics && $(PERL) ./mapping.pl | $(PYTHON) ./extract_tfms.py | $(PYTHON) ./extract_ttfs.py | $(PYTHON) ./format_json.py --width > ../src/fontMetricsData.js
|
|
|
|
clean:
|
|
rm -rf build/* $(NIS)
|
|
|
|
screenshots: test/screenshotter/unicode-fonts $(NIS)
|
|
dockers/Screenshotter/screenshotter.sh
|