feat: auto-restore cinny submodule after android build (stash/pop)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ node_modules
|
|||||||
devAssets
|
devAssets
|
||||||
|
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
.cinny-stash-pending
|
||||||
|
|||||||
@@ -7,11 +7,12 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"android:prepare": "node scripts/apply-overlay.mjs && cd cinny && npm install && npm run build && npx cap sync android",
|
"android:prepare": "node scripts/apply-overlay.mjs && cd cinny && npm install && npm run build && npx cap sync android",
|
||||||
|
"android:restore": "node scripts/restore-cinny.mjs",
|
||||||
"android:open": "cd cinny && npx cap open android",
|
"android:open": "cd cinny && npx cap open android",
|
||||||
"android:run": "cd cinny && npx cap run android",
|
"android:run": "cd cinny && npx cap run android",
|
||||||
"android:apk": "npm run android:prepare && cd cinny/android && gradlew.bat assembleDebug",
|
"android:apk": "npm run android:prepare && cd cinny/android && gradlew.bat assembleDebug && cd ../.. && node scripts/restore-cinny.mjs",
|
||||||
"android:apk:release": "npm run android:prepare && cd cinny/android && gradlew.bat assembleRelease",
|
"android:apk:release": "npm run android:prepare && cd cinny/android && gradlew.bat assembleRelease && cd ../.. && node scripts/restore-cinny.mjs",
|
||||||
"android:aab": "npm run android:prepare && cd cinny/android && gradlew.bat bundleRelease"
|
"android:aab": "npm run android:prepare && cd cinny/android && gradlew.bat bundleRelease && cd ../.. && node scripts/restore-cinny.mjs"
|
||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": {
|
"author": {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* the Capacitor / Android platform changes on top of it.
|
* the Capacitor / Android platform changes on top of it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { readFileSync, writeFileSync, mkdirSync, copyFileSync, readdirSync, statSync, existsSync } from 'fs';
|
import { readFileSync, writeFileSync, mkdirSync, copyFileSync, readdirSync, statSync, existsSync, unlinkSync } from 'fs';
|
||||||
import { join, dirname, relative, resolve } from 'path';
|
import { join, dirname, relative, resolve } from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { execSync } from 'child_process';
|
import { execSync } from 'child_process';
|
||||||
@@ -23,6 +23,20 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|||||||
const ROOT = join(__dirname, '..');
|
const ROOT = join(__dirname, '..');
|
||||||
const CINNY = join(ROOT, 'cinny');
|
const CINNY = join(ROOT, 'cinny');
|
||||||
const OVERLAY = join(ROOT, 'overlay');
|
const OVERLAY = join(ROOT, 'overlay');
|
||||||
|
const STASH_FLAG = join(ROOT, '.cinny-stash-pending');
|
||||||
|
|
||||||
|
// Stash any pre-existing cinny changes so the overlay applies cleanly.
|
||||||
|
// The restore-cinny script will pop them back afterwards.
|
||||||
|
const cinnyStatus = execSync('git status --porcelain', { cwd: CINNY, encoding: 'utf8' });
|
||||||
|
if (cinnyStatus.trim()) {
|
||||||
|
console.log('[apply-overlay] Stashing pre-existing cinny changes...');
|
||||||
|
execSync('git stash push -u -m "pre-overlay stash"', { cwd: CINNY, stdio: 'inherit' });
|
||||||
|
writeFileSync(STASH_FLAG, '1', 'utf8');
|
||||||
|
console.log('[apply-overlay] Stash saved.');
|
||||||
|
} else {
|
||||||
|
// Ensure no stale flag from a previous interrupted run
|
||||||
|
if (existsSync(STASH_FLAG)) unlinkSync(STASH_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively copy all files from src directory to dest directory.
|
* Recursively copy all files from src directory to dest directory.
|
||||||
|
|||||||
55
scripts/restore-cinny.mjs
Normal file
55
scripts/restore-cinny.mjs
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/**
|
||||||
|
* Restores the cinny submodule to its pre-build state after an Android build.
|
||||||
|
*
|
||||||
|
* This script:
|
||||||
|
* 1. Reverts all tracked file changes made by apply-overlay (git checkout)
|
||||||
|
* 2. Removes untracked overlay files (capacitor.config.json)
|
||||||
|
* 3. Removes the cinny/android junction
|
||||||
|
* 4. Pops the pre-overlay git stash if apply-overlay saved one
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { existsSync, unlinkSync } from 'fs';
|
||||||
|
import { join, dirname } from 'path';
|
||||||
|
import { fileURLToPath } from 'url';
|
||||||
|
import { execSync } from 'child_process';
|
||||||
|
|
||||||
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||||
|
const ROOT = join(__dirname, '..');
|
||||||
|
const CINNY = join(ROOT, 'cinny');
|
||||||
|
const STASH_FLAG = join(ROOT, '.cinny-stash-pending');
|
||||||
|
|
||||||
|
// 1. Revert all tracked overlay modifications
|
||||||
|
console.log('[restore-cinny] Reverting tracked changes...');
|
||||||
|
execSync('git checkout -- .', { cwd: CINNY, stdio: 'inherit' });
|
||||||
|
|
||||||
|
// 2. Remove untracked capacitor.config.json written by the overlay
|
||||||
|
const capConfig = join(CINNY, 'capacitor.config.json');
|
||||||
|
if (existsSync(capConfig)) {
|
||||||
|
unlinkSync(capConfig);
|
||||||
|
console.log('[restore-cinny] Removed cinny/capacitor.config.json');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Remove the android junction (rmdir only removes the junction, not the real directory)
|
||||||
|
const androidJunction = join(CINNY, 'android');
|
||||||
|
if (existsSync(androidJunction)) {
|
||||||
|
try {
|
||||||
|
execSync(`cmd /c rmdir "${androidJunction}"`, { stdio: 'pipe' });
|
||||||
|
console.log('[restore-cinny] Removed cinny/android junction');
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('[restore-cinny] Could not remove android junction:', err.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. Pop stash if apply-overlay saved one
|
||||||
|
if (existsSync(STASH_FLAG)) {
|
||||||
|
console.log('[restore-cinny] Popping pre-overlay stash...');
|
||||||
|
try {
|
||||||
|
execSync('git stash pop', { cwd: CINNY, stdio: 'inherit' });
|
||||||
|
console.log('[restore-cinny] Stash restored.');
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('[restore-cinny] Stash pop failed (may have conflicts):', err.message);
|
||||||
|
}
|
||||||
|
unlinkSync(STASH_FLAG);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[restore-cinny] Done. cinny submodule is clean.');
|
||||||
Reference in New Issue
Block a user