Install apm command when Atom starts

This changes the command installation to use symlinks instead
of copying over the contents of the file.
This commit is contained in:
Kevin Sawicki
2013-05-15 10:28:31 -07:00
parent 718175eb34
commit 61675c2e77
5 changed files with 104 additions and 38 deletions

View File

@@ -0,0 +1,50 @@
path = require 'path'
fs = require 'fs'
_ = require 'underscore'
async = require 'async'
mkdirp = require 'mkdirp'
fsUtils = require 'fs-utils'
symlinkCommand = (sourcePath, destinationPath, callback) ->
mkdirp fsUtils.directory(destinationPath), (error) ->
if error?
callback(error)
else
fs.symlink sourcePath, destinationPath, (error) ->
if error?
callback(error)
else
fs.chmod(destinationPath, 0o755, callback)
unlinkCommand = (destinationPath, callback) ->
fs.exists destinationPath, (exists) ->
if exists
fs.unlink(destinationPath, callback)
else
callback()
module.exports =
findInstallDirectory: (callback) ->
directories = ['/opt/boxen','/opt/github','/usr/local']
async.detect(directories, fsUtils.isDirectoryAsync, callback)
install: (commandPath, commandName, callback) ->
if not commandName? or _.isFunction(commandName)
callback = commandName
commandName = path.basename(commandPath, path.extname(commandPath))
installCallback = (error) ->
if error?
console.warn "Failed to install `#{commandName}` binary", error
callback?(error)
@findInstallDirectory (directory) ->
if directory?
destinationPath = path.join(directory, 'bin', commandName)
unlinkCommand destinationPath, (error) ->
if error?
installCallback(error)
else
symlinkCommand(commandPath, destinationPath, installCallback)
else
installCallback(new Error("No destination directory exists to install"))

View File

@@ -73,8 +73,11 @@ module.exports =
return done(false) unless path?.length > 0
fs.exists path, (exists) ->
if exists
fs.stat path, (err, stat) ->
done(stat?.isDirectory() ? false)
fs.stat path, (error, stat) ->
if error?
done(false)
else
done(stat.isDirectory())
else
done(false)
@@ -87,6 +90,13 @@ module.exports =
catch e
false
# Returns true if the specified path is exectuable.
isExecutable: (path) ->
try
(fs.statSync(path).mode & 0o777 & 1) isnt 0
catch e
false
# Returns an array with all the names of files contained
# in the directory path.
list: (rootPath, extensions) ->