Advertisement
Guest User

Untitled

a guest
Feb 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. const fs = require('fs');
  2. const MDS_path = '/home/nikita/Загрузки/123/';
  3. const style2_path = '/home/nikita/work/epbs-default/EPBS-Portal/EpbsStatic/Static/public_html/css/style2.css';
  4.  
  5. const MDS_classes = [];
  6. const style2_classes = [];
  7.  
  8. function showFiles(path) {
  9. const files = fs.readdirSync(path);
  10. files.forEach(file => {
  11. const isDirectory = fs.statSync(`${path}${file}`).isDirectory();
  12. if (isDirectory) {
  13. showFiles(`${path}${file}/`)
  14. } else if (file.toLowerCase().indexOf('page') > -1 && (file.endsWith('jspx') || file.endsWith('xml'))) {
  15. addCssClasses(`${path}${file}`);
  16. }
  17. });
  18. }
  19.  
  20. function addCssClasses(path) {
  21. const htmlPage = fs.readFileSync(path, 'utf8');
  22. let index = 0;
  23. while (index > -1) {
  24. index = htmlPage.indexOf('class="', index + 7);
  25. if (index > -1) {
  26. const className = htmlPage.substring(index + 7, htmlPage.indexOf('"', index + 7));
  27. if (MDS_classes.indexOf(className) === -1) {
  28. MDS_classes.push(className);
  29. }
  30. }
  31. }
  32. index = 0;
  33. while (index > -1) {
  34. index = htmlPage.indexOf('styleClass="', index + 12);
  35. if (index > -1) {
  36. const className = htmlPage.substring(index + 12, htmlPage.indexOf('"', index + 12));
  37. if (MDS_classes.indexOf(className) === -1) {
  38. MDS_classes.push(className);
  39. }
  40. }
  41. }
  42. index = 0;
  43. while (index > -1) {
  44. index = htmlPage.indexOf('class="', index + 12);
  45. if (index > -1) {
  46. const className = htmlPage.substring(index + 12, htmlPage.indexOf('"', index + 12));
  47. if (MDS_classes.indexOf(className) === -1) {
  48. MDS_classes.push(className);
  49. }
  50. }
  51. }
  52. index = 0;
  53. while (index > -1) {
  54. index = htmlPage.indexOf('class=\'', index + 7);
  55. if (index > -1) {
  56. const className = htmlPage.substring(index + 7, htmlPage.indexOf('\'', index + 7));
  57. if (MDS_classes.indexOf(className) === -1) {
  58. MDS_classes.push(className);
  59. }
  60. }
  61. }
  62. }
  63.  
  64. showFiles(MDS_path);
  65. checkClasses(1);
  66.  
  67. function checkClasses(count) {
  68. if (count === MDS_classes.length) {
  69. console.log(MDS_classes.length);
  70. style2ClassesFind();
  71. } else {
  72. setTimeout(() => checkClasses(MDS_classes.length), 50);
  73. }
  74. }
  75.  
  76. function style2ClassesFind() {
  77. const lineReader = require('readline').createInterface({
  78. input: require('fs').createReadStream(style2_path)
  79. });
  80.  
  81. lineReader.on('line', function (line) {
  82. if (line.trim().startsWith("."))
  83. console.log('Line from file:', line.trim());
  84. });
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement