function fileSubstitutions()

in source/solution-helper/index.js [72:135]


function fileSubstitutions(event, tempDir) {
  return new Promise(function(resolve,reject){
    try{
      
      console.log(tempDir);
      
      //Copy files out of Layer
      fs.copySync('/opt', tempDir);

      //What files were moved
      walkDir(tempDir, function(filePath) {
        //const fileContents = fs.readFileSync(filePath, 'utf8');
        console.log(filePath);
      });
      
      //File Substitutions
      if (event.ResourceProperties.Substitutions) {
          
        //File Patterns
        var files = event.ResourceProperties.Substitutions.FilePattern.split(',');
        
        files.forEach(function(file,index) {
          files[index] = `${tempDir}/**/${file}`;
        });
        
        //Values to Replace
        var from = [];
        var to = [];

        Object.keys(event.ResourceProperties.Substitutions.Values).forEach(function(key) {
          var val = event.ResourceProperties.Substitutions.Values[key];
          from.push(new RegExp('\\${' + key + '}', 'g'));
          to.push(val);
        });
        
        var options = {
          files: files,
          from: from,
          to: to,
          countMatches: true,
        };
        
        console.log(options);
        
        //const results = await replace(options);

        replace(options)
        .then(function (results){
          console.log('Replacement results:', JSON.stringify(results));
          resolve(results);
        })
        .catch(function(err){
          console.log(err);
          reject(err);
        });
      } else {
        resolve();
      }
    } catch (err){
      console.log(err);
      reject(err);
    }
  });
}