Skip to content

Instantly share code, notes, and snippets.

@imaman
Last active May 28, 2018 13:22
Show Gist options
  • Select an option

  • Save imaman/f21343e3f45a09a28ae178b46b39d641 to your computer and use it in GitHub Desktop.

Select an option

Save imaman/f21343e3f45a09a28ae178b46b39d641 to your computer and use it in GitHub Desktop.
print hierarchy of JS classes
node -e "var p = 'src/locators/selectors'; var kids = fs.readdirSync(p).map(x => fs.readFileSync(p + '/' + x, 'utf-8')).join('\n').split('\n').filter(x => x.match(/class .*{/)).map(x => x.replace('class ', '').replace(' {', '').replace(' extends ', ' ')).map(x => x.split(' ')).reduce((kids, p) => { kids[p[1]] = kids[p[1]] || []; kids[p[1]].push(p[0]); return kids; }, {}); function pr(indentation, k) { console.log(indentation + k); (kids[k] || []).forEach(x => pr(indentation + ' ', x)); }; pr('');"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment