From 4b746deb7314035ae107697df9c00fc822f80ff3 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Thu, 25 Sep 2014 13:11:15 -0600 Subject: [PATCH] Move shell command installation entirely into CommandInstaller --- src/command-installer.coffee | 39 +++++++++++++++++++++++++++--------- src/workspace.coffee | 19 +----------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/command-installer.coffee b/src/command-installer.coffee index f1a6ab6e3..a18ab7af1 100644 --- a/src/command-installer.coffee +++ b/src/command-installer.coffee @@ -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 diff --git a/src/workspace.coffee b/src/workspace.coffee index ad30eea74..78c178e19 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -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()