cocoapods-podfile-local 0.1.0 → 0.2.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 +4 -4
- data/README.md +5 -1
- data/lib/cocoapods-podfile-local.rb +9 -0
- data/lib/cocoapods_plugin.rb +2 -0
- data/lib/cocoapods_podfile_local/dsl.rb +4 -0
- data/lib/cocoapods_podfile_local/hook.rb +9 -0
- data/lib/cocoapods_podfile_local/override_manager.rb +6 -1
- data/lib/cocoapods_podfile_local/pods_project_integration.rb +72 -0
- data/lib/cocoapods_podfile_local/version.rb +2 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6dde6f4485ef1ea469899415b9e21f24dca2ab4b80c5671e0677202ae98a93ee
|
|
4
|
+
data.tar.gz: 1308d7accd337a4326ae8b42d0a128d7fa7e144214cf913a3baacb55412b252c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 59544d3511a1873d8f83839e98ad65df635e36e52cc823f1af1cfcf997b8a172f518ed7f339a0af05ac558f54b15f14bf1c304f48931d6235cb3b6355d420ff5
|
|
7
|
+
data.tar.gz: d38806881cc4bb885a9b1d1c48d695226917b067dea44cac99996114e6956b20bad6c0e27ad0137f6623e7d274bd8fec07fbbc624628a591c2baee1d27cd5e2b
|
data/README.md
CHANGED
|
@@ -45,7 +45,11 @@ bundle exec pod install
|
|
|
45
45
|
[Podfile.local] Overriding 'CustomLib' with {:git=>"git@gitlab.com:xxx/CustomLib.git", :branch=>"feature/login"}
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
### 3.
|
|
48
|
+
### 3. 在 Xcode 中查看
|
|
49
|
+
|
|
50
|
+
当根目录存在 `Podfile.local` 时,`pod install` 会把它像 `Podfile` 一样加入 **Pods** 工程(`Pods.xcodeproj` 根分组),打开 `*.xcworkspace` 后在左侧 **Pods** 项目里紧挨 `Podfile` 即可编辑。若删除了 `Podfile.local`,下次 `pod install` 会同步移除该文件引用。
|
|
51
|
+
|
|
52
|
+
### 4. 恢复原始状态
|
|
49
53
|
|
|
50
54
|
删除或清空 `Podfile.local`,重新 `pod install` 即可。
|
|
51
55
|
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
# 插件主入口:被 Gemfile / cocoapods_plugin 加载后顺序执行。
|
|
2
|
+
#
|
|
3
|
+
# 流程概览:
|
|
4
|
+
# 1. setup! —— 读 Podfile.local、若无覆盖则结束;若有则 prepend 拦截 Podfile 里的 `pod`。
|
|
5
|
+
# 2. register_post_install_hook! —— 安装结束后把 Podfile.local 挂进 Pods.xcodeproj,方便 Xcode 浏览。
|
|
6
|
+
|
|
1
7
|
require 'cocoapods_podfile_local/version'
|
|
2
8
|
require 'cocoapods_podfile_local/override_manager'
|
|
3
9
|
require 'cocoapods_podfile_local/dsl'
|
|
4
10
|
require 'cocoapods_podfile_local/hook'
|
|
11
|
+
require 'cocoapods_podfile_local/pods_project_integration'
|
|
5
12
|
|
|
6
13
|
CocoapodsPodfileLocal.setup!
|
|
14
|
+
# 注册 post_install:在 Pods 工程里同步 Podfile.local 的文件引用,便于在 Xcode 中浏览编辑。
|
|
15
|
+
CocoapodsPodfileLocal::PodsProjectIntegration.register_post_install_hook!
|
data/lib/cocoapods_plugin.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
module CocoapodsPodfileLocal
|
|
2
|
+
# 声明式 DSL:`edit 'PodName', ...` 与 Podfile 里 `pod` 的关键字参数风格一致。
|
|
2
3
|
module DSL
|
|
4
|
+
# 将某个 pod 的覆盖选项登记到 OverrideManager,后续在解析主 Podfile 的 `pod` 时合并生效。
|
|
3
5
|
def edit(pod_name, options = {})
|
|
4
6
|
CocoapodsPodfileLocal::OverrideManager.instance.register(pod_name, options)
|
|
5
7
|
end
|
|
@@ -8,6 +10,8 @@ end
|
|
|
8
10
|
|
|
9
11
|
module Pod
|
|
10
12
|
class Podfile
|
|
13
|
+
# 把 `edit` 混进官方 Podfile 类(与主 Podfile 同一解析上下文时可用)。
|
|
14
|
+
# 实际团队约定把覆盖写在 Podfile.local;hook 里另用 PodfileLocalLoader 做 instance_eval,不依赖此处。
|
|
11
15
|
include CocoapodsPodfileLocal::DSL
|
|
12
16
|
end
|
|
13
17
|
end
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
module CocoapodsPodfileLocal
|
|
2
|
+
# 控制台日志前缀,便于 grep 与区分 CocoaPods 自带输出。
|
|
2
3
|
TAG = '[Podfile.local]'.freeze
|
|
3
4
|
|
|
5
|
+
# 仅用于执行 Podfile.local 的轻量对象:提供 `edit`,内部转给 OverrideManager。
|
|
6
|
+
# 不能用主 Podfile 实例去 eval,因为插件加载时主 Podfile 尚未开始解析。
|
|
4
7
|
class PodfileLocalLoader
|
|
5
8
|
def edit(pod_name, options = {})
|
|
6
9
|
OverrideManager.instance.register(pod_name, options)
|
|
@@ -8,6 +11,7 @@ module CocoapodsPodfileLocal
|
|
|
8
11
|
end
|
|
9
12
|
|
|
10
13
|
class << self
|
|
14
|
+
# 插件被 require 时调用:先收集覆盖,再(若有覆盖)改写 Podfile::DSL#pod 的查找链。
|
|
11
15
|
def setup!
|
|
12
16
|
load_podfile_local!
|
|
13
17
|
return if OverrideManager.instance.empty?
|
|
@@ -16,15 +20,18 @@ module CocoapodsPodfileLocal
|
|
|
16
20
|
|
|
17
21
|
private
|
|
18
22
|
|
|
23
|
+
# 在工程根目录查找 Podfile.local,存在则 Ruby 实例内执行其内容(仅应包含 edit 调用)。
|
|
19
24
|
def load_podfile_local!
|
|
20
25
|
local_file = Pathname.pwd + 'Podfile.local'
|
|
21
26
|
return unless local_file.exist?
|
|
22
27
|
|
|
23
28
|
Pod::UI.message "#{TAG} Loading #{local_file}"
|
|
24
29
|
loader = PodfileLocalLoader.new
|
|
30
|
+
# 第二个参数为「虚拟文件名」,栈追踪里会显示 Podfile.local 路径,便于排错。
|
|
25
31
|
loader.instance_eval(local_file.read, local_file.to_s)
|
|
26
32
|
end
|
|
27
33
|
|
|
34
|
+
# 在 Pod::Podfile::DSL 前插入一个匿名模块:先处理覆盖再 call super,对未覆盖的 pod 原样透传。
|
|
28
35
|
def patch_pod_dsl!
|
|
29
36
|
manager = OverrideManager.instance
|
|
30
37
|
|
|
@@ -33,11 +40,13 @@ module CocoapodsPodfileLocal
|
|
|
33
40
|
if name && manager.overrides.key?(name)
|
|
34
41
|
override_opts = manager.overrides[name]
|
|
35
42
|
|
|
43
|
+
# CocoaPods 约定:版本/requirement 在前,最后一项可为 Hash(:path、:git 等)。
|
|
36
44
|
original_opts = requirements.last.is_a?(Hash) ? requirements.pop : {}
|
|
37
45
|
version_reqs = requirements
|
|
38
46
|
|
|
39
47
|
merged = manager.merge(original_opts, override_opts)
|
|
40
48
|
|
|
49
|
+
# 一旦指定了 path/git/podspec 等「外部源」,版本号约束无意义,与 CocoaPods 行为对齐。
|
|
41
50
|
if merged.key?(:path) || merged.key?(:git) || merged.key?(:podspec)
|
|
42
51
|
version_reqs = []
|
|
43
52
|
end
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
module CocoapodsPodfileLocal
|
|
2
|
+
# 单例:在「解析 Podfile.local」与「prepend 后的 pod 方法」之间共享覆盖表。
|
|
2
3
|
class OverrideManager
|
|
4
|
+
# 表示「依赖来源」的三类主键,与 CocoaPods pod 声明一致(与下方互斥规则对应)。
|
|
3
5
|
SOURCE_KEYS = %i[git path podspec].freeze
|
|
6
|
+
# 依附于 :git 的附加字段;与 path/podspec 来源互斥时一并清理。
|
|
4
7
|
GIT_EXTRAS = %i[branch tag commit].freeze
|
|
5
8
|
|
|
9
|
+
# 当 edit 指定某一来源时,应从「原 Podfile 选项」里删掉的冲突键,避免 path 与 git 等同时存在。
|
|
6
10
|
EXCLUSIVE_RULES = {
|
|
7
11
|
git: %i[path podspec],
|
|
8
12
|
path: %i[git branch tag commit podspec],
|
|
@@ -13,6 +17,7 @@ module CocoapodsPodfileLocal
|
|
|
13
17
|
@instance ||= new
|
|
14
18
|
end
|
|
15
19
|
|
|
20
|
+
# 测试或多次加载场景下可清空单例(一般 pod install 单次进程不需要)。
|
|
16
21
|
def self.reset!
|
|
17
22
|
@instance = nil
|
|
18
23
|
end
|
|
@@ -33,7 +38,7 @@ module CocoapodsPodfileLocal
|
|
|
33
38
|
@overrides.empty?
|
|
34
39
|
end
|
|
35
40
|
|
|
36
|
-
#
|
|
41
|
+
# 先把原 Hash 里与「新来源」冲突的键删掉,再 merge 覆盖项;覆盖键优先,其余保留原 Podfile。
|
|
37
42
|
def merge(original_options, override_options)
|
|
38
43
|
merged = original_options.dup
|
|
39
44
|
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Podfile.local 的 Xcode 集成:与依赖覆盖逻辑(hook.rb)独立,仅影响工程导航展示。
|
|
4
|
+
require 'pathname'
|
|
5
|
+
|
|
6
|
+
module CocoapodsPodfileLocal
|
|
7
|
+
# 把 Podfile.local 挂到 Pods.xcodeproj 的根分组里(和 CocoaPods 自带的 Podfile 引用方式一致),
|
|
8
|
+
# 这样打开 .xcworkspace 后能在 Xcode 左侧导航里直接点开编辑;若本地删掉了 Podfile.local,下次 install 会去掉引用。
|
|
9
|
+
module PodsProjectIntegration
|
|
10
|
+
# Pods 工程在 `项目/Pods/` 下,根目录的 Podfile.local 相对路径就是上一级目录里的文件。
|
|
11
|
+
PODFILE_RELATIVE = '../Podfile.local'
|
|
12
|
+
|
|
13
|
+
class << self
|
|
14
|
+
# 向 CocoaPods 注册「安装结束后」执行的钩子;同一 Ruby 进程里只注册一次,避免重复执行。
|
|
15
|
+
def register_post_install_hook!
|
|
16
|
+
return if @post_install_registered
|
|
17
|
+
|
|
18
|
+
@post_install_registered = true
|
|
19
|
+
# post_install 时 CocoaPods 已生成/更新完 Pods.xcodeproj,此时改工程文件是安全的。
|
|
20
|
+
Pod::HooksManager.register('cocoapods-podfile-local', :post_install) do |context|
|
|
21
|
+
sync_podfile_local_file_reference(context)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
# context 由 CocoaPods 传入,内含 sandbox、pods_project(即 Pods.xcodeproj 的 Xcodeproj 对象)等。
|
|
28
|
+
def sync_podfile_local_file_reference(context)
|
|
29
|
+
pods_project = context.pods_project
|
|
30
|
+
return unless pods_project
|
|
31
|
+
|
|
32
|
+
# main_group:Xcode 里 Pods 工程最顶层那个分组,Podfile 的引用就挂在这里。
|
|
33
|
+
main = pods_project.root_object.main_group
|
|
34
|
+
# sandbox_root 一般是 `.../Pods`,上一级才是壳工程根目录,Podfile.local 与 Podfile 同级。
|
|
35
|
+
local_path = Pathname(context.sandbox_root).parent + 'Podfile.local'
|
|
36
|
+
# 若上次 install 已加过引用,避免重复插入。
|
|
37
|
+
existing = main.files.find { |f| f.path == PODFILE_RELATIVE }
|
|
38
|
+
changed = false
|
|
39
|
+
|
|
40
|
+
if local_path.file?
|
|
41
|
+
unless existing
|
|
42
|
+
# :project 表示路径相对于「工程文件所在目录」,即 Pods/,会得到与 Podfile 相同的 SOURCE_ROOT + ../Podfile.local。
|
|
43
|
+
ref = main.new_reference(local_path, :project)
|
|
44
|
+
ref.name = 'Podfile.local'
|
|
45
|
+
# 下面这些属性与 CocoaPods 为 Podfile 生成的 PBXFileReference 一致,便于 Xcode 按 Ruby 语法高亮。
|
|
46
|
+
ref.set_explicit_file_type('text.script.ruby')
|
|
47
|
+
ref.last_known_file_type = 'text'
|
|
48
|
+
ref.indent_width = '2'
|
|
49
|
+
ref.tab_width = '2'
|
|
50
|
+
ref.xc_language_specification_identifier = 'xcode.lang.ruby'
|
|
51
|
+
|
|
52
|
+
# new_reference 默认把新文件加在分组末尾;这里挪到 Podfile 后面,导航里两条挨在一起。
|
|
53
|
+
podfile_ref = main.files.find { |f| f.path == '../Podfile' }
|
|
54
|
+
if podfile_ref
|
|
55
|
+
main.children.delete(ref)
|
|
56
|
+
idx = main.children.index(podfile_ref)
|
|
57
|
+
main.children.insert(idx + 1, ref) if idx
|
|
58
|
+
end
|
|
59
|
+
changed = true
|
|
60
|
+
end
|
|
61
|
+
elsif existing
|
|
62
|
+
# 开发者删了 Podfile.local 后,工程里会剩「断链」引用,主动删掉保持干净。
|
|
63
|
+
existing.remove_from_project
|
|
64
|
+
changed = true
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# 无变更不写盘,减少 pbxproj 无意义 diff、也略快一点。
|
|
68
|
+
pods_project.save if changed
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: cocoapods-podfile-local
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- dairuiquan
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: cocoapods
|
|
@@ -46,6 +46,7 @@ files:
|
|
|
46
46
|
- lib/cocoapods_podfile_local/dsl.rb
|
|
47
47
|
- lib/cocoapods_podfile_local/hook.rb
|
|
48
48
|
- lib/cocoapods_podfile_local/override_manager.rb
|
|
49
|
+
- lib/cocoapods_podfile_local/pods_project_integration.rb
|
|
49
50
|
- lib/cocoapods_podfile_local/version.rb
|
|
50
51
|
homepage: https://rubygems.org/gems/cocoapods-podfile-local
|
|
51
52
|
licenses:
|