Skip to content

Commit

Permalink
Extend capacitor plugin for android + ios configs (closes #604)
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed May 2, 2024
1 parent 9d05b6a commit 4af5c86
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
include ':capacitor-android'
project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')

include ':capacitor-app'
project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/android')

include ':capacitor-haptics'
project(':capacitor-haptics').projectDir = new File('../node_modules/@capacitor/haptics/android')

include ':capacitor-keyboard'
project(':capacitor-keyboard').projectDir = new File('../node_modules/@capacitor/keyboard/android')

include ':capacitor-status-bar'
project(':capacitor-status-bar').projectDir = new File('../node_modules/@capacitor/status-bar/android')
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"appName": "name",
"includePlugins": [
"@capacitor-community/http",
"@capacitor/android",
"@capacitor/app",
"@capacitor/splash-screen",
"@capacitor/status-bar",
Expand Down
3 changes: 1 addition & 2 deletions packages/knip/fixtures/plugins/capacitor/capacitor.config.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { CapacitorConfig } from '@capacitor/cli';
import type { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
appId: 'com.company.name',
appName: 'name',
includePlugins: [
'@capacitor-community/http',
'@capacitor/app',
'@capacitor/ios',
'@capacitor/splash-screen',
'@capacitor/status-bar',
'@capacitor/storage',
Expand Down
27 changes: 27 additions & 0 deletions packages/knip/fixtures/plugins/capacitor/ios/App/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
require_relative '../../node_modules/@capacitor/ios/scripts/pods_helpers'

platform :ios, '13.0'
use_frameworks!

# workaround to avoid Xcode caching of Pods that requires
# Product -> Clean Build Folder after new Cordova plugins installed
# Requires CocoaPods 1.6 or newer
install! 'cocoapods', :disable_input_output_paths => true

def capacitor_pods
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
pod 'CapacitorHaptics', :path => '../../node_modules/@capacitor/haptics'
pod 'CapacitorKeyboard', :path => '../../node_modules/@capacitor/keyboard'
pod 'CapacitorStatusBar', :path => '../../node_modules/@capacitor/status-bar'
end

target 'App' do
capacitor_pods
# Add your Pods here
end

post_install do |installer|
assertDeploymentTarget(installer)
end
14 changes: 12 additions & 2 deletions packages/knip/src/plugins/capacitor/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { IsPluginEnabled, Plugin, ResolveConfig } from '#p/types/plugins.js';
import { isFile } from '#p/util/fs.js';
import { join } from '#p/util/path.js';
import { hasDependency } from '#p/util/plugin.js';
import type { CapacitorConfig } from './types.js';

Expand All @@ -12,8 +14,16 @@ const isEnabled: IsPluginEnabled = ({ dependencies }) => hasDependency(dependenc

const config = ['capacitor.config.{json,ts}'];

const resolveConfig: ResolveConfig<CapacitorConfig> = config => {
return config.includePlugins ?? [];
const resolveConfig: ResolveConfig<CapacitorConfig> = async (config, { configFileDir }) => {
const exists = (filePath: string) => isFile(join(configFileDir, filePath));

const plugins = config.includePlugins ?? [];
const android = (await exists('android/capacitor.settings.gradle')) ? ['@capacitor/android'] : [];
const ios = (await exists('ios/App/Podfile')) ? ['@capacitor/ios'] : [];

console.log({ android, ios });

return [...plugins, ...android, ...ios];
};

export default {
Expand Down
4 changes: 3 additions & 1 deletion packages/knip/test/plugins/capacitor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ test('Find dependencies with the Capacitor plugin', async () => {

assert(issues.unlisted['capacitor.config.json']['@capacitor-community/http']);
assert(issues.unlisted['capacitor.config.json']['@capacitor/android']);
assert(issues.unlisted['capacitor.config.json']['@capacitor/ios']);
assert(issues.unlisted['capacitor.config.json']['@capacitor/app']);
assert(issues.unlisted['capacitor.config.json']['@capacitor/splash-screen']);
assert(issues.unlisted['capacitor.config.json']['@capacitor/status-bar']);
Expand All @@ -23,6 +24,7 @@ test('Find dependencies with the Capacitor plugin', async () => {

assert(issues.unlisted['capacitor.config.ts']['@capacitor-community/http']);
assert(issues.unlisted['capacitor.config.ts']['@capacitor/app']);
assert(issues.unlisted['capacitor.config.ts']['@capacitor/android']);
assert(issues.unlisted['capacitor.config.ts']['@capacitor/ios']);
assert(issues.unlisted['capacitor.config.ts']['@capacitor/splash-screen']);
assert(issues.unlisted['capacitor.config.ts']['@capacitor/status-bar']);
Expand All @@ -31,7 +33,7 @@ test('Find dependencies with the Capacitor plugin', async () => {

assert.deepEqual(counters, {
...baseCounters,
unlisted: 14,
unlisted: 16,
processed: 1,
total: 1,
});
Expand Down

0 comments on commit 4af5c86

Please sign in to comment.