diff --git a/.gitignore b/.gitignore index cf9cb086..1d96be26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea *.iml node_modules/ +dist/ diff --git a/.npmignore b/.npmignore index a3890379..cb29538e 100644 --- a/.npmignore +++ b/.npmignore @@ -2,6 +2,6 @@ example script specs -bower.json karma.conf.js webpack.config.js +dist/ diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..dbf33713 --- /dev/null +++ b/Makefile @@ -0,0 +1,64 @@ +# Mostly lifted from https://andreypopp.com/posts/2013-05-16-makefile-recipes-for-node-js.html +# Thanks @andreypopp + +BIN = ./node_modules/.bin +SRC = $(wildcard lib/*.js) +LIB = $(SRC:lib/%.js=dist/%.js) +MIN = $(SRC:lib/%.js=dist/%.min.js) + +.PHONY: test dev + +build: $(LIB) $(MIN) + +# Allows usage of `make install`, `make link` +install link: + @npm $@ + +# FIXME +dist/%.min.js: $(BIN) + @$(BIN)/uglifyjs dist/react-draggable.js \ + --output dist/react-draggable.min.js \ + --source-map dist/react-draggable.min.map \ + --source-map-url react-draggable.min.map \ + --in-source-map dist/react-draggable.map \ + --compress warnings=false + +dist/%.js: $(BIN) + @$(BIN)/webpack --devtool source-map + +test: $(BIN) + @$(BIN)/karma start --browsers Firefox --single-run + +dev: $(BIN) + script/build-watch + +node_modules/.bin: install + +define release + VERSION=`node -pe "require('./package.json').version"` && \ + NEXT_VERSION=`node -pe "require('semver').inc(\"$$VERSION\", '$(1)')"` && \ + node -e "\ + ['./package.json', './bower.json'].forEach(function(fileName) {\ + var j = require(fileName);\ + j.version = \"$$NEXT_VERSION\";\ + var s = JSON.stringify(j, null, 2);\ + require('fs').writeFileSync(fileName, s);\ + });" && \ + git add package.json bower.json CHANGELOG.md && \ + git add -f dist/ && \ + git commit -m "release v$$NEXT_VERSION" && \ + git tag "v$$NEXT_VERSION" -m "release v$$NEXT_VERSION" +endef + +release-patch: test build + @$(call release,patch) + +release-minor: test build + @$(call release,minor) + +release-major: test build + @$(call release,major) + +publish: + git push --tags origin HEAD:master + npm publish diff --git a/README.md b/README.md index ea8850e7..cc4a5482 100644 --- a/README.md +++ b/README.md @@ -6,17 +6,20 @@ A simple component for making elements draggable. ## Demo -http://mzabriskie.github.io/react-draggable/example/ +[View Demo](http://mzabriskie.github.io/react-draggable/example/) ## Installing ```bash $ npm install react-draggable -# or -$ bower install react-draggable ``` +If you aren't using browserify/webpack, a +[UMD version of react-draggable](http://mzabriskie.github.io/react-draggable/example/react-draggable.js) +is updated in the `gh-pages` branch and used for the demo. You can generate it yourself from master by cloning this +repository and running `$ make`. This will create umd dist files in the `dist/` folder. + ## Details A `` element wraps an existing element and extends it with new event handlers and styles. @@ -101,28 +104,19 @@ React.renderComponent(, document.body); ## Contributing - Fork the project -- `$ npm install` +- Run the project in development mode: `$ make dev` - Make changes. -- Run a static server in this folder to see your changes. - For example: `$ npm install -g static-server; static-server .` and open - http://localhost:9080/example.index.html -- Run webpack in development mode to recompile changes as you make them: - `$ npm run dev` - Add appropriate tests -- `$ npm test` +- `$ make test` - If tests don't pass, make them pass. - Update README with appropriate docs. -- Don't include `/dist` changes. These files are updated per-release. - Commit and PR ## Release checklist - Update CHANGELOG -- Update version in `bower.json` -- Update version in `package.json` -- Run build: `$ npm run build` -- Commit, tag, push -- `npm publish` +- `make release-patch`, `make release-minor`, or `make-release-major` +- `make publish` ## License diff --git a/karma.conf.js b/karma.conf.js index e59bb892..c0e85d7e 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -52,4 +52,4 @@ module.exports = function(config) { require('karma-webpack') ] }); -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 80160d14..3451a801 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,9 @@ "description": "React draggable component", "main": "index.js", "scripts": { - "test": "script/test --browsers Firefox --single-run", - "dev": "script/build-watch", - "build": "script/build" + "test": "make test", + "dev": "make dev", + "build": "make build" }, "repository": { "type": "git", @@ -31,7 +31,10 @@ "karma-firefox-launcher": "^0.1.3", "karma-jasmine": "^0.1.5", "karma-webpack": "^1.2.1", + "open": "0.0.5", "react": "^0.13.2", + "semver": "^4.3.3", + "static-server": "^2.0.0", "uglify-js": "^2.4.15", "webpack": "^1.3.2-beta8", "webpack-dev-server": "^1.4.7" diff --git a/script/build b/script/build deleted file mode 100755 index 7a513579..00000000 --- a/script/build +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh -webpack --devtool source-map - -node_modules/.bin/uglifyjs dist/react-draggable.js \ - --output dist/react-draggable.min.js \ - --source-map dist/react-draggable.min.map \ - --source-map-url react-draggable.min.map \ - --in-source-map dist/react-draggable.map \ - --compress warnings=false diff --git a/script/build-watch b/script/build-watch index 0b76a30c..1eb17972 100755 --- a/script/build-watch +++ b/script/build-watch @@ -1,2 +1,24 @@ -#!/bin/sh -webpack --watch --devtool inline-source-map +#!/bin/bash -e + +function finish { + echo -e "\nExiting..." + kill $WEBPACK_PID + kill $SERVER_PID +} + +webpack --watch --devtool inline-source-map & +WEBPACK_PID=$! + +# # Run a static server and run the example in it. +static-server . & +SERVER_PID=$! + +# Open browser +node -e "\ + var open = require('open'); open('http://localhost:9080/example'); \ +" + +# Kill webpack on exit. +trap finish EXIT + +wait diff --git a/script/test b/script/test deleted file mode 100755 index 92f515bb..00000000 --- a/script/test +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -node_modules/.bin/karma start "$@" \ No newline at end of file