<commit_before>'use strict'

chokidar = require 'chokidar'
fs = require 'fs'
utils = require 'src/utils'

module.exports = (platform, options, onBuild) ->
    changedFiles = []
    isWaiting = false
    isPending = false
    shouldBuildAgain = false

    ignored = '^(?:build|index\.js|local\.json|node_modules)|\.git'
    if options.out
        ignored += "|#{options.out}"

    update = ->
        isWaiting = false
        if isPending
            shouldBuildAgain = true
            return

        isPending = true
        buildOptions = utils.mergeAll {}, options,
            changedFiles: changedFiles
            buildBundleOnly: true
        changedFiles = []
        onBuild buildOptions, ->
            isPending = false

            if shouldBuildAgain
                shouldBuildAgain = false
                update()

    chokidarOptions =
        ignored: new RegExp ignored
        ignoreInitial: true
    chokidar.watch('.', chokidarOptions).on 'all', (event, path) ->
        if event is 'change'
            changedFiles.push fs.realpathSync path
        unless isWaiting<commit_msg>watch mode now works only on modified files<commit_after>'use strict'

chokidar = require 'chokidar'
fs = require 'fs'
utils = require 'src/utils'
moduleCache = require 'lib/module-cache'

module.exports = (platform, options, onBuild) ->
    changedFiles = []
    isWaiting = false
    isPending = false
    shouldBuildAgain = false
    files = Object.create null

    ignored = '^(?:build|index\.js|local\.json|node_modules)|\.git'
    if options.out
        ignored += "|#{options.out}"

    update = ->
        isWaiting = false
        if isPending
            shouldBuildAgain = true
            return

        isPending = true
        buildOptions = utils.mergeAll {}, options,
            changedFiles: changedFiles
            buildBundleOnly: true
        changedFiles = []
        onBuild buildOptions, ->
            isPending = false

            if shouldBuildAgain
                shouldBuildAgain = false
                update()

    chokidarOptions =
        ignored: new RegExp ignored
        ignoreInitial: true
    chokidar.watch('.', chokidarOptions).on 'all', (event, path) ->
        # do nothing when file has not been modified
        file = moduleCache.getFile path
        if files[path] is file
            return
        files[path] = file

        # add to changed files
        if event is 'change'
            changedFiles.push fs.realpathSync path

        # request build
        unless isWaiting
{'fraction_non_alphanumeric': 0.08875739644970414, 'fraction_numerical': 0.0, 'mean_word_length': 1.9800235017626322, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1865791', 'n_tokens_mistral': 697, 'n_tokens_neox': 684, 'n_words': 188}