Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): reinstall node_modules if react-script doesn't work #2195

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 26 additions & 17 deletions ui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,63 @@
# based on http://blog.jgc.org/2011/07/gnu-make-recursive-wildcard-function.html
rwildcard = $(foreach d, $(wildcard $1*), $(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))

node_modules/%: package.json package-lock.json
NODE_PATH := $(PWD)/node_modules/.bin
PATH := $(PATH):$(NODE_PATH)
SHELL := env PATH=$(PATH) /bin/sh

$(NODE_PATH)/%: package.json package-lock.json
@export D="$*"; \
if [ "$*" = "commitlint-travis" ]; then export D="@commitlint/travis-cli" ; fi; \
if [ "$*" = "build-storybook" ]; then export D="@storybook/react" ; fi; \
if [ "$*" = "percy-storybook" ]; then export D="@percy-io/percy-storybook" ; fi; \
if [ -d "$(PWD)/node_modules/$$D" ] && [ ! -x "$@" ]; then (echo "resetting node_modules" && rm -fr node_modules); fi
npm install
touch -c $@

build/index.html: node_modules/react-scripts/bin/react-scripts.js $(call rwildcard, public src, *)
build/index.html: $(NODE_PATH)/react-scripts $(call rwildcard, public src, *)
@rm -fr node_modules/.cache/eslint-loader
npm run build

.PHONY: build
build: build/index.html

.PHONY: test-js
test-js: node_modules/jest/bin/jest.js
test-js: $(NODE_PATH)/jest
CI=true NODE_OPTIONS="--unhandled-rejections=strict" npm test -- --coverage

.PHONY: test-demo
test-demo: node_modules/jest/bin/jest.js
CI=true ./node_modules/.bin/jest --runInBand e2e/demo.test.js
test-demo: $(NODE_PATH)/jest
CI=true jest --runInBand e2e/demo.test.js

.PHONY: test-percy
test-percy: node_modules/@storybook/react/bin/build.js
test-percy: $(NODE_PATH)/react-scripts $(NODE_PATH)/build-storybook $(NODE_PATH)/percy-storybook
CI=true npm run snapshot

.PHONY: lint-js
lint-js: node_modules/eslint/bin/eslint.js
lint-js: $(NODE_PATH)/eslint
@rm -fr node_modules/.cache/eslint-loader
node_modules/eslint/bin/eslint.js --ext .js,.jsx,.ts,.tsx src
eslint --ext .js,.jsx,.ts,.tsx src

.PHONY: lint-git-ci
lint-git-ci: node_modules/@commitlint/travis-cli/lib/cli.js
node_modules/@commitlint/travis-cli/lib/cli.js
lint-git-ci: $(NODE_PATH)/commitlint-travis
commitlint-travis

.PHONY: lint-docs
lint-docs: node_modules/markdownlint-cli/markdownlint.js
node_modules/markdownlint-cli/markdownlint.js ../*.md ../docs
lint-docs: $(NODE_PATH)/markdownlint
markdownlint ../*.md ../docs

.PHONY: lint-deps
lint-deps: node_modules/depcheck/bin/depcheck.js
node_modules/depcheck/bin/depcheck.js $(CURDIR)
lint-deps: $(NODE_PATH)/depcheck
depcheck $(CURDIR)

.PHONY: lint-typescript
lint-typescript:
@$(eval JSFILES := $(shell find $(CURDIR)/src \( -iname \*.js -o -iname \*.jsx \) -not -name setupTests.js ))
@if [ "$(JSFILES)" != "" ]; then echo "$(JSFILES)" | tr " " "\n"; exit 1 ; fi

.PHONY: format
format: node_modules/prettier/bin-prettier.js
node_modules/prettier/bin-prettier.js --write 'src/**/*.ts' 'src/**/*.tsx'
format: $(NODE_PATH)/prettier
prettier --write 'src/**/*.ts' 'src/**/*.tsx'

build/stats.json: build
node_modules/source-map-explorer/bin/cli.js build/static/*/*.{js,css} --json > build/stats.json
source-map-explorer build/static/*/*.{js,css} --json > build/stats.json