(config: Config, plugins: Plugin[])
| 97 | } |
| 98 | |
| 99 | export async function generatePackageText(config: Config, plugins: Plugin[]): Promise<string> { |
| 100 | const iosPlatformVersion = await getCapacitorPackageVersion(config, config.ios.name); |
| 101 | const iosVersion = getMajoriOSVersion(config); |
| 102 | const packageTraits = config.app.extConfig.experimental?.ios?.spm?.packageTraits ?? {}; |
| 103 | const packageOptions = config.app.extConfig.experimental?.ios?.spm?.packageOptions ?? {}; |
| 104 | const swiftToolsVersion = config.app.extConfig.experimental?.ios?.spm?.swiftToolsVersion ?? '5.9'; |
| 105 | |
| 106 | let packageSwiftText = `// swift-tools-version: ${swiftToolsVersion} |
| 107 | import PackageDescription |
| 108 | |
| 109 | // DO NOT MODIFY THIS FILE - managed by Capacitor CLI commands |
| 110 | let package = Package( |
| 111 | name: "CapApp-SPM", |
| 112 | platforms: [.iOS(.v${iosVersion})], |
| 113 | products: [ |
| 114 | .library( |
| 115 | name: "CapApp-SPM", |
| 116 | targets: ["CapApp-SPM"]) |
| 117 | ], |
| 118 | dependencies: [ |
| 119 | .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", exact: "${iosPlatformVersion}")`; |
| 120 | |
| 121 | for (const plugin of plugins) { |
| 122 | if (getPluginType(plugin, config.ios.name) === PluginType.Cordova) { |
| 123 | const platformTag = getPluginPlatform(plugin, config.ios.name); |
| 124 | if (platformTag.$?.package) { |
| 125 | const relPath = relative(config.ios.nativeXcodeProjDirAbs, plugin.rootPath); |
| 126 | packageSwiftText += `,\n .package(name: "${plugin.id}", path: "${relPath}")`; |
| 127 | } else { |
| 128 | const sourceFiles = getPlatformElement(plugin, config.ios.name, 'source-file'); |
| 129 | const headerFiles = getPlatformElement(plugin, config.ios.name, 'header-file'); |
| 130 | if (sourceFiles.length === 0 && headerFiles.length === 0) { |
| 131 | continue; |
| 132 | } |
| 133 | packageSwiftText += `,\n .package(name: "${plugin.name}", path: "../../capacitor-cordova-ios-plugins/sources/${plugin.name}")`; |
| 134 | } |
| 135 | } else { |
| 136 | const options = packageOptions[plugin.id]; |
| 137 | const symlink = options?.symlink; |
| 138 | const symlinkFolder = join('symlinks', plugin.name); |
| 139 | const relPath = symlink ? symlinkFolder : relative(config.ios.nativeXcodeProjDirAbs, plugin.rootPath); |
| 140 | if (symlink) { |
| 141 | await ensureSymlink(plugin.rootPath, resolve(config.ios.nativeProjectDirAbs, 'CapApp-SPM', symlinkFolder)); |
| 142 | } |
| 143 | const traits = packageTraits[plugin.id]; |
| 144 | const traitsSuffix = traits?.length |
| 145 | ? `, traits: [${traits |
| 146 | .map((t) => { |
| 147 | // Any trait is written with quotes, with the exception of .defaults |
| 148 | return /^\.?defaults?$/i.test(t) ? '.defaults' : `"${t}"`; |
| 149 | }) |
| 150 | .join(', ')}]` |
| 151 | : ''; |
| 152 | packageSwiftText += `,\n .package(name: "${plugin.ios?.name}", path: "${relPath}"${traitsSuffix})`; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | packageSwiftText += ` |
no test coverage detected