Skip to content

Commit

Permalink
add example constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Raynos committed Nov 22, 2012
1 parent 1e492be commit 434bf05
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bin/browserify-server.js
Expand Up @@ -7,13 +7,15 @@ var argv = require("optimist").argv

, Bundle = require("..")
, Server = require("../server")
, Example = require("../example")

, help = argv.help || argv.h
, index = argv.index || argv.i
, bundle = argv.bundle || argv.b
, server = argv.server || argv.s
, output = argv.output || argv.o
, port = argv.port || argv.p
, example = argv.example || argv.e

if (help) {
filed(path.join(__dirname, "usage.txt")).pipe(process.stdout)
Expand All @@ -26,4 +28,6 @@ if (help) {
, "with env", process.env.NODE_ENV)
} else if (server) {
Server(server, port)
} else if (example) {
Example(example)
}
31 changes: 31 additions & 0 deletions example.js
@@ -0,0 +1,31 @@
var fs = require("fs")
, read = fs.createReadStream
, write = fs.createWriteStream
, join = require("path").join
, mkdirp = require("mkdirp")

, resources = join(__dirname, "resources")
, uris = [
"Makefile"
, "index.js"
, ".gitignore"
, "package.json"
, join("static", "index.html")
]

module.exports = Example

function Example(uri) {
var exampleDir = join(process.cwd(), "examples", uri)

mkdirp(join(exampleDir, "static"), function (err) {
if (err) {
throw err
}

uris.forEach(function (file) {
read(join(resources, file))
.pipe(write(join(exampleDir, file)))
})
})
}
1 change: 1 addition & 0 deletions resources/.gitignore
@@ -0,0 +1 @@
static/bundle.js
18 changes: 18 additions & 0 deletions resources/Makefile
@@ -0,0 +1,18 @@
build:
./node_modules/.bin/browserify-server \
--bundle=index.js -o ./static/bundle.js

server:
./node_modules/.bin/browserify-server \
--server=./static --port=8081

watch:
./node_modules/.bin/nodemon "make build" .

live-reload:
./node_modules/.bin/live-reload

all:
make server &
make live-reload &
make watch
Empty file added resources/index.js
Empty file.
17 changes: 17 additions & 0 deletions resources/package.json
@@ -0,0 +1,17 @@
{
"name": "{{example}}",
"version": "0.1.0",
"description": "{{example}}",
"author": "{{author}}",
"main": "index",
"dependencies": {
},
"devDependencies": {
"browserify-server": "2.1.0",
"nodemon": "0.6.23",
"live-reload": "0.2.0"
},
"scripts": {
"build": "make all"
}
}
11 changes: 11 additions & 0 deletions resources/static/index.html
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>{{Title}}</title>
<meta charset="utf-8">
</head>
<body>
<script src="bundle.js"></script>
<script src="http://localhost:9090"></script>
</body>
</html>

0 comments on commit 434bf05

Please sign in to comment.