feat: auto-restore cinny submodule after android build (stash/pop)
Some checks failed
Build / increment-version (push) Successful in 5s
Build / build-linux (push) Failing after 27s
Build / build-windows (push) Has been cancelled
Build / build-android (push) Has been cancelled
Build / create-release (push) Has been cancelled

This commit is contained in:
2026-04-07 15:28:55 +10:00
parent b84392b51a
commit 740a991be0
4 changed files with 75 additions and 4 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ node_modules
devAssets
.DS_Store
.cinny-stash-pending

View File

@@ -7,11 +7,12 @@
},
"scripts": {
"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:run": "cd cinny && npx cap run android",
"android:apk": "npm run android:prepare && cd cinny/android && gradlew.bat assembleDebug",
"android:apk:release": "npm run android:prepare && cd cinny/android && gradlew.bat assembleRelease",
"android:aab": "npm run android:prepare && cd cinny/android && gradlew.bat bundleRelease"
"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 && cd ../.. && node scripts/restore-cinny.mjs",
"android:aab": "npm run android:prepare && cd cinny/android && gradlew.bat bundleRelease && cd ../.. && node scripts/restore-cinny.mjs"
},
"keywords": [],
"author": {

View File

@@ -14,7 +14,7 @@
* 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 { fileURLToPath } from 'url';
import { execSync } from 'child_process';
@@ -23,6 +23,20 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
const ROOT = join(__dirname, '..');
const CINNY = join(ROOT, 'cinny');
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.

55
scripts/restore-cinny.mjs Normal file
View 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.');