Remove Makefile and migrate to NPM scripts (#1135)

* Remove Makefile and migrate to NPM scripts

* Update documentation/.arclint

* Check node version in prestart

* Group test npm scripts into `test:`
This commit is contained in:
ylemkimon
2018-02-07 02:39:24 +09:00
committed by Kevin Barabash
parent 73d80f595c
commit 383a68b935
6 changed files with 19 additions and 112 deletions

View File

@@ -2,7 +2,7 @@
"linters": { "linters": {
"katex-linter": { "katex-linter": {
"type": "script-and-regex", "type": "script-and-regex",
"script-and-regex.script": "make lint || true", "script-and-regex.script": "npm run test:lint || true",
"script-and-regex.regex": "/^(?P<file>\\S+): line (?P<line>\\d+), col \\d+, (?P<message>.*)$/m" "script-and-regex.regex": "/^(?P<file>\\S+): line (?P<line>\\d+), col \\d+, (?P<message>.*)$/m"
} }
} }

View File

@@ -74,7 +74,7 @@ by running `npm install webpack-dev-server@2.7.1`.
The JavaScript parser and some of the HTML and MathML tree The JavaScript parser and some of the HTML and MathML tree
builders are tested with Jest. These tests can be run using node with builders are tested with Jest. These tests can be run using node with
`npm run jest`. If you need to debug the tests see `npm run test:jest`. If you need to debug the tests see
[https://facebook.github.io/jest/docs/troubleshooting.html](https://facebook.github.io/jest/docs/troubleshooting.html) [https://facebook.github.io/jest/docs/troubleshooting.html](https://facebook.github.io/jest/docs/troubleshooting.html)
The interactive editor can also be used for debugging tests in the browser by The interactive editor can also be used for debugging tests in the browser by

View File

@@ -1,95 +0,0 @@
.PHONY: build dist lint setup webpack serve clean metrics test coverage zip flow
build: test build/katex zip compress
ifeq ($(KATEX_DIST),skip)
dist:
else
dist: build
rm -rf dist/
cp -R build/katex/ dist/
endif
NODE := node # pass NODE=nodejs on Debian without package nodejs-legacy
NPM := npm
NODECHK := $(shell $(NODE) ./check-node-version.js)
ifneq ($(NODECHK),OK)
$(error "Node not found or wrong version")
endif
# 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)
$(NPM) run lint
webpack: katex.js $(wildcard src/*.js) src/katex.less submodules/katex-fonts/fonts.less $(NIS)
$(NPM) run build
.PHONY: build/fonts build/contrib
build/katex.js build/katex.min.js build/katex.css build/katex.min.css build/katex.css build/fonts build/contrib: webpack
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 ../../../
.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
@JSSIZE=`gzip -c build/katex.min.js | wc -c`; \
CSSSIZE=`gzip -c build/katex.min.css | wc -c`; \
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)
$(NPM) start
flow: $(NIS)
$(NPM) run flow
test: $(NIS)
$(NPM) test
coverage: $(NIS)
$(NPM) run coverage
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 --width > ../src/fontMetricsData.js
unicode:
cd src && $(NODE) unicodeMake.js >unicodeSymbols.js
src/unicodeSymbols.js: unicode
clean:
rm -rf build/* $(NIS)
screenshots: test/screenshotter/unicode-fonts $(NIS)
dockers/Screenshotter/screenshotter.sh

View File

@@ -39,6 +39,7 @@
"jspngopt": "^0.2.0", "jspngopt": "^0.2.0",
"less": "~2.7.1", "less": "~2.7.1",
"less-loader": "^4.0.5", "less-loader": "^4.0.5",
"mkdirp": "^0.5.1",
"nomnom": "^1.8.1", "nomnom": "^1.8.1",
"object-assign": "^4.1.0", "object-assign": "^4.1.0",
"pako": "1.0.4", "pako": "1.0.4",
@@ -55,23 +56,28 @@
}, },
"bin": "cli.js", "bin": "cli.js",
"scripts": { "scripts": {
"lint": "eslint katex.js katex.webpack.js cli.js webpack.common.js webpack.config.js webpack.dev.js src static test contrib dockers && stylelint src/katex.less", "test": "npm run prestart && npm run test:lint && npm run test:flow && npm run test:jest",
"flow": "flow", "test:lint": "eslint katex.js katex.webpack.js cli.js webpack.common.js webpack.config.js webpack.dev.js src static test contrib dockers && stylelint src/katex.less",
"jest": "jest", "test:flow": "flow",
"test:jest": "jest",
"jest-update": "jest --updateSnapshot", "jest-update": "jest --updateSnapshot",
"coverage": "jest --coverage", "coverage": "jest --coverage",
"clean": "rm -rf build/* node_modules/", "clean": "rm -rf build/* node_modules/",
"clean-install": "npm run clean && npm i", "clean-install": "npm run clean && npm i",
"test": "check-dependencies && npm run lint && npm run flow && npm run jest", "screenshots": "npm run prestart && dockers/Screenshotter/screenshotter.sh",
"verify-screenshots": "check-dependencies && dockers/Screenshotter/screenshotter.sh --verify", "verify-screenshots": "npm run screenshots -- --verify",
"start": "check-dependencies && webpack-dev-server --hot --config webpack.dev.js", "prestart": "node check-node-version.js && check-dependencies && cd src && node unicodeMake.js >unicodeSymbols.js",
"build": "check-dependencies && rimraf build/* && webpack", "start": "webpack-dev-server --hot --config webpack.dev.js",
"build": "npm run prestart && rimraf build/* && webpack",
"dist": "npm test && npm run build && npm run dist:copy && npm run dist:zip && npm run dist:dist",
"dist:copy": "cd build && mkdirp katex && cp -r katex.js katex.min.js katex.css katex.min.css contrib fonts ../README.md katex",
"dist:zip": "cd build && tar czf katex.tar.gz katex/ && zip -rq katex.zip katex/",
"dist:dist": "rimraf dist/ && cp -r build/katex/ dist/",
"watch": "npm run build -- --watch", "watch": "npm run build -- --watch",
"perf-test": "check-dependencies && NODE_ENV=test node test/perf-test.js", "perf-test": "npm run prestart && NODE_ENV=test node test/perf-test.js"
"prepublishOnly": "make NIS= dist"
}, },
"pre-commit": [ "pre-commit": [
"lint" "test:lint"
], ],
"dependencies": { "dependencies": {
"match-at": "^0.1.1" "match-at": "^0.1.1"

View File

@@ -104,7 +104,7 @@ git checkout --detach
# Build generated files and add them to the repository (for bower) # Build generated files and add them to the repository (for bower)
git clean -fdx build dist git clean -fdx build dist
make setup dist npm run dist
sed -i.bak -E '/^\/dist\/$/d' .gitignore sed -i.bak -E '/^\/dist\/$/d' .gitignore
rm -f .gitignore.bak rm -f .gitignore.bak
git add .gitignore dist/ git add .gitignore dist/

View File

@@ -4,10 +4,6 @@
// whose purpose is to generate unicodeSymbols.js in this directory. // whose purpose is to generate unicodeSymbols.js in this directory.
// In this way, only this tool, and not the distribution/browser, // In this way, only this tool, and not the distribution/browser,
// needs String's normalize function. // needs String's normalize function.
//
// This tool should be run (via `node unicodeMake.js` or `make unicode`)
// whenever KaTeX adds support for new accents, and whenever
// the Unicode spec adds new symbols that should be supported.
const accents = require('./unicodeAccents'); const accents = require('./unicodeAccents');