Here's my gulpfile.coffee:
# Dependencies
gulp           = require "gulp"
browserSync    = require "browser-sync"
minimist       = require "minimist"
# Configuration
available_arguments =
  # Default values
  default:
    path: ''
    mode: false
  # What arguments to treat as strings
  string: [
    'path'
  ]
# Preparation
args = minimist process.argv.slice(2), available_arguments
# Start BrowserSync
gulp.task "browser-sync", ->
  browserSync
    open:      args.path?
    startPath: args.path
    ghostMode: args.ghost
    server:
      baseDir: "./"
# Use default task to launch BrowserSync and watch JS files
gulp.task "default", ["browser-sync"], ->
  # add browserSync.reload to the tasks array to make
  # all browsers reload after tasks are complete.
  gulp.watch "*.html", browserSync.reload
It uses BrowserSync to watch for some files and reload the browser.
It is currently designed to work with static files.
I have started using a static site generator, Middleman. Middleman runs a development webserver that renders a generated web page from sources.
I'm capable of modifying the above Gulpfile so that BrowserSync proxies to Middleman rather than serves static files.
What i struggle to figure out is how to have Gulp start Middleman in background.
Requirements:
- Middleman should be started in background before gulp.watch(the last line).
- Middleman should run in parallel with Gulp. I. e. Gulp should not wait for Middleman to finish.
- Middleman should print to the terminal (both normal messages and errors).
- Middleman should be terminated when gulp watchterminates.
- Gulp should be terminated when Middleman terminates, so that i can restart Middleman after fixing the problem that caused it to terminate.
The command to run Middleman is bundle exec middleman server.
