chore: commit to move to laptop
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Post-sync script to fix capacitor.plugins.json
|
||||
* This ensures the DailyNotification plugin is always registered
|
||||
* even after npx cap sync overwrites the file
|
||||
* Post-sync script to fix Capacitor auto-generated files
|
||||
*
|
||||
* Fixes:
|
||||
* 1. capacitor.plugins.json - Ensures DailyNotification plugin is registered
|
||||
* 2. capacitor.settings.gradle - Corrects plugin path from android/ to android/plugin/
|
||||
*
|
||||
* This script should run automatically after 'npx cap sync android'
|
||||
* to fix issues with Capacitor's auto-generated files.
|
||||
*
|
||||
* @author Matthew Raymer
|
||||
*/
|
||||
@@ -16,12 +21,16 @@ 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...');
|
||||
|
||||
@@ -50,9 +59,66 @@ function fixCapacitorPlugins() {
|
||||
}
|
||||
}
|
||||
|
||||
// Run if called directly
|
||||
if (import.meta.url === `file://${process.argv[1]}`) {
|
||||
fixCapacitorPlugins();
|
||||
/**
|
||||
* Fix capacitor.settings.gradle to point to android/plugin/ instead of android/
|
||||
*/
|
||||
function fixCapacitorSettingsGradle() {
|
||||
console.log('🔧 Fixing 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 already points to android/plugin
|
||||
if (content.includes('android/plugin')) {
|
||||
console.log('✅ capacitor.settings.gradle already has correct path (android/plugin)');
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we need to fix the path (points to android but should be android/plugin)
|
||||
if (content.includes("project(':timesafari-daily-notification-plugin').projectDir = new File('../node_modules/@timesafari/daily-notification-plugin/android')")) {
|
||||
// Replace the path
|
||||
content = content.replace(
|
||||
"project(':timesafari-daily-notification-plugin').projectDir = new File('../node_modules/@timesafari/daily-notification-plugin/android')",
|
||||
`// NOTE: Plugin module is in android/plugin/ subdirectory, not android root
|
||||
// This file is auto-generated by Capacitor, but must be manually corrected for this plugin structure
|
||||
project(':timesafari-daily-notification-plugin').projectDir = new File('../node_modules/@timesafari/daily-notification-plugin/android/plugin')`
|
||||
);
|
||||
|
||||
fs.writeFileSync(SETTINGS_GRADLE_PATH, content);
|
||||
console.log('✅ Fixed plugin path in capacitor.settings.gradle (android -> android/plugin)');
|
||||
} else {
|
||||
console.log('ℹ️ capacitor.settings.gradle doesn\'t reference the plugin or uses a different structure');
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Error fixing capacitor.settings.gradle:', error.message);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
export { fixCapacitorPlugins };
|
||||
/**
|
||||
* 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 };
|
||||
|
||||
Reference in New Issue
Block a user