Call “npm install” automatically if package.json changed (#505)

This adds a stamp file which is used to detect whether the `package.json`
file got updated since the last `npm install`.  If so, `npm install` is run
again to update all modules to the version described in `package.json`.
This happens as a dependency of only those modules which actually need some
npm-installed module.

Setting the corresponding make variable to the empty string disables the
feature, which is used by the `make` invocation in the `prepublish` script
inside `package.json` to avoid infinite loops.  It can also be used by
developers working in an environment with reduced connectivity, as long as
they know what they are doing.
This commit is contained in:
Martin von Gagern
2016-08-24 03:05:50 +02:00
committed by Kevin Barabash
parent ec62ec39d8
commit e6de31d2d6
2 changed files with 15 additions and 10 deletions

View File

@@ -13,19 +13,24 @@ export UGLIFYJS = $(realpath ./node_modules/.bin/uglifyjs) \
--beautify \ --beautify \
ascii_only=true,beautify=false ascii_only=true,beautify=false
setup: # 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
npm install npm install
@touch $(NIS)
lint: katex.js server.js cli.js $(wildcard src/*.js) $(wildcard test/*.js) $(wildcard contrib/*/*.js) $(wildcard dockers/*/*.js) lint: $(NIS) katex.js server.js cli.js $(wildcard src/*.js) $(wildcard test/*.js) $(wildcard contrib/*/*.js) $(wildcard dockers/*/*.js)
./node_modules/.bin/eslint $^ ./node_modules/.bin/eslint $(filter-out *.stamp,$^)
build/katex.js: katex.js $(wildcard src/*.js) build/katex.js: katex.js $(wildcard src/*.js) $(NIS)
$(BROWSERIFY) $< --standalone katex > $@ $(BROWSERIFY) $< --standalone katex > $@
build/katex.min.js: build/katex.js build/katex.min.js: build/katex.js
$(UGLIFYJS) < $< > $@ $(UGLIFYJS) < $< > $@
build/katex.less.css: static/katex.less $(wildcard static/*.less) build/katex.less.css: static/katex.less $(wildcard static/*.less) $(NIS)
./node_modules/.bin/lessc $< $@ ./node_modules/.bin/lessc $< $@
build/katex.min.css: build/katex.less.css build/katex.min.css: build/katex.less.css
@@ -78,10 +83,10 @@ compress: build/katex.min.js build/katex.min.css
@printf "Minified, gzipped css: %6d\n" "${CSSSIZE}" @printf "Minified, gzipped css: %6d\n" "${CSSSIZE}"
@printf "Total: %6d\n" "${TOTAL}" @printf "Total: %6d\n" "${TOTAL}"
serve: serve: $(NIS)
node server.js node server.js
test: test: $(NIS)
JASMINE_CONFIG_PATH=test/jasmine.json node_modules/.bin/jasmine JASMINE_CONFIG_PATH=test/jasmine.json node_modules/.bin/jasmine
PERL=perl PERL=perl
@@ -94,7 +99,7 @@ extended_metrics:
cd metrics && $(PERL) ./mapping.pl | $(PYTHON) ./extract_tfms.py | $(PYTHON) ./extract_ttfs.py | $(PYTHON) ./format_json.py --width > ../src/fontMetricsData.js cd metrics && $(PERL) ./mapping.pl | $(PYTHON) ./extract_tfms.py | $(PYTHON) ./extract_ttfs.py | $(PYTHON) ./format_json.py --width > ../src/fontMetricsData.js
clean: clean:
rm -rf build/* rm -rf build/* $(NIS)
screenshots: test/screenshotter/unicode-fonts screenshots: test/screenshotter/unicode-fonts $(NIS)
dockers/Screenshotter/screenshotter.sh dockers/Screenshotter/screenshotter.sh

View File

@@ -33,7 +33,7 @@
"bin": "cli.js", "bin": "cli.js",
"scripts": { "scripts": {
"test": "make lint test", "test": "make lint test",
"prepublish": "make dist" "prepublish": "make NIS= dist"
}, },
"dependencies": { "dependencies": {
"match-at": "^0.1.0" "match-at": "^0.1.0"