Skip to content

Commit 0c3ba8f

Browse files
added node site
1 parent 9a3d21b commit 0c3ba8f

File tree

5 files changed

+89
-1
lines changed

5 files changed

+89
-1
lines changed

cakefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
console.log 'yes!'
1+
require 'coffee-script/register'
2+
module.exports = require './node/cakefile'

node/cakefile.coffee

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
require 'cake-gulp'
2+
path = require 'path'
3+
4+
browserify = require 'browserify'
5+
watchify = require 'watchify'
6+
7+
cjsx = require 'coffee-reactify'
8+
uglify = require 'uglifyify'
9+
10+
jquery = "#{path.dirname require.resolve 'jquery/dist/jquery'}"
11+
semantic = "#{path.dirname require.resolve 'semantic-ui/dist/semantic'}"
12+
13+
option '-w', '--watch', 'Watchify files.'
14+
15+
task 'build:clean', 'Delete all auto-generated files.', (options, callback) ->
16+
del ["#{__dirname}/dist/**/*"], (error, files) ->
17+
if error
18+
throw error
19+
log "[#{green 'Deleted'}]\n#{files.map(fancypath).join '\n'}"
20+
callback()
21+
22+
task 'build:files', 'Copies static files.', ['build:clean'], (options, callback) ->
23+
files = [
24+
"#{__dirname}/src/**/*.html"
25+
"#{__dirname}/src/**/*.png"
26+
"#{__dirname}/src/**/*.min.*"
27+
"#{jquery}/**/jquery.min.*"
28+
"#{semantic}/**/semantic.min.*"
29+
"#{semantic}/**/icons.*"
30+
]
31+
# if options.watch
32+
# watch files, 'build:files'
33+
src files
34+
.pipe dest "#{__dirname}/dist"
35+
36+
task 'build', 'Browserify all the things!', ['build:files'], (options, callback) ->
37+
config =
38+
entry: './src/bundle.cjsx'
39+
path: "#{__dirname}/dist"
40+
debug: options.watch
41+
if options.watch
42+
for own key of watchify.args
43+
unless key of options
44+
config[key] = watchify.args[key]
45+
for own key of options
46+
config[key] = options[key]
47+
bundler = if options.watch then watchify browserify config else browserify config
48+
49+
bundler.transform [cjsx, extension: 'cjsx']
50+
unless options.watch
51+
bundler.transform [uglify, global: yes]
52+
bundler.require require.resolve(config.entry), entry: yes
53+
54+
rebuild = (files) ->
55+
if Array.isArray files
56+
files = files
57+
.map fancypath
58+
.join '\n'
59+
log "[#{green if options.watch then 'Watchify!' else 'Browserify!'}]\n#{files or '...'}"
60+
bundler
61+
.bundle()
62+
.on 'error', log.bind 'Browserify Error: '
63+
.pipe source config.entry
64+
.pipe rename 'bundle.min.js'
65+
.pipe dest config.path
66+
67+
bundler
68+
.on 'update', rebuild
69+
.on 'log', log
70+
71+
rebuild()

node/lib/server.coffee

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
koala = require 'koala'
2+
send = require 'koa-send'
3+
4+
app = module.exports = new koala
5+
app.use (next) ->
6+
if @request.is 'json'
7+
@data = yield @request.json()
8+
yield next
9+
else
10+
if /\/[^\/\.]*$/.test @path
11+
yield send @, '/index.html', root: "#{__dirname}/../dist"
12+
else
13+
yield send @, @path, root: "#{__dirname}/../dist"
14+
15+
new (require './monitoring') app

node/src/bundle.cjsx

Whitespace-only changes.

node/src/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{\rtf1}

0 commit comments

Comments
 (0)