Guest User

Untitled

a guest
Aug 14th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. const fs = require('fs');
  2.  
  3. // Change this line to your template
  4. const templateFile = './example-template.json';
  5. const cfn = JSON.parse(fs.readFileSync(templateFile));
  6. const resources = cfn.Resources;
  7. const keys = Object.keys(resources);
  8.  
  9. let obj = {};
  10.  
  11. for (resource in resources) {
  12. const type = resources[resource]['Type'].split('::')[2];
  13.  
  14. if (obj.hasOwnProperty(type)) {
  15. obj[type].push(resource);
  16. } else {
  17. obj[type] = [resource];
  18. }
  19. }
  20.  
  21. const outputFile = './report.txt';
  22.  
  23. fs.writeFileSync(outputFile, '');
  24. const print = data => {
  25. fs.appendFileSync(outputFile, `${data}\n`);
  26. console.log(data);
  27. };
  28.  
  29. for (item in obj) {
  30. print(`${item}: ${obj[item].length}`);
  31. obj[item].forEach(i => {
  32. print(`\t${i}`);
  33. });
  34. }
Add Comment
Please, Sign In to add comment