cache-panel-view.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /** @babel */
  2. /** @jsx etch.dom */
  3. import path from 'path'
  4. import etch from 'etch'
  5. export default class CachePanelView {
  6. constructor () {
  7. etch.initialize(this)
  8. }
  9. update () {}
  10. destroy () {
  11. return etch.destroy(this)
  12. }
  13. render () {
  14. return (
  15. <div className='tool-panel padded package-panel'>
  16. <div className='inset-panel'>
  17. <div className='panel-heading'>Compile Cache</div>
  18. <div className='panel-body padded'>
  19. <div className='timing'>
  20. <span className='inline-block'>CoffeeScript files compiled</span>
  21. <span className='inline-block' ref='coffeeCompileCount'>Loading…</span>
  22. </div>
  23. <div className='timing'>
  24. <span className='inline-block'>Babel files compiled</span>
  25. <span className='inline-block' ref='babelCompileCount'>Loading…</span>
  26. </div>
  27. <div className='timing'>
  28. <span className='inline-block'>Typescript files compiled</span>
  29. <span className='inline-block' ref='typescriptCompileCount'>Loading…</span>
  30. </div>
  31. <div className='timing'>
  32. <span className='inline-block'>CSON files compiled</span>
  33. <span className='inline-block' ref='csonCompileCount'>Loading…</span>
  34. </div>
  35. <div className='timing'>
  36. <span className='inline-block'>Less files compiled</span>
  37. <span className='inline-block' ref='lessCompileCount'>Loading…</span>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. )
  43. }
  44. populate () {
  45. const compileCacheStats = this.getCompileCacheStats()
  46. if (compileCacheStats) {
  47. this.refs.coffeeCompileCount.classList.add('highlight-info')
  48. this.refs.coffeeCompileCount.textContent = compileCacheStats['.coffee'].misses
  49. this.refs.babelCompileCount.classList.add('highlight-info')
  50. this.refs.babelCompileCount.textContent = compileCacheStats['.js'].misses
  51. this.refs.typescriptCompileCount.classList.add('highlight-info')
  52. this.refs.typescriptCompileCount.textContent = compileCacheStats['.ts'].misses
  53. }
  54. this.refs.csonCompileCount.classList.add('highlight-info')
  55. this.refs.csonCompileCount.textContent = this.getCsonCompiles()
  56. this.refs.lessCompileCount.classList.add('highlight-info')
  57. this.refs.lessCompileCount.textContent = this.getLessCompiles()
  58. }
  59. getCompileCacheStats () {
  60. try {
  61. return require(path.join(atom.getLoadSettings().resourcePath, 'src', 'compile-cache')).getCacheStats()
  62. } catch (error) {
  63. return null
  64. }
  65. }
  66. getCsonCompiles () {
  67. try {
  68. const CSON = require(path.join(atom.getLoadSettings().resourcePath, 'node_modules', 'season'))
  69. if (CSON.getCacheMisses) {
  70. return CSON.getCacheMisses() || 0
  71. } else {
  72. return 0
  73. }
  74. } catch (error) {
  75. return 0
  76. }
  77. }
  78. getLessCompiles () {
  79. const lessCache = atom.themes.lessCache
  80. if (lessCache && lessCache.cache && lessCache.cache.stats && lessCache.cache.stats.misses) {
  81. return lessCache.cache.stats.misses || 0
  82. } else {
  83. return 0
  84. }
  85. }
  86. }