Skip to content

Commit 68f409a

Browse files
Copilotfarfromrefug
andcommitted
Support folder-based modules and Xcode 14+ single target mode
Co-authored-by: farfromrefug <655344+farfromrefug@users.noreply.github.com>
1 parent 92442bf commit 68f409a

3 files changed

Lines changed: 223 additions & 58 deletions

File tree

docs/watchos-integration.md

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ The NativeScript CLI now supports advanced watchOS integration beyond basic sour
88

99
1. Add Swift Package Manager (SPM) dependencies to watch app targets
1010
2. Integrate xcframework modules (like "Data" modules) that can be imported in your WatchApp
11-
3. Reuse existing targets from your xcworkspace (bonus feature)
11+
3. Integrate folder-based modules (non-compiled modules with Info.plist)
12+
4. Reuse existing targets from your xcworkspace (bonus feature)
13+
5. Support Xcode 14+ single target mode (watchapp without extension)
1214

1315
## Configuration
1416

1517
### Basic Watch App Structure
1618

1719
Place your watch app files in the following structure within your App_Resources:
1820

21+
#### Traditional Structure (Pre-Xcode 14)
1922
```
2023
App_Resources/
2124
iOS/ (or visionOS/)
@@ -29,6 +32,18 @@ App_Resources/
2932
... (watch extension sources)
3033
```
3134

35+
#### Xcode 14+ Single Target Structure
36+
```
37+
App_Resources/
38+
iOS/ (or visionOS/)
39+
watchapp/
40+
YourWatchApp/
41+
watchapp.json
42+
... (watch app sources and resources)
43+
```
44+
45+
**Note**: From Xcode 14+, the `watchextension` folder is optional. If only `watchapp` exists, the CLI will create a single target configuration suitable for modern watchOS development.
46+
3247
### Enhanced Configuration
3348

3449
#### 1. SPM Packages for Watch App
@@ -57,9 +72,13 @@ export default {
5772
}
5873
```
5974

60-
#### 2. Module Dependencies (xcframework modules)
75+
#### 2. Module Dependencies
76+
77+
The CLI supports two types of modules:
78+
79+
##### A. Compiled Frameworks (xcframework, framework)
6180

62-
If your watch app needs to import modules from xcframeworks (e.g., `import Data`), configure them in your watch app's `watchapp.json` or `extension.json`:
81+
If your watch app needs to import modules from compiled frameworks (e.g., `import Data`), configure them in your watch app's `watchapp.json` or `extension.json`:
6382

6483
**watchapp.json example:**
6584
```json
@@ -72,22 +91,60 @@ If your watch app needs to import modules from xcframeworks (e.g., `import Data`
7291
"path": "../../../Frameworks/Data.xcframework",
7392
"embed": true,
7493
"headerSearchPaths": [
75-
"../../../Frameworks/Data.xcframework/ios-arm64"
94+
"../../../Frameworks/Data.xcframework/watchos-arm64"
7695
],
7796
"linkerFlags": ["-ObjC"]
7897
}
7998
]
8099
}
81100
```
82101

102+
##### B. Folder-Based Modules (Non-Compiled)
103+
104+
For folder-based modules that contain an Info.plist (non-compiled modules), the CLI will automatically detect them and configure them as Xcode modules:
105+
106+
**watchapp.json example:**
107+
```json
108+
{
109+
"frameworks": ["WatchKit.framework"],
110+
"modules": [
111+
{
112+
"path": "Modules/MyModule",
113+
"headerSearchPaths": ["Modules/MyModule/include"],
114+
"moduleMap": "Modules/MyModule/module.modulemap"
115+
}
116+
]
117+
}
118+
```
119+
120+
The folder should have this structure:
121+
```
122+
Modules/
123+
MyModule/
124+
Info.plist # Required
125+
Headers/
126+
MyModule.h
127+
module.modulemap # Optional, can be specified in config
128+
Sources/
129+
MyModule.m
130+
```
131+
83132
**Module Configuration Options:**
84133

85-
- `name` (required): Name of the module (e.g., "Data")
86-
- `path` (optional): Path to the framework/xcframework containing the module (relative to project root)
134+
For **compiled frameworks** (xcframework, framework):
135+
- `name` (optional): Name of the module (e.g., "Data")
136+
- `path` (required): Path to the framework/xcframework (relative to project root)
87137
- `embed` (optional): Whether to embed the framework (default: true)
88138
- `headerSearchPaths` (optional): Additional header search paths for the module
89139
- `linkerFlags` (optional): Additional linker flags for the module
90140

141+
For **folder-based modules**:
142+
- `name` (optional): Name of the module (defaults to folder name)
143+
- `path` (required): Path to the folder containing Info.plist (relative to project root)
144+
- `headerSearchPaths` (optional): Additional header search paths for the module
145+
- `linkerFlags` (optional): Additional linker flags for the module
146+
- `moduleMap` (optional): Path to custom module.modulemap file
147+
91148
#### 3. Workspace Target Reference
92149

93150
To link an existing target from your xcworkspace to your watch app, add this to your watch app configuration:

lib/definitions/project.d.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,19 @@ export type IOSSPMPackage = IOSRemoteSPMPackage | IOSLocalSPMPackage;
124124
export type BundlerType = "webpack" | "rspack" | "vite";
125125

126126
/**
127-
* Watch app module configuration for xcframework modules
127+
* Watch app module configuration for xcframework modules or folder-based modules
128128
*/
129129
interface IWatchAppModuleConfig {
130130
/**
131131
* Name of the module (e.g., "Data")
132132
*/
133-
name: string;
133+
name?: string;
134134
/**
135-
* Path to the framework/xcframework containing the module
135+
* Path to the framework/xcframework or folder containing the module with Info.plist
136136
*/
137137
path?: string;
138138
/**
139-
* Whether to embed the framework (default: true)
139+
* Whether to embed the framework (default: true, only applies to compiled frameworks)
140140
*/
141141
embed?: boolean;
142142
/**
@@ -147,6 +147,10 @@ interface IWatchAppModuleConfig {
147147
* Additional linker flags for the module
148148
*/
149149
linkerFlags?: string[];
150+
/**
151+
* Path to custom module.modulemap file (for folder-based modules)
152+
*/
153+
moduleMap?: string;
150154
}
151155

152156
/**

0 commit comments

Comments
 (0)