nativescript 9.0.5 → 9.0.6-dev.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.
package/lib/constants.js CHANGED
@@ -324,6 +324,7 @@ var IOSNativeTargetTypes;
324
324
  IOSNativeTargetTypes["watchApp"] = "watch_app";
325
325
  IOSNativeTargetTypes["watchExtension"] = "watch_extension";
326
326
  IOSNativeTargetTypes["appExtension"] = "app_extension";
327
+ IOSNativeTargetTypes["application"] = "application";
327
328
  })(IOSNativeTargetTypes || (exports.IOSNativeTargetTypes = IOSNativeTargetTypes = {}));
328
329
  const pathToLoggerAppendersDir = (0, path_1.join)(__dirname, "common", "logger", "appenders");
329
330
  exports.LoggerAppenders = {
@@ -8,16 +8,27 @@ declare module "nativescript-dev-xcode" {
8
8
  }
9
9
 
10
10
  class project {
11
+ hash: any;
12
+ filepath: string;
11
13
  constructor(filename: string);
12
14
 
13
15
  parse(callback: () => void): void;
14
16
  parseSync(): void;
15
17
 
18
+ generateUuid(): string;
19
+
16
20
  writeSync(options: any): string;
17
21
 
18
22
  addFramework(filepath: string, options?: Options): void;
19
23
  removeFramework(filePath: string, options?: Options): void;
20
24
 
25
+
26
+ getProductFile(watchApptarget: target): any;
27
+ addToPbxFrameworksBuildPhase(file);
28
+ addToPbxCopyfilesBuildPhase(file, comment: string, targetid: string);
29
+ pbxFrameworksBuildPhaseObj(targetid: string): any;
30
+ pbxBuildFileSection(): {[k: string] : any};
31
+
21
32
  addPbxGroup(
22
33
  filePathsArray: any[],
23
34
  name: string,
@@ -27,17 +38,30 @@ declare module "nativescript-dev-xcode" {
27
38
 
28
39
  removePbxGroup(groupName: string, path: string): void;
29
40
 
41
+ addTargetDependency(target: string, dependencyTargets: string[]);
42
+
43
+ findTargetKey(name: string);
44
+ pbxTargetByName(name: string): target;
45
+ pbxNativeTargetSection(): {[key: string]: any};
46
+
30
47
  addToHeaderSearchPaths(options?: Options): void;
31
48
  removeFromHeaderSearchPaths(options?: Options): void;
32
49
  updateBuildProperty(key: string, value: any): void;
33
50
 
34
51
  pbxXCBuildConfigurationSection(): any;
35
52
 
53
+ buildPhaseObject(
54
+ buildPhaseType: string,
55
+ comment: string,
56
+ target: tstring
57
+ )
58
+
36
59
  addTarget(
37
60
  targetName: string,
38
61
  targetType: string,
39
62
  targetPath?: string,
40
- parentTarget?: string
63
+ parentTarget?: string,
64
+ productTargetType?: string
41
65
  ): target;
42
66
  addBuildPhase(
43
67
  filePathsArray: string[],
@@ -873,6 +873,38 @@ interface IRemoveExtensionsOptions {
873
873
 
874
874
  interface IRemoveWatchAppOptions extends IRemoveExtensionsOptions {}
875
875
 
876
+ interface IWatchAppJSONConfigModule {
877
+ name?: string;
878
+ path: string;
879
+ targetType?: string;
880
+ embed?: boolean;
881
+ frameworks?: Array<string | Record<string, string>>;
882
+ dependencies?: string[];
883
+ headerSearchPaths?: string[];
884
+ resources?: string[];
885
+ src?: string[];
886
+ linkerFlags?: string[];
887
+ buildConfigurationProperties?: Record<string, string>;
888
+ SPMPackages?: Array<IOSSPMPackage | string>;
889
+ }
890
+ interface IWatchAppJSONConfig {
891
+ targetType?: string;
892
+ forceAddEmbedWatchContent?: boolean;
893
+ sharedModulesBuildConfigurationProperties?: Record<string, string>;
894
+ basedir?: string;
895
+ infoPlistPath?: string;
896
+ xcprivacyPath?: string;
897
+ importSourcesFromMainFolder?: boolean;
898
+ importResourcesFromMainFolder?: boolean;
899
+ resources?: string[];
900
+ src?: string[];
901
+ resourcesExclude?: string[];
902
+ srcExclude?: string[];
903
+ modules: IWatchAppConfigModule[];
904
+ SPMPackages?: Array<IOSSPMPackage>;
905
+ }
906
+
907
+
876
908
  interface IRubyFunction {
877
909
  functionName: string;
878
910
  functionParameters?: string;
@@ -468,7 +468,6 @@ class IOSProjectService extends projectServiceBaseLib.PlatformProjectServiceBase
468
468
  }
469
469
  }
470
470
  }
471
- this.$iOSWatchAppService.removeWatchApp({ pbxProjPath });
472
471
  const addedWatchApp = await this.$iOSWatchAppService.addWatchAppFromPath({
473
472
  watchAppFolderPath: path.join(resourcesDirectoryPath, platformData.normalizedPlatformName),
474
473
  projectData,
@@ -4,34 +4,171 @@ exports.IOSWatchAppService = void 0;
4
4
  const path = require("path");
5
5
  const constants_1 = require("../constants");
6
6
  const yok_1 = require("../common/yok");
7
+ const trapezedev_project_1 = require("@nstudio/trapezedev-project");
8
+ const minimatch_1 = require("minimatch");
9
+ const sourceExtensions = [
10
+ '.swift', '.m', '.mm', '.c', '.cpp', '.cc', '.cxx', '.h', '.hpp'
11
+ ];
12
+ const resourceExtensions = [
13
+ '.png', '.jpg', '.jpeg', '.gif', '.svg', '.pdf', // Images
14
+ '.ttf', '.otf', '.woff', '.woff2', // Fonts
15
+ '.xcassets', // Asset catalogs
16
+ '.storyboard', '.xib', // Interface files
17
+ '.strings', '.stringsdict', // Localization
18
+ '.json', '.xml', '.plist', // Data files
19
+ '.m4a', '.mp3', '.wav', '.caf', // Audio
20
+ '.mp4', '.mov', // Video
21
+ '.bundle', // Resource bundles
22
+ ];
23
+ const WATCH_APP_IDENTIFIER = "watchkitapp";
24
+ const WACTCH_EXTENSION_IDENTIFIER = "watchkitextension";
25
+ const CONFIG_FILE_WATCHAPP = "watchapp.json";
26
+ const CONFIG_FILE_EXTENSION = "extension.json";
27
+ const RESOURCES_TO_IGNORE = [CONFIG_FILE_WATCHAPP, CONFIG_FILE_EXTENSION, 'node_modules'];
7
28
  class IOSWatchAppService {
8
- constructor($fs, $pbxprojDomXcode, $xcode, $iOSNativeTargetService) {
29
+ constructor($fs, $pbxprojDomXcode, $xcode, $iOSNativeTargetService, $logger) {
9
30
  this.$fs = $fs;
10
31
  this.$pbxprojDomXcode = $pbxprojDomXcode;
11
32
  this.$xcode = $xcode;
12
33
  this.$iOSNativeTargetService = $iOSNativeTargetService;
34
+ this.$logger = $logger;
35
+ }
36
+ addResourceFile(project, path, opt, group = 'WatchResources') {
37
+ const file = project.addResourceFile(path, opt, group);
38
+ project.addToResourcesPbxGroup(file, group);
39
+ }
40
+ addSourceFile(project, path, opt, group = 'WatchSrc') {
41
+ const file = project.addSourceFile(path, opt, group);
42
+ project.addToResourcesPbxGroup(file, group);
13
43
  }
14
44
  async addWatchAppFromPath({ watchAppFolderPath, projectData, platformData, pbxProjPath, }) {
45
+ var _a, _b;
15
46
  const targetUuids = [];
47
+ const targetNames = [];
16
48
  const appPath = path.join(watchAppFolderPath, constants_1.IOS_WATCHAPP_FOLDER);
17
- const extensionPath = path.join(watchAppFolderPath, constants_1.IOS_WATCHAPP_EXTENSION_FOLDER);
18
- if (!this.$fs.exists(appPath) || !this.$fs.exists(extensionPath)) {
49
+ // Check if watchapp exists - it's required
50
+ if (!this.$fs.exists(appPath)) {
19
51
  return false;
20
52
  }
21
53
  const appFolder = this.$iOSNativeTargetService.getTargetDirectories(appPath)[0];
22
- const extensionFolder = this.$iOSNativeTargetService.getTargetDirectories(extensionPath)[0];
23
54
  const project = new this.$xcode.project(pbxProjPath);
24
55
  project.parseSync();
25
- const watchApptarget = this.$iOSNativeTargetService.addTargetToProject(appPath, appFolder, constants_1.IOSNativeTargetTypes.watchApp, project, platformData, project.getFirstTarget().uuid);
26
- this.configureTarget(appFolder, path.join(appPath, appFolder), `${projectData.projectIdentifiers.ios}.${IOSWatchAppService.WATCH_APP_IDENTIFIER}`, "watchapp.json", watchApptarget, project);
56
+ const configPath = path.join(path.join(appPath, appFolder), "watchapp.json");
57
+ const config = this.$fs.exists(configPath) ? this.$fs.readJson(configPath) : null;
58
+ const targetType = (_a = config === null || config === void 0 ? void 0 : config.targetType) !== null && _a !== void 0 ? _a : constants_1.IOSNativeTargetTypes.watchApp;
59
+ project.removeTargetsByProductType(constants_1.IOSNativeTargetProductTypes.watchApp);
60
+ project.removeTargetsByProductType(targetType);
61
+ const parentTargetUuid = project.getFirstTarget().uuid;
62
+ const watchApptarget = this.addTarget(appPath, appFolder, targetType, project, platformData, parentTargetUuid, constants_1.IOSNativeTargetTypes.watchApp);
63
+ await this.configureTarget(appFolder, path.join(appPath, appFolder), `${projectData.projectIdentifiers.ios}.${WATCH_APP_IDENTIFIER}`, configPath, config, watchApptarget, project, projectData, platformData, pbxProjPath);
27
64
  targetUuids.push(watchApptarget.uuid);
28
- const watchExtensionTarget = this.$iOSNativeTargetService.addTargetToProject(extensionPath, extensionFolder, constants_1.IOSNativeTargetTypes.watchExtension, project, platformData, watchApptarget.uuid);
29
- this.configureTarget(extensionFolder, path.join(extensionPath, extensionFolder), `${projectData.projectIdentifiers.ios}.${IOSWatchAppService.WATCH_APP_IDENTIFIER}.${IOSWatchAppService.WACTCH_EXTENSION_IDENTIFIER}`, "extension.json", watchExtensionTarget, project);
30
- targetUuids.push(watchExtensionTarget.uuid);
65
+ targetNames.push(appFolder);
66
+ const extensionPath = path.join(watchAppFolderPath, constants_1.IOS_WATCHAPP_EXTENSION_FOLDER);
67
+ // Extension is optional (Xcode 14+ supports single target)
68
+ if (this.$fs.exists(extensionPath)) {
69
+ const extensionFolder = this.$iOSNativeTargetService.getTargetDirectories(extensionPath)[0];
70
+ const configPath = path.join(path.join(extensionPath, extensionFolder), "extension.json");
71
+ const config = this.$fs.exists(configPath) ? this.$fs.readJson(configPath) : null;
72
+ const targetType = (_b = config === null || config === void 0 ? void 0 : config.targetType) !== null && _b !== void 0 ? _b : constants_1.IOSNativeTargetTypes.watchExtension;
73
+ project.removeTargetsByProductType(constants_1.IOSNativeTargetProductTypes.watchExtension);
74
+ project.removeTargetsByProductType(targetType);
75
+ const watchExtensionTarget = this.addTarget(extensionPath, extensionFolder, targetType, project, platformData, watchApptarget.uuid);
76
+ await this.configureTarget(extensionFolder, path.join(extensionPath, extensionFolder), `${projectData.projectIdentifiers.ios}.${WATCH_APP_IDENTIFIER}.${WACTCH_EXTENSION_IDENTIFIER}`, configPath, config, watchExtensionTarget, project, projectData, platformData, pbxProjPath);
77
+ targetUuids.push(watchExtensionTarget.uuid);
78
+ targetNames.push(extensionFolder);
79
+ }
80
+ else {
81
+ this.$logger.debug("No watch extension found - using single target mode (Xcode 14+)");
82
+ }
31
83
  this.$fs.writeFile(pbxProjPath, project.writeSync({ omitEmptyValues: true }));
84
+ // Add SPM packages (file needs to be saved first)
85
+ const watchSPMPackages = this.getWatchSPMPackages(platformData);
86
+ await this.applySPMPackagesToTargets(targetNames, platformData, projectData.projectDir, watchSPMPackages);
87
+ // nothing done after we dont need to reload project
32
88
  this.$iOSNativeTargetService.prepareSigning(targetUuids, projectData, pbxProjPath);
33
89
  return true;
34
90
  }
91
+ addTarget(targetRootPath, targetFolder, targetType, project, platformData, parentTarget, productTargetType) {
92
+ const targetPath = path.join(targetRootPath, targetFolder);
93
+ const targetRelativePath = path.relative(platformData.projectRoot, targetPath);
94
+ const target = project.addTarget(targetFolder, targetType, targetRelativePath, parentTarget, productTargetType);
95
+ // Add build phases
96
+ project.addBuildPhase([], "PBXSourcesBuildPhase", "Sources", target.uuid);
97
+ project.addBuildPhase([], "PBXResourcesBuildPhase", "Resources", target.uuid);
98
+ project.addBuildPhase([], "PBXFrameworksBuildPhase", "Frameworks", target.uuid);
99
+ project.addBuildPhase([], "PBXCopyFilesBuildPhase", "Embed Frameworks", target.uuid);
100
+ project.addToHeaderSearchPaths(targetPath, target.pbxNativeTarget.productName);
101
+ return target;
102
+ }
103
+ /**
104
+ * Recursively add source files from a directory to a target
105
+ */
106
+ addSourceFilesFromDirectory(dirPath, targetUuid, project, platformData, groupName, excludePatterns) {
107
+ const items = this.getFolderFiles(dirPath, platformData.projectRoot, excludePatterns);
108
+ for (const item of items) {
109
+ const relativePath = path.relative(platformData.projectRoot, item);
110
+ // Check if file is a source file by extension
111
+ const ext = path.extname(item).toLowerCase();
112
+ if (sourceExtensions.includes(ext)) {
113
+ this.$logger.debug(`Adding source file: ${relativePath}`);
114
+ this.addSourceFile(project, relativePath, { target: targetUuid }, groupName);
115
+ }
116
+ }
117
+ }
118
+ async addTargetResources(watchAppFolderPath, targetUuids, project, platformData, groupName, excludePatterns) {
119
+ try {
120
+ if (!this.$fs.exists(watchAppFolderPath)) {
121
+ return;
122
+ }
123
+ for (let i = 0; i < targetUuids.length; i++) {
124
+ const targetUuid = targetUuids[i];
125
+ this.addResourcesFromDirectory(watchAppFolderPath, targetUuid, project, platformData, groupName, excludePatterns);
126
+ }
127
+ this.$logger.debug("Watch app resources added successfully");
128
+ }
129
+ catch (err) {
130
+ this.$logger.warn(`Error adding watch app resources: ${err.message}`);
131
+ }
132
+ }
133
+ /**
134
+ * Recursively add resources from a directory to a target
135
+ */
136
+ addResourcesFromDirectory(dirPath, targetUuid, project, platformData, groupName, excludePatterns) {
137
+ const items = this.$fs.readDirectory(dirPath);
138
+ for (const item of items) {
139
+ // Skip hidden files and excluded files/directories
140
+ if (item.startsWith('.') || RESOURCES_TO_IGNORE.indexOf(item) !== -1) {
141
+ continue;
142
+ }
143
+ const itemPath = path.join(dirPath, item);
144
+ const stats = this.$fs.getFsStats(itemPath);
145
+ const relativePath = path.relative(platformData.projectRoot, itemPath);
146
+ // Check if file/directory should be excluded based on patterns
147
+ if (excludePatterns && this.shouldExclude(relativePath, excludePatterns)) {
148
+ this.$logger.debug(`Excluding from resources: ${relativePath}`);
149
+ continue;
150
+ }
151
+ if (stats.isDirectory()) {
152
+ // Special handling for .xcassets, .bundle, and other resource bundles
153
+ if (item.endsWith('.xcassets') || item.endsWith('.bundle')) {
154
+ this.$logger.debug(`Adding resource bundle: ${relativePath}`);
155
+ this.addResourceFile(project, relativePath, { target: targetUuid }, groupName);
156
+ }
157
+ else {
158
+ // Recursively scan subdirectories
159
+ this.addResourcesFromDirectory(itemPath, targetUuid, project, platformData, groupName, excludePatterns);
160
+ }
161
+ }
162
+ else {
163
+ // Check if file is a resource by extension
164
+ const ext = path.extname(item).toLowerCase();
165
+ if (resourceExtensions.includes(ext)) {
166
+ this.$logger.debug(`Adding resource file: ${relativePath}`);
167
+ this.addResourceFile(project, relativePath, { target: targetUuid }, groupName);
168
+ }
169
+ }
170
+ }
171
+ }
35
172
  removeWatchApp({ pbxProjPath }) {
36
173
  const project = new this.$xcode.project(pbxProjPath);
37
174
  project.parseSync();
@@ -43,24 +180,460 @@ class IOSWatchAppService {
43
180
  const watchAppPath = path.join(projectData.getAppResourcesDirectoryPath(), platformData.normalizedPlatformName, constants_1.IOS_WATCHAPP_FOLDER);
44
181
  return this.$fs.exists(watchAppPath);
45
182
  }
46
- configureTarget(targetName, targetPath, identifier, configurationFileName, target, project) {
47
- const targetConfigurationJsonPath = path.join(targetPath, configurationFileName);
183
+ async configureTarget(targetName, targetPath, identifier, configPath, config, target, project, projectData, platformData, pbxProjPath) {
48
184
  const identifierParts = identifier.split(".");
49
185
  identifierParts.pop();
50
186
  const wkAppBundleIdentifier = identifierParts.join(".");
51
- this.$iOSNativeTargetService.setXcodeTargetBuildConfigurationProperties([
187
+ // Build configuration properties
188
+ const buildConfigProperties = [
52
189
  { name: "PRODUCT_BUNDLE_IDENTIFIER", value: identifier },
53
190
  { name: "SDKROOT", value: "watchos" },
54
191
  { name: "TARGETED_DEVICE_FAMILY", value: constants_1.IOSDeviceTargets.watchos },
55
192
  { name: "WATCHOS_DEPLOYMENT_TARGET", value: 5.2 },
56
193
  { name: "WK_APP_BUNDLE_IDENTIFIER", value: wkAppBundleIdentifier },
57
- ], targetName, project);
58
- this.$iOSNativeTargetService.setConfigurationsFromJsonFile(targetConfigurationJsonPath, target.uuid, targetName, project);
194
+ ];
195
+ const resourcesGroup = targetName + "Resources";
196
+ project.addPbxGroup([], resourcesGroup, project.filepath, null, {
197
+ isMain: true,
198
+ target: target.uuid,
199
+ filesRelativeToProject: true,
200
+ });
201
+ const srcGroup = targetName + "Src";
202
+ project.addPbxGroup([], srcGroup, project.filepath, null, {
203
+ isMain: true,
204
+ target: target.uuid,
205
+ filesRelativeToProject: true,
206
+ });
207
+ let basedir;
208
+ if (config === null || config === void 0 ? void 0 : config.basedir) {
209
+ basedir = path.resolve(path.dirname(configPath), config.basedir);
210
+ if (!this.$fs.exists(basedir)) {
211
+ this.$logger.warn(`Basedir not found, using config directory: ${basedir}`);
212
+ basedir = path.dirname(configPath);
213
+ }
214
+ }
215
+ else {
216
+ basedir = path.dirname(configPath);
217
+ }
218
+ const resourcesExclude = (config === null || config === void 0 ? void 0 : config.resourcesExclude) || [];
219
+ const srcExclude = (config === null || config === void 0 ? void 0 : config.srcExclude) || [];
220
+ // Handle custom Info.plist path
221
+ if (config === null || config === void 0 ? void 0 : config.infoPlistPath) {
222
+ const infoPlistPath = path.resolve(basedir, config.infoPlistPath);
223
+ if (this.$fs.exists(infoPlistPath)) {
224
+ const relativeInfoPlistPath = path.relative(platformData.projectRoot, infoPlistPath);
225
+ buildConfigProperties.push({
226
+ name: "INFOPLIST_FILE",
227
+ value: `"${infoPlistPath}"`
228
+ });
229
+ resourcesExclude.push(relativeInfoPlistPath);
230
+ }
231
+ else {
232
+ this.$logger.warn(`Custom Info.plist not found at: ${infoPlistPath}`);
233
+ }
234
+ }
235
+ // Handle custom xcprivacy file path
236
+ if (config === null || config === void 0 ? void 0 : config.xcprivacyPath) {
237
+ const xcprivacyPath = path.resolve(basedir, config.xcprivacyPath);
238
+ if (this.$fs.exists(xcprivacyPath)) {
239
+ const relativeXcprivacyPath = path.relative(platformData.projectRoot, xcprivacyPath);
240
+ this.addResourceFile(project, xcprivacyPath, { target: target.uuid }, targetName + "Resources");
241
+ resourcesExclude.push(relativeXcprivacyPath);
242
+ }
243
+ else {
244
+ this.$logger.warn(`Custom xcprivacy file not found at: ${xcprivacyPath}`);
245
+ }
246
+ }
247
+ this.$iOSNativeTargetService.setXcodeTargetBuildConfigurationProperties(buildConfigProperties, targetName, project);
248
+ this.$iOSNativeTargetService.setConfigurationsFromJsonFile(configPath, target.uuid, targetName, project);
59
249
  project.addToHeaderSearchPaths(targetPath, target.pbxNativeTarget.productName);
250
+ if ((config === null || config === void 0 ? void 0 : config.importSourcesFromMainFolder) !== false) {
251
+ await this.addSourceFilesFromDirectory(path.dirname(configPath), target.uuid, project, platformData, targetName + 'Src', srcExclude);
252
+ }
253
+ if ((config === null || config === void 0 ? void 0 : config.importResourcesFromMainFolder) !== false) {
254
+ await this.addTargetResources(path.dirname(configPath), [target.uuid], project, platformData, resourcesGroup, resourcesExclude);
255
+ }
256
+ if (config) {
257
+ // Process additional configurations
258
+ await this.processWatchAppConfiguration(config, basedir, targetName, target, project, projectData, platformData, pbxProjPath, srcExclude, resourcesExclude);
259
+ }
260
+ }
261
+ async processWatchAppConfiguration(config, basedir, targetName, target, project, projectData, platformData, pbxProjPath, srcExclude, resourcesExclude) {
262
+ this.$logger.debug(`processWatchAppConfiguration ${JSON.stringify(config)}`);
263
+ // Handle custom resources
264
+ if (config.resources && Array.isArray(config.resources)) {
265
+ this.$logger.debug(`Processing ${config.resources.length} custom resource(s) for watch target: ${targetName}`);
266
+ for (const resourcePath of config.resources) {
267
+ this.addCustomResource(resourcePath, target.uuid, project, projectData, platformData, targetName + "Resources", resourcesExclude, basedir);
268
+ }
269
+ }
270
+ if (config.src && Array.isArray(config.src)) {
271
+ this.$logger.debug(`Processing ${config.src.length} custom source file(s) for watch target: ${targetName}`);
272
+ for (const srcPath of config.src) {
273
+ this.addCustomSourceFile(srcPath, target.uuid, project, projectData, platformData, srcExclude, targetName + 'Src', basedir);
274
+ }
275
+ }
276
+ if (config.SPMPackages && Array.isArray(config.SPMPackages)) {
277
+ // to be able to add SPM the file needs to be saved
278
+ // but it means we need to reload it again after spm packages addition
279
+ this.$fs.writeFile(pbxProjPath, project.writeSync({ omitEmptyValues: true }));
280
+ await this.applySPMPackagesToTargets([targetName], platformData, basedir, config.SPMPackages);
281
+ project.parseSync();
282
+ }
283
+ if (config.modules && Array.isArray(config.modules)) {
284
+ this.$logger.debug(`Processing ${config.modules.length} module(s) for watch target: ${targetName}`);
285
+ for (const moduleDef of config.modules) {
286
+ await this.addModuleDependency(moduleDef, config, targetName, target, project, projectData, platformData, srcExclude, resourcesExclude, basedir);
287
+ }
288
+ }
289
+ }
290
+ addCustomResource(resourcePath, targetUuid, project, projectData, platformData, groupName, excludePatterns, basedir) {
291
+ const resolvedPath = this.resolvePathWithBasedir(resourcePath, basedir, projectData.projectDir);
292
+ if (!this.$fs.exists(resolvedPath)) {
293
+ this.$logger.warn(`Custom resource not found, skipping: ${resourcePath}`);
294
+ return;
295
+ }
296
+ const relativePath = path.relative(platformData.projectRoot, resolvedPath);
297
+ if (excludePatterns && this.shouldExclude(relativePath, excludePatterns)) {
298
+ this.$logger.debug(`Excluding from resources: ${relativePath}`);
299
+ return;
300
+ }
301
+ const stats = this.$fs.getFsStats(resolvedPath);
302
+ if (stats.isDirectory()) {
303
+ this.$logger.debug(`Recursively adding files from resource directory: ${resourcePath}`);
304
+ if (relativePath.endsWith('.xcassets') || relativePath.endsWith('.bundle')) {
305
+ this.$logger.debug(`Adding resource bundle: ${relativePath} for target:${targetUuid}`);
306
+ this.addResourceFile(project, relativePath, { target: targetUuid }, groupName);
307
+ }
308
+ else {
309
+ this.addAllResourcesRecursively(resolvedPath, targetUuid, project, platformData, groupName, excludePatterns);
310
+ }
311
+ }
312
+ else {
313
+ this.$logger.debug(`Adding custom resource file: ${relativePath}`);
314
+ this.addResourceFile(project, relativePath, { target: targetUuid }, groupName);
315
+ }
316
+ }
317
+ addCustomSourceFile(srcPath, targetUuid, project, projectData, platformData, excludePatterns, groupName, basedir) {
318
+ const resolvedPath = this.resolvePathWithBasedir(srcPath, basedir, projectData.projectDir);
319
+ if (!this.$fs.exists(resolvedPath)) {
320
+ this.$logger.warn(`Custom source file/folder not found, skipping: ${srcPath}`);
321
+ return;
322
+ }
323
+ const relativePath = path.relative(platformData.projectRoot, resolvedPath);
324
+ if (excludePatterns && this.shouldExclude(relativePath, excludePatterns)) {
325
+ this.$logger.debug(`Excluding from src: ${relativePath}`);
326
+ return;
327
+ }
328
+ const stats = this.$fs.getFsStats(resolvedPath);
329
+ if (stats.isDirectory()) {
330
+ this.$logger.debug(`Adding custom source directory: ${relativePath}`);
331
+ this.addAllSourceFilesFromDirectory(resolvedPath, targetUuid, project, platformData, groupName, excludePatterns);
332
+ }
333
+ else {
334
+ this.$logger.debug(`Adding custom source file: ${relativePath}`);
335
+ this.addSourceFile(project, relativePath, { target: targetUuid }, groupName);
336
+ }
337
+ }
338
+ resolvePathWithBasedir(relativePath, basedir, fallbackDir) {
339
+ return basedir
340
+ ? path.resolve(basedir, relativePath)
341
+ : path.resolve(fallbackDir, relativePath);
342
+ }
343
+ addAllSourceFilesFromDirectory(dirPath, targetUuid, project, platformData, groupName, excludePatterns) {
344
+ const items = this.getFolderFiles(dirPath, platformData.projectRoot, excludePatterns);
345
+ for (const item of items) {
346
+ const relativePath = path.relative(platformData.projectRoot, item);
347
+ // Check if file is a source file by extension
348
+ const ext = path.extname(item).toLowerCase();
349
+ if (sourceExtensions.includes(ext)) {
350
+ this.$logger.debug(`Adding source file: ${relativePath}`);
351
+ this.addSourceFile(project, relativePath, { target: targetUuid }, groupName);
352
+ }
353
+ }
354
+ }
355
+ addAllResourcesRecursively(dirPath, targetUuid, project, platformData, groupName, excludePatterns) {
356
+ const items = this.$fs.readDirectory(dirPath);
357
+ for (const item of items) {
358
+ if (item.startsWith('.')) {
359
+ continue;
360
+ }
361
+ const itemPath = path.join(dirPath, item);
362
+ const stats = this.$fs.getFsStats(itemPath);
363
+ const relativePath = path.relative(platformData.projectRoot, itemPath);
364
+ if (excludePatterns && this.shouldExclude(relativePath, excludePatterns)) {
365
+ this.$logger.debug(`Excluding from resources: ${relativePath}`);
366
+ return;
367
+ }
368
+ if (stats.isDirectory()) {
369
+ // Special handling for .xcassets, .bundle - add as bundles, not recursively
370
+ if (item.endsWith('.xcassets') || item.endsWith('.bundle')) {
371
+ this.$logger.debug(`Adding resource bundle: ${relativePath} for target:${targetUuid}`);
372
+ this.addResourceFile(project, relativePath, { target: targetUuid }, groupName);
373
+ }
374
+ else {
375
+ this.addAllResourcesRecursively(itemPath, targetUuid, project, platformData, groupName, excludePatterns);
376
+ }
377
+ }
378
+ else {
379
+ this.$logger.debug(`Adding resource file: ${relativePath}`);
380
+ this.addResourceFile(project, relativePath, { target: targetUuid }, groupName);
381
+ }
382
+ }
383
+ }
384
+ async addModuleDependency(moduleDef, config, targetName, target, project, projectData, platformData, srcExclude, resourcesExclude, basedir) {
385
+ const modulePath = moduleDef.path
386
+ ? this.resolvePathWithBasedir(moduleDef.path, basedir, projectData.projectDir)
387
+ : null;
388
+ if (!modulePath || !this.$fs.exists(modulePath)) {
389
+ this.$logger.warn(`Module path not found, skipping module: ${modulePath}`);
390
+ return;
391
+ }
392
+ const relativePath = path.relative(platformData.projectRoot, modulePath);
393
+ const stats = this.$fs.getFsStats(modulePath);
394
+ const isFramework = modulePath.endsWith('.framework') || modulePath.endsWith('.xcframework');
395
+ const isFolder = stats.isDirectory() && !isFramework;
396
+ this.$logger.debug(`Adding module dependency: ${JSON.stringify(moduleDef)} to ${targetName}, basedir:${basedir}, isFramework:${isFramework} isFolder:${isFolder}`);
397
+ if (isFramework) {
398
+ // Handle compiled frameworks (xcframework, framework)
399
+ this.addCompiledFramework(moduleDef, relativePath, targetName, target, project);
400
+ }
401
+ else if (isFolder) {
402
+ // Handle folder-based modules
403
+ await this.addFolderModule(moduleDef, modulePath, relativePath, targetName, target, config, project, basedir, srcExclude, resourcesExclude, projectData, platformData);
404
+ }
405
+ else {
406
+ this.$logger.warn(`Unknown module type for: ${modulePath}`);
407
+ }
408
+ if (moduleDef.headerSearchPaths && Array.isArray(moduleDef.headerSearchPaths)) {
409
+ for (const headerPath of moduleDef.headerSearchPaths) {
410
+ const resolvedPath = this.resolvePathWithBasedir(headerPath, basedir, projectData.projectDir);
411
+ const relPath = path.relative(platformData.projectRoot, resolvedPath);
412
+ project.addToHeaderSearchPaths(relPath, targetName);
413
+ this.$logger.debug(`Added header search path: ${relPath}`);
414
+ }
415
+ }
416
+ if (moduleDef.linkerFlags && Array.isArray(moduleDef.linkerFlags)) {
417
+ this.addLinkerFlags(moduleDef.linkerFlags, targetName, project);
418
+ }
419
+ }
420
+ addCompiledFramework(moduleDef, relativePath, targetName, target, project) {
421
+ const moduleName = moduleDef.name;
422
+ project.addFramework(relativePath, {
423
+ target: target.uuid,
424
+ customFramework: true,
425
+ embed: moduleDef.embed !== false, // Default to true
426
+ });
427
+ const frameworkDir = path.dirname(relativePath);
428
+ project.addBuildProperty("FRAMEWORK_SEARCH_PATHS", `"$(inherited)" "${frameworkDir}"`, null, targetName);
429
+ this.$logger.debug(`Added compiled framework ${moduleName} at ${relativePath}`);
430
+ }
431
+ getFolderFiles(dirPath, rootPath, excludePatterns) {
432
+ const result = [];
433
+ const files = this.$fs.readDirectory(dirPath).filter((fileName) => !fileName.startsWith("."));
434
+ for (const item of files) {
435
+ const itemPath = path.join(dirPath, item);
436
+ const stats = this.$fs.getFsStats(itemPath);
437
+ const relativePath = path.relative(rootPath, itemPath);
438
+ if (excludePatterns && this.shouldExclude(relativePath, excludePatterns)) {
439
+ this.$logger.debug(`Excluding from src: ${relativePath}`);
440
+ continue;
441
+ }
442
+ if (stats.isDirectory()) {
443
+ result.push(...this.getFolderFiles(itemPath, rootPath, excludePatterns));
444
+ }
445
+ else {
446
+ result.push(itemPath);
447
+ }
448
+ }
449
+ return result;
450
+ }
451
+ addBuildPhaseIfNotExisting(project, buildPhaseType, comment, target) {
452
+ let buildPhase = project.buildPhaseObject(buildPhaseType, comment, target);
453
+ if (!buildPhase) {
454
+ project.addBuildPhase([], buildPhaseType, comment, target);
455
+ }
456
+ }
457
+ async addFolderModule(moduleDef, modulePath, relativePath, targetName, target, config, project, basedir, srcExclude, resourcesExclude, projectData, platformData) {
458
+ var _a;
459
+ const moduleName = moduleDef.name || path.basename(modulePath);
460
+ const targetRelativePath = path.relative(platformData.projectRoot, modulePath);
461
+ const moduleTarget = project.addTarget(moduleName, (_a = moduleDef.targetType) !== null && _a !== void 0 ? _a : 'framework', targetRelativePath, target.uuid);
462
+ this.$logger.debug(`Adding folder module ${moduleName} with path ${modulePath} with target uuid:${moduleTarget.uuid}`);
463
+ const { path: filePath, name, dependencies, frameworks, buildConfigurationProperties, src, resources, SPMPackages, ...otherProps } = moduleDef;
464
+ project.addFramework(moduleName + '.framework', {
465
+ target: target.uuid,
466
+ basename: moduleName,
467
+ path: moduleName + '.framework',
468
+ customFramework: true,
469
+ explicitFileType: 'wrapper.framework',
470
+ ...otherProps
471
+ });
472
+ // Add build phases
473
+ project.addBuildPhase([], "PBXSourcesBuildPhase", "Sources", moduleTarget.uuid);
474
+ project.addBuildPhase([], "PBXResourcesBuildPhase", "Resources", moduleTarget.uuid);
475
+ project.addBuildPhase([], "PBXFrameworksBuildPhase", "Frameworks", moduleTarget.uuid);
476
+ project.addBuildPhase([], "PBXCopyFilesBuildPhase", "Embed Frameworks", moduleTarget.uuid);
477
+ const files = this.getFolderFiles(modulePath, platformData.projectRoot, srcExclude);
478
+ this.$logger.debug(`module ${moduleName} has ${files.length} files`);
479
+ if (files.length > 0) {
480
+ project.addPbxGroup(files, moduleName, modulePath, null, {
481
+ isMain: true,
482
+ target: moduleTarget.uuid,
483
+ filesRelativeToProject: true,
484
+ });
485
+ }
486
+ if (moduleDef.frameworks && Array.isArray(moduleDef.frameworks)) {
487
+ this.$logger.debug(`Adding ${moduleDef.frameworks.length} framework(s) for module ${JSON.stringify(moduleDef)}`);
488
+ for (const framework of moduleDef.frameworks) {
489
+ this.$logger.debug(`Adding framework ${JSON.stringify(framework)} for module ${JSON.stringify(moduleDef)}`);
490
+ if (typeof framework === 'string') {
491
+ project.addFramework(framework, { target: moduleTarget.uuid });
492
+ }
493
+ else {
494
+ project.addFramework(framework.path, { target: moduleTarget.uuid, ...framework });
495
+ }
496
+ this.$logger.debug(`Added framework dependency: ${framework}`);
497
+ }
498
+ }
499
+ if (moduleDef.src && Array.isArray(moduleDef.src)) {
500
+ this.$logger.debug(`Processing ${config.src.length} custom source file(s) for target: ${moduleName}`);
501
+ for (const srcPath of moduleDef.src) {
502
+ this.addCustomSourceFile(srcPath, moduleTarget.uuid, project, projectData, platformData, srcExclude, moduleName + 'Src', basedir);
503
+ }
504
+ }
505
+ if (moduleDef.resources && Array.isArray(moduleDef.resources)) {
506
+ this.$logger.debug(`Processing ${moduleDef.resources.length} custom resource(s) for target: ${moduleName}/${moduleTarget.uuid}`);
507
+ for (const resourcePath of moduleDef.resources) {
508
+ this.addCustomResource(resourcePath, moduleTarget.uuid, project, projectData, platformData, targetName + "Resources", resourcesExclude, basedir);
509
+ }
510
+ }
511
+ if (moduleDef.dependencies && Array.isArray(moduleDef.dependencies)) {
512
+ const currentTargets = project.pbxNativeTargetSection();
513
+ const currentTargetsArray = Object.keys(currentTargets).map(k => currentTargets[k]['name'] ? ({ uuid: k, name: currentTargets[k]['name'] }) : null).filter(t => !!t);
514
+ const targets = moduleDef.dependencies.map(dependency => currentTargetsArray.find(t => t.name === `\"${dependency}\"`)).filter(s => !!s);
515
+ if (targets.length) {
516
+ this.$logger.debug(`Adding target dependencies ${moduleDef.dependencies} with uuids:${targets.map(t => t.uuid)} for module ${moduleDef.name}`);
517
+ project.addTargetDependency(moduleTarget.uuid, targets.map(t => t.uuid));
518
+ }
519
+ }
520
+ if (moduleDef.SPMPackages && Array.isArray(moduleDef.SPMPackages)) {
521
+ // to be able to add SPM the file needs to be saved
522
+ // but it means we need to reload it again after spm packages addition
523
+ this.$fs.writeFile(project.filepath, project.writeSync({ omitEmptyValues: true }));
524
+ await this.applySPMPackagesToTargets([moduleName], platformData, basedir, moduleDef.SPMPackages.map(t => {
525
+ if (typeof t === 'string') {
526
+ return config.SPMPackages.find(s => s.name === t);
527
+ }
528
+ return t;
529
+ }));
530
+ project.parseSync();
531
+ }
532
+ if (moduleDef.buildConfigurationProperties || config.sharedModulesBuildConfigurationProperties) {
533
+ const configurationProperties = { ...(config.sharedModulesBuildConfigurationProperties || {}), ...(moduleDef.buildConfigurationProperties || {}) };
534
+ this.$iOSNativeTargetService.setXcodeTargetBuildConfigurationProperties(Object.keys(configurationProperties).map(k => ({ name: k, value: configurationProperties[k] })), moduleName, project);
535
+ }
536
+ this.$logger.debug(`Added folder-based module ${moduleName} at ${relativePath}`);
537
+ }
538
+ /**
539
+ * Add linker flags to a target's build settings
540
+ */
541
+ addLinkerFlags(flags, targetName, project) {
542
+ for (const flag of flags) {
543
+ const currentFlags = this.getBuildProperty("OTHER_LDFLAGS", targetName, project);
544
+ const flagsArray = currentFlags
545
+ ? (Array.isArray(currentFlags) ? currentFlags : [currentFlags])
546
+ : ['"$(inherited)"'];
547
+ if (!flagsArray.includes(flag)) {
548
+ flagsArray.push(flag);
549
+ }
550
+ project.addBuildProperty("OTHER_LDFLAGS", flagsArray, null, targetName);
551
+ this.$logger.debug(`Added linker flag: ${flag}`);
552
+ }
553
+ }
554
+ /**
555
+ * Get build property value for a specific target
556
+ */
557
+ getBuildProperty(propertyName, targetName, project) {
558
+ // Access the project hash to read build settings
559
+ const projectHash = project.hash;
560
+ if (!projectHash) {
561
+ return null;
562
+ }
563
+ const configurations = projectHash.project.objects.XCBuildConfiguration;
564
+ if (!configurations) {
565
+ return null;
566
+ }
567
+ for (const key in configurations) {
568
+ const config = configurations[key];
569
+ if (config && config.buildSettings &&
570
+ (config.buildSettings.PRODUCT_NAME === targetName ||
571
+ config.buildSettings.PRODUCT_NAME === `"${targetName}"`)) {
572
+ return config.buildSettings[propertyName];
573
+ }
574
+ }
575
+ return null;
576
+ }
577
+ /**
578
+ * Check if a path should be excluded based on glob patterns
579
+ */
580
+ shouldExclude(filePath, excludePatterns) {
581
+ for (const pattern of excludePatterns) {
582
+ const matcher = new minimatch_1.Minimatch(pattern, { dot: true });
583
+ if (matcher.match(filePath)) {
584
+ return true;
585
+ }
586
+ }
587
+ return false;
588
+ }
589
+ /**
590
+ * Apply SPM packages to watch app targets
591
+ */
592
+ async applySPMPackagesToTargets(targetNames, platformData, basedir, watchSPMPackages) {
593
+ try {
594
+ this.$logger.debug(`applySPMPackagesToTargets ${JSON.stringify(watchSPMPackages)}`);
595
+ if (watchSPMPackages.length === 0) {
596
+ return;
597
+ }
598
+ this.$logger.debug(`Applying ${watchSPMPackages.length} SPM package(s) to targets:${targetNames}`);
599
+ const project = new trapezedev_project_1.MobileProject(platformData.projectRoot, {
600
+ ios: {
601
+ path: ".",
602
+ },
603
+ enableAndroid: false,
604
+ });
605
+ await project.load();
606
+ if (!project.ios) {
607
+ this.$logger.debug("No iOS project found via trapeze");
608
+ return;
609
+ }
610
+ // Add SPM packages to each watch target
611
+ for (const pkg of watchSPMPackages) {
612
+ if ("path" in pkg) {
613
+ pkg.path = path.resolve(basedir, pkg.path);
614
+ }
615
+ this.$logger.debug(`Adding SPM package ${JSON.stringify(pkg)} to targets ${targetNames}`);
616
+ for (const targetName of targetNames) {
617
+ project.ios.addSPMPackage(targetName, pkg);
618
+ }
619
+ }
620
+ await project.commit();
621
+ this.$logger.debug(`Successfully applied SPM packages to targets ${targetNames}`);
622
+ }
623
+ catch (err) {
624
+ this.$logger.debug(`Error applying SPM packages to targets ${targetNames} "`, err);
625
+ }
626
+ }
627
+ /**
628
+ * Get SPM packages configured for watch app targets
629
+ */
630
+ getWatchSPMPackages(platformData) {
631
+ const $projectConfigService = yok_1.injector.resolve("projectConfigService");
632
+ // Check for watch-specific SPM packages in config
633
+ const watchPackages = $projectConfigService.getValue(`${platformData.platformNameLowerCase}.watchApp.SPMPackages`, []);
634
+ return watchPackages;
60
635
  }
61
636
  }
62
637
  exports.IOSWatchAppService = IOSWatchAppService;
63
- IOSWatchAppService.WATCH_APP_IDENTIFIER = "watchkitapp";
64
- IOSWatchAppService.WACTCH_EXTENSION_IDENTIFIER = "watchkitextension";
65
638
  yok_1.injector.register("iOSWatchAppService", IOSWatchAppService);
66
639
  //# sourceMappingURL=ios-watch-app-service.js.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nativescript",
3
3
  "main": "./lib/nativescript-cli-lib.js",
4
- "version": "9.0.5",
4
+ "version": "9.0.6-dev.0",
5
5
  "author": "NativeScript <oss@nativescript.org>",
6
6
  "description": "Command-line interface for building NativeScript projects",
7
7
  "bin": {
@@ -81,7 +81,7 @@
81
81
  "minimatch": "10.2.4",
82
82
  "mkdirp": "3.0.1",
83
83
  "mute-stream": "2.0.0",
84
- "nativescript-dev-xcode": "0.8.1",
84
+ "nativescript-dev-xcode": "0.8.2-dev.0",
85
85
  "open": "8.4.2",
86
86
  "ora": "5.4.1",
87
87
  "pacote": "21.0.4",