brick-module 0.1.4 → 0.1.6

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.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import BrickModule_default from "./BrickModule.js";
1
+ import BrickModule from "./BrickModule.js";
2
2
 
3
3
  //#region src/index.ts
4
4
  /**
@@ -15,4 +15,4 @@ var BrickModuleError = class extends Error {
15
15
  };
16
16
 
17
17
  //#endregion
18
- export { BrickModule_default as BrickModule, BrickModuleError };
18
+ export { BrickModule, BrickModuleError };
@@ -1,5 +1,8 @@
1
1
  import Foundation
2
2
 
3
+ @objc public protocol BrickModuleRegistableViewControllerType {
4
+ @objc var moduleRegistry: BrickModuleRegistry? { get }
5
+ }
3
6
  /**
4
7
  * Minimal protocol that all Brick modules must implement
5
8
  * Contains only essential properties for module identification
@@ -7,6 +10,9 @@ import Foundation
7
10
  public protocol BrickModuleBase {
8
11
  /// The name of the module (required for registration)
9
12
  var moduleName: String { get }
13
+ var controller: BrickModuleRegistableViewControllerType { get set }
14
+
15
+ init (controller: BrickModuleRegistableViewControllerType)
10
16
  }
11
17
 
12
18
  /**
@@ -49,3 +55,11 @@ public enum BrickModuleError: Error, LocalizedError {
49
55
  }
50
56
  }
51
57
  }
58
+
59
+
60
+ public protocol BrickModuleAddableViewControllerType: UIViewController {
61
+ func addBrickModule(_ module: BrickModuleBase)
62
+ }
63
+
64
+
65
+
@@ -6,13 +6,12 @@ import React
6
6
  * Manages module lifecycle and provides simple module storage
7
7
  */
8
8
  @objc public class BrickModuleRegistry: NSObject {
9
- @objc public static let shared = BrickModuleRegistry()
10
9
 
11
10
  private var modules: [String: Any] = [:]
12
11
  private var isRegistered: Bool = false
13
- private weak var eventEmitter: RCTEventEmitter?
12
+ public weak var eventEmitter: RCTEventEmitter?
14
13
 
15
- private override init() {
14
+ public override init() {
16
15
  super.init()
17
16
  }
18
17
 
@@ -35,7 +34,7 @@ import React
35
34
 
36
35
  isRegistered = true
37
36
  print("✅ BrickModuleRegistry: Successfully registered \(self.modules.count) modules")
38
-
37
+
39
38
  if ProcessInfo.processInfo.environment["GRANITE_DEBUG"] == "1" {
40
39
  debugPrintRegisteredModules()
41
40
  }
@@ -136,3 +135,7 @@ import React
136
135
  print("🧹 BrickModuleRegistry: Registry cleared")
137
136
  }
138
137
  }
138
+
139
+ public class ModuleRegistry {
140
+
141
+ }
@@ -304,12 +304,14 @@ typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
304
304
  @class NSArray;
305
305
  @class NSString;
306
306
  @class RCTEventEmitter;
307
+ @class RCTBridge;
307
308
 
308
309
  /// Central registry for all Brick modules
309
310
  /// Manages module lifecycle and provides simple module storage
310
311
  SWIFT_CLASS("_TtC11BrickModule19BrickModuleRegistry")
311
312
  @interface BrickModuleRegistry : NSObject
312
- SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, strong) BrickModuleRegistry * _Nonnull shared;)
313
+ @property (nonatomic, weak) RCTBridge * _Nullable bridge;
314
+ //SWIFT_CLASS_PROPERTY(@property (nonatomic, class, readonly, strong) BrickModuleRegistry * _Nonnull shared;)
313
315
  + (BrickModuleRegistry * _Nonnull)shared SWIFT_WARN_UNUSED_RESULT;
314
316
  - (nonnull instancetype)init SWIFT_UNAVAILABLE;
315
317
  + (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brick-module",
3
- "version": "0.1.4",
3
+ "version": "0.1.6",
4
4
  "description": "Better React Native native module development",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -51,7 +51,7 @@
51
51
  "brick-codegen": "./bin/brick-codegen.js"
52
52
  },
53
53
  "dependencies": {
54
- "brick-codegen": "0.1.4"
54
+ "brick-codegen": "0.1.6"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "react": ">=18.2.0",
@@ -60,8 +60,8 @@
60
60
  "devDependencies": {
61
61
  "@types/react": "^18.2.0",
62
62
  "@types/react-native": "^0.72.0",
63
- "tsdown": "^0.12.8",
64
- "typescript": "^5.1.0"
63
+ "tsdown": "^0.14.0",
64
+ "typescript": "^5.9.2"
65
65
  },
66
66
  "codegenConfig": {
67
67
  "name": "BrickModuleSpec",
package/podfile_helper.rb CHANGED
@@ -6,8 +6,79 @@
6
6
  require 'json'
7
7
  require 'pathname'
8
8
 
9
+ def find_brick_json(start_dir)
10
+ # Walk up the directory tree looking for brick.json
11
+ current = File.expand_path(start_dir)
12
+ root = File.expand_path('/')
13
+
14
+ while current != root
15
+ brick_json_path = File.join(current, 'brick.json')
16
+ if File.exist?(brick_json_path)
17
+ return brick_json_path
18
+ end
19
+ parent = File.dirname(current)
20
+ break if parent == current # Reached filesystem root
21
+ current = parent
22
+ end
23
+
24
+ return nil
25
+ end
26
+
27
+ def find_project_root
28
+ ios_root = Pod::Config.instance.installation_root
29
+
30
+ # 1. Walk up directory tree to find brick.json
31
+ brick_json_path = find_brick_json(ios_root)
32
+ if brick_json_path
33
+ Pod::UI.puts "[Brick] Found brick.json at: #{brick_json_path}"
34
+ begin
35
+ config = JSON.parse(File.read(brick_json_path))
36
+ if config['projectRoot']
37
+ project_root = resolve_project_root(config['projectRoot'], File.dirname(brick_json_path))
38
+ if project_root
39
+ Pod::UI.puts "[Brick] Using projectRoot from brick.json: #{project_root}"
40
+ return project_root
41
+ end
42
+ end
43
+ # If brick.json exists but has no projectRoot, use its directory as project root
44
+ return File.dirname(brick_json_path)
45
+ rescue => e
46
+ Pod::UI.warn "[Brick] Failed to parse brick.json: #{e.message}"
47
+ end
48
+ end
49
+
50
+ # 2. Walk up to find package.json with node_modules
51
+ current = ios_root
52
+ while current != '/'
53
+ if File.exist?(File.join(current, 'package.json')) && File.exist?(File.join(current, 'node_modules'))
54
+ Pod::UI.puts "[Brick] Found project root via package.json: #{current}"
55
+ return current
56
+ end
57
+ parent = File.dirname(current)
58
+ break if parent == current
59
+ current = parent
60
+ end
61
+
62
+ # If no project root found, use default fallback
63
+ default_root = File.expand_path(File.join(ios_root, '..'))
64
+ Pod::UI.warn "[Brick] Warning: Failed to find project root via brick.json or package.json. Using default: #{default_root}"
65
+ return default_root
66
+ end
67
+
68
+ def resolve_project_root(project_root_path, config_dir)
69
+ # Handle both absolute and relative paths
70
+ if Pathname.new(project_root_path).absolute?
71
+ return project_root_path if File.exist?(project_root_path)
72
+ else
73
+ # Relative to brick.json location
74
+ resolved_path = File.expand_path(File.join(config_dir, project_root_path))
75
+ return resolved_path if File.exist?(resolved_path)
76
+ end
77
+ return nil
78
+ end
79
+
9
80
  def use_brick_modules!
10
- brick_root = "#{Pod::Config.instance.installation_root}/.."
81
+ brick_root = find_project_root
11
82
  discovered_modules = []
12
83
 
13
84
  begin
@@ -21,9 +92,12 @@ def use_brick_modules!
21
92
  # Generate BrickModuleProvider.swift for auto-registration
22
93
  generate_brick_module_provider(brick_root, discovered_modules)
23
94
 
95
+ # Get iOS output path from brick.json if it exists
96
+ ios_brick_path = get_brick_ios_path(brick_root)
97
+
24
98
  # Add generated BrickCodegen pod if it exists
25
- brick_codegen_podspec_path = "#{brick_root}/ios/.brick/BrickCodegen.podspec"
26
- brick_codegen_pod_path = "#{brick_root}/ios/.brick"
99
+ brick_codegen_podspec_path = "#{brick_root}/#{ios_brick_path}/BrickCodegen.podspec"
100
+ brick_codegen_pod_path = "#{brick_root}/#{ios_brick_path}"
27
101
 
28
102
  if File.exist?(brick_codegen_podspec_path)
29
103
  begin
@@ -68,17 +142,24 @@ def discover_brick_modules(project_root)
68
142
  brick_config = dep_package_json['brickModule']
69
143
  ios_config = brick_config['ios'] || {}
70
144
 
71
- # Extract the iOS module name and class name
72
- module_name = ios_config['moduleName']
73
- class_name = ios_config['className']
74
-
75
- modules << {
76
- 'name' => dep_name,
77
- 'moduleName' => module_name,
78
- 'className' => class_name,
79
- }
145
+ # Check if autoRegister is enabled (default: true)
146
+ auto_register = brick_config['autoRegister'] != false
80
147
 
81
- Pod::UI.puts "[Brick] Found module: #{dep_name} (#{module_name})"
148
+ if auto_register
149
+ # Extract the iOS module name and class name
150
+ module_name = ios_config['moduleName']
151
+ class_name = ios_config['className']
152
+
153
+ modules << {
154
+ 'name' => dep_name,
155
+ 'moduleName' => module_name,
156
+ 'className' => class_name,
157
+ }
158
+
159
+ Pod::UI.puts "[Brick] Found module: #{dep_name} (#{module_name})"
160
+ else
161
+ Pod::UI.puts "[Brick] Skipping module (autoRegister=false): #{dep_name}"
162
+ end
82
163
  end
83
164
  rescue => e
84
165
  Pod::UI.warn "[Brick] Failed to parse #{dep_package_json_path}: #{e.message}"
@@ -91,11 +172,49 @@ def discover_brick_modules(project_root)
91
172
  modules
92
173
  end
93
174
 
175
+ def get_brick_ios_path(project_root)
176
+ # Walk up from project_root to find brick.json
177
+ brick_config_path = find_brick_json(project_root)
178
+
179
+ if brick_config_path && File.exist?(brick_config_path)
180
+ begin
181
+ config = JSON.parse(File.read(brick_config_path))
182
+
183
+ # Get the effective project root
184
+ effective_root = project_root
185
+ if config['projectRoot']
186
+ resolved_root = resolve_project_root(config['projectRoot'], File.dirname(brick_config_path))
187
+ effective_root = resolved_root if resolved_root
188
+ end
189
+
190
+ ios_path = config.dig('output', 'ios')
191
+ if ios_path && !ios_path.empty?
192
+ # Handle absolute paths (though not recommended)
193
+ if Pathname.new(ios_path).absolute?
194
+ Pod::UI.warn "[Brick] Using absolute path for iOS output is not recommended: #{ios_path}"
195
+ return ios_path
196
+ else
197
+ # Relative to effective project root
198
+ return File.join(effective_root, ios_path)
199
+ end
200
+ end
201
+ rescue => e
202
+ Pod::UI.warn "[Brick] Failed to parse brick.json: #{e.message}"
203
+ end
204
+ end
205
+
206
+ # Return default path relative to project root
207
+ return File.join(project_root, 'ios/.brick')
208
+ end
209
+
94
210
  def generate_brick_module_provider(project_root, modules)
95
211
  return if modules.empty?
96
212
 
97
- # Create the .brick directory if it doesn't exist
98
- brick_dir = File.join(project_root, 'ios', '.brick')
213
+ # Get iOS output path from brick.json
214
+ ios_brick_path = get_brick_ios_path(project_root)
215
+
216
+ # Create the brick directory if it doesn't exist
217
+ brick_dir = File.join(project_root, ios_brick_path)
99
218
  FileUtils.mkdir_p(brick_dir) unless File.exist?(brick_dir)
100
219
 
101
220
  # Generate imports and module instances