Skip to content

Commit bc9c850

Browse files
author
Soumya Mahunt
committed
feat: allow specifying different path for remote sources
1 parent 4f021fb commit bc9c850

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ plugin 'cocoapods-embed-flutter'
3030
pub 'flutter_module', :path => '../'
3131
```
3232

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

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

44+
*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.*
45+
46+
```rb
47+
pub 'flutter_module', :git => 'https://github.com/gowalla/flutter_module.git', :tag => '0.7.0', :path => 'relative path/to/project'
48+
```
49+
4350
## Limitations
4451

4552
- Modules hosted in [pub.dev](https://pub.dev/) are not supported, only local modules and modules in remote sources like git are supported.

lib/cocoapods-embed-flutter/flutter/external_sources.rb

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ def self.fetchWithNameAndOptions(name, options)
3838
options = options.last if options.is_a?(Array)
3939
raise StandardError, "No options specified for flutter module: '#{name}'." unless options.is_a?(Hash)
4040

41-
if options.key?(:path)
42-
path = options[:path]
43-
elsif SOURCE_KEYS.keys.any? { |key| options.key?(key) }
41+
if SOURCE_KEYS.keys.any? { |key| options.key?(key) }
4442
source = DownloaderSource.new(name, options, Pod::Config.instance.podfile_path)
4543
source.fetch(Pod::Config.instance.sandbox)
4644
path = source.normalized_pupspec_path
45+
elsif options.key?(:path)
46+
path = options[:path]
4747
else
4848
raise StandardError, "Invalid flutter module: '#{name}'."
4949
end
@@ -116,8 +116,8 @@ def fetch(sandbox)
116116
# @return [String] a string representation of the source suitable for UI.
117117
#
118118
def description
119-
strategy = Pod::Downloader.strategy_from_options(params)
120-
options = params.dup
119+
strategy = Pod::Downloader.strategy_from_options(download_params)
120+
options = download_params.dup
121121
url = options.delete(strategy)
122122
result = "from `#{url}`"
123123
options.each do |key, value|
@@ -148,7 +148,8 @@ def normalized_pupspec_path(declared_path)
148148
# and expanding it if necessary.
149149
#
150150
def normalized_pupspec_path
151-
Spec.find_file(name, target)
151+
search_path = params[:path].nil? ? target : File.expand_path(params[:path], target)
152+
Spec.find_file(name, search_path)
152153
end
153154

154155
private
@@ -203,10 +204,16 @@ def pre_download(sandbox)
203204
def download_request
204205
Pod::Downloader::Request.new(
205206
:name => name,
206-
:params => params,
207+
:params => download_params,
207208
)
208209
end
209210

211+
# @return [Hash] the options for remote source download.
212+
#
213+
def download_params
214+
params.select { |key, value| !key.equal?(:path) }
215+
end
216+
210217
# @return [String] the path where this flutter project
211218
# will be downloaded relative paths.
212219
#

lib/cocoapods-embed-flutter/src/pub.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ module DSL
9999
# pub 'flutter_module', :git => 'https://github.com/octokit/flutter_module.git', :commit => '082f8319af'
100100
#
101101
# The flutter module or its `pubspec` file is expected to be in the
102-
# root of the repository.
102+
# root of the repository, if that's not the case specify relative path
103+
# to flutter project in repository.
104+
#
105+
# pub 'flutter_module', :git => 'https://github.com/octokit/flutter_module.git', :tag => '0.7.0', :path => 'custom/flutter_module'
103106
#
104107
#
105108
# @note This method allow a nil name and the raises to be more

0 commit comments

Comments
 (0)