serve through npm, dev and gh-pages; closes #106

This commit is contained in:
Radek Stepan 2016-01-26 12:17:40 +01:00
parent d4653f8d39
commit e9f611652f
5 changed files with 135 additions and 38 deletions

View File

@ -5,12 +5,15 @@ BROWSERIFY = ./node_modules/.bin/browserify
UGLIFY = ./node_modules/.bin/uglifyjs UGLIFY = ./node_modules/.bin/uglifyjs
CLEANCSS = ./node_modules/.bin/cleancss CLEANCSS = ./node_modules/.bin/cleancss
MOCHA = ./node_modules/.bin/mocha MOCHA = ./node_modules/.bin/mocha
SERVER = ./node_modules/.bin/superstatic BIN = ./bin/burnchart.js
MOCHA-OPTS = --compilers js:babel-register --ui exports --timeout 5000 --bail MOCHA-OPTS = --compilers js:babel-register --ui exports --timeout 5000 --bail
serve: start:
${SERVER} --port 8080 ${BIN}
start-dev:
${BIN} --dev
watch-js: build-js watch-js: build-js
${WATCHIFY} -e -s burnchart ./src/js/index.jsx -t babelify -o public/js/bundle.js -d -v ${WATCHIFY} -e -s burnchart ./src/js/index.jsx -t babelify -o public/js/bundle.js -d -v

View File

@ -1,21 +1,33 @@
#[burnchart v3](http://radekstepan.com/burnchart) #[burnchart](http://radekstepan.com/burnchart)
A [React](http://facebook.github.io/react/) app utilizing a [Flux](http://facebook.github.io/flux/) architecture.
- EventEmitter listeners can use RegExp paths thus allowing the use of namespaces
- routing resets the whole UI between page changes and so Components are easier to reason about (`componentDidMount`)
##Quickstart ##Quickstart
```bash
$ npm install burnchart -g
$ burnchart --port 8080
# burnchart/3.0.0 started on port 8080
```
##Development
To run your local version of the app, install all the NPM dependencies, watch the source files in one window, and start the static file server in the other in `--dev` mode.
```bash ```bash
$ nvm use $ nvm use
$ npm install $ npm install
$ make watch $ make watch
$ npm start $ make start --dev
# Server started on port 8080 # burnchart/3.0.0 (dev) started on port 8080
``` ```
##Changelog ###GitHub Pages
###v3.0.0 To serve the app from GitHub Pages that are in sync with master branch, add these two lines to `.git/config`, in the `[remote "origin"]` section:
- switch to React & Flux architecture
```
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:user/repo.git
push = +refs/heads/master:refs/heads/gh-pages
push = +refs/heads/master:refs/heads/master
```

64
bin/burnchart.js Executable file
View File

@ -0,0 +1,64 @@
#!/usr/bin/env node
var Args = require('argparse').ArgumentParser,
clrs = require('colors/safe'),
stat = require('node-static'),
path = require('path'),
http = require('http'),
exec = require('child_process').exec,
pakg = require('../package.json'),
fs = require('fs');
var parser = new Args({
version: pakg.version
});
parser.addArgument(
[ '-p', '--port' ],
{
'help': 'Specify port number to start app on',
'defaultValue': 8080,
'type': 'int'
}
);
parser.addArgument(
[ '-d', '--dev' ],
{
'help': 'Development mode, unminified builds are served',
'nargs': 0
}
);
var args = parser.parseArgs();
var opts = {
'serverInfo': 'burnchart/' + pakg.version
};
var dir = path.resolve(__dirname, '../');
var pub = new stat.Server(dir, opts);
// Be ready to serve unminified builds.
var index = fs.readFileSync(dir + '/index.html', 'utf8');
index = index.replace(/bundle\.min/gm, 'bundle');
var server = http.createServer(function(req, res) {
req.addListener('end', function() {
// Serve a custom index file in dev mode.
if (args.dev && req.url == '/') {
res.writeHead(200, {
'Content-Length': index.length,
'Content-Type': 'text/html'
});
res.end(index);
} else {
pub.serve(req, res);
}
}).resume();
}).listen(args.port);
server.on('listening', function() {
var addr = server.address();
var dev = args.dev ? ' (' + clrs.bold('dev') + ')' : '';
console.log('burnchart/' + pakg.version + dev + ' started on port ' + addr.port);
});

11
index.html Normal file
View File

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link href="public/css/bundle.min.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="app" />
<script type="text/javascript" src="public/js/bundle.min.js"></script>
</body>
</html>

View File

@ -1,29 +1,20 @@
{ {
"name": "burnchart", "name": "burnchart",
"version": "3.0.0-alpha", "version": "3.0.0-alpha",
"bin": {
"burnchart": "./bin/burnchart.js"
},
"scripts": {
"start": "make start",
"test": "make test"
},
"dependencies": { "dependencies": {
"async": "^1.5.2", "argparse": "^1.0.4",
"classnames": "^2.2.3", "colors": "^1.1.2",
"d3": "^3.5.12", "node-static": "^0.7.7"
"d3-tip": "^0.6.7",
"deep-diff": "^0.3.3",
"firebase": "^2.3.2",
"lesshat": "^3.0.2",
"lodash": "^3.10.1",
"lscache": "^1.0.5",
"marked": "^0.3.5",
"moment": "^2.11.1",
"normalize.less": "^1.0.0",
"object-assign": "^4.0.1",
"object-path": "^0.9.2",
"react": "^0.14.6",
"react-addons-css-transition-group": "^0.14.6",
"react-mini-router": "^2.0.0",
"semver": "^5.1.0",
"sortedindex-compare": "0.0.1",
"superagent": "^1.6.1"
}, },
"devDependencies": { "devDependencies": {
"async": "^1.5.2",
"babel": "^6.3.26", "babel": "^6.3.26",
"babel-preset-es2015": "^6.3.13", "babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13", "babel-preset-react": "^6.3.13",
@ -31,12 +22,30 @@
"babelify": "^7.2.0", "babelify": "^7.2.0",
"browserify": "^13.0.0", "browserify": "^13.0.0",
"chai": "^3.4.1", "chai": "^3.4.1",
"classnames": "^2.2.3",
"clean-css": "^3.4.9", "clean-css": "^3.4.9",
"coffeeify": "^2.0.1", "coffeeify": "^2.0.1",
"d3": "^3.5.12",
"d3-tip": "^0.6.7",
"deep-diff": "^0.3.3",
"firebase": "^2.3.2",
"less": "^2.5.3", "less": "^2.5.3",
"lesshat": "^3.0.2",
"lodash": "^3.10.1",
"lscache": "^1.0.5",
"marked": "^0.3.5",
"mocha": "^2.3.4", "mocha": "^2.3.4",
"moment": "^2.11.1",
"normalize.less": "^1.0.0",
"object-assign": "^4.0.1",
"object-path": "^0.9.2",
"proxyquire": "^1.7.3", "proxyquire": "^1.7.3",
"superstatic": "^4.0.1", "react": "^0.14.6",
"react-addons-css-transition-group": "^0.14.6",
"react-mini-router": "^2.0.0",
"semver": "^5.1.0",
"sortedindex-compare": "0.0.1",
"superagent": "^1.6.1",
"uglify-js": "^2.6.1", "uglify-js": "^2.6.1",
"watch": "^0.17.1", "watch": "^0.17.1",
"watch-less": "0.0.4", "watch-less": "0.0.4",
@ -45,7 +54,5 @@
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git://github.com/radekstepan/burnchart.git" "url": "git://github.com/radekstepan/burnchart.git"
}, }
"private": true,
"license": "LicenseRef-LICENSE"
} }