nativescript 9.0.5 → 9.0.6-dev.1

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