Skip to content

Commit

Permalink
Instead of generating the Podfile, just fill it with dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile committed Feb 28, 2018
1 parent d3ccecd commit 5b162c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
26 changes: 9 additions & 17 deletions cli/src/ios/update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { checkCocoaPods, checkIOSProject, getIOSPlugins } from './common';
import { CheckFunction, log, logInfo, logWarn, runCommand, runTask } from '../common';
import { copySync, removeSync, writeFileAsync } from '../util/fs';
import { copySync, readFileAsync, removeSync, writeFileAsync } from '../util/fs';
import { Config } from '../config';
import { join, resolve } from 'path';
import { getPlatformElement, getPluginPlatform, getPlugins, getPluginType, Plugin, PluginType, printPlugins } from '../plugin';
Expand Down Expand Up @@ -94,11 +94,13 @@ export async function installCocoaPodsPlugins(config: Config, plugins: Plugin[],
}

export async function updatePodfile(config: Config, plugins: Plugin[], needsUpdate: boolean) {
const content = generatePodFile(config, plugins);
const dependenciesContent = generatePodFile(config, plugins);
const projectName = config.ios.nativeProjectName;
const podfilePath = resolve(config.app.rootDir, config.ios.name, projectName, 'Podfile');

await writeFileAsync(podfilePath, content, 'utf8');
let podfileContent = await readFileAsync(podfilePath, 'utf8');
podfileContent = podfileContent.replace(/(Automatic Capacitor Pod dependencies, do not delete)[\s\S]*(# Do not delete)/, '$1' + dependenciesContent + '\n $2');
podfileContent = podfileContent.replace(/platform :ios, '[^']*'/ , `platform :ios, '${config.ios.minVersion}'`);
await writeFileAsync(podfilePath, podfileContent, 'utf8');

if (needsUpdate) {
await runCommand(`cd "${config.app.rootDir}" && cd "${config.ios.name}" && cd "${projectName}" && pod update && xcodebuild -project App.xcodeproj clean`);
Expand All @@ -112,30 +114,20 @@ export function generatePodFile(config: Config, plugins: Plugin[]) {
const pods = capacitorPlugins
.map((p) => `pod '${p.ios!.name}', :path => '../../node_modules/${p.id}/${p.ios!.path}'`);
const cordovaPlugins = plugins.filter(p => p.ios!.type === PluginType.Cordova);
let dependencies = '';
let dependencies: Array<string> = [];
cordovaPlugins.map((p: any) => {
const frameworks = getPlatformElement(p, platform, 'framework');
frameworks.map((framework: any) => {
if (framework.$.type && framework.$.type === 'podspec') {
dependencies += `pod '${framework.$.src}', '${framework.$.spec}'\n `;
dependencies.push(`pod '${framework.$.src}', '${framework.$.spec}'`);
}
});
});
return `
# DO NOT MODIFY.
# This Podfile was autogenerated by the Capacitor CLI.
# It is used to resolve the native dependencies of Capacitor plugins.
platform :ios, '${config.ios.minVersion}'
use_frameworks!
target 'App' do
${config.ios.capacitorRuntimePod}
pod 'CordovaPlugins', :path => '../../node_modules/@capacitor/cli/assets/capacitor-cordova-ios-plugins'
pod 'CordovaPluginsResources', :path => '../../node_modules/@capacitor/cli/assets/capacitor-cordova-ios-plugins'
${pods.join('\n ')}
${dependencies}
end`;
${pods.join('\n ')}${dependencies.join('\n ')}`;
}

function getFrameworkName(framework: any) {
Expand Down
10 changes: 5 additions & 5 deletions ios-template/App/Podfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '10.0'
use_frameworks!

target 'App' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Add your Pods here

# Pods for IonicRunner
# Automatic Capacitor Pod dependencies, do not delete
pod 'Capacitor'
# Do not delete
end

0 comments on commit 5b162c6

Please sign in to comment.