Command installer should use known channel names

This commit is contained in:
David Wilson
2018-06-26 17:06:15 -07:00
parent d54bb625aa
commit 691d5da97c

View File

@@ -27,22 +27,35 @@ class CommandInstaller {
}, () => {})
}
this.installAtomCommand(true, error => {
this.installAtomCommand(true, (error, atomCommandName) => {
if (error) return showErrorDialog(error)
this.installApmCommand(true, error => {
this.installApmCommand(true, (error, apmCommandName) => {
if (error) return showErrorDialog(error)
this.applicationDelegate.confirm({
message: 'Commands installed.',
detail: 'The shell commands `atom` and `apm` are installed.'
detail: `The shell commands '${atomCommandName}' and '${apmCommandName}' are installed.`
}, () => {})
})
})
}
getCommandNameForChannel (commandName) {
switch (atom.getReleaseChannel()) {
case 'beta':
return `${commandName}-beta`
case 'nightly':
return `${commandName}-nightly`
case 'dev':
return `${commandName}-dev`
default:
return commandName
}
}
installAtomCommand (askForPrivilege, callback) {
this.installCommand(
path.join(this.getResourcesDirectory(), 'app', 'atom.sh'),
this.appVersion.includes('beta') ? 'atom-beta' : 'atom',
this.getCommandNameForChannel('atom'),
askForPrivilege,
callback
)
@@ -51,7 +64,7 @@ class CommandInstaller {
installApmCommand (askForPrivilege, callback) {
this.installCommand(
path.join(this.getResourcesDirectory(), 'app', 'apm', 'node_modules', '.bin', 'apm'),
this.appVersion.includes('beta') ? 'apm-beta' : 'apm',
this.getCommandNameForChannel('apm'),
askForPrivilege,
callback
)
@@ -64,11 +77,11 @@ class CommandInstaller {
fs.readlink(destinationPath, (error, realpath) => {
if (error && error.code !== 'ENOENT') return callback(error)
if (realpath === commandPath) return callback()
if (realpath === commandPath) return callback(null, commandName)
this.createSymlink(fs, commandPath, destinationPath, error => {
if (error && error.code === 'EACCES' && askForPrivilege) {
const fsAdmin = require('fs-admin')
this.createSymlink(fsAdmin, commandPath, destinationPath, callback)
this.createSymlink(fsAdmin, commandPath, destinationPath, (error) => { callback(error, commandName) })
} else {
callback(error)
}