Skip to content

Commit

Permalink
feat: allow specifying different path for remote sources
Browse files Browse the repository at this point in the history
  • Loading branch information
soumyamahunt committed Mar 27, 2022
1 parent db4bdb5 commit 56178ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ plugin 'cocoapods-embed-flutter'
pub 'flutter_module', :path => '../'
```

<a name="path_desc"></a>
*`:path` can be path pointing to `pubspec.yaml` or to the directory containing `pubspec.yaml` or to the directory containg flutter module.*

### Embedding module from a repository.
Expand All @@ -40,6 +41,12 @@ pub 'flutter_module', :git => 'https://github.com/gowalla/flutter_module.git', :
pub 'flutter_module', :git => 'https://github.com/gowalla/flutter_module.git', :commit => '082f8319af'
```

*flutter module project should be at the root of repository, if that's not the case add additional `:path` attribute for relative path to flutter project in repository. `:path` follows [these](#path_desc) restictions.*

```rb
pub 'flutter_module', :git => 'https://github.com/gowalla/flutter_module.git', :tag => '0.7.0', :path => 'relative path/to/project'
```

## Limitations

- Modules hosted in [pub.dev](https://pub.dev/) are not supported, only local modules and modules in remote sources like git are supported.
Expand Down
21 changes: 14 additions & 7 deletions lib/cocoapods-embed-flutter/flutter/external_sources.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ def self.fetchWithNameAndOptions(name, options)
options = options.last if options.is_a?(Array)
raise StandardError, "No options specified for flutter module: '#{name}'." unless options.is_a?(Hash)

if options.key?(:path)
path = options[:path]
elsif SOURCE_KEYS.keys.any? { |key| options.key?(key) }
if SOURCE_KEYS.keys.any? { |key| options.key?(key) }
source = DownloaderSource.new(name, options, Pod::Config.instance.podfile_path)
source.fetch(Pod::Config.instance.sandbox)
path = source.normalized_pupspec_path
elsif options.key?(:path)
path = options[:path]
else
raise StandardError, "Invalid flutter module: '#{name}'."
end
Expand Down Expand Up @@ -116,8 +116,8 @@ def fetch(sandbox)
# @return [String] a string representation of the source suitable for UI.
#
def description
strategy = Pod::Downloader.strategy_from_options(params)
options = params.dup
strategy = Pod::Downloader.strategy_from_options(download_params)
options = download_params.dup
url = options.delete(strategy)
result = "from `#{url}`"
options.each do |key, value|
Expand Down Expand Up @@ -148,7 +148,8 @@ def normalized_pupspec_path(declared_path)
# and expanding it if necessary.
#
def normalized_pupspec_path
Spec.find_file(name, target)
search_path = params[:path].nil? ? target : File.expand_path(params[:path], target)
Spec.find_file(name, search_path)
end

private
Expand Down Expand Up @@ -203,10 +204,16 @@ def pre_download(sandbox)
def download_request
Pod::Downloader::Request.new(
:name => name,
:params => params,
:params => download_params,
)
end

# @return [Hash] the options for remote source download.
#
def download_params
params.select { |key, value| !key.equal?(:path) }
end

# @return [String] the path where this flutter project
# will be downloaded relative paths.
#
Expand Down
5 changes: 4 additions & 1 deletion lib/cocoapods-embed-flutter/src/pub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ module DSL
# pub 'flutter_module', :git => 'https://github.com/octokit/flutter_module.git', :commit => '082f8319af'
#
# The flutter module or its `pubspec` file is expected to be in the
# root of the repository.
# root of the repository, if that's not the case specify relative path
# to flutter project in repository.
#
# pub 'flutter_module', :git => 'https://github.com/octokit/flutter_module.git', :tag => '0.7.0', :path => 'custom/flutter_module'
#
#
# @note This method allow a nil name and the raises to be more
Expand Down

0 comments on commit 56178ed

Please sign in to comment.