Class: Sumodev::Commands::Project

Inherits:
Sumodev::Command show all
Defined in:
lib/sumodev/commands/project.rb

Instance Method Summary collapse

Methods inherited from Sumodev::Command

banner

Instance Method Details

#get(repo, stage = "staging") ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sumodev/commands/project.rb', line 20

def get(repo, stage="staging")
  begin
    tmp_path = File.expand_path(Sumodev::Config.get('SUMO_TEMP_PATH'));
    capfile_path = "#{tmp_path}/temp_project/Capfile"
    sites_path = File.expand_path(Sumodev::Config.get('SUMO_SITES_PATH'))

    clone_repo(repo, "#{tmp_path}/temp_project")

    if options[:project_path].nil?
      client, project = process_capfile(capfile_path)
      project_path = File.expand_path("#{sites_path}/#{client}/#{project}")
    else
      project_path = File.expand_path(options[:project_path])
    end

    move_project("#{tmp_path}/temp_project", project_path)

    if !options[:only_clone]
      install_bundles(project_path) if options[:bundles]
      install_node_modules(project_path) if options[:node_modules]
      install_bower_packages(project_path) if options[:bower]
      install_composer_packages(project_path, options[:composer_run_scripts]) if options[:composer]
      fetch_data(project_path, stage) if options[:fetch_data]
      mark_as_installed(project_path) if options[:mark_as_installed]
    end

    change_location(project_path)
    say "All done", :green
  rescue Exception => e
    say e.message, :red
  end
end

#new(type, client, project) ⇒ Object



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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/sumodev/commands/project.rb', line 62

def new(type, client, project)
  begin
    if type != "fork"
      raise "Only fork is implemented"
    end

    repo = "[email protected]:sumocoders/#{client}-#{project}.git"
    repo_url = repo.gsub('.be:', '.be/').gsub('git@', 'http://').gsub('.git', '')

    # check if repo exists
    begin
      self.run_command_without_output("git ls-remote #{repo}", nil, "--> Check if repo #{repo} exists.")
    rescue Exception => e
      raise "Please create a repository named #{client}-#{project} first:\nhttp://git.sumocoders.be/projects/new"
    end

    tmp_path = File.expand_path(Sumodev::Config.get('SUMO_TEMP_PATH'));
    sites_path = File.expand_path(Sumodev::Config.get('SUMO_SITES_PATH'))

    if options[:project_path].nil?
      project_path = File.expand_path("#{sites_path}/#{client}/#{project}")
    else
      project_path = File.expand_path(options[:project_path])
    end

    clone_repo("git://github.com/sumocoders/forkcms.git", "#{tmp_path}/temp_project")
    run_command_without_output("rm -rf #{tmp_path}/temp_project/.git")
    initialize_repo("#{tmp_path}/temp_project", repo)

    # ask to set the default branch to staging
    run_command_without_output("open #{repo_url}/edit")
    continue?("Gitlab will now open, change the default branch to *staging*")

    # ask to add a new app in Errbit and get the errbit_api_key
    run_command_without_output("open https://errors.sumocoders.be/apps/new")
    errbit_api_key = ask("Errbit will now open, enter the Errbit API key:")

    # move it into place
    move_project("#{tmp_path}/temp_project", project_path)
    populate_capfile("#{project_path}/Capfile", client, project, repo, errbit_api_key)

    # install assets
    install_bundles(project_path) if options[:bundles]
    install_node_modules(project_path) if options[:node_modules]
    create_npm_shrinkwrap(project_path) if options[:npm_shrinkwrap]
    install_bower_packages(project_path) if options[:bower]
    install_composer_packages(project_path, options[:composer_run_scripts]) if options[:composer]

    # create database
    run_command_without_output(
      [
        "bundle exec cap staging sumodev:db:create",
        "bundle exec cap staging sumodev:db:get"
      ],
      project_path,
      "--> Creating database on staging and local"
    )

    # grab database information
    output = run_command_without_output("bundle exec cap staging sumodev:db:info 2>&1", project_path)
    database_information = output.out
      .gsub("** [out :: dev.sumocoders.be] ", "")
      .gsub("\n", "")

    database_name = database_information.scan(/database:(.*)user/)[0][0].gsub(/\s+/, '')
    database_user = database_information.scan(/user:(.*)pass/)[0][0].gsub(/\s+/, '')
    database_password = database_information.scan(/pass:(.*)command/)[0][0].gsub(/\s+/, '')

    run_command_without_output(
      "sed -i '' -e 's|site.path_www:.*|site.path_www: /home/vagrant/pow/#{client}/#{project}|g' #{project_path}/app/config/parameters_install.yml",
      nil,
      "--> Configuring parameters_install.yml"
    )
    run_command_without_output("rm -rf #{project_path}/app/cache/install")

    # run the installer
    run_command_without_output("open http://#{project}.#{client}.dev")
    continue?("The installer will now open.\nYou can use *#{database_name}* as the database_name.")

    install_initial_theme(project_path, database_name)

    # commit our changes
    run_command_without_output(
      [
        "git add Capfile",
        "git add app/config/parameters_install.yml",
        "git add package.json",
        "git add npm-shrinkwrap.json",
        "git add Gemfile.lock",
        "git add src/Frontend/Themes/Custom",
        "git commit -n -m 'Init configuration of the project'",
        "git push"
      ],
      project_path,
      "--> Commiting the initial configuration of the project"
    )

    # deploy
    initial_deploy(project_path, client, project, database_name, database_user, database_password, errbit_api_key)
    deploy(project_path, "staging")

    change_location(project_path)
    say "All done", :green
  rescue Exception => e
    say e.message, :red
  end
end