Update capacitor version
This commit is contained in:
parent
91155bce0a
commit
f3b3a86b32
610 changed files with 28718 additions and 7101 deletions
158
@capacitor/cli/dist/ios/update.js
vendored
158
@capacitor/cli/dist/ios/update.js
vendored
|
|
@ -2,7 +2,7 @@
|
|||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.installCocoaPodsPlugins = exports.updateIOS = void 0;
|
||||
const tslib_1 = require("tslib");
|
||||
const utils_fs_1 = require("@ionic/utils-fs");
|
||||
const fs_extra_1 = require("fs-extra");
|
||||
const path_1 = require("path");
|
||||
const colors_1 = tslib_1.__importDefault(require("../colors"));
|
||||
const common_1 = require("../common");
|
||||
|
|
@ -21,34 +21,79 @@ const common_2 = require("./common");
|
|||
const platform = 'ios';
|
||||
async function updateIOS(config, deployment) {
|
||||
const plugins = await getPluginsTask(config);
|
||||
const capacitorPlugins = plugins.filter(p => (0, plugin_1.getPluginType)(p, platform) === 0 /* PluginType.Core */);
|
||||
if ((await (0, spm_1.checkPackageManager)(config)) === 'SPM') {
|
||||
await (0, spm_1.generatePackageFile)(config, capacitorPlugins);
|
||||
}
|
||||
else {
|
||||
await updateIOSCocoaPods(config, plugins, deployment);
|
||||
}
|
||||
const capacitorPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 0 /* PluginType.Core */);
|
||||
await updatePluginFiles(config, plugins, deployment);
|
||||
await (0, common_1.checkPlatformVersions)(config, platform);
|
||||
(0, iosplugin_1.generateIOSPackageJSON)(config, plugins);
|
||||
(0, plugin_1.printPlugins)(capacitorPlugins, 'ios');
|
||||
}
|
||||
exports.updateIOS = updateIOS;
|
||||
async function updateIOSCocoaPods(config, plugins, deployment) {
|
||||
async function updatePluginFiles(config, plugins, deployment) {
|
||||
var _a;
|
||||
await removePluginsNativeFiles(config);
|
||||
const cordovaPlugins = plugins.filter(p => (0, plugin_1.getPluginType)(p, platform) === 1 /* PluginType.Cordova */);
|
||||
const cordovaPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 1 /* PluginType.Cordova */);
|
||||
if (cordovaPlugins.length > 0) {
|
||||
await copyPluginsNativeFiles(config, cordovaPlugins);
|
||||
}
|
||||
if (!(await (0, utils_fs_1.pathExists)(await config.ios.webDirAbs))) {
|
||||
if (!(await (0, fs_extra_1.pathExists)(await config.ios.webDirAbs))) {
|
||||
await (0, copy_1.copy)(config, platform);
|
||||
}
|
||||
await (0, cordova_1.handleCordovaPluginsJS)(cordovaPlugins, config, platform);
|
||||
await (0, cordova_1.checkPluginDependencies)(plugins, platform);
|
||||
await generateCordovaPodspecs(cordovaPlugins, config);
|
||||
await installCocoaPodsPlugins(config, plugins, deployment);
|
||||
await (0, cordova_1.checkPluginDependencies)(plugins, platform, (_a = config.app.extConfig.cordova) === null || _a === void 0 ? void 0 : _a.failOnUninstalledPlugins);
|
||||
if ((await (0, spm_1.checkPackageManager)(config)) === 'SPM') {
|
||||
await generateCordovaPackageFiles(cordovaPlugins, config);
|
||||
const validSPMPackages = await (0, spm_1.checkPluginsForPackageSwift)(config, plugins);
|
||||
await (0, spm_1.generatePackageFile)(config, validSPMPackages);
|
||||
}
|
||||
else {
|
||||
await generateCordovaPodspecs(cordovaPlugins, config);
|
||||
await installCocoaPodsPlugins(config, plugins, deployment);
|
||||
}
|
||||
await (0, cordova_1.logCordovaManualSteps)(cordovaPlugins, config, platform);
|
||||
const incompatibleCordovaPlugins = plugins.filter(p => (0, plugin_1.getPluginType)(p, platform) === 2 /* PluginType.Incompatible */);
|
||||
const incompatibleCordovaPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 2 /* PluginType.Incompatible */);
|
||||
(0, plugin_1.printPlugins)(incompatibleCordovaPlugins, platform, 'incompatible');
|
||||
await (0, common_1.checkPlatformVersions)(config, platform);
|
||||
}
|
||||
async function generateCordovaPackageFiles(cordovaPlugins, config) {
|
||||
cordovaPlugins.map((plugin) => {
|
||||
generateCordovaPackageFile(plugin, config);
|
||||
});
|
||||
}
|
||||
async function generateCordovaPackageFile(p, config) {
|
||||
const iosPlatformVersion = await (0, common_1.getCapacitorPackageVersion)(config, config.ios.name);
|
||||
const iosVersion = (0, common_2.getMajoriOSVersion)(config);
|
||||
const headerFiles = (0, plugin_1.getPlatformElement)(p, platform, 'header-file');
|
||||
let headersText = '';
|
||||
if (headerFiles.length > 0) {
|
||||
headersText = `,
|
||||
publicHeadersPath: "."`;
|
||||
}
|
||||
const content = `// swift-tools-version: 5.9
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "${p.name}",
|
||||
platforms: [.iOS(.v${iosVersion})],
|
||||
products: [
|
||||
.library(
|
||||
name: "${p.name}",
|
||||
targets: ["${p.name}"]
|
||||
)
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "${iosPlatformVersion}")
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "${p.name}",
|
||||
dependencies: [
|
||||
.product(name: "Cordova", package: "capacitor-swift-pm")
|
||||
],
|
||||
path: "."${headersText}
|
||||
)
|
||||
]
|
||||
)`;
|
||||
await (0, fs_extra_1.writeFile)((0, path_1.join)(config.ios.cordovaPluginsDirAbs, 'sources', p.name, 'Package.swift'), content);
|
||||
}
|
||||
async function installCocoaPodsPlugins(config, plugins, deployment) {
|
||||
await (0, common_1.runTask)(`Updating iOS native dependencies with ${colors_1.default.input(`${await config.ios.podPath} install`)}`, () => {
|
||||
|
|
@ -60,31 +105,23 @@ async function updatePodfile(config, plugins, deployment) {
|
|||
const dependenciesContent = await generatePodFile(config, plugins);
|
||||
const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config);
|
||||
const podfilePath = (0, path_1.join)(config.ios.nativeProjectDirAbs, 'Podfile');
|
||||
let podfileContent = await (0, utils_fs_1.readFile)(podfilePath, { encoding: 'utf-8' });
|
||||
let podfileContent = await (0, fs_extra_1.readFile)(podfilePath, { encoding: 'utf-8' });
|
||||
podfileContent = podfileContent.replace(/(def capacitor_pods)[\s\S]+?(\nend)/, `$1${dependenciesContent}$2`);
|
||||
podfileContent = podfileContent.replace(/(require_relative)[\s\S]+?(@capacitor\/ios\/scripts\/pods_helpers')/, `require_relative '${relativeCapacitoriOSPath}/scripts/pods_helpers'`);
|
||||
podfileContent = podfileContent.replace(`def assertDeploymentTarget(installer)
|
||||
installer.pods_project.targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
# ensure IPHONEOS_DEPLOYMENT_TARGET is at least 13.0
|
||||
deployment_target = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'].to_f
|
||||
should_upgrade = deployment_target < 13.0 && deployment_target != 0.0
|
||||
if should_upgrade
|
||||
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '13.0'
|
||||
end
|
||||
end
|
||||
end
|
||||
end`, `require_relative '${relativeCapacitoriOSPath}/scripts/pods_helpers'`);
|
||||
await (0, utils_fs_1.writeFile)(podfilePath, podfileContent, { encoding: 'utf-8' });
|
||||
await (0, fs_extra_1.writeFile)(podfilePath, podfileContent, { encoding: 'utf-8' });
|
||||
const podPath = await config.ios.podPath;
|
||||
const useBundler = podPath.startsWith('bundle');
|
||||
const useBundler = podPath.startsWith('bundle') && (await (0, subprocess_1.isInstalled)('bundle'));
|
||||
const podCommandExists = await (0, subprocess_1.isInstalled)('pod');
|
||||
if (useBundler || podCommandExists) {
|
||||
if (useBundler) {
|
||||
await (0, subprocess_1.runCommand)('bundle', ['exec', 'pod', 'install', ...(deployment ? ['--deployment'] : [])], { cwd: config.ios.nativeProjectDirAbs });
|
||||
await (0, subprocess_1.runCommand)('bundle', ['exec', 'pod', 'install', ...(deployment ? ['--deployment'] : [])], {
|
||||
cwd: config.ios.nativeProjectDirAbs,
|
||||
});
|
||||
}
|
||||
else {
|
||||
await (0, subprocess_1.runCommand)(podPath, ['install', ...(deployment ? ['--deployment'] : [])], { cwd: config.ios.nativeProjectDirAbs });
|
||||
await (0, subprocess_1.runCommand)(podPath, ['install', ...(deployment ? ['--deployment'] : [])], {
|
||||
cwd: config.ios.nativeProjectDirAbs,
|
||||
});
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -106,18 +143,18 @@ async function getRelativeCapacitoriOSPath(config) {
|
|||
(0, errors_1.fatal)(`Unable to find ${colors_1.default.strong('node_modules/@capacitor/ios')}.\n` +
|
||||
`Are you sure ${colors_1.default.strong('@capacitor/ios')} is installed?`);
|
||||
}
|
||||
return (0, fs_1.convertToUnixPath)((0, path_1.relative)(config.ios.nativeProjectDirAbs, await (0, utils_fs_1.realpath)((0, path_1.dirname)(capacitoriOSPath))));
|
||||
return (0, fs_1.convertToUnixPath)((0, path_1.relative)(config.ios.nativeProjectDirAbs, await (0, fs_extra_1.realpath)((0, path_1.dirname)(capacitoriOSPath))));
|
||||
}
|
||||
async function generatePodFile(config, plugins) {
|
||||
const relativeCapacitoriOSPath = await getRelativeCapacitoriOSPath(config);
|
||||
const capacitorPlugins = plugins.filter(p => (0, plugin_1.getPluginType)(p, platform) === 0 /* PluginType.Core */);
|
||||
const capacitorPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 0 /* PluginType.Core */);
|
||||
const pods = await Promise.all(capacitorPlugins.map(async (p) => {
|
||||
if (!p.ios) {
|
||||
return '';
|
||||
}
|
||||
return ` pod '${p.ios.name}', :path => '${(0, fs_1.convertToUnixPath)((0, path_1.relative)(config.ios.nativeProjectDirAbs, await (0, utils_fs_1.realpath)(p.rootPath)))}'\n`;
|
||||
return ` pod '${p.ios.name}', :path => '${(0, fs_1.convertToUnixPath)((0, path_1.relative)(config.ios.nativeProjectDirAbs, await (0, fs_extra_1.realpath)(p.rootPath)))}'\n`;
|
||||
}));
|
||||
const cordovaPlugins = plugins.filter(p => (0, plugin_1.getPluginType)(p, platform) === 1 /* PluginType.Cordova */);
|
||||
const cordovaPlugins = plugins.filter((p) => (0, plugin_1.getPluginType)(p, platform) === 1 /* PluginType.Cordova */);
|
||||
cordovaPlugins.map(async (p) => {
|
||||
const podspecs = (0, plugin_1.getPlatformElement)(p, platform, 'podspec');
|
||||
podspecs.map((podspec) => {
|
||||
|
|
@ -140,8 +177,8 @@ async function generatePodFile(config, plugins) {
|
|||
});
|
||||
});
|
||||
});
|
||||
const staticPlugins = cordovaPlugins.filter(p => (0, cordova_1.needsStaticPod)(p, config));
|
||||
const noStaticPlugins = cordovaPlugins.filter(el => !staticPlugins.includes(el));
|
||||
const staticPlugins = cordovaPlugins.filter((p) => (0, cordova_1.needsStaticPod)(p));
|
||||
const noStaticPlugins = cordovaPlugins.filter((el) => !staticPlugins.includes(el));
|
||||
if (noStaticPlugins.length > 0) {
|
||||
pods.push(` pod 'CordovaPlugins', :path => '../capacitor-cordova-ios-plugins'\n`);
|
||||
}
|
||||
|
|
@ -164,16 +201,14 @@ function getFrameworkName(framework) {
|
|||
}
|
||||
return framework.$.src.substr(0, framework.$.src.indexOf('.'));
|
||||
}
|
||||
return framework.$.src
|
||||
.substr(0, framework.$.src.indexOf('.'))
|
||||
.replace('lib', '');
|
||||
return framework.$.src.substr(0, framework.$.src.indexOf('.')).replace('lib', '');
|
||||
}
|
||||
function isFramework(framework) {
|
||||
return framework.$.src.split('.').pop().includes('framework');
|
||||
}
|
||||
async function generateCordovaPodspecs(cordovaPlugins, config) {
|
||||
const staticPlugins = cordovaPlugins.filter(p => (0, cordova_1.needsStaticPod)(p, config));
|
||||
const noStaticPlugins = cordovaPlugins.filter(el => !staticPlugins.includes(el));
|
||||
const staticPlugins = cordovaPlugins.filter((p) => (0, cordova_1.needsStaticPod)(p));
|
||||
const noStaticPlugins = cordovaPlugins.filter((el) => !staticPlugins.includes(el));
|
||||
generateCordovaPodspec(noStaticPlugins, config, false);
|
||||
generateCordovaPodspec(staticPlugins, config, true);
|
||||
}
|
||||
|
|
@ -267,7 +302,7 @@ async function generateCordovaPodspec(cordovaPlugins, config, isStatic) {
|
|||
}
|
||||
});
|
||||
});
|
||||
const onlySystemLibraries = systemLibraries.filter(library => removeNoSystem(library, sourceFrameworks));
|
||||
const onlySystemLibraries = systemLibraries.filter((library) => removeNoSystem(library, sourceFrameworks));
|
||||
if (weakFrameworks.length > 0) {
|
||||
frameworkDeps.push(`s.weak_frameworks = '${weakFrameworks.join(`', '`)}'`);
|
||||
}
|
||||
|
|
@ -312,7 +347,7 @@ async function generateCordovaPodspec(cordovaPlugins, config, isStatic) {
|
|||
s.swift_version = '5.1'
|
||||
${frameworksString}
|
||||
end`;
|
||||
await (0, utils_fs_1.writeFile)((0, path_1.join)(config.ios.cordovaPluginsDirAbs, `${name}.podspec`), content);
|
||||
await (0, fs_extra_1.writeFile)((0, path_1.join)(config.ios.cordovaPluginsDirAbs, `${name}.podspec`), content);
|
||||
}
|
||||
function getLinkerFlags(config) {
|
||||
var _a;
|
||||
|
|
@ -328,7 +363,7 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
|
|||
const codeFiles = sourceFiles.concat(headerFiles);
|
||||
const frameworks = (0, plugin_1.getPlatformElement)(p, platform, 'framework');
|
||||
let sourcesFolderName = 'sources';
|
||||
if ((0, cordova_1.needsStaticPod)(p, config)) {
|
||||
if ((0, cordova_1.needsStaticPod)(p)) {
|
||||
sourcesFolderName += 'static';
|
||||
}
|
||||
const sourcesFolder = (0, path_1.join)(config.ios.cordovaPluginsDirAbs, sourcesFolderName, p.name);
|
||||
|
|
@ -339,35 +374,33 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
|
|||
fileName = 'lib' + fileName;
|
||||
}
|
||||
let destFolder = sourcesFolderName;
|
||||
if (codeFile.$['compiler-flags'] &&
|
||||
codeFile.$['compiler-flags'] === '-fno-objc-arc') {
|
||||
if (codeFile.$['compiler-flags'] && codeFile.$['compiler-flags'] === '-fno-objc-arc') {
|
||||
destFolder = 'noarc';
|
||||
}
|
||||
const filePath = (0, plugin_1.getFilePath)(config, p, codeFile.$.src);
|
||||
const fileDest = (0, path_1.join)(config.ios.cordovaPluginsDirAbs, destFolder, p.name, fileName);
|
||||
await (0, utils_fs_1.copy)(filePath, fileDest);
|
||||
await (0, fs_extra_1.copy)(filePath, fileDest);
|
||||
if (!codeFile.$.framework) {
|
||||
let fileContent = await (0, utils_fs_1.readFile)(fileDest, { encoding: 'utf-8' });
|
||||
let fileContent = await (0, fs_extra_1.readFile)(fileDest, { encoding: 'utf-8' });
|
||||
if (fileExt === 'swift') {
|
||||
fileContent = 'import Cordova\n' + fileContent;
|
||||
await (0, utils_fs_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
|
||||
await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
|
||||
}
|
||||
else {
|
||||
if (fileContent.includes('@import Firebase;')) {
|
||||
fileContent = fileContent.replace('@import Firebase;', '#import <Firebase/Firebase.h>');
|
||||
await (0, utils_fs_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
|
||||
await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
|
||||
}
|
||||
if (fileContent.includes('[NSBundle bundleForClass:[self class]]') ||
|
||||
fileContent.includes('[NSBundle bundleForClass:[CDVCapture class]]')) {
|
||||
fileContent = fileContent.replace('[NSBundle bundleForClass:[self class]]', '[NSBundle mainBundle]');
|
||||
fileContent = fileContent.replace('[NSBundle bundleForClass:[CDVCapture class]]', '[NSBundle mainBundle]');
|
||||
await (0, utils_fs_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
|
||||
await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
|
||||
}
|
||||
if (fileContent.includes('[self.webView superview]') ||
|
||||
fileContent.includes('self.webView.superview')) {
|
||||
if (fileContent.includes('[self.webView superview]') || fileContent.includes('self.webView.superview')) {
|
||||
fileContent = fileContent.replace(/\[self.webView superview\]/g, 'self.viewController.view');
|
||||
fileContent = fileContent.replace(/self.webView.superview/g, 'self.viewController.view');
|
||||
await (0, utils_fs_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
|
||||
await (0, fs_extra_1.writeFile)(fileDest, fileContent, { encoding: 'utf-8' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -375,17 +408,17 @@ async function copyPluginsNativeFiles(config, cordovaPlugins) {
|
|||
const resourceFiles = (0, plugin_1.getPlatformElement)(p, platform, 'resource-file');
|
||||
for (const resourceFile of resourceFiles) {
|
||||
const fileName = resourceFile.$.src.split('/').pop();
|
||||
await (0, utils_fs_1.copy)((0, plugin_1.getFilePath)(config, p, resourceFile.$.src), (0, path_1.join)(config.ios.cordovaPluginsDirAbs, 'resources', fileName));
|
||||
await (0, fs_extra_1.copy)((0, plugin_1.getFilePath)(config, p, resourceFile.$.src), (0, path_1.join)(config.ios.cordovaPluginsDirAbs, 'resources', fileName));
|
||||
}
|
||||
for (const framework of frameworks) {
|
||||
if (framework.$.custom && framework.$.custom === 'true') {
|
||||
await (0, utils_fs_1.copy)((0, plugin_1.getFilePath)(config, p, framework.$.src), (0, path_1.join)(sourcesFolder, framework.$.src));
|
||||
await (0, fs_extra_1.copy)((0, plugin_1.getFilePath)(config, p, framework.$.src), (0, path_1.join)(sourcesFolder, framework.$.src));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
async function removePluginsNativeFiles(config) {
|
||||
await (0, utils_fs_1.remove)(config.ios.cordovaPluginsDirAbs);
|
||||
await (0, fs_extra_1.remove)(config.ios.cordovaPluginsDirAbs);
|
||||
await (0, template_1.extractTemplate)(config.cli.assets.ios.cordovaPluginsTemplateArchiveAbs, config.ios.cordovaPluginsDirAbs);
|
||||
}
|
||||
function filterResources(plugin) {
|
||||
|
|
@ -394,12 +427,11 @@ function filterResources(plugin) {
|
|||
}
|
||||
function filterARCFiles(plugin) {
|
||||
const sources = (0, plugin_1.getPlatformElement)(plugin, platform, 'source-file');
|
||||
const sourcesARC = sources.filter((sourceFile) => sourceFile.$['compiler-flags'] &&
|
||||
sourceFile.$['compiler-flags'] === '-fno-objc-arc');
|
||||
const sourcesARC = sources.filter((sourceFile) => sourceFile.$['compiler-flags'] && sourceFile.$['compiler-flags'] === '-fno-objc-arc');
|
||||
return sourcesARC.length > 0;
|
||||
}
|
||||
function removeNoSystem(library, sourceFrameworks) {
|
||||
const libraries = sourceFrameworks.filter(framework => framework.includes(library));
|
||||
const libraries = sourceFrameworks.filter((framework) => framework.includes(library));
|
||||
return libraries.length === 0;
|
||||
}
|
||||
async function getPluginsTask(config) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue