44 lines
1.9 KiB
JavaScript
Executable file
44 lines
1.9 KiB
JavaScript
Executable file
#!/usr/bin/env node
|
|
/**
|
|
* Add Android App Links + the custom scheme to the generated manifest.
|
|
* Capacitor regenerates AndroidManifest.xml, so this must run after `cap sync`
|
|
* and before Gradle (see package.json android:build).
|
|
*
|
|
* HTTPS links are verified with https://skate-spots.org/.well-known/assetlinks.json
|
|
* (release signing certificate). The custom scheme is for Amber deep links and
|
|
* fallback launches where no verified domain is available.
|
|
*/
|
|
import { readFileSync, writeFileSync } from 'node:fs';
|
|
import { join } from 'node:path';
|
|
|
|
const root = join(new URL('..', import.meta.url).pathname);
|
|
const manifestPath = join(root, 'android/app/src/main/AndroidManifest.xml');
|
|
let manifest = readFileSync(manifestPath, 'utf8');
|
|
|
|
if (manifest.includes('android:host="skate-spots.org"')) {
|
|
console.log('[inject-deep-links] already present');
|
|
process.exit(0);
|
|
}
|
|
|
|
const filters = `
|
|
<intent-filter android:autoVerify="true">
|
|
<action android:name="android.intent.action.VIEW" />
|
|
<category android:name="android.intent.category.DEFAULT" />
|
|
<category android:name="android.intent.category.BROWSABLE" />
|
|
<data android:scheme="https" android:host="skate-spots.org" />
|
|
</intent-filter>
|
|
<intent-filter>
|
|
<action android:name="android.intent.action.VIEW" />
|
|
<category android:name="android.intent.category.DEFAULT" />
|
|
<category android:name="android.intent.category.BROWSABLE" />
|
|
<data android:scheme="org.skatespots.app" />
|
|
</intent-filter>`;
|
|
|
|
const marker = /(\s*<\/activity>)/i;
|
|
if (!marker.test(manifest)) {
|
|
console.warn('[inject-deep-links] <activity> close not found — skipped');
|
|
process.exit(0);
|
|
}
|
|
manifest = manifest.replace(marker, `${filters}\n </activity>`);
|
|
writeFileSync(manifestPath, manifest);
|
|
console.log('[inject-deep-links] Android App Links + org.skatespots.app added.');
|