js-beautify/Makefile

169 lines
5.3 KiB
Makefile
Raw Normal View History

2018-07-10 19:16:10 +00:00
PROJECT_ROOT=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))
2018-07-11 00:17:44 +00:00
BUILD_DIR=$(PROJECT_ROOT)build
SCRIPT_DIR=$(PROJECT_ROOT)tools
2018-07-10 19:16:10 +00:00
SHELL=/bin/bash
PYTHON=$(SCRIPT_DIR)/python
NODE=$(SCRIPT_DIR)/node
NPM=$(SCRIPT_DIR)/npm
all: depends generate-tests js beautify py package jstest pytest perf
2018-07-10 19:16:10 +00:00
help:
@echo "make <action>"
@echo " all - build both implementations"
2020-08-19 21:06:38 +00:00
@echo " serve - serve site locally from localhost:8080"
2018-07-10 19:16:10 +00:00
@echo " js - build javascript"
@echo " py - build python"
@echo " alltest - test both implementations, js and python"
@echo " pytest - test python implementation"
@echo " jstest - test javascript implementation"
ci: all git-status-clear
2020-08-19 21:06:38 +00:00
serve: js/lib/*.js
@./node_modules/.bin/serve
2018-07-10 19:16:10 +00:00
js: generate-tests js/lib/*.js
2018-07-26 05:40:13 +00:00
@echo Testing node beautify functionality...
2018-07-12 22:21:51 +00:00
./node_modules/.bin/mocha --recursive js/test && \
2018-07-26 05:40:13 +00:00
./js/test/node-src-index-tests.js
2018-07-10 19:16:10 +00:00
py: generate-tests $(BUILD_DIR)/python
2018-07-26 05:40:13 +00:00
@echo Testing python beautify functionality...
2020-07-08 01:53:03 +00:00
$(SCRIPT_DIR)/python-dev3 black --config=python/pyproject.toml python
2018-07-26 05:40:13 +00:00
$(SCRIPT_DIR)/python-dev python python/js-beautify-test.py || exit 1
2018-07-10 19:16:10 +00:00
2018-09-01 20:03:47 +00:00
jstest: depends js build/*.tgz
2018-07-10 19:16:10 +00:00
@echo Testing javascript implementation...
2018-07-26 05:40:13 +00:00
@$(NODE) js/test/node-beautify-tests.js || exit 1
@$(NODE) js/test/amd-beautify-tests.js || exit 1
2018-07-10 19:16:10 +00:00
@$(NODE) --version && \
2018-07-26 05:40:13 +00:00
./js/test/shell-test.sh
2018-07-10 19:16:10 +00:00
2018-09-01 20:03:47 +00:00
pytest: depends py python/dist/*
2018-07-10 19:16:10 +00:00
@echo Testing python implementation...
@cd python && \
$(PYTHON) --version && \
2018-07-26 05:40:13 +00:00
./jsbeautifier/tests/shell-test.sh
alltest: jstest pytest
2018-07-26 05:40:13 +00:00
package: js py build/*.tgz python/dist/*
perf:
@echo ----------------------------------------
@echo Testing node js beautify performance...
2018-07-26 05:40:13 +00:00
$(NODE) js/test/node-beautify-perf-tests.js || exit 1
@echo Testing node css beautify performance...
$(NODE) js/test/node-beautify-css-perf-tests.js || exit 1
2018-07-26 05:40:13 +00:00
@echo Testing html-beautify performance...
$(NODE) js/test/node-beautify-html-perf-tests.js || exit 1
@echo Testing python js beautify performance...
2018-07-26 07:02:12 +00:00
$(SCRIPT_DIR)/python-dev python python/test-perf-jsbeautifier.py || exit 1
@echo Testing python css beautify performance...
$(SCRIPT_DIR)/python-dev python python/test-perf-cssbeautifier.py || exit 1
2018-07-26 05:40:13 +00:00
@echo ----------------------------------------
2018-07-10 19:16:10 +00:00
2018-07-12 22:21:51 +00:00
generate-tests: $(BUILD_DIR)/generate
2018-07-10 19:16:10 +00:00
beautify:
$(SCRIPT_DIR)/build.sh beautify
# Build
#######################################################
# javascript bundle generation
2018-11-19 22:00:57 +00:00
js/lib/*.js: $(BUILD_DIR)/node $(BUILD_DIR)/generate $(wildcard js/src/*) $(wildcard js/src/**/*) $(wildcard web/*.js) js/index.js tools/template/* webpack.config.js
2018-07-10 19:16:10 +00:00
$(SCRIPT_DIR)/build.sh js
# python package generation
2021-04-15 16:16:16 +00:00
python/dist/*: $(BUILD_DIR)/python $(BUILD_DIR)/generate $(wildcard python/**/*.py) python/jsbeautifier/* python/cssbeautifier/*
2018-07-26 05:40:13 +00:00
@echo Building python package...
@rm -f python/dist/*
2018-07-10 19:16:10 +00:00
@cd python && \
cp setup-css.py setup.py && \
$(PYTHON) setup.py sdist && \
rm setup.py
@cd python && \
cp setup-js.py setup.py && \
$(PYTHON) setup.py sdist && \
rm setup.py
# Order matters here! Install css then js to make sure the local dist version of js is used
$(SCRIPT_DIR)/python-rel pip install -U python/dist/cssbeautifier*
$(SCRIPT_DIR)/python-rel pip install -U python/dist/jsbeautifier*
2018-07-10 19:16:10 +00:00
2018-07-26 05:40:13 +00:00
# python package generation
build/*.tgz: js/lib/*.js
@echo Building node package...
mkdir -p build/node_modules
rm -f build/*.tgz
rm -rf node_modules/js-beautify
$(NPM) pack && mv *.tgz build/
cd build && \
$(NPM) install ./*.tgz
2018-07-10 19:16:10 +00:00
# Test generation
2018-07-12 22:21:51 +00:00
$(BUILD_DIR)/generate: $(BUILD_DIR)/node test/generate-tests.js $(wildcard test/data/**/*)
@echo Generating tests...
2018-07-10 19:16:10 +00:00
$(NODE) test/generate-tests.js
2018-07-12 22:21:51 +00:00
@touch $(BUILD_DIR)/generate
2018-07-10 19:16:10 +00:00
# Handling dependencies
#######################################################
depends: $(BUILD_DIR)/node $(BUILD_DIR)/python
2018-07-12 22:21:51 +00:00
@$(NODE) --version
@$(PYTHON) --version
2018-07-10 19:16:10 +00:00
# update dependencies information
update: depends
2022-03-29 18:03:35 +00:00
@rm package-lock.json
2022-03-29 18:34:54 +00:00
$(NPM) update --save
2018-07-10 19:16:10 +00:00
# when we pull dependencies also pull docker image
# without this images can get stale and out of sync from CI system
$(BUILD_DIR)/node: package.json package-lock.json | $(BUILD_DIR)
2018-07-12 22:21:51 +00:00
@$(NODE) --version
2019-01-30 10:41:47 +00:00
$(NPM) --version
2022-03-29 18:03:35 +00:00
$(NPM) install
2018-07-10 19:16:10 +00:00
@touch $(BUILD_DIR)/node
2021-04-15 16:16:16 +00:00
$(BUILD_DIR)/python: $(BUILD_DIR)/generate python/setup-js.py python/setup-css.py | $(BUILD_DIR) $(BUILD_DIR)/virtualenv
2018-07-12 22:21:51 +00:00
@$(PYTHON) --version
# Order matters here! Install css then js to make sure the local dist version of js is used
@cp ./python/setup-css.py ./python/setup.py
$(SCRIPT_DIR)/python-dev pip install -e ./python
@cp ./python/setup-js.py ./python/setup.py
2018-07-25 21:07:59 +00:00
$(SCRIPT_DIR)/python-dev pip install -e ./python
@rm ./python/setup.py
2018-07-10 19:16:10 +00:00
@touch $(BUILD_DIR)/python
$(BUILD_DIR)/virtualenv: | $(BUILD_DIR)
virtualenv --version || pip install virtualenv
virtualenv build/python-dev
virtualenv build/python-rel
# ignore pip upgrade failure to allow windows builds to continue
$(SCRIPT_DIR)/python-dev pip install pip --upgrade || exit 0
$(SCRIPT_DIR)/python-rel pip install pip --upgrade || exit 0
2022-03-29 07:21:09 +00:00
$(SCRIPT_DIR)/python-dev3 pip install black
@touch $(BUILD_DIR)/virtualenv
2018-07-10 19:16:10 +00:00
# Miscellaneous tasks
#######################################################
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
git-status-clear:
$(SCRIPT_DIR)/git-status-clear.sh
clean:
git clean -xfd
#######################################################
2020-08-19 21:06:38 +00:00
.PHONY: all beautify clean depends generate-tests git-status-clear help serve update
2018-07-10 19:16:10 +00:00