fastlane-plugin-static_assets 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8cc591df3ad12f9c0cec748628e4e0ad11c19de
4
- data.tar.gz: 42746a59b7af3f80957c9f4c09d90c243f8c7def
3
+ metadata.gz: 4055d7723c5a029c3a52f045063202bba3cbd4c6
4
+ data.tar.gz: 5ac1cca8f05f71e6154729df01bcb7d2ea881a0f
5
5
  SHA512:
6
- metadata.gz: 847f4419242b0bd51a3b18ca709bbfc165cc24c156b27f1cc90f2976c1722759af51e792199bbffbdbd75f2d7f0528ee25d45c5ce6196e79b37e4c949345695e
7
- data.tar.gz: afe7dc3028c5e8e354ef2fe1d2122f8d6c6488e724155dff0518671aab357318e837917adb39a1e2b3e2dc1f7e7ecec936a0a30af2639bad50712c83dd74b90b
6
+ metadata.gz: 1d0afb56b6c43dcebf426a2ba19d50d7b61fab35253540861cc6cc8c9272e7878f28e425c6242fa4e9a40e4aeae61641b9691598114e7e8cd449dab7d757200f
7
+ data.tar.gz: 0294543c875ef3e3641ca7fa2adacbb8329b2274caf1f2e9dbe82d59d56993fd6a7dbd0937358159350108c5a8bafd1e7967edeed3eb176154f259ae15427880
@@ -6,17 +6,7 @@ module Fastlane
6
6
  params[:paths] = [params[:paths]]
7
7
  end
8
8
 
9
- image_names = []
10
- params[:paths].each do |path|
11
- path_arr = Dir["#{FastlaneCore::FastlaneFolder.path}../#{path}/**/*.imageset"].each do |image_path|
12
- path_arr = image_path.split('/')
13
- image_name = path_arr[path_arr.length - 1].sub('.imageset', '')
14
- if image_names.include?(image_name)
15
- raise "'#{image_name}' is a duplicate".red
16
- end
17
- image_names << image_name
18
- end
19
- end
9
+ image_names = Helper::StaticAssetsHelper.fetch_images(params[:paths]).keys
20
10
  output_path = "#{FastlaneCore::FastlaneFolder.path}/../#{params[:output]}"
21
11
  FileUtils.mkdir_p(File.dirname(output_path))
22
12
  file = open(output_path, 'w')
@@ -27,24 +17,19 @@ module Fastlane
27
17
  sanitized_image_name = sanitize_name(image_name)
28
18
  file.write("\tpublic static UIImage #{sanitized_image_name} { get { return UIImage.FromBundle(\"#{image_name}\"); } }\n")
29
19
  end
30
- file.write("}")
31
20
  else
32
21
  file.write("import UIKit\nstruct Images {\n")
33
22
 
34
23
  image_names.each do |image_name|
35
- sanitized_image_name = sanitize_name(image_name)
24
+ sanitized_image_name = Helper::StaticAssetsHelper.sanitize_name(image_name)
36
25
  file.write("\tstatic let #{sanitized_image_name} = UIImage(named:\"#{image_name}\")!\n")
37
26
  end
38
- file.write("}")
39
27
  end
28
+ file.write("}")
40
29
 
41
30
  file.close
42
31
  end
43
32
 
44
- def self.sanitize_name(name)
45
- name.tr(' ', '_')
46
- end
47
-
48
33
  def self.description
49
34
  "Generate code for buildtime-safe assignments of images."
50
35
  end
@@ -0,0 +1,93 @@
1
+ require 'find'
2
+
3
+ module Fastlane
4
+ module Actions
5
+ class UnusedImagesAction < Action
6
+ def self.run(params)
7
+ params[:paths] = [params[:paths]] unless params[:paths].kind_of?(Array)
8
+ params[:ignore] = [params[:ignore]] unless params[:ignore].kind_of?(Array)
9
+ params[:extensions] = [params[:extensions]] unless params[:extensions].kind_of?(Array)
10
+
11
+ ignore = params[:ignore].map do |i|
12
+ File.expand_path("#{FastlaneCore::FastlaneFolder.path}/../#{i}")
13
+ end
14
+
15
+ code_path = params[:code_path]
16
+ extensions = params[:extensions].join('|')
17
+
18
+ image_paths = Helper::StaticAssetsHelper.fetch_images(params[:paths])
19
+
20
+ files = Find.find("#{FastlaneCore::FastlaneFolder.path}../#{code_path}").grep(/.*#{extensions}$/)
21
+
22
+ files = files.delete_if do |file|
23
+ ignore.include?(File.expand_path(file))
24
+ end
25
+
26
+ deletable_images = image_paths.keys.reject do |image|
27
+ r = files.inject(false) do |result, file|
28
+ result || File.foreach(file).grep(/#{image}/).any?
29
+ end
30
+ r
31
+ end
32
+
33
+ if deletable_images.count == 0
34
+ UI.success "No unused images present"
35
+ else
36
+ UI.header "#{deletable_images.count} unused images:"
37
+ deletable_images.each do |image|
38
+ image_path = image_paths[image]
39
+ image_path.each do |ip|
40
+ UI.important " - removing #{ip.sub('./fastlane/../', '')}"
41
+ Helper::StaticAssetsHelper.remove_dir(ip) unless params[:dry_run] || !File.exist?(ip)
42
+ end
43
+ end
44
+ end
45
+ end
46
+
47
+ def self.available_options
48
+ [
49
+ FastlaneCore::ConfigItem.new(key: :dry_run,
50
+ env_name: "FL_IOS_IMAGE_ASSETS_UNUSED_IMAGES_DRY_RUN",
51
+ description: "Dry run - will not delete images",
52
+ default_value: false,
53
+ optional: true,
54
+ is_string: false),
55
+ FastlaneCore::ConfigItem.new(key: :paths,
56
+ env_name: 'FL_IOS_IMAGE_ASSETS_UNUSED_IMAGES_PATHS',
57
+ description: 'single path or Array of paths to image assets to convert',
58
+ is_string: false),
59
+ FastlaneCore::ConfigItem.new(key: :code_path,
60
+ env_name: 'FL_IOS_IMAGE_ASSETS_UNUSED_IMAGES_CODE_PATH',
61
+ description: 'path to check',
62
+ is_string: true),
63
+ FastlaneCore::ConfigItem.new(key: :ignore,
64
+ env_name: 'FL_IOS_IMAGE_ASSETS_UNUSED_IMAGES_CODE_IGNORE',
65
+ description: 'paths to ignore',
66
+ is_string: false),
67
+ FastlaneCore::ConfigItem.new(key: :extensions,
68
+ env_name: 'FL_IOS_IMAGE_ASSETS_UNUSED_IMAGES_EXTENSIONS',
69
+ description: '',
70
+ is_string: false)
71
+
72
+ ]
73
+ end
74
+
75
+ def self.output
76
+ [
77
+ ]
78
+ end
79
+
80
+ def self.return_value
81
+ # If you method provides a return value, you can describe here what it does
82
+ end
83
+
84
+ def self.authors
85
+ ['Krzysztof Piatkowski', 'Jakob Jensen']
86
+ end
87
+
88
+ def self.is_supported?(platform)
89
+ [:ios].include? platform
90
+ end
91
+ end
92
+ end
93
+ end
@@ -1,11 +1,38 @@
1
1
  module Fastlane
2
2
  module Helper
3
3
  class StaticAssetsHelper
4
- # class methods that you define here become available in your action
5
- # as `Helper::StaticAssetsHelper.your_method`
6
- #
7
- def self.show_message
8
- UI.message("Hello from the static_assets plugin helper!")
4
+ def self.fetch_images(paths)
5
+ image = {}
6
+ paths.each do |path|
7
+ path_arr = Dir["#{FastlaneCore::FastlaneFolder.path}../#{path}/**/*.imageset"].each do |image_path|
8
+ path = image_path.sub('.imageset', '')
9
+ path_arr = path.split('/')
10
+ image_name = path_arr[path_arr.length - 1]
11
+
12
+ key = self.sanitize_name(image_name)
13
+ image[key] ||= []
14
+
15
+ image[key] << image_path
16
+ end
17
+ end
18
+ image
19
+ end
20
+
21
+ def self.sanitize_name(name)
22
+ name.tr(' ', '_')
23
+ end
24
+
25
+ def self.remove_dir(path)
26
+ if File.directory?(path)
27
+ Dir.foreach(path) do |file|
28
+ if (file.to_s != ".") and (file.to_s != "..")
29
+ remove_dir("#{path}/#{file}")
30
+ end
31
+ end
32
+ Dir.delete(path)
33
+ else
34
+ File.delete(path)
35
+ end
9
36
  end
10
37
  end
11
38
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module StaticAssets
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-static_assets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Jensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-20 00:00:00.000000000 Z
11
+ date: 2017-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -101,12 +101,13 @@ extensions: []
101
101
  extra_rdoc_files: []
102
102
  files:
103
103
  - lib/fastlane/plugin/static_assets/actions/static_images_action.rb
104
+ - lib/fastlane/plugin/static_assets/actions/unused_images_action.rb
104
105
  - lib/fastlane/plugin/static_assets/helper/static_assets_helper.rb
105
106
  - lib/fastlane/plugin/static_assets/version.rb
106
107
  - lib/fastlane/plugin/static_assets.rb
107
108
  - README.md
108
109
  - LICENSE
109
- homepage:
110
+ homepage: https://github.com/trifork/fastlane-plugin-static_assets
110
111
  licenses:
111
112
  - MIT
112
113
  metadata: {}