From 14a2fd0a329185a2296afa1ed347e8257a51b9bd Mon Sep 17 00:00:00 2001 From: Bruno Dias Date: Wed, 7 Jun 2017 22:42:42 -0300 Subject: [PATCH] [chore] improving build and publish pipeline. --- .gitignore | 4 ++ .travis.yml | 2 + Makefile | 95 +++++++++++++++++++++++++++++++++++++++++ package.json | 13 ++---- scripts/build | 2 - scripts/dev-examples | 3 -- scripts/preview-release | 2 - scripts/release | 3 -- scripts/test | 2 - scripts/version | 20 +++++++++ 10 files changed, 124 insertions(+), 22 deletions(-) create mode 100644 Makefile delete mode 100755 scripts/build delete mode 100755 scripts/dev-examples delete mode 100755 scripts/preview-release delete mode 100755 scripts/release delete mode 100755 scripts/test create mode 100644 scripts/version diff --git a/.gitignore b/.gitignore index 3d6fc093..c863a029 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,7 @@ examples/**/*-bundle.js node_modules/ .idea/ _book +coverage/* +*.patch +*.diff +examples/__build__ diff --git a/.travis.yml b/.travis.yml index 29a568b7..8635d814 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,5 @@ node_js: before_script: - export DISPLAY=:99.0 - sh -e /etc/init.d/xvfb start +script: + - make tests-ci diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..6dcc6002 --- /dev/null +++ b/Makefile @@ -0,0 +1,95 @@ +NODE=$(shell which node) +NPM=$(shell which npm) +YARN=$(shell which yarn) +JQ=$(shell which jq) + +VERSION=$(shell jq ".version" package.json) + +help: info + @echo + @echo "List of commands:" + @echo + @echo " make info - display node, npm and yarn versions..." + @echo " make deps - install all dependencies." + @echo " make serve - start the server." + @echo " make tests - run tests." + @echo " make docs - build and serve the docs." + @echo " make build - build project artifacts." + @echo " make publish - build and publish version on npm." + @echo " make publish-docs - build the docs and publish to gh-pages." + @echo " make publish-all - publish version and docs." + +info: + @echo node version: `$(NODE) --version` "($(NODE))" + @echo npm version: `$(NPM) --version` "($(NPM))" + @echo yarn version: `$(YARN) --version` "($(YARN))" + @echo jq version: `$(JQ) --version` "($(JQ))" + @echo react-modal version: $(VERSION) + +deps: + @[[ ! -z "$(YARN)" ]] && $(YARN) install || $(NPM) install + @gitbook install + +# Rules for development + +serve: + @npm start + +tests: + @npm run test + +tests-ci: + @npm run test -- --single-run + +docs: build-docs + gitbook serve + +# Rules for build and publish + +build: + @echo "[Building dists]" + @./node_modules/.bin/webpack --config webpack.dist.config.js + +build-docs: + @echo "[Building documentation]" + @rm -rf _book/* + @gitbook build -g reactjs/react-modal + +version: + @echo "[Updating react-modal version]" + @sh ./scripts/version $(VERSION) + +release-commit: + @$(JQ) '.version' package.json | cut -d\" -f2 > .version + git commit --allow-empty -m "Release v`cat .version`." + @rm .version + git add . + git commit --amend -m "`git log -1 --format=%s`" + +release-tag: + @$(JQ) '.version' package.json | cut -d\" -f2 > .version + git tag "v`cat .version`" + @rm .version + +publish-version: release-commit release-tag + @echo "[Publishing]" + @$(JQ) '.version' package.json | cut -d\" -f2 > .version + git push git@github.com:reactjs/react-modal "`git branch | grep '^*' | awk '{ print $$2 }'`" "v`cat .version`" + npm publish + @rm .version + +publish: version build publish-version publish-finished + +publish-docs: build-docs + @echo "[Publishing docs]" + cd _book + git init + git commit --allow-empty -m 'update book' + git checkout -b gh-pages + touch .nojekyll + git add . + git commit -am 'update book' + git push git@github.com:reactjs/react-modal gh-pages --force + cd .. + +publish-all: publish publish-docs diff --git a/package.json b/package.json index e8150002..50e87678 100644 --- a/package.json +++ b/package.json @@ -13,15 +13,8 @@ "example": "examples" }, "scripts": { - "test": "NODE_ENV=test karma start", - "start": "scripts/dev-examples", - "docs": "npm-run-all docs:*", - "docs-dev": "npm-run-all docs:clean docs:prepare docs:build:watch", - "docs:clean": "rimraf _book", - "docs:prepare": "gitbook install", - "docs:build": "gitbook build -g reactjs/react-modal", - "docs:build:watch": "gitbook serve", - "docs:publish": "cd _book && git init && git commit --allow-empty -m 'update book' && git checkout -b gh-pages && touch .nojekyll && git add . && git commit -am 'update book' && git push git@github.com:reactjs/react-modal gh-pages --force" + "start": "./node_modules/.bin/webpack-dev-server --inline --host 127.0.0.1 --content-base examples/", + "test": "NODE_ENV=test karma start" }, "authors": [ "Ryan Florence" @@ -77,4 +70,4 @@ "modal", "dialog" ] -} \ No newline at end of file +} diff --git a/scripts/build b/scripts/build deleted file mode 100755 index 547bfc7a..00000000 --- a/scripts/build +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -node_modules/.bin/webpack --config webpack.dist.config.js diff --git a/scripts/dev-examples b/scripts/dev-examples deleted file mode 100755 index a213dd34..00000000 --- a/scripts/dev-examples +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -node_modules/.bin/webpack-dev-server --inline --host 0.0.0.0 --content-base examples/ - diff --git a/scripts/preview-release b/scripts/preview-release deleted file mode 100755 index 89cf9452..00000000 --- a/scripts/preview-release +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -node_modules/.bin/changelog -t preview -s diff --git a/scripts/release b/scripts/release deleted file mode 100755 index b839eb36..00000000 --- a/scripts/release +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -scripts/build -node_modules/.bin/release diff --git a/scripts/test b/scripts/test deleted file mode 100755 index 61133350..00000000 --- a/scripts/test +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -NODE_ENV=test node_modules/.bin/karma start "$@" diff --git a/scripts/version b/scripts/version new file mode 100644 index 00000000..4e16838d --- /dev/null +++ b/scripts/version @@ -0,0 +1,20 @@ +#!/bin/sh + +JQ=$(which jq) + +if [[ -z "$JQ" ]]; then + echo "jq is missing." +fi + +echo "Current version is: $1" + +read -p "Bump to: " NEW_VERSION + +FILES="package.json bower.json" + +for F in $FILES; do + $JQ ".version = \"${NEW_VERSION}\"" "$F" > up.json + cat up.json > "$F" +done + +rm up.json