|
| 1 | +{View, Task, BufferedProcess} = require 'atom' |
| 2 | + |
| 3 | +module.exports = |
| 4 | +class EmberCliHelperView extends View |
| 5 | + |
| 6 | + @content: -> |
| 7 | + @div class: 'ember-cli-helper tool-panel panel-bottom native-key-bindings', => |
| 8 | + @div class: 'ember-cli-btn-group', => |
| 9 | + @button outlet: 'server', click: 'startServer', class: 'btn', 'Server' |
| 10 | + @button outlet: 'test', click: 'startTesting', class: 'btn', 'Test' |
| 11 | + @button outlet: 'exit', click: 'stopProcess', class: 'btn', 'Exit' |
| 12 | + @button outlet: 'hide', click: 'toggle', class: 'btn btn-right', 'Close' |
| 13 | + @button outlet: 'mini', click: 'minimize', class: 'btn btn-right', 'Minimize' |
| 14 | + @div outlet: 'panel', class: 'panel-body padded hidden', => |
| 15 | + @ul outlet: 'messages', class: 'list-group' |
| 16 | + |
| 17 | + initialize: -> |
| 18 | + # Register Commands |
| 19 | + atom.workspaceView.command "ember-cli-helper:toggle", => @toggle() |
| 20 | + |
| 21 | + # Enable or disable the helper |
| 22 | + try |
| 23 | + ember = require("#{atom.project.getPath()}/package.json").devDependencies["ember-cli"] |
| 24 | + catch e |
| 25 | + error = e.code |
| 26 | + |
| 27 | + if ember? |
| 28 | + # @toggle() |
| 29 | + else |
| 30 | + @emberProject = false |
| 31 | + @addLine "This is not an Ember CLI projet!" |
| 32 | + |
| 33 | + |
| 34 | + # Returns an object that can be retrieved when package is activated |
| 35 | + serialize: -> |
| 36 | + |
| 37 | + |
| 38 | + # Tear down any state and detach |
| 39 | + destroy: -> |
| 40 | + @detach() |
| 41 | + |
| 42 | + |
| 43 | + toggle: -> |
| 44 | + if @hasParent() |
| 45 | + @detach() |
| 46 | + else |
| 47 | + atom.workspaceView.prependToBottom this |
| 48 | + |
| 49 | + |
| 50 | + minimize: -> |
| 51 | + @panel.toggleClass 'hidden' |
| 52 | + |
| 53 | + |
| 54 | + startServer: -> |
| 55 | + @runCommand 'Ember CLI Server Started'.fontcolor("green"), 'server' |
| 56 | + |
| 57 | + |
| 58 | + startTesting: -> |
| 59 | + @runCommand 'Ember CLI Testing Started'.fontcolor("green"), 'test' |
| 60 | + |
| 61 | + |
| 62 | + runCommand: (message, task) -> |
| 63 | + @minimize() if @panel.hasClass 'hidden' |
| 64 | + @clearPanel() |
| 65 | + @addLine message |
| 66 | + stdout = (out) -> |
| 67 | + @addLine out |
| 68 | + exit = (code) -> |
| 69 | + atom.beep() unless code == 0 |
| 70 | + @addLine "Ember CLI exited: code #{code}" |
| 71 | + try |
| 72 | + @process = new BufferedProcess |
| 73 | + command: 'ember' |
| 74 | + args: [task] |
| 75 | + options: {cwd: atom.project.getPath()} |
| 76 | + stdout: stdout.bind @ |
| 77 | + exit: exit.bind @ |
| 78 | + catch e |
| 79 | + @addLine "There was an error running the script" |
| 80 | + |
| 81 | + |
| 82 | + stopProcess: -> |
| 83 | + if @process? |
| 84 | + @process.kill() |
| 85 | + @process = null |
| 86 | + @addLine "Ember CLI Stopped".fontcolor("red") |
| 87 | + |
| 88 | + |
| 89 | + # Borrowed from grunt-runner by @nickclaw |
| 90 | + # https://github.com/nickclaw/atom-grunt-runner |
| 91 | + addLine: (text, type = "plain") -> |
| 92 | + [panel, messages] = [@panel, @messages] |
| 93 | + text = text.trim().replace /[\r\n]+/g, '<br />' |
| 94 | + stuckToBottom = messages.height() - panel.height() - panel.scrollTop() == 0 |
| 95 | + messages.append "<li class='text-#{type}'>#{text}</li>" |
| 96 | + panel.scrollTop messages.height() if stuckToBottom |
| 97 | + |
| 98 | + clearPanel: -> |
| 99 | + @messages.empty() |
0 commit comments