Class: Deliver::DeliverfileCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/deliver/deliverfile/deliverfile_creator.rb

Overview

Helps new user quickly adopt Deliver

Class Method Summary collapse

Class Method Details

.create(deliver_path, project_name = nil) ⇒ Object

This method will ask the user what he wants to do

Parameters:

  • deliver_path (String)

    The path in which the Deliverfile should be created

  • project_name (String) (defaults to: nil)

    The default name of the project, which is used in the generated Deliverfile



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
# File 'lib/deliver/deliverfile/deliverfile_creator.rb', line 8

def self.create(deliver_path, project_name = nil)
  deliver_file_path = [deliver_path, Deliver::Deliverfile::Deliverfile::FILE_NAME].join("/")
  raise "Deliverfile already exists at path '#{deliver_file_path}'. Run 'deliver' to use Deliver.".red if File.exists?(deliver_file_path)

  project_name ||= Dir.pwd.split("/").last

  if agree("Do you want Deliver to automatically create the Deliverfile for you based " + 
          "on your current app? (y/n)", true)

    puts "\n\nFirst, you need to login with your iTunesConnect credentials. ".yellow + 
      "\nThis is necessary to fetch the latest metadata from your app and use it to create a Deliverfile for you." + 
      "\nIf you have previously entered your credentials already, you will not be asked again."

    if Deliver::PasswordManager.shared_manager.username and Deliver::PasswordManager.shared_manager.password
      identifier = ''
      while identifier.length < 3
        identifier = ask("\nApp Identifier of your app (e.g. at.felixkrause.app_name): ")
      end

      self.create_based_on_identifier(deliver_path, identifier, project_name)
    else
      self.create_example_deliver_file(deliver_file_path, project_name)
    end
  else
    self.create_example_deliver_file(deliver_file_path, project_name)
  end
end

.create_based_on_identifier(deliver_path, identifier, project_name) ⇒ Object

This will download all the app metadata and store its data into JSON files

Parameters:

  • deliver_path (String)

    The directory in which the Deliverfile should be created

  • identifier (String)

    The app identifier we want to create Deliverfile based on

  • project_name (String)

    The default name of the project, which is used in the generated Deliverfile



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/deliver/deliverfile/deliverfile_creator.rb', line 53

def self.create_based_on_identifier(deliver_path, identifier, project_name)
  app = Deliver::App.new(app_identifier: identifier)
  app.("/tmp") # we don't want to pollute the current folder
  app. # this will download the latest app metadata
  
  file_path = [deliver_path, Deliver::Deliverfile::Deliverfile::FILE_NAME].join('/')
  json = generate_deliver_file(app, deliver_path, project_name)
  File.write(file_path, json)
  
  puts "Successfully created new Deliverfile at '#{file_path}'".green
end

.create_example_deliver_file(path, project_name) ⇒ Object

This method is used, when the user does not want to automatically create the Deliverfile

Parameters:

  • path (String)

    The exact path (including the file name) in which the Deliverfile should be created

  • project_name (String)

    The default name of the project, which is used in the generated Deliverfile



39
40
41
42
43
44
45
46
47
# File 'lib/deliver/deliverfile/deliverfile_creator.rb', line 39

def self.create_example_deliver_file(path, project_name)
  example = File.read("#{gem_path}/lib/assets/DeliverfileExample")
  example.gsub!("[[APP_NAME]]", project_name)
  File.write(path, example)

  FileUtils.mkdir_p './screenshots/'

  puts "Successfully created new Deliverfile at '#{path}'".green
end