Install atom executable during window.startup()

Previously this was done during `rake install`.

Also default to `~/github/atom` as the default resource path
when no `--resource-path` argument is specified.  This argument
will now be required when running in dev mode if the repository
is not at the default location.

Closes #300
This commit is contained in:
Kevin Sawicki 2013-02-22 20:49:37 -08:00
parent c7ff431d13
commit d35c871e17
6 changed files with 59 additions and 39 deletions

View File

@ -41,17 +41,6 @@ task :install => [:clean, :build] do
`rm -rf #{dest}`
`cp -r #{path} #{File.expand_path(dest)}`
# Install cli atom
usr_bin_path = "/opt/github/bin"
cli_path = "#{usr_bin_path}/atom"
template = ERB.new CLI_SCRIPT
namespace = OpenStruct.new(:application_path => dest, :resource_path => ATOM_SRC_PATH)
File.open(cli_path, "w") do |f|
f.write template.result(namespace.instance_eval { binding })
f.chmod(0755)
end
Rake::Task["clone-default-bundles"].invoke()
puts "\033[32mType `atom` to start Atom! In Atom press `cmd-,` to edit your `~/.atom` directory\033[0m"
@ -130,30 +119,3 @@ def application_path
return nil
end
CLI_SCRIPT = <<-EOF
#!/bin/sh
open -a Atom -n --args --resource-path="<%= resource_path %>" --executed-from="$(pwd)" --pid=$$ $@
# Used to exit process when atom is used as $EDITOR
on_die() {
exit 0
}
trap 'on_die' SIGQUIT SIGTERM
# Don't exit process if we were told to wait.
while [ "$#" -gt "0" ]; do
case $1 in
-W|--wait)
WAIT=1
;;
esac
shift
done
if [ $WAIT ]; then
while true; do
sleep 1
done
fi
EOF

24
atom.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/sh
open -a Atom -n --args --executed-from="$(pwd)" --pid=$$ $@
# Used to exit process when atom is used as $EDITOR
on_die() {
exit 0
}
trap 'on_die' SIGQUIT SIGTERM
# Don't exit process if we were told to wait.
while [ "$#" -gt "0" ]; do
case $1 in
-W|--wait)
WAIT=1
;;
esac
shift
done
if [ $WAIT ]; then
while true; do
sleep 1
done
fi

View File

@ -33,6 +33,17 @@
AtomApplication *atomApplication = (AtomApplication *)[AtomApplication sharedApplication];
_resourcePath = [atomApplication.arguments objectForKey:@"resource-path"];
if (!alwaysUseBundleResourcePath && !_resourcePath) {
NSString *defaultRepositoryPath = @"~/github/atom";
defaultRepositoryPath = [defaultRepositoryPath stringByStandardizingPath];
if ([defaultRepositoryPath characterAtIndex:0] == '/') {
BOOL isDir = false;
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:defaultRepositoryPath isDirectory:&isDir];
if (isDir && exists)
_resourcePath = defaultRepositoryPath;
}
}
if (alwaysUseBundleResourcePath || !_resourcePath) {
_resourcePath = [[NSBundle mainBundle] resourcePath];
}

View File

@ -38,4 +38,4 @@ for CSON_FILE in $CSON_FILES; do
done;
# Copy non-coffee files into bundle
rsync --archive --recursive --exclude="src/**/*.coffee" --exclude="src/**/*.cson" src static vendor spec benchmark themes dot-atom "$RESOUCES_PATH"
rsync --archive --recursive --exclude="src/**/*.coffee" --exclude="src/**/*.cson" src static vendor spec benchmark themes dot-atom atom.sh "$RESOUCES_PATH"

View File

@ -116,3 +116,16 @@ describe "Window", ->
window.shutdown()
window.shutdown()
expect(atom.setRootViewStateForPath.callCount).toBe 1
describe ".installAtomCommand(commandPath)", ->
commandPath = '/tmp/installed-atom-command/atom'
afterEach ->
fs.remove(commandPath) if fs.exists(commandPath)
describe "when the command path doesn't exist", ->
it "copies atom.sh to the specified path", ->
expect(fs.exists(commandPath)).toBeFalsy()
window.installAtomCommand(commandPath)
expect(fs.exists(commandPath)).toBeTruthy()
expect(fs.read(commandPath).length).toBeGreaterThan 1

View File

@ -1,5 +1,6 @@
fs = require 'fs'
$ = require 'jquery'
ChildProcess = require 'child-process'
require 'jquery-extensions'
require 'underscore-extensions'
require 'space-pen-extensions'
@ -39,6 +40,7 @@ window.setUpEnvironment = ->
# This method is only called when opening a real application window
window.startup = ->
installAtomCommand('/opt/github/bin/atom')
handleWindowEvents()
config.load()
atom.loadTextPackage()
@ -65,6 +67,14 @@ window.shutdown = ->
window.rootView = null
window.project = null
window.installAtomCommand = (commandPath) ->
return if fs.exists(commandPath)
bundledCommandPath = fs.resolve(window.resourcePath, 'atom.sh')
if bundledCommandPath?
fs.write(commandPath, fs.read(bundledCommandPath))
ChildProcess.exec("chmod u+x '#{commandPath}'")
window.handleWindowEvents = ->
$(window).on 'core:close', => window.close()
$(window).command 'window:close', => window.close()