<commit_before>'use strict'

each = require 'async-each'
sysPath = require 'path'
generate = require './generate'
helpers = require '../helpers'
logger = require 'loggy'

getPaths = (sourceFile, joinConfig) ->
  sourceFileJoinConfig = joinConfig[sourceFile.type + 's'] or {}
  Object.keys(sourceFileJoinConfig)
    .filter (key) ->
      key isnt 'pluginHelpers'
    .filter (generatedFilePath) ->
      if sourceFile.isHelper
        generatedFilePath in sourceFileJoinConfig.pluginHelpers
      else
        checker = sourceFileJoinConfig[generatedFilePath]
        checker sourceFile.path

getFiles = (fileList, config, joinConfig, startTime) ->
  map = {}

  fileList.files.forEach (file) ->
    return if not file.error? and not file.data?
    paths = getPaths file, joinConfig
    paths.forEach (path) ->
      map[path] ?= []
      map[path].push file
    unless paths.length
      if file.error
        logger.error formatError file
      if file.data and file.compilationTime >= startTime
        logger.warn "'#{file.path}' compiled, but not written. Check your #{file.type}.joinTo config."

  Object.keys(map).map (generatedFilePath) ->
    sourceFiles = map[generatedFilePath]
    fullPath = sysPath.join config.paths.public, generatedFilePath
    {sourceFiles, path: fullPath}

changedSince = (startTime) -> (generated) ->
  generated.sourceFiles.some (sourceFile) ->
    sourceFile.compilationTime >= startTime or sourceFile.removed

formatError = (sourceFile) ->
  helpers.formatError sourceFile.error, sourceFile.path<commit_msg>Suppress warning for env-specific files<commit_after>'use strict'

each = require 'async-each'
sysPath = require 'path'
generate = require './generate'
helpers = require '../helpers'
logger = require 'loggy'
{matcher} = require 'anysort'

getPaths = (sourceFile, joinConfig) ->
  sourceFileJoinConfig = joinConfig[sourceFile.type + 's'] or {}
  Object.keys(sourceFileJoinConfig)
    .filter (key) ->
      key isnt 'pluginHelpers'
    .filter (generatedFilePath) ->
      if sourceFile.isHelper
        generatedFilePath in sourceFileJoinConfig.pluginHelpers
      else
        checker = sourceFileJoinConfig[generatedFilePath]
        checker sourceFile.path

getFiles = (fileList, config, joinConfig, startTime) ->
  map = {}

  anyJoinTo = {}
  checkAnyJoinTo = (file) ->
    joinSpecs = anyJoinTo[file.type] ?=
      Object.keys(config.overrides).map (_) ->
        config.overrides[_].files
      .concat [config.files]
      .map (_) -> _?["#{file.type}s"]?.joinTo
      .filter (_) -> _

    if typeof joinSpecs is 'function'
      joinSpecs file.path
    else if joinSpecs.some((_) -> typeof _ is 'string')
      anyJoinTo[file.type] = -> true
    else if not joinSpecs.length
      anyJoinTo[file.type] = -> false
      false
    else
      anyJoinTo[file.type] = matcher joinSpecs.reduce (flat, aJoinTo) ->
        flat.concat Object.keys(aJoinTo).map (_) -> aJoinTo[_]
      , []
      anyJoinTo[file.type] file.path

  fileList.files.forEach (file) ->
    return if not file.error? and not file.data?
    paths = getPaths file, joinConfig
    paths.forEach (path) ->
      map[path] ?= []
      map[path].push file
    unless paths.length
      if file.error
        logger.error formatError file
      if file.data and file.compilationTime >= startTime
        unless checkAnyJoinTo file
          logger.warn "'#{file.path}' compiled, but not written. Check your #{file.type}s.joinTo config."

  Object.keys(map).map (generatedFilePath) ->
    sourceFiles = map[generatedFilePath]
    fullPath = sysPath.join config.paths.public, generatedFilePath
    {sourceFiles, path: fullPath}

changedSince = (startTime) -> (generated) ->
  generated.sourceFiles.some (sourceFile) ->
    sourceFile.compilationTime >= startTime or sourceFile.removed

formatError = (sourceFile) ->
  helpers.formatError sourceFile.error, sourceFile.path
{'fraction_non_alphanumeric': 0.1166323377960865, 'fraction_numerical': 0.0, 'mean_word_length': 3.2412663755458517, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, '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': '2728534', 'n_tokens_mistral': 1144, 'n_tokens_neox': 1153, 'n_words': 280}