Move shell command installation entirely into CommandInstaller

This commit is contained in:
Nathan Sobo
2014-09-25 13:11:15 -06:00
parent 442223f97b
commit 4b746deb73
2 changed files with 30 additions and 28 deletions

View File

@@ -30,14 +30,41 @@ module.exports =
getInstallDirectory: ->
"/usr/local/bin"
install: (commandPath, askForPrivilege, callback) ->
installShellCommandsInteractively: ->
showErrorDialog = (error) ->
atom.confirm
message: "Failed to install shell commands"
detailedMessage: error.message
resourcePath = atom.getLoadSettings().resourcePath
@installAtomCommand resourcePath, true, (error) =>
if error?
showErrorDialog(error)
else
@installApmCommand resourcePath, true, (error) =>
if error?
showErrorDialog(error)
else
atom.confirm
message: "Commands installed."
detailedMessage: "The shell commands `atom` and `apm` are installed."
installAtomCommand: (resourcePath, askForPrivilege, callback) ->
commandPath = path.join(resourcePath, 'atom.sh')
@createSymlink commandPath, askForPrivilege, callback
installApmCommand: (resourcePath, askForPrivilege, callback) ->
commandPath = path.join(resourcePath, 'apm', 'node_modules', '.bin', 'apm')
@createSymlink commandPath, askForPrivilege, callback
createSymlink: (commandPath, askForPrivilege, callback) ->
return unless process.platform is 'darwin'
commandName = path.basename(commandPath, path.extname(commandPath))
destinationPath = path.join(@getInstallDirectory(), commandName)
fs.readlink destinationPath, (error, realpath) ->
if realpath == commandPath
if realpath is commandPath
callback()
return
@@ -49,11 +76,3 @@ module.exports =
catch error
callback?(error)
installAtomCommand: (resourcePath, askForPrivilege, callback) ->
commandPath = path.join(resourcePath, 'atom.sh')
@install commandPath, askForPrivilege, callback
installApmCommand: (resourcePath, askForPrivilege, callback) ->
commandPath = path.join(resourcePath, 'apm', 'node_modules', '.bin', 'apm')
@install commandPath, askForPrivilege, callback

View File

@@ -102,24 +102,7 @@ class Workspace extends Model
@emit 'editor-created', editor
installShellCommands: ->
showErrorDialog = (error) ->
installDirectory = CommandInstaller.getInstallDirectory()
atom.confirm
message: "Failed to install shell commands"
detailedMessage: error.message
resourcePath = atom.getLoadSettings().resourcePath
CommandInstaller.installAtomCommand resourcePath, true, (error) ->
if error?
showErrorDialog(error)
else
CommandInstaller.installApmCommand resourcePath, true, (error) ->
if error?
showErrorDialog(error)
else
atom.confirm
message: "Commands installed."
detailedMessage: "The shell commands `atom` and `apm` are installed."
CommandInstaller.installShellCommandsInteractively()
subscribeToActiveItem: ->
@updateWindowTitle()