Install atom command as 'atom-beta' when using beta version

This commit is contained in:
Max Brunsfeld 2015-09-21 10:04:01 -07:00
parent 69949eef31
commit a9531fc4dd
4 changed files with 78 additions and 32 deletions

View File

@ -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

View File

@ -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()

View File

@ -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) ->

View File

@ -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()