Skip to content

Commit a01a232

Browse files
committed
Move to Makefile for building, add dist/ to .gitignore (diff noise)
Bower is still workable through the make script, which will force-add dist/.
1 parent 4ec45f8 commit a01a232

File tree

9 files changed

+107
-34
lines changed

9 files changed

+107
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea
22
*.iml
33
node_modules/
4+
dist/

.npmignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
example
33
script
44
specs
5-
bower.json
65
karma.conf.js
76
webpack.config.js
7+
dist/

Makefile

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Mostly lifted from https://andreypopp.com/posts/2013-05-16-makefile-recipes-for-node-js.html
2+
# Thanks @andreypopp
3+
4+
BIN = ./node_modules/.bin
5+
SRC = $(wildcard lib/*.js)
6+
LIB = $(SRC:lib/%.js=dist/%.js)
7+
MIN = $(SRC:lib/%.js=dist/%.min.js)
8+
9+
.PHONY: test dev
10+
11+
build: $(LIB) $(MIN)
12+
13+
# Allows usage of `make install`, `make link`
14+
install link:
15+
@npm $@
16+
17+
# FIXME
18+
dist/%.min.js: $(BIN)
19+
@$(BIN)/uglifyjs dist/react-draggable.js \
20+
--output dist/react-draggable.min.js \
21+
--source-map dist/react-draggable.min.map \
22+
--source-map-url react-draggable.min.map \
23+
--in-source-map dist/react-draggable.map \
24+
--compress warnings=false
25+
26+
dist/%.js: $(BIN)
27+
@$(BIN)/webpack --devtool source-map
28+
29+
test: $(BIN)
30+
@$(BIN)/karma start --browsers Firefox --single-run
31+
32+
dev: $(BIN)
33+
script/build-watch
34+
35+
node_modules/.bin: install
36+
37+
define release
38+
VERSION=`node -pe "require('./package.json').version"` && \
39+
NEXT_VERSION=`node -pe "require('semver').inc(\"$$VERSION\", '$(1)')"` && \
40+
node -e "\
41+
['./package.json', './bower.json'].forEach(function(fileName) {\
42+
var j = require(fileName);\
43+
j.version = \"$$NEXT_VERSION\";\
44+
var s = JSON.stringify(j, null, 2);\
45+
require('fs').writeFileSync(fileName, s);\
46+
});" && \
47+
git add package.json bower.json CHANGELOG.md && \
48+
git add -f dist/ && \
49+
git commit -m "release v$$NEXT_VERSION" && \
50+
git tag "v$$NEXT_VERSION" -m "release v$$NEXT_VERSION"
51+
endef
52+
53+
release-patch: test build
54+
@$(call release,patch)
55+
56+
release-minor: test build
57+
@$(call release,minor)
58+
59+
release-major: test build
60+
@$(call release,major)
61+
62+
publish:
63+
git push --tags origin HEAD:master
64+
npm publish

README.md

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,20 @@ A simple component for making elements draggable.
66

77
## Demo
88

9-
http://mzabriskie.github.io/react-draggable/example/
9+
[View Demo](http://mzabriskie.github.io/react-draggable/example/)
1010

1111

1212
## Installing
1313

1414
```bash
1515
$ npm install react-draggable
16-
# or
17-
$ bower install react-draggable
1816
```
1917

18+
If you aren't using browserify/webpack, a
19+
[UMD version of react-draggable](http://mzabriskie.github.io/react-draggable/example/react-draggable.js)
20+
is updated in the `gh-pages` branch and used for the demo. You can generate it yourself from master by cloning this
21+
repository and running `$ make`. This will create umd dist files in the `dist/` folder.
22+
2023
## Details
2124

2225
A `<Draggable>` element wraps an existing element and extends it with new event handlers and styles.
@@ -101,28 +104,19 @@ React.renderComponent(<App/>, document.body);
101104
## Contributing
102105

103106
- Fork the project
104-
- `$ npm install`
107+
- Run the project in development mode: `$ make dev`
105108
- Make changes.
106-
- Run a static server in this folder to see your changes.
107-
For example: `$ npm install -g static-server; static-server .` and open
108-
http://localhost:9080/example.index.html
109-
- Run webpack in development mode to recompile changes as you make them:
110-
`$ npm run dev`
111109
- Add appropriate tests
112-
- `$ npm test`
110+
- `$ make test`
113111
- If tests don't pass, make them pass.
114112
- Update README with appropriate docs.
115-
- Don't include `/dist` changes. These files are updated per-release.
116113
- Commit and PR
117114

118115
## Release checklist
119116

120117
- Update CHANGELOG
121-
- Update version in `bower.json`
122-
- Update version in `package.json`
123-
- Run build: `$ npm run build`
124-
- Commit, tag, push
125-
- `npm publish`
118+
- `make release-patch`, `make release-minor`, or `make-release-major`
119+
- `make publish`
126120

127121
## License
128122

karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ module.exports = function(config) {
5252
require('karma-webpack')
5353
]
5454
});
55-
};
55+
};

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"description": "React draggable component",
55
"main": "index.js",
66
"scripts": {
7-
"test": "script/test --browsers Firefox --single-run",
8-
"dev": "script/build-watch",
9-
"build": "script/build"
7+
"test": "make test",
8+
"dev": "make dev",
9+
"build": "make build"
1010
},
1111
"repository": {
1212
"type": "git",
@@ -31,7 +31,10 @@
3131
"karma-firefox-launcher": "^0.1.3",
3232
"karma-jasmine": "^0.1.5",
3333
"karma-webpack": "^1.2.1",
34+
"open": "0.0.5",
3435
"react": "^0.13.2",
36+
"semver": "^4.3.3",
37+
"static-server": "^2.0.0",
3538
"uglify-js": "^2.4.15",
3639
"webpack": "^1.3.2-beta8",
3740
"webpack-dev-server": "^1.4.7"

script/build

Lines changed: 0 additions & 9 deletions
This file was deleted.

script/build-watch

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1-
#!/bin/sh
2-
webpack --watch --devtool inline-source-map
1+
#!/bin/bash -e
2+
3+
function finish {
4+
echo -e "\nExiting..."
5+
kill $WEBPACK_PID
6+
kill $SERVER_PID
7+
}
8+
9+
webpack --watch --devtool inline-source-map &
10+
WEBPACK_PID=$!
11+
12+
# # Run a static server and run the example in it.
13+
static-server . &
14+
SERVER_PID=$!
15+
16+
# Open browser
17+
node -e "\
18+
var open = require('open'); open('http://localhost:9080/example'); \
19+
"
20+
21+
# Kill webpack on exit.
22+
trap finish EXIT
23+
24+
wait

script/test

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)