From d7d0d9bf880ae1c829f10e5a329321cd41046937 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 18 Dec 2019 16:05:51 +1000 Subject: [PATCH] add prettier, tidy up makefile --- Makefile | 140 ++++++++++++++++++++++++++++--------------- ts/.prettierrc | 5 ++ ts/package-lock.json | 6 ++ ts/package.json | 9 +-- 4 files changed, 107 insertions(+), 53 deletions(-) create mode 100644 ts/.prettierrc diff --git a/Makefile b/Makefile index 382eda6ae..3c6cf77bd 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,9 @@ RUNARGS := $(shell mkdir -p .build) +# Installing +###################### + .PHONY: all install uninstall all: @@ -45,56 +48,10 @@ uninstall: @echo @echo "Uninstall complete." -.PHONY: clean build run +# Prerequisites +###################### -clean: - rm -rf .build - rm -rf $(JSDEPS) - -build: reqs .build/ui .build/js - -.build/ui: $(shell find designer -name '*.ui') - ./tools/build_ui.sh - touch $@ - -run: build - ./runanki ${RUNARGS} - -CHECKDEPS := build $(shell find anki aqt -name '*.py') - -.PHONY: check mypy test lint pytype - -check: mypy test lint pytype -mypy: .build/mypy -test: .build/test -lint: .build/lint -pytype: .build/pytype - -.build/mypy: $(CHECKDEPS) - mypy anki aqt - touch $@ - -.build/test: $(CHECKDEPS) - ./tools/tests.sh - touch $@ - -.build/lint: $(CHECKDEPS) - pylint -j 0 --rcfile=.pylintrc -f colorized --extension-pkg-whitelist=PyQt5 anki aqt - touch $@ - -.build/pytype: $(CHECKDEPS) - pytype --config pytype.conf - touch $@ - -TSDEPS := $(wildcard ts/src/*.ts) -JSDEPS := $(patsubst ts/src/%.ts, web/%.js, $(TSDEPS)) - -.build/js: $(TSDEPS) - (cd ts && ./node_modules/.bin/tsc --build) - touch $@ - -.PHONY: reqs -reqs: .build/pyrunreqs .build/pydevreqs .build/jsreqs +REQS := .build/pyrunreqs .build/pydevreqs .build/jsreqs .build/pyrunreqs: requirements.txt pip install -r $< @@ -107,3 +64,88 @@ reqs: .build/pyrunreqs .build/pydevreqs .build/jsreqs .build/jsreqs: ts/package.json (cd ts && npm i) touch $@ + +# Building +###################### + +BUILDDEPS := $(REQS) .build/ui .build/js + +.build/ui: $(shell find designer -name '*.ui') + ./tools/build_ui.sh + touch $@ + +.build/js: $(TSDEPS) + (cd ts && npm run build) + touch $@ + +.PHONY: build clean + +build: $(BUILDDEPS) + +.PHONY: clean +clean: + rm -rf .build + rm -rf $(JSDEPS) + +# Running +###################### + +.PHONY: run +run: build + ./runanki ${RUNARGS} + +# Checking +###################### + +.PHONY: check +check: mypy pytest pylint pytype checkpretty + +# Checking python +###################### + +PYCHECKDEPS := $(BUILDDEPS) $(shell find anki aqt -name '*.py') + +.build/mypy: $(PYCHECKDEPS) + mypy anki aqt + touch $@ + +.build/pytest: $(PYCHECKDEPS) + ./tools/tests.sh + touch $@ + +.build/pylint: $(PYCHECKDEPS) + pylint -j 0 --rcfile=.pylintrc -f colorized --extension-pkg-whitelist=PyQt5 anki aqt + touch $@ + +.build/pytype: $(PYCHECKDEPS) + pytype --config pytype.conf + touch $@ + +.PHONY: mypy pytest pylint pytype +mypy: .build/mypy +pytest: .build/pytest +pylint: .build/pylint +pytype: .build/pytype + +# Typescript source +###################### + +TSDEPS := $(wildcard ts/src/*.ts) +JSDEPS := $(patsubst ts/src/%.ts, web/%.js, $(TSDEPS)) + +# Checking typescript +###################### + +TSCHECKDEPS := $(BUILDDEPS) $(TSDEPS) + +.build/checkpretty: $(TSCHECKDEPS) + (cd ts && npm run check-pretty) + touch $@ + +.build/pretty: $(TSCHECKDEPS) + (cd ts && npm run pretty) + touch $@ + +.PHONY: pretty checkpretty +pretty: .build/pretty +checkpretty: .build/checkpretty diff --git a/ts/.prettierrc b/ts/.prettierrc new file mode 100644 index 000000000..c23b64108 --- /dev/null +++ b/ts/.prettierrc @@ -0,0 +1,5 @@ +{ + "trailingComma": "es5", + "tabWidth": 4, + "semi": true +} diff --git a/ts/package-lock.json b/ts/package-lock.json index ab2f91216..3256a1878 100644 --- a/ts/package-lock.json +++ b/ts/package-lock.json @@ -34,6 +34,12 @@ "integrity": "sha512-7EJYyKTL7tFR8+gDbB6Wwz/arpGa0Mywk1TJbNzKzHtzbwVmY4HR9WqS5VV7dsBUKQmPNr192jHr/VpBluj/hg==", "dev": true }, + "prettier": { + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-1.19.1.tgz", + "integrity": "sha512-s7PoyDv/II1ObgQunCbB9PdLmUcBZcnWOcxDh7O0N/UwDEsHyqkW+Qh28jW+mVuCdx7gLB0BotYI1Y6uI9iyew==", + "dev": true + }, "typescript": { "version": "3.7.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.3.tgz", diff --git a/ts/package.json b/ts/package.json index 1f8e27e7b..240bffea9 100644 --- a/ts/package.json +++ b/ts/package.json @@ -2,18 +2,19 @@ "name": "anki-dtop-js", "version": "1.0.0", "description": "Anki desktop js support files", - "directories": { - "test": "tests" - }, "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "build": "tsc --build", + "pretty": "prettier --write src/*.ts", + "check-pretty": "prettier --check src/*.ts" }, + "private": true, "author": "Ankitects Pty Ltd", "license": "AGPL-3.0-or-later", "devDependencies": { "@types/jquery": "^3.3.31", "@types/jqueryui": "^1.12.9", "@types/mathjax": "0.0.36", + "prettier": "^1.19.1", "typescript": "^3.7.3" } }