"use strict";

const path = require('path');
const webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const chalk = require('chalk');
const del = require('del');

let getWebpackConfig = require('./get-webpack-config');
module.exports = function (options, callback) {
    options || (options = {});

    options.cwd = options.cwd ? options.cwd : process.cwd();
    options.tmpCacheDir = '.tmpCache';

    function printLog (msg) {
        options.quiet || (console.log('[Guido] ' + msg));
    }

    printLog(chalk.blue('Load Config...'));
    let webpackConfig = getWebpackConfig(options);

    // Run compiler.
    const compiler = webpack(webpackConfig);

    function doneHandler(err, stats) {
        del(path.join(options.cwd, options.tmpCacheDir));

        if (callback) {
            callback(err, stats);
        }
    }

    if (options.devServer) {
        printLog(chalk.blue('Start Dev Server'));
        const server = new WebpackDevServer(compiler, webpackConfig.devServer);
        server.listen(webpackConfig.devServer.port, webpackConfig.devServer.host, function () {
            printLog(chalk.blue('Starting server on http://' + webpackConfig.devServer.host + ':' + webpackConfig.devServer.port));
        });
    } else {
        let msg = options.watch ? 'Start Watch' : 'Start Compiler';
        printLog(chalk.blue(msg));
        compiler.run(doneHandler);
    }
};

@@ -34,24 +34,25 @@
 re('path');%0A
+%0A
 const webpac
@@ -81,17 +81,17 @@
 ;%0Aconst 
-W
+w
 ebpackDe
@@ -127,24 +127,25 @@
 v-server');%0A
+%0A
 const chalk 
@@ -283,16 +283,21 @@
 (options
+ = %7B%7D
 , callba
@@ -306,40 +306,8 @@
 ) %7B%0A
-    options %7C%7C (options = %7B%7D);%0A%0A
     
@@ -393,19 +393,46 @@
 r = 
-'.tmpC
+path.join(options.cwd, '.guido-c
 ache'
+)
 ;%0A%0A 
@@ -617,24 +617,88 @@
 (options);%0A%0A
+    // %E5%9B%9E%E8%B0%83%E5%87%BA%E5%8E%BB%E7%94%A8%0A    let webpackStateConfig = webpackConfig.stats;%0A%0A
     // Run c
@@ -748,24 +748,52 @@
 ckConfig);%0A%0A
+    let lastBuildStateHash;%0A
     function
@@ -831,59 +831,335 @@
     
-del(path.join(options.cwd, options.tmpCacheDir));%0A%0A
+// wait fix bug %22Multiple compilation triggered in webpack2 watch mode%22%0A        // https://github.com/webpack/webpack.js.org/issues/1096%0A        // https://runkit.com/kidney/multiple-compilation-triggered-in-webpack2-watch-mode%0A        if (lastBuildStateHash !== stats.hash) %7B%0A            lastBuildStateHash = stats.hash;%0A%0A    
     
@@ -1190,16 +1190,20 @@
         
+   
+ 
 callback
@@ -1217,31 +1217,243 @@
 tats
-);%0A        %7D%0A    %7D%0A%0A   
+, webpackStateConfig);%0A            %7D%0A        %7D%0A    %7D%0A    del(options.tmpCacheDir);%0A%0A    if (options.watch) %7B%0A        printLog(chalk.blue('Start Watch'));%0A        compiler.watch(webpackConfig.watchOptions %7C%7C %7B%7D, doneHandler);%0A    %7D else
  if 
@@ -1551,17 +1551,17 @@
 r = new 
-W
+w
 ebpackDe
@@ -1869,99 +1869,44 @@
     
-let msg = options.watch ? 'Start Watch' : 'Start Compiler';%0A        printLog(chalk.blue(msg
+printLog(chalk.blue('Start Compiler'
 ));%0A

improve watch mode