Skip to content
Permalink
Browse files

feat(server): add quick server startup with spawn server and use node…

…mon for dev build
  • Loading branch information
jyounce committed Jul 28, 2015
1 parent 19ce257 commit cd289bf9146e90921162dcf0364da1695b9c5465
@@ -14,6 +14,7 @@ module.exports = (rbDir, options) ->
config = require("#{config.req.config}/config-rb") config, rbDir
config = require("#{config.req.config}/config-app") config, options
config = require("#{config.req.config}/config-ports") config, options
config = require("#{config.req.config}/config-server") config
config = require("#{config.req.config}/config-file-names") config
config = require("#{config.req.config}/config-minify") config, options
config = require("#{config.req.config}/config-dist-and-src") config, options
@@ -18,8 +18,8 @@ module.exports = (config, options) ->
views: 'views'

file =
appServer: 'routes' # app server dist entry file
rbServer: 'server' # rb server dist bootstrap file
appServer: 'routes.js' # app server dist entry file
rbServer: 'server.js' # rb server dist bootstrap file

# dirs
# ====
@@ -140,6 +140,10 @@ module.exports = (config, options) ->
removeServerDir() # server dir is server.scripts.dir
addToServerAppDist() # add file and path
config.dist.rb.server.scripts.file = file.rbServer # rb server dist bootstrap file
config.dist.rb.server.scripts.path = path.join(
config.dist.rb.server.scripts.dir
config.dist.rb.server.scripts.file
)

# final touch-ups
# ===============
@@ -0,0 +1,31 @@
module.exports = (config) ->
log = require "#{config.req.helpers}/log"
test = require("#{config.req.helpers}/test")()

# init server
# ===========
server = {}

# messages
# ========
server.msg =
start: "Server started on #{config.ports.server}"
noScripts: 'No application server scripts to load.'

# add server to config
# ====================
config.server = server

# logs
# ====
# log.json server, 'server ='

# tests
# =====
test.log 'true', config.server, 'add server to config'

# return
# ======
config


@@ -20,7 +20,7 @@ module.exports = (gulp, config) ->
gulp.task config.rb.tasks.dev, ["#{config.rb.prefix.task}common"], (cb) ->
gulpSequence(
"#{config.rb.prefix.task}build-spa"
"#{config.rb.prefix.task}start-server"
"#{config.rb.prefix.task}start-server:dev"
"#{config.rb.prefix.task}browser-sync"
"#{config.rb.prefix.task}watch"
cb
@@ -72,6 +72,7 @@ module.exports = (gulp, config) ->
# server
# ======
require("#{config.req.tasks}/server/start-server") gulp, config # start-server
require("#{config.req.tasks}/server/spawn-server") gulp, config # spawn-server
require("#{config.req.tasks}/server/nodemon") gulp, config, bs # nodemon

# test
@@ -11,7 +11,7 @@ appFilePath = path.join appPath, appFile # app server dist entry script

app.use express.static client
app.listen port, ->
console.log "Server Started on #{config.ports.server}"
console.log config.server.msg.start

app.get '/', (req, res) ->
res.sendFile spa, root:client
@@ -30,6 +30,6 @@ catch e
if e.code and
e.code.toLowerCase() is 'module_not_found' and
e.message.indexOf(appFilePath) isnt -1
console.log 'no app server scripts to load'
console.log config.server.msg.noScripts
else
console.log e # log e if there is an actual error
@@ -5,11 +5,8 @@ module.exports = (gulp, config, browserSync) ->

# globals
# =======
rbServerFile = path.join(
config.dist.rb.server.scripts.dir,
config.dist.rb.server.scripts.file
)
watchDir = config.dist.app.server.scripts.dir
rbServerFile = config.dist.rb.server.scripts.path
watchDir = config.dist.app.server.scripts.dir
ignoreDirs = [
config.node_modules.rb.dist.dir
config.node_modules.app.dist.dir
@@ -0,0 +1,15 @@
module.exports = (gulp, config) ->
q = require 'q'
spawn = require('child_process').spawn
rbServerFile = config.dist.rb.server.scripts.path

# register task
# =============
gulp.task "#{config.rb.prefix.task}spawn-server", ->
defer = q.defer()
server = spawn 'node', [ rbServerFile ]
server.stdout.on 'data', (data) ->
msg = data.toString().trim()
console.log msg.yellow
defer.resolve() if msg.indexOf(config.server.msg.start) isnt -1
defer.promise
@@ -1,9 +1,11 @@
module.exports = (gulp, config) ->
# task deps
# =========
taskDeps = ["#{config.rb.prefix.task}nodemon"]
taskDeps = ["#{config.rb.prefix.task}spawn-server"]
taskDepsDev = ["#{config.rb.prefix.task}nodemon"]

# register task
# =============
gulp.task "#{config.rb.prefix.task}start-server", taskDeps
gulp.task "#{config.rb.prefix.task}start-server:dev", taskDepsDev

0 comments on commit cd289bf

Please sign in to comment.
You can’t perform that action at this time.