Class: Jiveapps::Command::Livedev

Inherits:
BaseWithApp show all
Defined in:
lib/jiveapps/commands/livedev.rb

Instance Attribute Summary

Attributes inherited from BaseWithApp

#app

Attributes inherited from Base

#args, #autodetected_app

Instance Method Summary collapse

Methods inherited from BaseWithApp

#initialize

Methods inherited from Base

#extract_app, #extract_app_from_git_config, #extract_app_in_dir, #extract_option, #git_remotes, #initialize, #jiveapps

Methods included from Helpers

#ask, #catch_args, #check_git_version, #confirm, #confirm_command, #debug, #debug_mode?, #display, #display_oauth_services, #error, #get_app_prop_with_default, #get_or_set_git_prop, #git_version, #has_program?, #home_directory, #running_on_a_mac?, #running_on_windows?, #sh, #usage, #user_git_version

Constructor Details

This class inherits a constructor from Jiveapps::Command::BaseWithApp

Instance Method Details

#offObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/jiveapps/commands/livedev.rb', line 46

def off
  display "\n\n\n=== Stopping LiveDev: #{app}"

  # remove livedev run file if it exists
  remove_livedev_run_file

  # switch server to run in normal mode
  display "1/3: Switching the Jive App Sandbox to point to master branch."
  jiveapps.livedev(app, 'off')

  display "2/3: Checking out master branch and pulling any remote changes."
  run("git checkout master")
  run("git pull jiveapps master")

  if `git diff #{livedev_branch_name} master`.length > 0
    display "3/3: Merging changes from LiveDev branch without committing."
    result = `git merge #{livedev_branch_name} --squash`

    # Check if a merge conflict occurred and display git message if so
    if result =~ /CONFLICT/
      puts "\n\n=== Merge conflicts occured:"
      puts result
    end

    display "\n\n\n=== You can now review your changes, then keep or forget them:"
    display " 1. Review your changes:"
    display "    $ git status"
    display "    $ git diff --cached  # review changes staged for commit"
    display "    $ git diff           # review conflicts" if result =~ /CONFLICT/
    display ""

    if result =~ /CONFLICT/
      display "        ... edit and fix conflicts ..."
      display ""
    end

    display " 2. Commit them to the master branch:"
    display "    $ git add <fixed-conflict-file-names>" if result =~ /CONFLICT/
    display "    $ git commit -m 'your commit message here'"
    display "    $ git push jiveapps master"
    display "    $ git branch -D #{livedev_branch_name}"
    display ""
    display " 3. Or forget them:"
    display "    $ git reset --hard HEAD"
    display "    $ git branch -D #{livedev_branch_name}"
  else
    display "=== No changes exist in the LiveDev branch. Now running in standard dev mode."
    run("git branch -d #{livedev_branch_name}") # deleting livedev branch since no changes exist
  end
end

#onObject Also known as: index



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/jiveapps/commands/livedev.rb', line 5

def on
  info = jiveapps.info(app)
  if info == nil
    display "App not found."
  else
    check_for_jiveapps_remote(info)

    # Check if LiveDev is already running...
    if File.exist?(".git/livedev")
      return unless confirm "LiveDev appears to already be running in another window.\nIf so, you should not run it twice, or strange things could happen.\nType \"y\" to continue anyway, or anything else to quit (recommended): (y/N)?"
    else
      # Create livedev run file so above check can happen
      # if command is run in two separate terminals
      File.open(".git/livedev", 'w') {|f| f.write("") }
    end

    display "=== Starting LiveDev: #{app}"

    display "1/4: Checking out LiveDev branch #{livedev_branch_name}."

    ask_to_recreate_branch_if_livedev_exists
    checkout_livedev_branch

    # sync remote livedev branch with local - force update to match local
    display "2/4: Syncing local branch with remote server."
    run("git push -f jiveapps #{livedev_branch_name}")

    # switch server to run in livedev mode
    display "3/4: Switching the Jive App Sandbox to point to LiveDev branch."
    jiveapps.livedev(app, 'on')

    display "4/4: Watching directory for changes. Leave this process running"
    display "     until you wish to quit LiveDev. Type \"exit\" to quit."
    display "     To view your app while in LiveDev mode, go to:"
    display "     #{info['sandbox_canvas_url']}"
    display "================================================================"
    watch_dir_and_commit_changes
  end
end