Class: Fastlane::Actions::ZipAction::Runner

Inherits:
Object
  • Object
show all
Defined in:
fastlane/lib/fastlane/actions/zip.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Runner

Returns a new instance of Runner.



7
8
9
10
11
12
13
14
15
16
17
# File 'fastlane/lib/fastlane/actions/zip.rb', line 7

def initialize(params)
  @output_path = File.expand_path(params[:output_path] || params[:path])
  @path = params[:path]
  @verbose = params[:verbose]
  @password = params[:password]
  @symlinks = params[:symlinks]
  @include = params[:include] || []
  @exclude = params[:exclude] || []

  @output_path += ".zip" unless @output_path.end_with?(".zip")
end

Instance Attribute Details

#excludeObject (readonly)

Returns the value of attribute exclude.



5
6
7
# File 'fastlane/lib/fastlane/actions/zip.rb', line 5

def exclude
  @exclude
end

#includeObject (readonly)

Returns the value of attribute include.



5
6
7
# File 'fastlane/lib/fastlane/actions/zip.rb', line 5

def include
  @include
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



5
6
7
# File 'fastlane/lib/fastlane/actions/zip.rb', line 5

def output_path
  @output_path
end

#passwordObject (readonly)

Returns the value of attribute password.



5
6
7
# File 'fastlane/lib/fastlane/actions/zip.rb', line 5

def password
  @password
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'fastlane/lib/fastlane/actions/zip.rb', line 5

def path
  @path
end

Returns the value of attribute symlinks.



5
6
7
# File 'fastlane/lib/fastlane/actions/zip.rb', line 5

def symlinks
  @symlinks
end

#verboseObject (readonly)

Returns the value of attribute verbose.



5
6
7
# File 'fastlane/lib/fastlane/actions/zip.rb', line 5

def verbose
  @verbose
end

Instance Method Details

#create_output_dirObject



29
30
31
32
# File 'fastlane/lib/fastlane/actions/zip.rb', line 29

def create_output_dir
  output_dir = File.expand_path("..", output_path)
  FileUtils.mkdir_p(output_dir)
end

#runObject



19
20
21
22
23
24
25
26
27
# File 'fastlane/lib/fastlane/actions/zip.rb', line 19

def run
  UI.message("Compressing #{path}...")

  create_output_dir
  run_zip_command

  UI.success("Successfully generated zip file at path '#{output_path}'")
  output_path
end

#run_zip_commandObject



34
35
36
37
38
39
# File 'fastlane/lib/fastlane/actions/zip.rb', line 34

def run_zip_command
  # The 'zip' command archives relative to the working directory, chdir to produce expected results relative to `path`
  Dir.chdir(File.expand_path("..", path)) do
    Actions.sh(*zip_command)
  end
end

#zip_commandObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'fastlane/lib/fastlane/actions/zip.rb', line 41

def zip_command
  zip_options = verbose ? "r" : "rq"
  zip_options += "y" if symlinks

  command = ["zip", "-#{zip_options}"]

  if password
    command << "-P"
    command << password
  end

  # The zip command is executed from the paths **parent** directory, as a result we use just the basename, which is the file or folder within
  basename = File.basename(path)

  command << output_path
  command << basename

  unless include.empty?
    command << "-i"
    command += include.map { |path| File.join(basename, path) }
  end

  unless exclude.empty?
    command << "-x"
    command += exclude.map { |path| File.join(basename, path) }
  end

  command
end