Class: Pod::Command::Spec::Create
- Inherits:
-
Pod::Command::Spec
- Object
- CLAide::Command
- Pod::Command
- Pod::Command::Spec
- Pod::Command::Spec::Create
- Defined in:
- lib/cocoapods/command/spec/create.rb
Instance Method Summary collapse
-
#default_data_for_template(name) ⇒ Object
private
Templates and GitHub information retrieval for spec create.
- #github_data_for_template(repo_id) ⇒ Object private
-
#initialize(argv) ⇒ Create
constructor
A new instance of Create.
- #run ⇒ Object
- #semantic_versioning_notice(repo_id, repo) ⇒ Object private
- #spec_template(data) ⇒ Object private
- #suggested_ref_and_version(repo) ⇒ Object private
- #validate! ⇒ Object
Methods inherited from Pod::Command::Spec
#all_paths_from_set, #get_path_of_spec, #pathname_from_spec, #spec_and_source_from_set, #validate_regex!
Methods inherited from Pod::Command
#ensure_master_spec_repo_exists!, ensure_not_root_or_allowed!, git_version, #installer_for_config, options, report_error, run, #verify_lockfile_exists!, verify_minimum_git_version!, #verify_podfile_exists!, verify_xcode_license_approved!
Methods included from Pod::Config::Mixin
Constructor Details
#initialize(argv) ⇒ Create
Returns a new instance of Create.
17 18 19 20 21 |
# File 'lib/cocoapods/command/spec/create.rb', line 17 def initialize(argv) @name_or_url = argv.shift_argument @url = argv.shift_argument super end |
Instance Method Details
#default_data_for_template(name) ⇒ Object (private)
TODO:
It would be nice to have a template class that accepts options and uses the default ones if not provided.
TODO:
The template is outdated.
Templates and GitHub information retrieval for spec create
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cocoapods/command/spec/create.rb', line 53 def default_data_for_template(name) { :name => name, :version => '0.0.1', :summary => "A short description of #{name}.", :homepage => "http://EXAMPLE/#{name}", :author_name => Executable.capture_command('git', %w(config --get user.name), :capture => :out).first.strip, :author_email => Executable.capture_command('git', %w(config --get user.email), :capture => :out).first.strip, :source_url => "http://EXAMPLE/#{name}.git", :ref_type => ':tag', :ref => '#{spec.version}', } end |
#github_data_for_template(repo_id) ⇒ Object (private)
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cocoapods/command/spec/create.rb', line 67 def github_data_for_template(repo_id) repo = GitHub.repo(repo_id) raise Informative, "Unable to fetch data for `#{repo_id}`" unless repo user = GitHub.user(repo['owner']['login']) raise Informative, "Unable to fetch data for `#{repo['owner']['login']}`" unless user data = {} data[:name] = repo['name'] data[:summary] = (repo['description'] || '').gsub(/["]/, '\"') data[:homepage] = (repo['homepage'] && !repo['homepage'].empty?) ? repo['homepage'] : repo['html_url'] data[:author_name] = user['name'] || user['login'] data[:author_email] = user['email'] || '[email protected]' data[:source_url] = repo['clone_url'] data.merge suggested_ref_and_version(repo) end |
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/cocoapods/command/spec/create.rb', line 28 def run if repo_id_match = (@url || @name_or_url).match(%r{github.com/([^/\.]*\/[^/\.]*)\.*}) repo_id = repo_id_match[1] data = github_data_for_template(repo_id) data[:name] = @name_or_url if @url UI.puts semantic_versioning_notice(repo_id, data[:name]) if data[:version] == '0.0.1' else data = default_data_for_template(@name_or_url) end spec = spec_template(data) (Pathname.pwd + "#{data[:name]}.podspec").open('w') { |f| f << spec } UI.puts "\nSpecification created at #{data[:name]}.podspec".green end |
#semantic_versioning_notice(repo_id, repo) ⇒ Object (private)
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/cocoapods/command/spec/create.rb', line 252 def semantic_versioning_notice(repo_id, repo) "\n\#{'\u2015\u2015\u2015 MARKDOWN TEMPLATE \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015'.reversed}\n\nI\u2019ve recently added [\#{repo}](https://github.com/CocoaPods/Specs/tree/master/\#{repo}) to the [CocoaPods](https://github.com/CocoaPods/CocoaPods) package manager repo.\n\nCocoaPods is a tool for managing dependencies for OSX and iOS Xcode projects and provides a central repository for iOS/OSX libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.\n\nHowever, \#{repo} doesn't have any version tags. I\u2019ve added the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.\n\n[Semantic version](https://semver.org) tags (instead of plain commit hashes/revisions) allow for [resolution of cross-dependencies](https://github.com/CocoaPods/Specs/wiki/Cross-dependencies-resolution-example).\n\nIn case you didn\u2019t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:\n\n```\n$ git tag -a 1.0.0 -m \"Tag release 1.0.0\"\n$ git push --tags\n```\n\n\#{'\u2015\u2015\u2015 TEMPLATE END \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015'.reversed}\n\n\#{'[!] This repo does not appear to have semantic version tags.'.yellow}\n\nAfter commiting the specification, consider opening a ticket with the template displayed above:\n - link: https://github.com/\#{repo_id}/issues/new\n - title: Please add semantic version tags\n EOS\nend\n" |
#spec_template(data) ⇒ Object (private)
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/cocoapods/command/spec/create.rb', line 109 def spec_template(data) "#\n# Be sure to run `pod spec lint \#{data[:name]}.podspec' to ensure this is a\n# valid spec and to remove all comments including this before submitting the spec.\n#\n# To learn more about Podspec attributes see https://guides.cocoapods.org/syntax/podspec.html\n# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/\n#\n\nPod::Spec.new do |spec|\n\n # \u2015\u2015\u2015 Spec Metadata \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015 #\n #\n # These will help people to find your library, and whilst it\n # can feel like a chore to fill in it's definitely to your advantage. The\n # summary should be tweet-length, and the description more in depth.\n #\n\n spec.name = \"\#{data[:name]}\"\n spec.version = \"\#{data[:version]}\"\n spec.summary = \"\#{data[:summary]}\"\n\n # This description is used to generate tags and improve search results.\n # * Think: What does it do? Why did you write it? What is the focus?\n # * Try to keep it short, snappy and to the point.\n # * Write the description between the DESC delimiters below.\n # * Finally, don't worry about the indent, CocoaPods strips it!\n spec.description = <<-DESC\n DESC\n\n spec.homepage = \"\#{data[:homepage]}\"\n # spec.screenshots = \"www.example.com/screenshots_1.gif\", \"www.example.com/screenshots_2.gif\"\n\n\n # \u2015\u2015\u2015 Spec License \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015 #\n #\n # Licensing your code is important. See https://choosealicense.com for more info.\n # CocoaPods will detect a license file if there is a named LICENSE*\n # Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.\n #\n\n spec.license = \"MIT (example)\"\n # spec.license = { :type => \"MIT\", :file => \"FILE_LICENSE\" }\n\n\n # \u2015\u2015\u2015 Author Metadata \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015 #\n #\n # Specify the authors of the library, with email addresses. Email addresses\n # of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also\n # accepts just a name if you'd rather not provide an email address.\n #\n # Specify a social_media_url where others can refer to, for example a twitter\n # profile URL.\n #\n\n spec.author = { \"\#{data[:author_name]}\" => \"\#{data[:author_email]}\" }\n # Or just: spec.author = \"\#{data[:author_name]}\"\n # spec.authors = { \"\#{data[:author_name]}\" => \"\#{data[:author_email]}\" }\n # spec.social_media_url = \"https://twitter.com/\#{data[:author_name]}\"\n\n # \u2015\u2015\u2015 Platform Specifics \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015 #\n #\n # If this Pod runs only on iOS or OS X, then specify the platform and\n # the deployment target. You can optionally include the target after the platform.\n #\n\n # spec.platform = :ios\n # spec.platform = :ios, \"5.0\"\n\n # When using multiple platforms\n # spec.ios.deployment_target = \"5.0\"\n # spec.osx.deployment_target = \"10.7\"\n # spec.watchos.deployment_target = \"2.0\"\n # spec.tvos.deployment_target = \"9.0\"\n # spec.visionos.deployment_target = \"1.0\"\n\n\n # \u2015\u2015\u2015 Source Location \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015 #\n #\n # Specify the location from where the source should be retrieved.\n # Supports git, hg, bzr, svn and HTTP.\n #\n\n spec.source = { :git => \"\#{data[:source_url]}\", \#{data[:ref_type]} => \"\#{data[:ref]}\" }\n\n\n # \u2015\u2015\u2015 Source Code \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015 #\n #\n # CocoaPods is smart about how it includes source code. For source files\n # giving a folder will include any swift, h, m, mm, c & cpp files.\n # For header files it will include any header in the folder.\n # Not including the public_header_files will make all headers public.\n #\n\n spec.source_files = \"Classes\", \"Classes/**/*.{h,m}\"\n spec.exclude_files = \"Classes/Exclude\"\n\n # spec.public_header_files = \"Classes/**/*.h\"\n\n\n # \u2015\u2015\u2015 Resources \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015 #\n #\n # A list of resources included with the Pod. These are copied into the\n # target bundle with a build phase script. Anything else will be cleaned.\n # You can preserve files from being cleaned, please don't preserve\n # non-essential files like tests, examples and documentation.\n #\n\n # spec.resource = \"icon.png\"\n # spec.resources = \"Resources/*.png\"\n\n # spec.preserve_paths = \"FilesToSave\", \"MoreFilesToSave\"\n\n\n # \u2015\u2015\u2015 Project Linking \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015 #\n #\n # Link your library with frameworks, or libraries. Libraries do not include\n # the lib prefix of their name.\n #\n\n # spec.framework = \"SomeFramework\"\n # spec.frameworks = \"SomeFramework\", \"AnotherFramework\"\n\n # spec.library = \"iconv\"\n # spec.libraries = \"iconv\", \"xml2\"\n\n\n # \u2015\u2015\u2015 Project Settings \u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015\u2015 #\n #\n # If your library depends on compiler flags you can set them in the xcconfig hash\n # where they will only apply to your library. If you depend on other Podspecs\n # you can include multiple dependencies to ensure it works.\n\n # spec.requires_arc = true\n\n # spec.xcconfig = { \"HEADER_SEARCH_PATHS\" => \"$(SDKROOT)/usr/include/libxml2\" }\n # spec.dependency \"JSONKit\", \"~> 1.4\"\n\nend\n SPEC\nend\n" |
#suggested_ref_and_version(repo) ⇒ Object (private)
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/cocoapods/command/spec/create.rb', line 84 def suggested_ref_and_version(repo) = GitHub.(repo['html_url']).map { |tag| tag['name'] } = {} .each do |tag| clean_tag = tag.gsub(/^v(er)? ?/, '') [Gem::Version.new(clean_tag)] = tag if Gem::Version.correct?(clean_tag) end version = .keys.sort.last || '0.0.1' data = { :version => version } if version == '0.0.1' branches = GitHub.branches(repo['html_url']) master_name = repo['master_branch'] || 'master' master = branches.find { |branch| branch['name'] == master_name } raise Informative, "Unable to find any commits on the master branch for the repository `#{repo['html_url']}`" unless master data[:ref_type] = ':commit' data[:ref] = master['commit']['sha'] else data[:ref_type] = ':tag' data[:ref] = [version] data[:ref] = '#{spec.version}' if "#{version}" == [version] data[:ref] = 'v#{spec.version}' if "v#{version}" == [version] end data end |
#validate! ⇒ Object
23 24 25 26 |
# File 'lib/cocoapods/command/spec/create.rb', line 23 def validate! super help! 'A pod name or repo URL is required.' unless @name_or_url end |