Guest User

Untitled

a guest
Dec 10th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. // 該当ディレクトリ以下で find . | grep -E "jsx$" | xargs -I {} node searchSameMethod.js {}
  2. const fs = require('fs');
  3. const filepath = process.argv[2]
  4.  
  5. const main = async (filepath) => {
  6. const file = await readutf8(filepath);
  7. const pa = file.match(/^ ([a-zA-z]*)\(/gm);
  8. const pb = file.match(/^ ([a-zA-z]*) =/gm);
  9. let matched;
  10. if (pa && pb) {
  11. matched = pa.concat(pb);
  12. } else if (pb === null) {
  13. matched = pa;
  14. } else {
  15. matched = pb;
  16. }
  17.  
  18. if (!matched) {
  19. return;
  20. }
  21.  
  22. matched.forEach((e, i) => {
  23. const filterd = matched.filter((b, idx) => idx !== i);
  24. filterd.forEach(element => {
  25. if (element === e) console.log('element', filepath, element);
  26. });
  27. });
  28. }
  29.  
  30. main(filepath)
  31.  
  32. async function readutf8(filepath) {
  33. return new Promise((resolve, reject) => {
  34. return fs.readFile(filepath, { encoding: 'utf8' }, (err, data) => {
  35. return err ? reject(err) : resolve(data);
  36. });
  37. });
  38. }
  39.  
  40. ```
Add Comment
Please, Sign In to add comment