Restructure Android project from nested module layout to standard Capacitor plugin structure following community conventions. Structure Changes: - Move plugin code from android/plugin/ to android/src/main/java/ - Move test app from android/app/ to test-apps/android-test-app/app/ - Remove nested android/plugin module structure - Remove nested android/app test app structure Build Infrastructure: - Add Gradle wrapper files (gradlew, gradlew.bat, gradle/wrapper/) - Transform android/build.gradle from root project to library module - Update android/settings.gradle for standalone plugin builds - Add android/gradle.properties with AndroidX configuration - Add android/consumer-rules.pro for ProGuard rules Configuration Updates: - Add prepare script to package.json for automatic builds on npm install - Update package.json version to 1.0.1 - Update android/build.gradle to properly resolve Capacitor dependencies - Update test-apps/android-test-app/settings.gradle with correct paths - Remove android/variables.gradle (hardcode values in build.gradle) Documentation: - Update BUILDING.md with new structure and build process - Update INTEGRATION_GUIDE.md to reflect standard structure - Update README.md to remove path fix warnings - Add test-apps/BUILD_PROCESS.md documenting test app build flows Test App Configuration: - Fix android-test-app to correctly reference plugin and Capacitor - Remove capacitor-cordova-android-plugins dependency (not needed) - Update capacitor.settings.gradle path verification in fix script BREAKING CHANGE: Plugin now uses standard Capacitor Android structure. Consuming apps must update their capacitor.settings.gradle to reference android/ instead of android/plugin/. This is automatically handled by Capacitor CLI for apps using standard plugin installation.
126 lines
4.3 KiB
JavaScript
Executable File
126 lines
4.3 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
||
|
||
/**
|
||
* Post-sync script to fix Capacitor auto-generated files
|
||
*
|
||
* Fixes:
|
||
* 1. capacitor.plugins.json - Ensures DailyNotification plugin is registered
|
||
* 2. capacitor.settings.gradle - Verifies plugin path points to android/ (standard structure)
|
||
*
|
||
* This script should run automatically after 'npx cap sync android'
|
||
* to verify Capacitor's auto-generated files are correct.
|
||
*
|
||
* @author Matthew Raymer
|
||
*/
|
||
|
||
import fs from 'fs';
|
||
import path from 'path';
|
||
import { fileURLToPath } from 'url';
|
||
|
||
const __filename = fileURLToPath(import.meta.url);
|
||
const __dirname = path.dirname(__filename);
|
||
|
||
const PLUGINS_JSON_PATH = path.join(__dirname, '../android/app/src/main/assets/capacitor.plugins.json');
|
||
const SETTINGS_GRADLE_PATH = path.join(__dirname, '../android/capacitor.settings.gradle');
|
||
|
||
const PLUGIN_ENTRY = {
|
||
name: "DailyNotification",
|
||
classpath: "com.timesafari.dailynotification.DailyNotificationPlugin"
|
||
};
|
||
|
||
/**
|
||
* Fix capacitor.plugins.json to ensure DailyNotification is registered
|
||
*/
|
||
function fixCapacitorPlugins() {
|
||
console.log('🔧 Fixing capacitor.plugins.json...');
|
||
|
||
try {
|
||
// Read current content
|
||
let plugins = [];
|
||
if (fs.existsSync(PLUGINS_JSON_PATH)) {
|
||
const content = fs.readFileSync(PLUGINS_JSON_PATH, 'utf8');
|
||
plugins = JSON.parse(content);
|
||
}
|
||
|
||
// Check if our plugin is already there
|
||
const hasPlugin = plugins.some(p => p.name === PLUGIN_ENTRY.name);
|
||
|
||
if (!hasPlugin) {
|
||
plugins.push(PLUGIN_ENTRY);
|
||
fs.writeFileSync(PLUGINS_JSON_PATH, JSON.stringify(plugins, null, 2));
|
||
console.log('✅ Added DailyNotification plugin to capacitor.plugins.json');
|
||
} else {
|
||
console.log('✅ DailyNotification plugin already exists in capacitor.plugins.json');
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error('❌ Error fixing capacitor.plugins.json:', error.message);
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Fix capacitor.settings.gradle to verify plugin path points to android/ (standard structure)
|
||
*/
|
||
function fixCapacitorSettingsGradle() {
|
||
console.log('🔧 Verifying capacitor.settings.gradle...');
|
||
|
||
if (!fs.existsSync(SETTINGS_GRADLE_PATH)) {
|
||
console.log('ℹ️ capacitor.settings.gradle not found (may not be a test-app)');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
let content = fs.readFileSync(SETTINGS_GRADLE_PATH, 'utf8');
|
||
const originalContent = content;
|
||
|
||
// Check if the path correctly points to android/ (standard structure)
|
||
const correctPath = "project(':timesafari-daily-notification-plugin').projectDir = new File('../node_modules/@timesafari/daily-notification-plugin/android')";
|
||
const oldPluginPath = "project(':timesafari-daily-notification-plugin').projectDir = new File('../node_modules/@timesafari/daily-notification-plugin/android/plugin')";
|
||
|
||
// Check if it's using the old android/plugin/ path (needs fixing)
|
||
if (content.includes('android/plugin')) {
|
||
console.log('⚠️ capacitor.settings.gradle uses old path (android/plugin/) - fixing to standard structure');
|
||
content = content.replace(
|
||
oldPluginPath,
|
||
`// Plugin uses standard Capacitor structure: android/ (not android/plugin/)
|
||
${correctPath}`
|
||
);
|
||
|
||
if (content !== originalContent) {
|
||
fs.writeFileSync(SETTINGS_GRADLE_PATH, content);
|
||
console.log('✅ Fixed plugin path in capacitor.settings.gradle (android/plugin -> android)');
|
||
}
|
||
} else if (content.includes(correctPath) || content.includes("android')")) {
|
||
console.log('✅ capacitor.settings.gradle has correct path (android/)');
|
||
} else {
|
||
console.log('ℹ️ capacitor.settings.gradle doesn\'t reference the plugin or uses a different structure');
|
||
}
|
||
|
||
} catch (error) {
|
||
console.error('❌ Error verifying capacitor.settings.gradle:', error.message);
|
||
process.exit(1);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* Run all fixes
|
||
*/
|
||
function fixAll() {
|
||
console.log('🔧 DailyNotification Plugin - Post-Sync Fix Script');
|
||
console.log('================================================\n');
|
||
|
||
fixCapacitorPlugins();
|
||
fixCapacitorSettingsGradle();
|
||
|
||
console.log('\n✅ All fixes applied successfully!');
|
||
console.log('💡 These fixes will persist until the next "npx cap sync android"');
|
||
}
|
||
|
||
// Run if called directly
|
||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||
fixAll();
|
||
}
|
||
|
||
export { fixCapacitorPlugins, fixCapacitorSettingsGradle, fixAll };
|