Skip to content

Commit

Permalink
Move to Makefile for building, add dist/ to .gitignore (diff noise)
Browse files Browse the repository at this point in the history
Bower is still workable through the make script, which will force-add dist/.
  • Loading branch information
STRML committed May 2, 2015
1 parent 4ec45f8 commit a01a232
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
*.iml
node_modules/
dist/
2 changes: 1 addition & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
example
script
specs
bower.json
karma.conf.js
webpack.config.js
dist/
64 changes: 64 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
26 changes: 10 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<Draggable>` element wraps an existing element and extends it with new event handlers and styles.
Expand Down Expand Up @@ -101,28 +104,19 @@ React.renderComponent(<App/>, 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

Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ module.exports = function(config) {
require('karma-webpack')
]
});
};
};
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
9 changes: 0 additions & 9 deletions script/build

This file was deleted.

26 changes: 24 additions & 2 deletions script/build-watch
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions script/test

This file was deleted.

0 comments on commit a01a232

Please sign in to comment.