import path from 'path';
import fs from 'fs';
import SubCommand from '../models/sub-command';
import browserSync from 'browser-sync';

var resolve = require('resolve').sync;
var basedir = process.cwd();

var metalpressPath = resolve('metalpress', { basedir });
var module = require(metalpressPath);
if (module.default) {
  var metalpress = module.default;
} else {
  var metalpress = module;
}

export default class Serve extends SubCommand {
  constructor() {
    super();
    this.serverStarted = false;
    this.baseDir = './dist';
    this.config = this.settings.settings || {};
  }

  printUserHelp() {
    this.ui.write('Serves a metalpress project on a browser-sync server (default: http://localhost:3000)\n');
  }

  build(cb) {
    metalpress(this.config, cb);
  }

  run() {
    const settings = {
      ghostMode: {
        clicks: true,
        scroll: true,
        links: true,
        forms: true
      },
      server: {
        baseDir: this.baseDir
      }
    };

    browserSync.watch('src/**', () => build(browserSync.reload));
    browserSync.watch('templates/_layouts/*.liquid', () => build(browserSync.reload));
    browserSync.watch('templates/_includes/**/*.liquid', () => build(browserSync.reload));

    browserSync.init(settings);
  }
}
@@ -724,18 +724,16 @@
   build(
-cb
 ) %7B%0A    
@@ -743,16 +743,23 @@
 alpress(
+%0A      
 this.con
@@ -767,24 +767,77 @@
 ig, 
-cb);%0A  %7D%0A%0A  run(
+%0A      this.watch.bind(this, this.baseDir)%0A    );%0A  %7D%0A%0A  watch(server
 ) %7B%0A
@@ -988,49 +988,8 @@
 rver
-: %7B%0A        baseDir: this.baseDir%0A      %7D
 %0A   
@@ -1273,10 +1273,43 @@
 gs);%0A  %7D
+%0A%0A  run() %7B%0A    this.build();%0A  %7D
 %0A%7D

fix serve command