<commit_before>var path = require("path")
var exec = require("child_process").exec
var buildCmd = "python kango/kango.py build ."
var webpack = require("webpack")
var ExtractTextPlugin = require("extract-text-webpack-plugin")
var _ = require('lodash')
require('colors')

var compiler = webpack({
    entry: {
        main: "./app/app.js",
    },
    target: "web",
    cache: true,
    stats: {
        colors: true,
        reasons: false,
        timings: true,
    },
    devtool: "source-map",
    output: {
        path: path.join(__dirname, "src/common"),
        filename: "[name].js",
        chunkFilename: "[name].js",
        sourceMapFilename: "[name].js.map",
    },
    plugins: [
        new ExtractTextPlugin("styles.css")
    ],
    module: {
        loaders: [
            {
                test: /\.(less|css)$/,
                loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader"),
            },
            {
                include: /\.json$/, loaders: ["json-loader"]
            },
            {
                include: /\.js$/,
                exclude: /node_modules/,
                loader: "babel",
                query: {
                    "plugins": [
                        "typecheck",
                        "transform-class-properties",
                        "transform-decorators-legacy",
                        "transform-object-assign",
                        "transform-object-rest-spread",
                        "transform-export-extensions",
                        "add-module-exports"
                    ],
                    "presets": [
                        "es2015",
                        "react",
                        "stage-0"
                    ],
                },
            },
            {
                test: /\.(png|ttf|eot|svg|woff(2)?)(\?=[a-z0-9]+)?$/,
                loader: "url?limit=1000",
            }
        ],
    },
    resolve: {
        modulesDirectories: [
            "app",
            "node_modules"
        ],
        extensions: ["", ".json", ".js"],
    },
})

let compilationNumber = 0

//noinspection JSUnresolvedFunction
compiler.plugin("done", function (a) {
    const comp = a.compilation
    const modulesWithErrors = _.filter(comp.modules, module => module.error)
    const anyErrors = modulesWithErrors.length
    const compilationTime = (a.endTime - a.startTime) / 1000

    if (anyErrors) {
        console.log("We have errors in some of the modules:")

        modulesWithErrors.forEach((module, index) => {
            console.log(`#${module.id} Module at ${module.resource.blue} has error\n`, module.error.message.red)
        })
    } else {
        console.log(`#${++compilationNumber} Successful webpack compilation in ${compilationTime.toFixed(1)}s`.green)
    }
})

compiler.watch({}, function (err, stats) {
    if (!err) {
        exec(buildCmd, function (error, stdout, stderr) {
            if (error) {
                console.error(err)
            }

            console.log(stdout)
        })
    } else {
        console.error(err)
    }
})<commit_msg>Exit process if not watch<commit_after>var path = require("path")
var exec = require("child_process").exec
var buildCmd = "python kango/kango.py build ."
var webpack = require("webpack")
var ExtractTextPlugin = require("extract-text-webpack-plugin")
var _ = require('lodash')
require('colors')

var compiler = webpack({
    entry: {
        main: "./app/app.js",
    },
    target: "web",
    cache: true,
    stats: {
        colors: true,
        reasons: false,
        timings: true,
    },
    devtool: "source-map",
    output: {
        path: path.join(__dirname, "src/common"),
        filename: "[name].js",
        chunkFilename: "[name].js",
        sourceMapFilename: "[name].js.map",
    },
    plugins: [
        new ExtractTextPlugin("styles.css")
    ],
    module: {
        loaders: [
            {
                test: /\.(less|css)$/,
                loader: ExtractTextPlugin.extract("style-loader", "css-loader!less-loader"),
            },
            {
                include: /\.json$/, loaders: ["json-loader"]
            },
            {
                include: /\.js$/,
                exclude: /node_modules/,
                loader: "babel",
                query: {
                    "plugins": [
                        "typecheck",
                        "transform-class-properties",
                        "transform-decorators-legacy",
                        "transform-object-assign",
                        "transform-object-rest-spread",
                        "transform-export-extensions",
                        "add-module-exports"
                    ],
                    "presets": [
                        "es2015",
                        "react",
                        "stage-0"
                    ],
                },
            },
            {
                test: /\.(png|ttf|eot|svg|woff(2)?)(\?=[a-z0-9]+)?$/,
                loader: "url?limit=1000",
            }
        ],
    },
    resolve: {
        modulesDirectories: [
            "app",
            "node_modules"
        ],
        extensions: ["", ".json", ".js"],
    },
})

let compilationNumber = 0

//noinspection JSUnresolvedFunction
compiler.plugin("done", function (a) {
    const comp = a.compilation
    const modulesWithErrors = _.filter(comp.modules, module => module.error)
    const anyErrors = modulesWithErrors.length
    const compilationTime = (a.endTime - a.startTime) / 1000

    if (anyErrors) {
        console.log("We have errors in some of the modules:")

        modulesWithErrors.forEach((module, index) => {
            console.log(`#${module.id} Module at ${module.resource.blue} has error\n`, module.error.message.red)
        })
    } else {
        console.log(`#${++compilationNumber} Successful webpack compilation in ${compilationTime.toFixed(1)}s`.green)
    }
})

compiler.watch({}, function (err, stats) {
    if (!err) {
        exec(buildCmd, function (error, stdout, stderr) {
            if (error) {
                console.error(err)
            }

            console.log(stdout)

            if (!process.argv.includes('--watch')) {
                process.exit(0)
            }
        })
    } else {
        console.error(err)
    }
})
{'fraction_non_alphanumeric': 0.14348925410872312, 'fraction_numerical': 0.005847029077117573, 'mean_word_length': 1.4645638629283488, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5728652', 'n_tokens_mistral': 1810, 'n_tokens_neox': 1707, 'n_words': 327}