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,EAEA,cAAc,UAAU,YAAc,SAAS,EAAQ,GACrD,EAAW,KAAK,KAAK,KAAK,WAAW,GAAI,GACzC,IAAI,EAAW,GAAG,aAAa,EAAU,CAAE,SAAU,SAerD,OAbA,KAAK,QAAQ,SAAS,SAAQ,SAAS,GACrC,IAAI,EAAc,EAAQ,YAEC,mBAAhB,IACT,EAAc,WACZ,IAAI,EAAO,MAAM,UAAU,MAAM,KAAK,WACtC,OAAO,EAAQ,YAAY,MAAM,KAAM,CAAC,GAAQ,OAAO,GACzD,GAGF,EAAW,EAAS,QAAQ,EAAQ,MAAO,EAC7C,IAEO,CACT,EAEA,cAAc,UAAU,UAAY,SAAS,EAAU,GAChD,GAAG,WAAW,KAAK,QAAQ,KAC9B,GAAG,WAAW,KAAK,QAAQ,IAG7B,GAAG,cAAc,EAAU,EAAU,CAAE,SAAU,QACnD,EAEA,cAAc,UAAU,YAAc,SAAS,EAAK,GAClD,OAAO,KAAK,KAAK,QAAQ,SAAQ,SAAS,GACpC,KAAK,OAAO,GAAM,OAAS,EAAI,aAC1B,KAAK,OAAO,EAEvB,GAAG,MAEH,KAAK,OAAO,EAAI,MAAQ,CACtB,KAAM,EAAI,KACV,SAAU,EAEd,EAEA,cAAc,UAAU,cAAgB,WACtC,OAAO,KAAK,KAAK,KAAK,WAAW,GAAI,KAAK,QAAQ,WACpD,EAEA,cAAc,UAAU,UAAY,WAClC,IAAI,EAAW,GAAG,aAAa,KAAK,gBAAiB,CAAE,SAAU,SACjE,OAAO,KAAK,MAAM,EACpB,EAEA,OAAO,QAAU","file":"/npm/broccoli-config-replace-2@1.1.2/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/broccoli-config-replace-2@1.1.2/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict';\n\nvar fs = require('fs-extra');\nvar path = require('path');\nvar Plugin = require('broccoli-plugin');\nvar hashStrings = require('broccoli-kitchen-sink-helpers').hashStrings;\nvar debug = require('debug')('broccoli-config-replace');\n\nfunction ConfigReplace(inputNode, configNode, options) {\n  options = options || {};\n\n  // this._super();\n  Plugin.call(this, [inputNode, configNode], {\n    annotation: options.annotation\n  });\n\n  this._persistentOutput = true;\n\n  this.options = options;\n  this._cache = {};\n}\n\nConfigReplace.prototype = Object.create(Plugin.prototype);\nConfigReplace.prototype.constructor = ConfigReplace;\n\nConfigReplace.prototype.build = function () {\n  var config = this.getConfig();\n\n  this.options.files.forEach(function(file) {\n    var key = this.deriveCacheKey(file);\n    var entry = this._cache[key.hash];\n    var contents, filePath;\n\n    debug('cache hit: %o, for: %s', !!entry, file);\n\n    if (entry) { return; }\n\n    filePath = file;\n    contents = this.processFile(config, filePath);\n    this.updateCache(key, contents);\n\n    filePath = path.join(this.outputPath, filePath);\n    this.writeFile(filePath, contents);\n  }, this);\n};\n\nConfigReplace.prototype.deriveCacheKey = function(file) {\n  var configStat = fs.statSync(this.getConfigPath());\n  var fileStat = fs.statSync(this.inputPaths[0] + '/' + file);\n\n  if (configStat.isDirectory()) {\n    throw new Error('Must provide a path for the config file, you supplied a directory');\n  }\n\n  var patterns = this.options.patterns.reduce(function(a, b) {\n    return a + b.match;\n  }, '');\n\n\n  return {\n    file: file,\n    hash: hashStrings([\n      file,\n      this.configPath,\n      patterns,\n      configStat.size,\n      configStat.mode,\n      configStat.mtime.getTime(),\n      fileStat.size,\n      fileStat.mode,\n      fileStat.mtime.getTime(),\n    ])\n  };\n};\n\nConfigReplace.prototype.processFile = function(config, filePath) {\n  filePath = path.join(this.inputPaths[0], filePath);\n  var contents = fs.readFileSync(filePath, { encoding: 'utf8' });\n\n  this.options.patterns.forEach(function(pattern) {\n    var replacement = pattern.replacement;\n\n    if (typeof replacement === 'function') {\n      replacement = function() {\n        var args = Array.prototype.slice.call(arguments);\n        return pattern.replacement.apply(null, [config].concat(args));\n      }\n    }\n\n    contents = contents.replace(pattern.match, replacement);\n  });\n\n  return contents;\n};\n\nConfigReplace.prototype.writeFile = function(destPath, contents) {\n  if (!fs.existsSync(path.dirname(destPath))) {\n    fs.mkdirpSync(path.dirname(destPath));\n  }\n\n  fs.writeFileSync(destPath, contents, { encoding: 'utf8' });\n};\n\nConfigReplace.prototype.updateCache = function(key, contents) {\n  Object.keys(this._cache).forEach(function(hash) {\n    if (this._cache[hash].file === key.file) {\n      delete this._cache[hash];\n    }\n  }, this);\n\n  this._cache[key.hash] = {\n    file: key.file,\n    contents: contents\n  };\n};\n\nConfigReplace.prototype.getConfigPath = function() {\n  return path.join(this.inputPaths[1], this.options.configPath);\n};\n\nConfigReplace.prototype.getConfig = function() {\n  var contents = fs.readFileSync(this.getConfigPath(), { encoding: 'utf8' });\n  return JSON.parse(contents);\n};\n\nmodule.exports = ConfigReplace;\n"]}