cocoapods-prune-localizations 0.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 +7 -0
- data/.gitignore +3 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +15 -0
- data/Rakefile +13 -0
- data/cocoapods-prune-localizations.gemspec +23 -0
- data/lib/cocoapods-prune-localizations.rb +3 -0
- data/lib/cocoapods_plugin.rb +6 -0
- data/lib/pruner.rb +148 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1772c80903e5f7a17d9c618d51a0096d185092af
|
4
|
+
data.tar.gz: 1f7741bef9920363de9faa52be1398f0d9824b18
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1437df160da25f7ee1c5d2e33bee4924b6006d08ed0eceb4815d2886dfad0da1acb80ec1fc8f50224301faa62e3f6a8b2fb000d59337cc0e24ee6a6c1f077184
|
7
|
+
data.tar.gz: 817f33cc8a346541b72ebe92c72b24a369d0d6fe4a616a0ae794ad26fbd97f80e0e1fbab36b7bf7eb95b346cadec3a52a28b9c6683857a6eb066ea33069aee05
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Diego Torres <contact@dtorres.me>
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# cocoapods-prune-localizations
|
2
|
+
|
3
|
+
This plugin allows you to remove unused localizations provided by the Pods you depend on.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install cocoapods-prune-localizations
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
In your Podfile, add this line:
|
12
|
+
|
13
|
+
plugin 'cocoapods-prune-localizations', {:localizations => ["en.lproj", "es.lproj"]}
|
14
|
+
|
15
|
+
This will keep the English and Spanish localizations in the Pods. Modify the localizations to your needs.
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cocoapods-prune-localizations.rb'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "cocoapods-prune-localizations"
|
8
|
+
spec.version = CocoapodsPruneLocalizations::VERSION
|
9
|
+
spec.authors = ["Diego Torres"]
|
10
|
+
spec.email = ["contact@dtorres.me"]
|
11
|
+
spec.description = %q{Remove unused localizations from your app}
|
12
|
+
spec.summary = %q{Upon running pod install, this plugin will remove unused localizations by your project}
|
13
|
+
spec.homepage = "https://github.com/dtorres/cocoapods-prune-localizations"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/pruner.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
require "FileUtils"
|
2
|
+
|
3
|
+
module CocoapodsPruneLocalizations
|
4
|
+
class Pruner
|
5
|
+
def initialize(context, user_options)
|
6
|
+
@sandbox_root = Pathname.new context.sandbox_root
|
7
|
+
@pod_project = Xcodeproj::Project.open File.join(context.sandbox_root, 'Pods.xcodeproj')
|
8
|
+
@user_options = user_options
|
9
|
+
@pruned_bundles_path = File.join(context.sandbox_root, "Pruned Localized Bundles")
|
10
|
+
FileUtils.mkdir @pruned_bundles_path unless Dir.exist? @pruned_bundles_path
|
11
|
+
end
|
12
|
+
|
13
|
+
def resources_scripts(group)
|
14
|
+
file_references = []
|
15
|
+
group.children.objects.each do |children|
|
16
|
+
if children.class == Xcodeproj::Project::Object::PBXFileReference && children.path.end_with?("resources.sh")
|
17
|
+
file_references << children
|
18
|
+
elsif children.class == Xcodeproj::Project::Object::PBXGroup
|
19
|
+
file_references.concat(self.resources_scripts(children))
|
20
|
+
end
|
21
|
+
end
|
22
|
+
file_references
|
23
|
+
end
|
24
|
+
|
25
|
+
def prune!
|
26
|
+
rsrc_scripts_files = Hash.new
|
27
|
+
self.resources_scripts(@pod_project["Targets Support Files"]).each do |file|
|
28
|
+
rsrc_scripts_files[file] = File.readlines(file.real_path)
|
29
|
+
end
|
30
|
+
|
31
|
+
langs_to_keep = @user_options["localizations"] || []
|
32
|
+
Pod::UI.section 'Pruning unused localizations' do
|
33
|
+
pod_groups = @pod_project["Pods"].children.objects
|
34
|
+
dev_pod_group = @pod_project["Development Pods"]
|
35
|
+
pod_groups += dev_pod_group.children.objects if dev_pod_group
|
36
|
+
pod_groups.each do |group|
|
37
|
+
resGroup = group["Resources"]
|
38
|
+
next unless resGroup
|
39
|
+
|
40
|
+
markForRemoval = []
|
41
|
+
trimmedBundlesToAdd = Hash.new
|
42
|
+
resGroup.files.each do |file|
|
43
|
+
keep = true
|
44
|
+
if file.path.end_with? ".lproj"
|
45
|
+
keep = langs_to_keep.include?(File.basename(file.path))
|
46
|
+
elsif file.path.end_with? ".bundle"
|
47
|
+
trimmed_bundle = self.trimmed_bundle(file.real_path)
|
48
|
+
if trimmed_bundle
|
49
|
+
trimmedBundlesToAdd[file.real_path] = trimmed_bundle
|
50
|
+
keep = false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
if !keep
|
54
|
+
markForRemoval << file
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
if markForRemoval.length > 0
|
59
|
+
Pod::UI.section "Pruning in #{group.path}" do
|
60
|
+
markForRemoval.each do |file|
|
61
|
+
Pod::UI.message "Pruning #{file}"
|
62
|
+
|
63
|
+
unless file.path.end_with? ".bundle"
|
64
|
+
relative_path = file.real_path.relative_path_from @sandbox_root
|
65
|
+
rsrc_scripts_files.each_value do |lines|
|
66
|
+
for i in 0...lines.length
|
67
|
+
line = lines[i]
|
68
|
+
if line.include?(relative_path.to_s)
|
69
|
+
lines[i] = ""
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
file.remove_from_project
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
if trimmedBundlesToAdd.length > 0
|
80
|
+
group_path = File.join(@pruned_bundles_path, group.path)
|
81
|
+
FileUtils.mkdir group_path unless Dir.exist? group_path
|
82
|
+
Pod::UI.message "Adding trimmed bundles to #{group.path}" do
|
83
|
+
trimmedBundlesToAdd.each_pair do |original_bundle_path, bundle_path|
|
84
|
+
bundle_name = File.basename(original_bundle_path)
|
85
|
+
new_bundle_path = File.join(group_path, bundle_name)
|
86
|
+
FileUtils.rm_r(new_bundle_path) if File.exist? new_bundle_path
|
87
|
+
FileUtils.mv(bundle_path, new_bundle_path)
|
88
|
+
group.new_reference(new_bundle_path)
|
89
|
+
|
90
|
+
relative_path = original_bundle_path.relative_path_from(@sandbox_root).to_s
|
91
|
+
new_relative_path = Pathname.new(new_bundle_path).relative_path_from(@sandbox_root).to_s
|
92
|
+
rsrc_scripts_files.each_value do |lines|
|
93
|
+
for i in 0...lines.length
|
94
|
+
lines[i] = lines[i].gsub(relative_path, new_relative_path)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
rsrc_scripts_files.each_pair do |file, lines|
|
104
|
+
fd = File.open(file.real_path, "w")
|
105
|
+
lines.each do |line|
|
106
|
+
fd.puts line unless (line == "")
|
107
|
+
end
|
108
|
+
fd.close
|
109
|
+
end
|
110
|
+
@pod_project.save
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def trimmed_bundle(bundle_path)
|
115
|
+
langs_to_keep = @user_options["localizations"] || []
|
116
|
+
return unless Dir.exist? bundle_path
|
117
|
+
tmp_dir = Dir.mktmpdir
|
118
|
+
changed_bundle = false
|
119
|
+
Dir.foreach(bundle_path) do |file_name|
|
120
|
+
if (file_name == "." || file_name == "..")
|
121
|
+
next
|
122
|
+
end
|
123
|
+
|
124
|
+
absolute_file_path = File.join(bundle_path, file_name)
|
125
|
+
if file_name.end_with? ".lproj"
|
126
|
+
if langs_to_keep.include?(file_name)
|
127
|
+
FileUtils.cp_r(absolute_file_path, tmp_dir)
|
128
|
+
else
|
129
|
+
changed_bundle = true
|
130
|
+
end
|
131
|
+
elsif file_name.end_with? ".bundle"
|
132
|
+
sub_trimmed_bundle = self.trimmed_bundle(absolute_file_path)
|
133
|
+
if sub_trimmed_bundle
|
134
|
+
sub_bundle_path = File.join(tmp_dir, file_name)
|
135
|
+
FileUtils.mv(sub_trimmed_bundle, sub_bundle_path)
|
136
|
+
changed_bundle = true
|
137
|
+
else
|
138
|
+
FileUtils.cp_r(absolute_file_path, tmp_dir)
|
139
|
+
end
|
140
|
+
else
|
141
|
+
FileUtils.cp_r(absolute_file_path, tmp_dir)
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
tmp_dir if changed_bundle
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cocoapods-prune-localizations
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Diego Torres
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Remove unused localizations from your app
|
42
|
+
email:
|
43
|
+
- contact@dtorres.me
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- cocoapods-prune-localizations.gemspec
|
54
|
+
- lib/cocoapods-prune-localizations.rb
|
55
|
+
- lib/cocoapods_plugin.rb
|
56
|
+
- lib/pruner.rb
|
57
|
+
homepage: https://github.com/dtorres/cocoapods-prune-localizations
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.4.4
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Upon running pod install, this plugin will remove unused localizations by
|
81
|
+
your project
|
82
|
+
test_files: []
|