<commit_before>/**
 * @file
 * @author zdying
 */

var configUtil = require('../webpackConfig');

var webpack = require('webpack');
var colors = require('colors');
var path = require('path');
var fs = require('fs');

var logger = log.namespace('Compiler');
var type = require('../helpers/type');

var configWatchers = {};

function Compiler(projectName, root, env){
    this.isCompiling = false;
    this.projectName = projectName;
    this.root = root || path.resolve('./' + projectName);
    this.webpackCompiler = null;
    this.watching = null;
    this.env = env;
    this.configFileChanged = false;

    this.watchConfigFile(this.onConfigFileChange.bind(this));

    logger.debug('create new compiler', projectName.bold.green, 'env', env.bold.green);
}

Compiler.prototype = {
    constructor: Compiler,

    _compile: function(isDLL, isWatch, option, callback){
        var cbk = function(err, state){
            callback && callback(err, state);
        };

        var compiler = this.webpackCompiler = this._getWebpackCompiler(isDLL, option);

        if(this.watching && this.watching.close){
            this.watching.close(function(){
                logger.debug('watching closed.');
            });
        }

        if(!compiler){
            var err = new Error();
            err.code = "COMPILER_NULL";
            return cbk(err, null)
        }

        if(isWatch){
            logger.info('watching ...');
            return this.watching = compiler.watch({}, cbk);
        }else{
            logger.info('run ...');
            return compiler.run(cbk);
        }
    },

    compile: function(option, callback){
        log.debug('compiler.compile() - ', this.env);

        if(arguments.length === 1){
            callback = option;
            option = {
                watch: true
            };
        }
        var isWatch = option.watch;

        if(this.webpackCompiler === null || this.configFileChanged){

            if(this.configFileChanged){<commit_msg>fixbug<commit_after>/**
 * @file
 * @author zdying
 */

var configUtil = require('../webpackConfig');

var webpack = require('webpack');
var colors = require('colors');
var path = require('path');
var fs = require('fs');

var logger = log.namespace('Compiler');
var type = require('../helpers/type');

var configWatchers = {};

function Compiler(projectName, root, env){
    this.isCompiling = false;
    this.projectName = projectName;
    this.root = root || path.resolve('./' + projectName);
    this.webpackCompiler = null;
    this.watching = null;
    this.env = env;
    this.configFileChanged = false;

    // if(env === 'loc'){
    //     this.watchConfigFile(this.onConfigFileChange.bind(this));
    // }

    logger.debug('create new compiler', projectName.bold.green, 'env', env.bold.green);
}

Compiler.prototype = {
    constructor: Compiler,

    _compile: function(isDLL, isWatch, option, callback){
        var cbk = function(err, state){
            callback && callback(err, state);
        };

        if(this.watching && this.watching.close){
            this.watching.close(function(){
                logger.debug('watching closed.');
            });
        }

        var compiler = this.webpackCompiler = this._getWebpackCompiler(isDLL, option);

        if(!compiler){
            var err = new Error();
            err.code = "COMPILER_NULL";
            return cbk(err, null)
        }

        if(isWatch){
            logger.info('watching ...');
            return this.watching = compiler.watch({}, cbk);
        }else{
            logger.info('run ...');
            return compiler.run(cbk);
        }
    },

    compile: function(option, callback){
        log.debug('compiler.compile() - ', this.env);

        if(arguments.length === 1){
            callback = option;
            option = {
                watch: true
            };
        }
        var isWatch = option.watch;

        if(this.webpackCompiler === null || this.configFileChanged){

            if(this.configFileChanged){
{'fraction_non_alphanumeric': 0.14732919254658386, 'fraction_numerical': 0.0004968944099378882, 'mean_word_length': 2.185126582278481, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5592305', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1122, 'n_words': 237}