MCPcopy
hub / github.com/ionic-team/capacitor / writeGeneratedPackageSwift

Function writeGeneratedPackageSwift

cli/src/ios/update.ts:253–312  ·  view source on GitHub ↗
(p: Plugin, config: Config, iosPlatformVersion: string)

Source from the content-addressed store, hash-verified

251}
252
253async function writeGeneratedPackageSwift(p: Plugin, config: Config, iosPlatformVersion: string) {
254 const iosVersion = getMajoriOSVersion(config);
255 const headerFiles = getPlatformElement(p, platform, 'header-file');
256 const headersText =
257 headerFiles.length > 0
258 ? `,
259 publicHeadersPath: "."`
260 : '';
261 const resources = getPlatformElement(p, platform, 'resource-file');
262 const sourceFiles = getPlatformElement(p, platform, 'source-file');
263 if (sourceFiles.length === 0 && headerFiles.length === 0 && resources.length === 0) {
264 return;
265 }
266 const frameworks = getPlatformElement(p, platform, 'framework');
267 const { binaryTargetsText, binaryDepsText } = buildBinaryTargetEntries(p, frameworks);
268 const cSettingsText = buildCSettingsText(p, sourceFiles);
269 const systemFrameworks = frameworks.filter((f: any) => !f.$.custom && f.$.src.endsWith('.framework'));
270 const hasWeakFrameworks = systemFrameworks.some((f: any) => f.$.weak === 'true');
271 const requiredSystemFrameworks = systemFrameworks.filter((f: any) => f.$.weak !== 'true');
272 const resourcesText = buildResourcesText(resources);
273
274 const libraryTypeText = hasWeakFrameworks ? `\n type: .dynamic,` : '';
275 const linkerSettingsText =
276 requiredSystemFrameworks.length > 0
277 ? `,
278 linkerSettings: [
279${requiredSystemFrameworks.map((f: any) => ` .linkedFramework("${f.$.src.replace('.framework', '')}")`).join(',\n')}
280 ]`
281 : '';
282 const { packageText, productText } = await buildDependencyTexts(p, config);
283
284 const content = `// swift-tools-version: 5.9
285
286import PackageDescription
287
288let package = Package(
289 name: "${p.name}",
290 platforms: [.iOS(.v${iosVersion})],
291 products: [
292 .library(
293 name: "${p.name}",${libraryTypeText}
294 targets: ["${p.name}"]
295 )
296 ],
297 dependencies: [
298 .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "${iosPlatformVersion}")${packageText}
299 ],
300 targets: [
301 .target(
302 name: "${p.name}",
303 dependencies: [
304 .product(name: "Cordova", package: "capacitor-swift-pm")${binaryDepsText}${productText}
305 ],
306 path: "."${resourcesText}${headersText}${cSettingsText}${linkerSettingsText}
307 )${binaryTargetsText}
308 ]
309)`;
310

Callers 1

Calls 6

getMajoriOSVersionFunction · 0.90
getPlatformElementFunction · 0.90
buildBinaryTargetEntriesFunction · 0.85
buildCSettingsTextFunction · 0.85
buildResourcesTextFunction · 0.85
buildDependencyTextsFunction · 0.85

Tested by

no test coverage detected