From a9531fc4dd051ed51310877d28bef26714f541b6 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 21 Sep 2015 10:04:01 -0700 Subject: [PATCH] Install atom command as 'atom-beta' when using beta version --- spec/command-installer-spec.coffee | 78 +++++++++++++++++++++--------- src/atom.coffee | 6 ++- src/command-installer.coffee | 22 ++++++--- src/workspace.coffee | 4 +- 4 files changed, 78 insertions(+), 32 deletions(-) diff --git a/spec/command-installer-spec.coffee b/spec/command-installer-spec.coffee index b87a08edc..e63bfb82c 100644 --- a/spec/command-installer-spec.coffee +++ b/spec/command-installer-spec.coffee @@ -1,34 +1,66 @@ path = require 'path' fs = require 'fs-plus' temp = require 'temp' -installer = require '../src/command-installer' +CommandInstaller = require '../src/command-installer' -describe "install(commandPath, callback)", -> - commandFilePath = temp.openSync("atom-command").path - commandName = path.basename(commandFilePath) - installationPath = temp.mkdirSync("atom-bin") - installationFilePath = path.join(installationPath, commandName) +describe "CommandInstaller on #darwin", -> + [resourcesPath, installationPath, atomBinPath, apmBinPath] = [] beforeEach -> - fs.chmodSync(commandFilePath, '755') - spyOn(installer, 'getInstallDirectory').andReturn installationPath + installationPath = temp.mkdirSync("atom-bin") - describe "on #darwin", -> - it "symlinks the command and makes it executable", -> - expect(fs.isFileSync(commandFilePath)).toBeTruthy() - expect(fs.isFileSync(installationFilePath)).toBeFalsy() + resourcesPath = temp.mkdirSync('atom-app') + atomBinPath = path.join(resourcesPath, 'app', 'atom.sh') + apmBinPath = path.join(resourcesPath, 'app', 'apm', 'node_modules', '.bin', 'apm') + fs.writeFileSync(atomBinPath, "") + fs.writeFileSync(apmBinPath, "") + fs.chmodSync(atomBinPath, '755') + fs.chmodSync(apmBinPath, '755') - installDone = false - installError = null - installer.createSymlink commandFilePath, false, (error) -> - installDone = true - installError = error + spyOn(CommandInstaller::, 'getResourcesDirectory').andReturn(resourcesPath) + spyOn(CommandInstaller::, 'getInstallDirectory').andReturn(installationPath) - waitsFor -> - installDone + describe "installApmCommand(callback)", -> + it "symlinks the apm command and makes it executable", -> + installer = new CommandInstaller("2.0.2") + installedApmPath = path.join(installationPath, 'apm') + + expect(fs.isFileSync(installedApmPath)).toBeFalsy() + + waitsFor (done) -> + installer.installApmCommand(false, done) runs -> - expect(installError).toBeNull() - expect(fs.isFileSync(installationFilePath)).toBeTruthy() - expect(fs.realpathSync(installationFilePath)).toBe fs.realpathSync(commandFilePath) - expect(fs.isExecutableSync(installationFilePath)).toBeTruthy() + expect(fs.realpathSync(installedApmPath)).toBe fs.realpathSync(apmBinPath) + expect(fs.isExecutableSync(installedApmPath)).toBeTruthy() + + describe "installAtomCommand(askForPrivilege, callback)", -> + describe "when using a stable version of atom", -> + it "installs the atom command as 'atom'", -> + installer = new CommandInstaller("2.0.2") + installedAtomPath = path.join(installationPath, 'atom') + + expect(fs.isFileSync(installedAtomPath)).toBeFalsy() + + waitsFor (done) -> + installer.installAtomCommand(false, done) + + runs -> + expect(fs.realpathSync(installedAtomPath)).toBe fs.realpathSync(atomBinPath) + expect(fs.isExecutableSync(installedAtomPath)).toBe true + expect(fs.isFileSync(path.join(installationPath, 'atom-beta'))).toBe false + + describe "when using a beta version of atom", -> + it "installs the atom command as 'atom-beta'", -> + installer = new CommandInstaller("2.2.0-beta.0") + installedAtomPath = path.join(installationPath, 'atom-beta') + + expect(fs.isFileSync(installedAtomPath)).toBeFalsy() + + waitsFor (done) -> + installer.installAtomCommand(false, done) + + runs -> + expect(fs.realpathSync(installedAtomPath)).toBe fs.realpathSync(atomBinPath) + expect(fs.isExecutableSync(installedAtomPath)).toBe true + expect(fs.isFileSync(path.join(installationPath, 'atom'))).toBe false diff --git a/src/atom.coffee b/src/atom.coffee index 23c9c2cec..59d7765ac 100644 --- a/src/atom.coffee +++ b/src/atom.coffee @@ -573,9 +573,11 @@ class Atom extends Model {safeMode} = @getLoadSettings() CommandInstaller = require './command-installer' - CommandInstaller.installAtomCommand false, (error) -> + + commandInstaller = new CommandInstaller(@getVersion()) + commandInstaller.installAtomCommand false, (error) -> console.warn error.message if error? - CommandInstaller.installApmCommand false, (error) -> + commandInstaller.installApmCommand false, (error) -> console.warn error.message if error? @loadConfig() diff --git a/src/command-installer.coffee b/src/command-installer.coffee index 4a0e52bd8..3b4775fe1 100644 --- a/src/command-installer.coffee +++ b/src/command-installer.coffee @@ -25,9 +25,15 @@ symlinkCommandWithPrivilegeSync = (sourcePath, destinationPath) -> throw new Error("Failed to symlink '#{sourcePath}' to '#{destinationPath}'") module.exports = +class CommandInstaller + constructor: (@appVersion) -> + getInstallDirectory: -> "/usr/local/bin" + getResourcesDirectory: -> + process.resourcesPath + installShellCommandsInteractively: -> showErrorDialog = (error) -> atom.confirm @@ -47,17 +53,21 @@ module.exports = detailedMessage: "The shell commands `atom` and `apm` are installed." installAtomCommand: (askForPrivilege, callback) -> - commandPath = path.join(process.resourcesPath, 'app', 'atom.sh') - @createSymlink commandPath, askForPrivilege, callback + launcherName = if @appVersion.includes("beta") + "atom-beta" + else + "atom" + + commandPath = path.join(@getResourcesDirectory(), 'app', 'atom.sh') + @createSymlink commandPath, launcherName, askForPrivilege, callback installApmCommand: (askForPrivilege, callback) -> - commandPath = path.join(process.resourcesPath, 'app', 'apm', 'node_modules', '.bin', 'apm') - @createSymlink commandPath, askForPrivilege, callback + commandPath = path.join(@getResourcesDirectory(), 'app', 'apm', 'node_modules', '.bin', 'apm') + @createSymlink commandPath, 'apm', askForPrivilege, callback - createSymlink: (commandPath, askForPrivilege, callback) -> + createSymlink: (commandPath, commandName, 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) -> diff --git a/src/workspace.coffee b/src/workspace.coffee index 8e15a950e..bda6e9b45 100644 --- a/src/workspace.coffee +++ b/src/workspace.coffee @@ -119,7 +119,9 @@ class Workspace extends Model editorAdded: (editor) -> installShellCommands: -> - require('./command-installer').installShellCommandsInteractively() + CommandInstaller = require('./command-installer') + commandInstaller = new CommandInstaller(atom.getVersion()) + commandInstaller.installShellCommandsInteractively() subscribeToActiveItem: -> @updateWindowTitle()