fastlane-plugin-pod_spec_generator 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +52 -0
- data/lib/cocoapods/pod_file_extension.rb +113 -0
- data/lib/cocoapods/pod_specification_extension.rb +18 -0
- data/lib/cocoapods_plugin.rb +3 -0
- data/lib/fastlane/plugin/pod_spec_generator/actions/pod_file_generator_action.rb +64 -0
- data/lib/fastlane/plugin/pod_spec_generator/actions/pod_spec_generator_action.rb +131 -0
- data/lib/fastlane/plugin/pod_spec_generator/helper/pod_file_builder.rb +52 -0
- data/lib/fastlane/plugin/pod_spec_generator/helper/pod_spec_builder.rb +128 -0
- data/lib/fastlane/plugin/pod_spec_generator/helper/pod_spec_generator_helper.rb +14 -0
- data/lib/fastlane/plugin/pod_spec_generator/version.rb +5 -0
- data/lib/fastlane/plugin/pod_spec_generator.rb +16 -0
- metadata +69 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 030c121fb95de7ecb68b24fb7fb7de91c087548d9bce3e0d1e3019c2b7cb8585
|
4
|
+
data.tar.gz: 1b1fed0b388162b44d9ea9730a632aacaf1efdd284f2a8ed23f55be5b5449fcb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc85d77599f2aae2f7086b678c5ae9d53511e7edd3e8c725eb3e7f4d30303a526334c01bf8f0e04789f947fd5a0d61377c784b0379a22887a7a94d4d28070106
|
7
|
+
data.tar.gz: 21f9cddf3181a6816b68d9bf31ba67479a66ddc5abfbf6c88350f44f71a4525b2f4e355ea1c6c061566dad3d665dc86a0855a9a923f38d8180409e7799bd31c7
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Alex Crowe <alexei.hmelevski@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# pod_spec_generator plugin
|
2
|
+
|
3
|
+
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-pod_spec_generator)
|
4
|
+
|
5
|
+
## Getting Started
|
6
|
+
|
7
|
+
This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-pod_spec_generator`, add it to your project by running:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
fastlane add_plugin pod_spec_generator
|
11
|
+
```
|
12
|
+
|
13
|
+
## About pod_spec_generator
|
14
|
+
|
15
|
+
Generate a simple pod spec for CI automation
|
16
|
+
|
17
|
+
**Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here.
|
18
|
+
|
19
|
+
## Example
|
20
|
+
|
21
|
+
Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`.
|
22
|
+
|
23
|
+
**Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary)
|
24
|
+
|
25
|
+
## Run tests for this plugin
|
26
|
+
|
27
|
+
To run both the tests, and code style validation, run
|
28
|
+
|
29
|
+
```
|
30
|
+
rake
|
31
|
+
```
|
32
|
+
|
33
|
+
To automatically fix many of the styling issues, use
|
34
|
+
```
|
35
|
+
rubocop -a
|
36
|
+
```
|
37
|
+
|
38
|
+
## Issues and Feedback
|
39
|
+
|
40
|
+
For any other issues and feedback about this plugin, please submit it to this repository.
|
41
|
+
|
42
|
+
## Troubleshooting
|
43
|
+
|
44
|
+
If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
|
45
|
+
|
46
|
+
## Using _fastlane_ Plugins
|
47
|
+
|
48
|
+
For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
|
49
|
+
|
50
|
+
## About _fastlane_
|
51
|
+
|
52
|
+
_fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'cocoapods'
|
3
|
+
|
4
|
+
class Pod::Podfile
|
5
|
+
alias original_post_install! post_install!
|
6
|
+
def post_install!(installer)
|
7
|
+
puts "post_install! #{self}"
|
8
|
+
project = installer.pods_project
|
9
|
+
clean_spm_dependencies_from_target(project)
|
10
|
+
install_remote_spm_dependencies(project)
|
11
|
+
install_local_spm_dependencies(project)
|
12
|
+
run_swift_fix_for_project(project)
|
13
|
+
original_post_install!(installer)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def add_local_spm_to_target(project, target, path, products)
|
18
|
+
loc_pkg_class = Xcodeproj::Project::Object::XCLocalSwiftPackageReference
|
19
|
+
ref_class = Xcodeproj::Project::Object::XCSwiftPackageProductDependency
|
20
|
+
pkg = project.root_object.package_references.find { |p| p.class == loc_pkg_class && p.path == path }
|
21
|
+
|
22
|
+
unless pkg
|
23
|
+
pkg = project.new(loc_pkg_class)
|
24
|
+
pkg.relative_path = path
|
25
|
+
project.root_object.package_references << pkg
|
26
|
+
end
|
27
|
+
products.each do |product_name|
|
28
|
+
ref = target.package_product_dependencies.find do |r|
|
29
|
+
r.class == ref_class && r.package == pkg && r.product_name == product_name
|
30
|
+
end
|
31
|
+
next if ref
|
32
|
+
|
33
|
+
ref = project.new(ref_class)
|
34
|
+
ref.package = pkg
|
35
|
+
ref.product_name = product_name
|
36
|
+
target.package_product_dependencies << ref
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_spm_to_target(project, target, url, requirement, products)
|
41
|
+
pkg_class = Xcodeproj::Project::Object::XCRemoteSwiftPackageReference
|
42
|
+
ref_class = Xcodeproj::Project::Object::XCSwiftPackageProductDependency
|
43
|
+
pkg = project.root_object.package_references.find { |p| p.class == pkg_class && p.repositoryURL == url }
|
44
|
+
|
45
|
+
if !pkg
|
46
|
+
pkg = project.new(pkg_class)
|
47
|
+
pkg.repositoryURL = url
|
48
|
+
pkg.requirement = requirement
|
49
|
+
project.root_object.package_references << pkg
|
50
|
+
end
|
51
|
+
products.each do |product_name|
|
52
|
+
ref = target.package_product_dependencies.find do |r|
|
53
|
+
r.class == ref_class && r.package == pkg && r.product_name == product_name
|
54
|
+
end
|
55
|
+
next if ref
|
56
|
+
|
57
|
+
ref = project.new(ref_class)
|
58
|
+
ref.package = pkg
|
59
|
+
ref.product_name = product_name
|
60
|
+
target.package_product_dependencies << ref
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def clean_spm_dependencies_from_target(project)
|
65
|
+
project.root_object.package_references.delete_if { |pkg| pkg.class == Xcodeproj::Project::Object::XCRemoteSwiftPackageReference }
|
66
|
+
end
|
67
|
+
|
68
|
+
def install_local_spm_dependencies(project)
|
69
|
+
puts "installing local dependencies"
|
70
|
+
Pod::Specification::LOCAL_SPM_DEPENDENCIES_BY_POD.each do |pod_name, dependencies|
|
71
|
+
dependencies.each do |spm_spec|
|
72
|
+
puts "installing #{spm_spec[:path]}, #{spm_spec[:products]}"
|
73
|
+
add_local_spm_to_target(
|
74
|
+
project,
|
75
|
+
project.targets.find { |t| t.name == pod_name},
|
76
|
+
spm_spec[:path],
|
77
|
+
spm_spec[:products]
|
78
|
+
)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def install_remote_spm_dependencies(project)
|
84
|
+
Pod::Specification::SPM_DEPENDENCIES_BY_POD.each do |pod_name, dependencies|
|
85
|
+
dependencies.each do |spm_spec|
|
86
|
+
add_spm_to_target(
|
87
|
+
project,
|
88
|
+
project.targets.find { |t| t.name == pod_name},
|
89
|
+
spm_spec[:url],
|
90
|
+
spm_spec[:requirement],
|
91
|
+
spm_spec[:products]
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def run_swift_fix_for_project(project)
|
98
|
+
Pod::Specification::LOCAL_SPM_DEPENDENCIES_BY_POD.merge(Pod::Specification::SPM_DEPENDENCIES_BY_POD).each do |pod_name, dependencies|
|
99
|
+
target = project.targets.find { |t| t.name == pod_name}
|
100
|
+
target.build_configurations.each do |config|
|
101
|
+
target.build_settings(config.name)['SWIFT_INCLUDE_PATHS'] ||= ['$(inherited)']
|
102
|
+
search_path = '${SYMROOT}/${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}/'
|
103
|
+
unless target.build_settings(config.name)['SWIFT_INCLUDE_PATHS'].include?(search_path)
|
104
|
+
target.build_settings(config.name)['SWIFT_INCLUDE_PATHS'].push(search_path)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# class Pod::Podfile
|
112
|
+
# prepend PodFileExtension
|
113
|
+
# end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'cocoapods'
|
3
|
+
class Pod::Specification
|
4
|
+
SPM_DEPENDENCIES_BY_POD = {}
|
5
|
+
LOCAL_SPM_DEPENDENCIES_BY_POD = {}
|
6
|
+
def spm_dependency(url:, requirement:, products:)
|
7
|
+
@spm_dependencies ||= []
|
8
|
+
@spm_dependencies << { url: url, requirement: requirement, products: products }
|
9
|
+
SPM_DEPENDENCIES_BY_POD[self.name] = @spm_dependencies
|
10
|
+
end
|
11
|
+
|
12
|
+
def local_spm_dependency(path:, products:)
|
13
|
+
puts "local dependency #{path}"
|
14
|
+
@local_spm_dependencies ||= []
|
15
|
+
@local_spm_dependencies << { path: path, products: products}
|
16
|
+
LOCAL_SPM_DEPENDENCIES_BY_POD[self.name] = @local_spm_dependencies
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/pod_file_builder'
|
3
|
+
module Fastlane
|
4
|
+
module Actions
|
5
|
+
|
6
|
+
class PodFileGeneratorAction < Action
|
7
|
+
|
8
|
+
def self.run(params)
|
9
|
+
builder = PodFileBuilder.new
|
10
|
+
builder.apply_local_spm_fix = params[:apply_local_spm_fix] ? true : false
|
11
|
+
builder.targets = params[:targets]
|
12
|
+
builder.use_frameworks = params[:use_frameworks] ? true : false
|
13
|
+
output = builder.build_pod_file_string
|
14
|
+
File.write("#{params[:folder]}/Podfile", output)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.description
|
19
|
+
"Generate a simple pod spec for CI automation"
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.authors
|
23
|
+
["Swift Gurus / Alex Crowe"]
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.return_value
|
27
|
+
# If your method provides a return value, you can describe here what it does
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.details
|
31
|
+
"Generate a simple pod file for CI automation, local and prod specs"
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.available_options
|
35
|
+
[
|
36
|
+
FastlaneCore::ConfigItem.new(key: :use_frameworks,
|
37
|
+
env_name: "POD_FILE_GENERATOR_VERSION",
|
38
|
+
description: "Version String",
|
39
|
+
default_value: true,
|
40
|
+
optional: true),
|
41
|
+
FastlaneCore::ConfigItem.new(key: :apply_local_spm_fix,
|
42
|
+
env_name: "POD_LOCAL_SPM",
|
43
|
+
description: "Use local spm",
|
44
|
+
optional: true,
|
45
|
+
type: String),
|
46
|
+
FastlaneCore::ConfigItem.new(key: :targets,
|
47
|
+
description: "Targets",
|
48
|
+
optional: false,
|
49
|
+
type: Array),
|
50
|
+
FastlaneCore::ConfigItem.new(key: :folder,
|
51
|
+
env_name: "POD_FILE_GENERATOR_FOLDER",
|
52
|
+
description: "Folder for the file String",
|
53
|
+
optional: false,
|
54
|
+
type: String)
|
55
|
+
|
56
|
+
]
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.is_supported?(platform)
|
60
|
+
[:ios, :mac].include?(platform)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'fastlane/action'
|
2
|
+
require_relative '../helper/pod_spec_builder'
|
3
|
+
|
4
|
+
module Fastlane
|
5
|
+
module Actions
|
6
|
+
|
7
|
+
class PodSpecGeneratorAction < Action
|
8
|
+
|
9
|
+
def self.run(params)
|
10
|
+
builder = PodSpecBuilder.new
|
11
|
+
builder.author = params[:author]
|
12
|
+
builder.version = params[:version]
|
13
|
+
builder.summary = params[:summary]
|
14
|
+
builder.name = params[:name]
|
15
|
+
builder.description = params[:description]
|
16
|
+
builder.homepage = params[:homepage]
|
17
|
+
builder.license = params[:license]
|
18
|
+
(params[:dependencies]).each do |dep|
|
19
|
+
builder.add_dependency(dep[:name], dep[:version])
|
20
|
+
end
|
21
|
+
builder.source = params[:source]
|
22
|
+
builder.source_files = params[:source_files]
|
23
|
+
builder.swift_version = params[:swift_version]
|
24
|
+
builder.spm_local_dependencies = params[:spm_local_dependencies]
|
25
|
+
builder.platform = params[:platform].reduce([]) do |content, pair|
|
26
|
+
content += pair
|
27
|
+
end
|
28
|
+
|
29
|
+
output = builder.build_pod_spec_string
|
30
|
+
File.write("#{params[:folder]}/#{params[:name]}.podspec", output)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.description
|
35
|
+
"Generate a simple pod spec for CI automation"
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.authors
|
39
|
+
["Swift Gurus / Alex Crowe"]
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.return_value
|
43
|
+
# If your method provides a return value, you can describe here what it does
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.details
|
47
|
+
"Generate a simple pod spec for CI automation, local and prod specs"
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.available_options
|
51
|
+
[
|
52
|
+
FastlaneCore::ConfigItem.new(key: :version,
|
53
|
+
env_name: "POD_SPEC_GENERATOR_VERSION",
|
54
|
+
description: "Version String",
|
55
|
+
optional: false,
|
56
|
+
type: String),
|
57
|
+
FastlaneCore::ConfigItem.new(key: :summary,
|
58
|
+
env_name: "POD_SPEC_GENERATOR_SUMMARY",
|
59
|
+
description: "Summary String",
|
60
|
+
optional: false,
|
61
|
+
type: String),
|
62
|
+
FastlaneCore::ConfigItem.new(key: :description,
|
63
|
+
env_name: "POD_SPEC_GENERATOR_DESCRIPTION",
|
64
|
+
description: "Description String",
|
65
|
+
optional: false,
|
66
|
+
type: String),
|
67
|
+
FastlaneCore::ConfigItem.new(key: :name,
|
68
|
+
env_name: "POD_SPEC_GENERATOR_NAME",
|
69
|
+
description: "Pod Name String",
|
70
|
+
optional: false,
|
71
|
+
type: String),
|
72
|
+
FastlaneCore::ConfigItem.new(key: :homepage,
|
73
|
+
env_name: "POD_SPEC_GENERATOR_HOMEPAGE",
|
74
|
+
description: "Homepage",
|
75
|
+
optional: false,
|
76
|
+
type: String),
|
77
|
+
FastlaneCore::ConfigItem.new(key: :license,
|
78
|
+
description: "License Object",
|
79
|
+
default_value: { type: "MIT", file: "LICENSE" },
|
80
|
+
optional: false,
|
81
|
+
type: Hash),
|
82
|
+
FastlaneCore::ConfigItem.new(key: :dependencies,
|
83
|
+
description: "Dependencies array",
|
84
|
+
default_value: [],
|
85
|
+
optional: true,
|
86
|
+
type: Array),
|
87
|
+
FastlaneCore::ConfigItem.new(key: :source,
|
88
|
+
description: "Source",
|
89
|
+
optional: true,
|
90
|
+
type: Hash),
|
91
|
+
FastlaneCore::ConfigItem.new(key: :author,
|
92
|
+
description: "Author",
|
93
|
+
optional: true,
|
94
|
+
type: Hash),
|
95
|
+
FastlaneCore::ConfigItem.new(key: :source_files,
|
96
|
+
description: "Source Files",
|
97
|
+
default_value: [],
|
98
|
+
optional: true,
|
99
|
+
type: Array),
|
100
|
+
FastlaneCore::ConfigItem.new(key: :swift_version,
|
101
|
+
env_name: "POD_SPEC_GENERATOR_SWIFT_VERSION",
|
102
|
+
description: "Source Files",
|
103
|
+
default_value: "5.9",
|
104
|
+
optional: true,
|
105
|
+
type: String),
|
106
|
+
FastlaneCore::ConfigItem.new(key: :folder,
|
107
|
+
env_name: "POD_SPEC_GENERATOR_FOLDER",
|
108
|
+
description: "Folder for the file String",
|
109
|
+
optional: false,
|
110
|
+
type: String),
|
111
|
+
FastlaneCore::ConfigItem.new(key: :platform,
|
112
|
+
env_name: "POD_SPEC_GENERATOR_PLATFORM",
|
113
|
+
description: "Platform",
|
114
|
+
default_value: {ios: "14.0"},
|
115
|
+
optional: true,
|
116
|
+
type: Hash),
|
117
|
+
FastlaneCore::ConfigItem.new(key: :spm_local_dependencies,
|
118
|
+
description: "Local spm dependencies",
|
119
|
+
default_value: [],
|
120
|
+
optional: true,
|
121
|
+
type: Array)
|
122
|
+
|
123
|
+
]
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.is_supported?(platform)
|
127
|
+
[:ios, :mac].include?(platform)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class PodFileBuilder
|
4
|
+
attr_writer :use_frameworks,
|
5
|
+
:targets,
|
6
|
+
:apply_local_spm_fix
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@use_frameworks = true
|
10
|
+
@targets = []
|
11
|
+
@apply_local_spm_fix = false
|
12
|
+
end
|
13
|
+
|
14
|
+
def build_pod_file_string
|
15
|
+
[use_frameworks_string,
|
16
|
+
apply_local_spm_fix_string,
|
17
|
+
targets_string,
|
18
|
+
].compact
|
19
|
+
.join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def targets_string
|
25
|
+
@targets.reduce("") do |str, target|
|
26
|
+
str += "#{create_target_string(target)}\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_target_string(target)
|
31
|
+
start = "target '#{target[:name]}' do"
|
32
|
+
dependencies = target[:dependencies].map do |dependency|
|
33
|
+
"\t#{create_dependencies_string(dependency)}\n"
|
34
|
+
end
|
35
|
+
[start, dependencies, "end"].join("\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
def create_dependencies_string(dependency)
|
39
|
+
start = "pod '#{dependency[:name]}'"
|
40
|
+
[start, dependency[:version]].compact.join(", ")
|
41
|
+
end
|
42
|
+
|
43
|
+
def apply_local_spm_fix_string
|
44
|
+
return "plugin 'fastlane-plugin-pod_spec_generator'" if @apply_local_spm_fix
|
45
|
+
return nil
|
46
|
+
end
|
47
|
+
def use_frameworks_string
|
48
|
+
return "use_frameworks!" if @use_frameworks
|
49
|
+
|
50
|
+
return nil
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'fastlane/actions/cocoapods'
|
3
|
+
class PodSpecBuilder
|
4
|
+
attr_writer :version,
|
5
|
+
:summary,
|
6
|
+
:author,
|
7
|
+
:license,
|
8
|
+
:description,
|
9
|
+
:homepage,
|
10
|
+
:platform,
|
11
|
+
:name,
|
12
|
+
:subspecs,
|
13
|
+
:swift_version,
|
14
|
+
:source_files,
|
15
|
+
:source,
|
16
|
+
:dependencies,
|
17
|
+
:spm_local_dependencies
|
18
|
+
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
@version = nil
|
22
|
+
@summary = nil
|
23
|
+
@author = nil
|
24
|
+
@homepage = nil
|
25
|
+
@platform = nil
|
26
|
+
@name = nil
|
27
|
+
@dependencies = []
|
28
|
+
@subscpecs = []
|
29
|
+
@source = nil
|
30
|
+
@source_files = nil
|
31
|
+
@swift_version = nil
|
32
|
+
@source_files = nil
|
33
|
+
@source = nil
|
34
|
+
@spm_local_dependencies = []
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_pod_spec_string
|
38
|
+
[start_of_spec,
|
39
|
+
podspec_content_setting_string,
|
40
|
+
generate_dependencies(@dependencies),
|
41
|
+
generate_local_spm_dependencies(@spm_local_dependencies),
|
42
|
+
end_of_spec
|
43
|
+
].reject { |s| s.empty? }.join("\n")
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_dependency(name, version = nil)
|
47
|
+
@dependencies.append({:name=>name, :version=>version})
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_subspec(name, local_files, dependencies)
|
51
|
+
@subscpecs.append({
|
52
|
+
name:,
|
53
|
+
local_files:,
|
54
|
+
dependencies:
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def podspec_content_setting_string
|
61
|
+
to_hash.sort.map do |k, v|
|
62
|
+
if v.is_a?(String)
|
63
|
+
"\ts.#{k} = '#{v}'"
|
64
|
+
else
|
65
|
+
"\ts.#{k} = #{v}"
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
.join("\n")
|
70
|
+
end
|
71
|
+
def to_hash
|
72
|
+
hash = {}
|
73
|
+
instance_variables.reject { |var| exclude(var) }
|
74
|
+
.each { |var| hash[var.to_s.delete("@")] = instance_variable_get(var) }
|
75
|
+
|
76
|
+
hash.compact.reject { |_k, v| v.empty? }
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
def exclude(variable)
|
81
|
+
%w[@subspecs @dependencies @spm_local_dependencies].include? variable.to_s
|
82
|
+
end
|
83
|
+
def content(items)
|
84
|
+
items.reject(&:empty?).reduce(String.new) do |content, item|
|
85
|
+
content += "#{item}\n"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
def subscpecs_string
|
92
|
+
@subscpecs.reduce(String.new) do |content, subscpec|
|
93
|
+
content += "#{subspec_string(subscpec)}\n"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def subspec_string(sub)
|
98
|
+
"
|
99
|
+
s.subspec '#{sub[:name]}' do |s|
|
100
|
+
#{generate_dependencies(sub[:dependencies])}
|
101
|
+
end
|
102
|
+
"
|
103
|
+
end
|
104
|
+
|
105
|
+
def generate_dependencies(dependencies)
|
106
|
+
dependencies.reduce(String.new) do |content, dep|
|
107
|
+
dependency = "\n\ts.dependency '#{dep[:name]}'"
|
108
|
+
vers = dep[:version] ? "'#{dep[:version]}'" : nil
|
109
|
+
out = [dependency, vers].compact.join(", ~>")
|
110
|
+
content += "#{out}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def generate_local_spm_dependencies(dependencies)
|
115
|
+
dependencies.reduce(String.new) do |content, dep|
|
116
|
+
dependency = "\n\ts.local_spm_dependency(path: '#{dep[:path]}', products: #{dep[:products]})"
|
117
|
+
content += "#{dependency}"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def start_of_spec
|
122
|
+
"Pod::Spec.new do |s|"
|
123
|
+
end
|
124
|
+
|
125
|
+
def end_of_spec
|
126
|
+
"end"
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'fastlane_core/ui/ui'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
UI = FastlaneCore::UI unless Fastlane.const_defined?(:UI)
|
5
|
+
|
6
|
+
module Helper
|
7
|
+
class PodSpecGeneratorHelper
|
8
|
+
|
9
|
+
def self.show_message
|
10
|
+
UI.message("Hello from the pod_spec_generator plugin helper!")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fastlane/plugin/pod_spec_generator/version'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module PodSpecGenerator
|
5
|
+
# Return all .rb files inside the "actions" and "helper" directory
|
6
|
+
def self.all_classes
|
7
|
+
Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# By default we want to import all available actions and helpers
|
13
|
+
# A plugin can contain any number of actions and plugins
|
14
|
+
Fastlane::PodSpecGenerator.all_classes.each do |current|
|
15
|
+
require current
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fastlane-plugin-pod_spec_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Crowe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: cocoapods
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description:
|
28
|
+
email: alexei.hmelevski@gmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- LICENSE
|
34
|
+
- README.md
|
35
|
+
- lib/cocoapods/pod_file_extension.rb
|
36
|
+
- lib/cocoapods/pod_specification_extension.rb
|
37
|
+
- lib/cocoapods_plugin.rb
|
38
|
+
- lib/fastlane/plugin/pod_spec_generator.rb
|
39
|
+
- lib/fastlane/plugin/pod_spec_generator/actions/pod_file_generator_action.rb
|
40
|
+
- lib/fastlane/plugin/pod_spec_generator/actions/pod_spec_generator_action.rb
|
41
|
+
- lib/fastlane/plugin/pod_spec_generator/helper/pod_file_builder.rb
|
42
|
+
- lib/fastlane/plugin/pod_spec_generator/helper/pod_spec_builder.rb
|
43
|
+
- lib/fastlane/plugin/pod_spec_generator/helper/pod_spec_generator_helper.rb
|
44
|
+
- lib/fastlane/plugin/pod_spec_generator/version.rb
|
45
|
+
homepage: https://github.com/Swift-Gurus/fastlane_pod_spec_generator
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
metadata:
|
49
|
+
rubygems_mfa_required: 'true'
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '3.0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubygems_version: 3.4.10
|
66
|
+
signing_key:
|
67
|
+
specification_version: 4
|
68
|
+
summary: Generate a simple pod spec for CI automation
|
69
|
+
test_files: []
|