codeplay-common 4.11.28 → 4.11.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -0
- package/README.md +89 -89
- package/RELEASE_NOTES.md +13 -13
- package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -0
- package/files/buildCodeplay/add-splash-screen.js +1 -1
- package/files/buildCodeplay/codeplayBeforeBuild.js +4756 -4755
- package/files/buildCodeplay/disabled-ads.mjs +45 -45
- package/files/buildCodeplay/ensure-current-build.cjs +42 -42
- package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
- package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
- package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
- package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
- package/files/buildCodeplay/huawei-privacy-entry.js +135 -0
- package/files/buildCodeplay/huawei-privacy.cjs +92 -0
- package/files/buildCodeplay/huawei-privacy.css +22 -0
- package/files/buildCodeplay/iap-alias.cjs +116 -108
- package/files/buildCodeplay/ios-ad-consent.cjs +56 -56
- package/files/buildCodeplay/ios-emi-admob-modification.js +25 -25
- package/files/buildCodeplay/migrate-system-bars.cjs +115 -115
- package/files/buildCodeplay/newly added.txt +89 -89
- package/files/buildCodeplay/non-google-billing.pro +3 -3
- package/files/buildCodeplay/release-sync.config.json +4 -4
- package/files/buildCodeplay/remove-force-kotlin-disable.js +43 -43
- package/files/buildCodeplay/ruads.cjs +211 -211
- package/files/buildCodeplay/saf-mediastore-dependency.cjs +21 -21
- package/files/buildCodeplay/setSplashAnimation.js +2 -2
- package/files/buildCodeplay/setup-ruads.cjs +55 -55
- package/files/buildCodeplay/splash-setup.cjs +88 -88
- package/files/buildCodeplay/store-billing.cjs +43 -43
- package/files/buildCodeplay/tests/huawei-privacy.test.cjs +49 -0
- package/files/buildCodeplay/tests/huawei-vite.test.cjs +35 -0
- package/files/scripts-common/generate-baseline-profile.js +46 -46
- package/files/take-screen-image.js +4414 -4414
- package/package.json +28 -28
- package/runtime/splash-ready.mjs +52 -52
- package/runtime/vk-ads/vk-ad-configuration.json +39 -39
- package/scripts/ensure-current-build.test.cjs +76 -76
- package/scripts/iap-alias.test.cjs +117 -78
- package/scripts/ios-ad-consent.test.cjs +99 -99
- package/scripts/ruads-install.test.cjs +180 -180
- package/scripts/ruads-policy.test.cjs +174 -174
- package/scripts/saf-mediastore-dependency.test.cjs +44 -44
- package/scripts/splash-setup.test.cjs +142 -142
- package/scripts/sync-files.js +1 -1
- package/scripts/system-bars.test.cjs +77 -77
- package/scripts/vite-build-settings.test.cjs +92 -92
|
@@ -1,88 +1,88 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const crypto = require('crypto');
|
|
4
|
-
const runtimeImport = "import { hideSplashWhenReady } from 'codeplay-common/runtime/splash-ready.mjs';";
|
|
5
|
-
const knownReadyHash = '451fd2e0ca63712e0f771ee0ed03ae5bd3a379f0ca1e75e971cd7acee0802a2b';
|
|
6
|
-
|
|
7
|
-
function readSplashOptions(config) {
|
|
8
|
-
const options = config.plugins?.CodeplaySplashScreen || {};
|
|
9
|
-
const duration = options.exitAnimationDuration ?? 1000;
|
|
10
|
-
const timeout = options.readinessTimeout ?? 8000;
|
|
11
|
-
const imageSelector = options.readyImageSelector ?? '[data-splash-ready], .t-film-art img';
|
|
12
|
-
if (!Number.isInteger(duration) || duration < 0 || duration > 10000) throw new Error('CodeplaySplashScreen.exitAnimationDuration must be an integer from0 to10000.');
|
|
13
|
-
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 60000) throw new Error('CodeplaySplashScreen.readinessTimeout must be an integer from1 to60000.');
|
|
14
|
-
if (typeof imageSelector !== 'string') throw new Error('CodeplaySplashScreen.readyImageSelector must be a string.');
|
|
15
|
-
if (options.migrateLegacyReadiness !== undefined && typeof options.migrateLegacyReadiness !== 'boolean') throw new Error('CodeplaySplashScreen.migrateLegacyReadiness must be boolean.');
|
|
16
|
-
return { duration, timeout, imageSelector, migrateLegacy: options.migrateLegacyReadiness === true };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function migrateSplashTheme(content) {
|
|
20
|
-
// Repair only the known package default; preserve custom themes and styling.
|
|
21
|
-
return content.replace(/(<item\s+name=["']postSplashScreenTheme["']\s*>\s*)@style\/Theme\.AppCompat\.NoActionBar(\s*<\/item>)/g,
|
|
22
|
-
'$1@style/Theme.AppCompat.DayNight.NoActionBar$2');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function migrateReadinessSource(source, options) {
|
|
26
|
-
if (!/\b(?:var|let|const)\s+capacitorApp\s*=/.test(source)) return { source, status: 'unsupported' };
|
|
27
|
-
const handler = / handleSplashscreen:\s*function\s*\(\)\s*\{([\s\S]*?)\r?\n \},/;
|
|
28
|
-
const match = source.match(handler);
|
|
29
|
-
if (!match) return { source, status: 'unsupported' };
|
|
30
|
-
const body = match[1].replace(/\s+/g, '');
|
|
31
|
-
const isReady = crypto.createHash('sha256').update(body).digest('hex') === knownReadyHash;
|
|
32
|
-
const isManaged = /^if\(!window\.Capacitor\)return;returnhideSplashWhenReady\(\{f7:capacitorApp\.f7,hide:\(\)=>SplashScreen\.hide\(\),imageSelector:"(?:\\.|[^"\\])*",timeout:\d+\}\);$/.test(body)
|
|
33
|
-
&& source.includes(runtimeImport);
|
|
34
|
-
const isLegacy = body === "if(!window.Capacitor)return;setTimeout(()=>{if(window.Capacitor.Plugins?.SplashScreen)window.Capacitor.Plugins.SplashScreen.hide();},2000);"
|
|
35
|
-
|| body === "if(!window.Capacitor)return;setTimeout(()=>{if(window.Capacitor.Plugins&&window.Capacitor.Plugins.SplashScreen){window.Capacitor.Plugins.SplashScreen.hide();}},2000);";
|
|
36
|
-
if (!isReady && !isManaged && !(isLegacy && options.migrateLegacy)) return { source, status: isLegacy ? 'opt-in-required' : 'custom-preserved' };
|
|
37
|
-
const newline = source.includes('\r\n') ? '\r\n' : '\n';
|
|
38
|
-
const method = [
|
|
39
|
-
' handleSplashscreen: function () {',
|
|
40
|
-
' if (!window.Capacitor) return;',
|
|
41
|
-
' return hideSplashWhenReady({',
|
|
42
|
-
' f7: capacitorApp.f7,',
|
|
43
|
-
' hide: () => SplashScreen.hide(),',
|
|
44
|
-
` imageSelector: ${JSON.stringify(options.imageSelector)},`,
|
|
45
|
-
` timeout: ${options.timeout}`, ' });', ' },'
|
|
46
|
-
].join(newline);
|
|
47
|
-
let updated = source.replace(handler, () => method);
|
|
48
|
-
if (!updated.includes(runtimeImport)) updated = runtimeImport + newline + updated;
|
|
49
|
-
if (!/import\s*\{[^}]*\bSplashScreen\b[^}]*\}\s*from\s*['"]@capacitor\/splash-screen['"]/.test(updated)) {
|
|
50
|
-
updated = "import { SplashScreen } from '@capacitor/splash-screen';" + newline + updated;
|
|
51
|
-
}
|
|
52
|
-
return { source: updated, status: 'managed' };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function syncSplashSetup(projectRoot, { log = console.log } = {}) {
|
|
56
|
-
const configPath = path.join(projectRoot, 'capacitor.config.json');
|
|
57
|
-
if (!fs.existsSync(configPath)) return;
|
|
58
|
-
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
59
|
-
const options = readSplashOptions(config);
|
|
60
|
-
const theme = path.join(projectRoot, 'buildCodeplay/splashxml/codeplay_splashScreen.xml');
|
|
61
|
-
if (fs.existsSync(theme)) {
|
|
62
|
-
const content = fs.readFileSync(theme, 'utf8');
|
|
63
|
-
const updated = migrateSplashTheme(content);
|
|
64
|
-
if (updated !== content) { fs.writeFileSync(theme, updated); log('codeplay-common: repaired legacy splash DayNight theme template; Android sync applies it.'); }
|
|
65
|
-
}
|
|
66
|
-
const app = path.join(projectRoot, 'src/js/capacitor-app.js');
|
|
67
|
-
if (!fs.existsSync(app)) return;
|
|
68
|
-
const source = fs.readFileSync(app, 'utf8');
|
|
69
|
-
const migrated = migrateReadinessSource(source, options);
|
|
70
|
-
if (migrated.status === 'managed') {
|
|
71
|
-
if (source !== migrated.source) {
|
|
72
|
-
const launch = config.plugins?.SplashScreen;
|
|
73
|
-
if (launch?.launchAutoHide !== true || !(launch.launchShowDuration >= options.timeout)) {
|
|
74
|
-
log('codeplay-common: readiness migration skipped; set SplashScreen.launchAutoHide=true and launchShowDuration>=readinessTimeout for the native fallback.');
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const dependency = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
78
|
-
if (!dependency.dependencies?.['@capacitor/splash-screen'] && !dependency.devDependencies?.['@capacitor/splash-screen']) {
|
|
79
|
-
log('codeplay-common: readiness migration skipped; @capacitor/splash-screen must be installed.');
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
fs.writeFileSync(app, migrated.source);
|
|
83
|
-
log('codeplay-common: connected supported startup handler to shared splash readiness.');
|
|
84
|
-
}
|
|
85
|
-
} else log(`codeplay-common: splash readiness ${migrated.status}; app startup preserved. See shared splash setup in README.`);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
module.exports = { readSplashOptions, migrateSplashTheme, migrateReadinessSource, syncSplashSetup };
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const crypto = require('crypto');
|
|
4
|
+
const runtimeImport = "import { hideSplashWhenReady } from 'codeplay-common/runtime/splash-ready.mjs';";
|
|
5
|
+
const knownReadyHash = '451fd2e0ca63712e0f771ee0ed03ae5bd3a379f0ca1e75e971cd7acee0802a2b';
|
|
6
|
+
|
|
7
|
+
function readSplashOptions(config) {
|
|
8
|
+
const options = config.plugins?.CodeplaySplashScreen || {};
|
|
9
|
+
const duration = options.exitAnimationDuration ?? 1000;
|
|
10
|
+
const timeout = options.readinessTimeout ?? 8000;
|
|
11
|
+
const imageSelector = options.readyImageSelector ?? '[data-splash-ready], .t-film-art img';
|
|
12
|
+
if (!Number.isInteger(duration) || duration < 0 || duration > 10000) throw new Error('CodeplaySplashScreen.exitAnimationDuration must be an integer from0 to10000.');
|
|
13
|
+
if (!Number.isInteger(timeout) || timeout < 1 || timeout > 60000) throw new Error('CodeplaySplashScreen.readinessTimeout must be an integer from1 to60000.');
|
|
14
|
+
if (typeof imageSelector !== 'string') throw new Error('CodeplaySplashScreen.readyImageSelector must be a string.');
|
|
15
|
+
if (options.migrateLegacyReadiness !== undefined && typeof options.migrateLegacyReadiness !== 'boolean') throw new Error('CodeplaySplashScreen.migrateLegacyReadiness must be boolean.');
|
|
16
|
+
return { duration, timeout, imageSelector, migrateLegacy: options.migrateLegacyReadiness === true };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function migrateSplashTheme(content) {
|
|
20
|
+
// Repair only the known package default; preserve custom themes and styling.
|
|
21
|
+
return content.replace(/(<item\s+name=["']postSplashScreenTheme["']\s*>\s*)@style\/Theme\.AppCompat\.NoActionBar(\s*<\/item>)/g,
|
|
22
|
+
'$1@style/Theme.AppCompat.DayNight.NoActionBar$2');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function migrateReadinessSource(source, options) {
|
|
26
|
+
if (!/\b(?:var|let|const)\s+capacitorApp\s*=/.test(source)) return { source, status: 'unsupported' };
|
|
27
|
+
const handler = / handleSplashscreen:\s*function\s*\(\)\s*\{([\s\S]*?)\r?\n \},/;
|
|
28
|
+
const match = source.match(handler);
|
|
29
|
+
if (!match) return { source, status: 'unsupported' };
|
|
30
|
+
const body = match[1].replace(/\s+/g, '');
|
|
31
|
+
const isReady = crypto.createHash('sha256').update(body).digest('hex') === knownReadyHash;
|
|
32
|
+
const isManaged = /^if\(!window\.Capacitor\)return;returnhideSplashWhenReady\(\{f7:capacitorApp\.f7,hide:\(\)=>SplashScreen\.hide\(\),imageSelector:"(?:\\.|[^"\\])*",timeout:\d+\}\);$/.test(body)
|
|
33
|
+
&& source.includes(runtimeImport);
|
|
34
|
+
const isLegacy = body === "if(!window.Capacitor)return;setTimeout(()=>{if(window.Capacitor.Plugins?.SplashScreen)window.Capacitor.Plugins.SplashScreen.hide();},2000);"
|
|
35
|
+
|| body === "if(!window.Capacitor)return;setTimeout(()=>{if(window.Capacitor.Plugins&&window.Capacitor.Plugins.SplashScreen){window.Capacitor.Plugins.SplashScreen.hide();}},2000);";
|
|
36
|
+
if (!isReady && !isManaged && !(isLegacy && options.migrateLegacy)) return { source, status: isLegacy ? 'opt-in-required' : 'custom-preserved' };
|
|
37
|
+
const newline = source.includes('\r\n') ? '\r\n' : '\n';
|
|
38
|
+
const method = [
|
|
39
|
+
' handleSplashscreen: function () {',
|
|
40
|
+
' if (!window.Capacitor) return;',
|
|
41
|
+
' return hideSplashWhenReady({',
|
|
42
|
+
' f7: capacitorApp.f7,',
|
|
43
|
+
' hide: () => SplashScreen.hide(),',
|
|
44
|
+
` imageSelector: ${JSON.stringify(options.imageSelector)},`,
|
|
45
|
+
` timeout: ${options.timeout}`, ' });', ' },'
|
|
46
|
+
].join(newline);
|
|
47
|
+
let updated = source.replace(handler, () => method);
|
|
48
|
+
if (!updated.includes(runtimeImport)) updated = runtimeImport + newline + updated;
|
|
49
|
+
if (!/import\s*\{[^}]*\bSplashScreen\b[^}]*\}\s*from\s*['"]@capacitor\/splash-screen['"]/.test(updated)) {
|
|
50
|
+
updated = "import { SplashScreen } from '@capacitor/splash-screen';" + newline + updated;
|
|
51
|
+
}
|
|
52
|
+
return { source: updated, status: 'managed' };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function syncSplashSetup(projectRoot, { log = console.log } = {}) {
|
|
56
|
+
const configPath = path.join(projectRoot, 'capacitor.config.json');
|
|
57
|
+
if (!fs.existsSync(configPath)) return;
|
|
58
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
59
|
+
const options = readSplashOptions(config);
|
|
60
|
+
const theme = path.join(projectRoot, 'buildCodeplay/splashxml/codeplay_splashScreen.xml');
|
|
61
|
+
if (fs.existsSync(theme)) {
|
|
62
|
+
const content = fs.readFileSync(theme, 'utf8');
|
|
63
|
+
const updated = migrateSplashTheme(content);
|
|
64
|
+
if (updated !== content) { fs.writeFileSync(theme, updated); log('codeplay-common: repaired legacy splash DayNight theme template; Android sync applies it.'); }
|
|
65
|
+
}
|
|
66
|
+
const app = path.join(projectRoot, 'src/js/capacitor-app.js');
|
|
67
|
+
if (!fs.existsSync(app)) return;
|
|
68
|
+
const source = fs.readFileSync(app, 'utf8');
|
|
69
|
+
const migrated = migrateReadinessSource(source, options);
|
|
70
|
+
if (migrated.status === 'managed') {
|
|
71
|
+
if (source !== migrated.source) {
|
|
72
|
+
const launch = config.plugins?.SplashScreen;
|
|
73
|
+
if (launch?.launchAutoHide !== true || !(launch.launchShowDuration >= options.timeout)) {
|
|
74
|
+
log('codeplay-common: readiness migration skipped; set SplashScreen.launchAutoHide=true and launchShowDuration>=readinessTimeout for the native fallback.');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const dependency = JSON.parse(fs.readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
|
|
78
|
+
if (!dependency.dependencies?.['@capacitor/splash-screen'] && !dependency.devDependencies?.['@capacitor/splash-screen']) {
|
|
79
|
+
log('codeplay-common: readiness migration skipped; @capacitor/splash-screen must be installed.');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
fs.writeFileSync(app, migrated.source);
|
|
83
|
+
log('codeplay-common: connected supported startup handler to shared splash readiness.');
|
|
84
|
+
}
|
|
85
|
+
} else log(`codeplay-common: splash readiness ${migrated.status}; app startup preserved. See shared splash setup in README.`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = { readSplashOptions, migrateSplashTheme, migrateReadinessSource, syncSplashSetup };
|
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
const start = '// BEGIN CODEPLAY NON-GOOGLE STORE BILLING';
|
|
5
|
-
const end = '// END CODEPLAY NON-GOOGLE STORE BILLING';
|
|
6
|
-
const block = `${start}
|
|
7
|
-
configurations.configureEach {
|
|
8
|
-
exclude group: 'com.android.billingclient'
|
|
9
|
-
}
|
|
10
|
-
android.buildTypes.configureEach {
|
|
11
|
-
proguardFile file('../../buildCodeplay/non-google-billing.pro')
|
|
12
|
-
}
|
|
13
|
-
${end}`;
|
|
14
|
-
|
|
15
|
-
function syncStoreBillingPolicy(projectRoot, storeId, platform = 'android') {
|
|
16
|
-
if (platform !== 'android') return false;
|
|
17
|
-
const excluded = [4, 10].includes(Number(storeId));
|
|
18
|
-
const gradle = path.join(projectRoot, 'android/app/build.gradle');
|
|
19
|
-
if (!fs.existsSync(gradle)) return false;
|
|
20
|
-
const original = fs.readFileSync(gradle, 'utf8');
|
|
21
|
-
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
22
|
-
const clean = original.replace(new RegExp(`${start}[\\s\\S]*?${end}\\r?\\n?`, 'g'), '');
|
|
23
|
-
const updated = excluded
|
|
24
|
-
? `${clean.trimEnd()}${newline}${newline}${block.replaceAll('\n', newline)}${newline}`
|
|
25
|
-
: clean;
|
|
26
|
-
let changed = updated !== original;
|
|
27
|
-
if (changed) fs.writeFileSync(gradle, updated);
|
|
28
|
-
|
|
29
|
-
// The excluded library supplies its own permission. Also remove any explicit
|
|
30
|
-
// app declaration; other permissions and supported-store billing stay intact.
|
|
31
|
-
const manifest = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
|
|
32
|
-
if (excluded && fs.existsSync(manifest)) {
|
|
33
|
-
const current = fs.readFileSync(manifest, 'utf8');
|
|
34
|
-
const next = current.replace(/^[ \t]*<uses-permission\b(?=[^>]*\bandroid:name\s*=\s*(['"])com\.android\.vending\.BILLING\1)[^>]*\/\s*>[ \t]*(?:\r?\n)?/gm, '');
|
|
35
|
-
if (next !== current) {
|
|
36
|
-
fs.writeFileSync(manifest, next);
|
|
37
|
-
changed = true;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return changed;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
module.exports = { syncStoreBillingPolicy };
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const start = '// BEGIN CODEPLAY NON-GOOGLE STORE BILLING';
|
|
5
|
+
const end = '// END CODEPLAY NON-GOOGLE STORE BILLING';
|
|
6
|
+
const block = `${start}
|
|
7
|
+
configurations.configureEach {
|
|
8
|
+
exclude group: 'com.android.billingclient'
|
|
9
|
+
}
|
|
10
|
+
android.buildTypes.configureEach {
|
|
11
|
+
proguardFile file('../../buildCodeplay/non-google-billing.pro')
|
|
12
|
+
}
|
|
13
|
+
${end}`;
|
|
14
|
+
|
|
15
|
+
function syncStoreBillingPolicy(projectRoot, storeId, platform = 'android') {
|
|
16
|
+
if (platform !== 'android') return false;
|
|
17
|
+
const excluded = [4, 10].includes(Number(storeId));
|
|
18
|
+
const gradle = path.join(projectRoot, 'android/app/build.gradle');
|
|
19
|
+
if (!fs.existsSync(gradle)) return false;
|
|
20
|
+
const original = fs.readFileSync(gradle, 'utf8');
|
|
21
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
22
|
+
const clean = original.replace(new RegExp(`${start}[\\s\\S]*?${end}\\r?\\n?`, 'g'), '');
|
|
23
|
+
const updated = excluded
|
|
24
|
+
? `${clean.trimEnd()}${newline}${newline}${block.replaceAll('\n', newline)}${newline}`
|
|
25
|
+
: clean;
|
|
26
|
+
let changed = updated !== original;
|
|
27
|
+
if (changed) fs.writeFileSync(gradle, updated);
|
|
28
|
+
|
|
29
|
+
// The excluded library supplies its own permission. Also remove any explicit
|
|
30
|
+
// app declaration; other permissions and supported-store billing stay intact.
|
|
31
|
+
const manifest = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
|
|
32
|
+
if (excluded && fs.existsSync(manifest)) {
|
|
33
|
+
const current = fs.readFileSync(manifest, 'utf8');
|
|
34
|
+
const next = current.replace(/^[ \t]*<uses-permission\b(?=[^>]*\bandroid:name\s*=\s*(['"])com\.android\.vending\.BILLING\1)[^>]*\/\s*>[ \t]*(?:\r?\n)?/gm, '');
|
|
35
|
+
if (next !== current) {
|
|
36
|
+
fs.writeFileSync(manifest, next);
|
|
37
|
+
changed = true;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return changed;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
module.exports = { syncStoreBillingPolicy };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const os = require('node:os');
|
|
4
|
+
const path = require('node:path');
|
|
5
|
+
const { syncHuaweiPrivacy } = require('../huawei-privacy.cjs');
|
|
6
|
+
|
|
7
|
+
const root = fs.mkdtempSync(path.join(os.tmpdir(), 'codeplay-huawei-privacy-'));
|
|
8
|
+
const indexPath = path.join(root, 'src/index.html');
|
|
9
|
+
const manifestPath = path.join(root, 'android/app/src/main/AndroidManifest.xml');
|
|
10
|
+
const appEntry = path.join(root, 'src/js/app.js');
|
|
11
|
+
const wrapperPath = path.join(root, 'buildCodeplay/huawei-privacy-generated.js');
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
for (const file of [indexPath, manifestPath, appEntry, wrapperPath]) fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
15
|
+
const index = '<html><body><div id="app"></div><script type="module" src="./js/app.js"></script></body></html>\n';
|
|
16
|
+
const manifest = '<manifest><application><activity android:name=".MainActivity" /></application></manifest>\n';
|
|
17
|
+
fs.writeFileSync(indexPath, index);
|
|
18
|
+
fs.writeFileSync(manifestPath, manifest);
|
|
19
|
+
fs.writeFileSync(appEntry, 'document.body.dataset.ready = "yes";\n');
|
|
20
|
+
fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify({ appName: 'Test App', android: { APP_UNIQUE_ID: 2 } }));
|
|
21
|
+
|
|
22
|
+
syncHuaweiPrivacy(root, 1);
|
|
23
|
+
assert.equal(fs.readFileSync(indexPath, 'utf8'), index);
|
|
24
|
+
assert.equal(fs.readFileSync(manifestPath, 'utf8'), manifest);
|
|
25
|
+
|
|
26
|
+
const existing = '<manifest><application>\n <meta-data android:name="firebase_analytics_collection_enabled" android:value="true" />\n <activity android:name=".MainActivity" /></application></manifest>\n';
|
|
27
|
+
fs.writeFileSync(manifestPath, existing);
|
|
28
|
+
syncHuaweiPrivacy(root, 4);
|
|
29
|
+
assert.match(fs.readFileSync(manifestPath, 'utf8'), /firebase_analytics_collection_enabled" android:value="false"/);
|
|
30
|
+
syncHuaweiPrivacy(root, 1);
|
|
31
|
+
assert.equal(fs.readFileSync(manifestPath, 'utf8'), existing);
|
|
32
|
+
fs.writeFileSync(manifestPath, manifest);
|
|
33
|
+
|
|
34
|
+
syncHuaweiPrivacy(root, 4);
|
|
35
|
+
const huaweiIndex = fs.readFileSync(indexPath, 'utf8');
|
|
36
|
+
const huaweiManifest = fs.readFileSync(manifestPath, 'utf8');
|
|
37
|
+
assert.match(huaweiIndex, /huawei-privacy-generated\.js/);
|
|
38
|
+
assert.match(huaweiManifest, /firebase_analytics_collection_enabled" android:value="false"/);
|
|
39
|
+
assert.match(fs.readFileSync(wrapperPath, 'utf8'), /import\("\.\.\/src\/js\/app\.js"\)/);
|
|
40
|
+
syncHuaweiPrivacy(root, 4);
|
|
41
|
+
assert.equal(fs.readFileSync(indexPath, 'utf8'), huaweiIndex);
|
|
42
|
+
assert.equal(fs.readFileSync(manifestPath, 'utf8'), huaweiManifest);
|
|
43
|
+
|
|
44
|
+
syncHuaweiPrivacy(root, 1);
|
|
45
|
+
assert.equal(fs.readFileSync(indexPath, 'utf8'), index);
|
|
46
|
+
assert.equal(fs.readFileSync(manifestPath, 'utf8'), manifest);
|
|
47
|
+
} finally {
|
|
48
|
+
fs.rmSync(root, { recursive: true, force: true });
|
|
49
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const assert = require('node:assert/strict');
|
|
2
|
+
const fs = require('node:fs');
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
const { execFileSync } = require('node:child_process');
|
|
5
|
+
const { syncHuaweiPrivacy } = require('../huawei-privacy.cjs');
|
|
6
|
+
|
|
7
|
+
const appRoot = path.resolve(process.argv[2] || '');
|
|
8
|
+
const vite = path.join(appRoot, 'node_modules/vite/bin/vite.js');
|
|
9
|
+
if (!fs.existsSync(vite)) throw new Error('Pass an app root with Vite installed.');
|
|
10
|
+
const tempRoot = path.join(appRoot, 'agent-temp');
|
|
11
|
+
fs.mkdirSync(tempRoot, { recursive: true });
|
|
12
|
+
const fixture = fs.mkdtempSync(path.join(tempRoot, 'huawei-vite-'));
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const src = path.join(fixture, 'src');
|
|
16
|
+
const build = path.join(fixture, 'buildCodeplay');
|
|
17
|
+
const manifest = path.join(fixture, 'android/app/src/main/AndroidManifest.xml');
|
|
18
|
+
fs.mkdirSync(path.join(src, 'js'), { recursive: true });
|
|
19
|
+
fs.mkdirSync(build, { recursive: true });
|
|
20
|
+
fs.mkdirSync(path.dirname(manifest), { recursive: true });
|
|
21
|
+
fs.writeFileSync(path.join(src, 'index.html'), '<html><body><div id="app"></div><script type="module" src="./js/app.js"></script></body></html>');
|
|
22
|
+
fs.writeFileSync(path.join(src, 'js/app.js'), 'document.body.dataset.ready = "yes";');
|
|
23
|
+
fs.writeFileSync(manifest, '<manifest><application></application></manifest>');
|
|
24
|
+
fs.writeFileSync(path.join(fixture, 'capacitor.config.json'), '{"appName":"Fixture","android":{"APP_UNIQUE_ID":2}}');
|
|
25
|
+
for (const name of ['huawei-privacy-entry.js', 'huawei-privacy.css']) {
|
|
26
|
+
fs.copyFileSync(path.join(__dirname, '..', name), path.join(build, name));
|
|
27
|
+
}
|
|
28
|
+
syncHuaweiPrivacy(fixture, 4);
|
|
29
|
+
execFileSync(process.execPath, [vite, 'build', src, '--outDir', path.join(fixture, 'dist')], { cwd: appRoot, stdio: 'inherit' });
|
|
30
|
+
assert.match(fs.readFileSync(path.join(fixture, 'dist/index.html'), 'utf8'), /assets\/index-/);
|
|
31
|
+
} finally {
|
|
32
|
+
const resolved = path.resolve(fixture);
|
|
33
|
+
assert.equal(path.dirname(resolved), path.resolve(tempRoot));
|
|
34
|
+
fs.rmSync(resolved, { recursive: true, force: true });
|
|
35
|
+
}
|
|
@@ -1,46 +1,46 @@
|
|
|
1
|
-
const { execFileSync, spawnSync } = require('child_process');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const { syncGeneratedProfileBackup } = require('./setup-baseline-profile.js');
|
|
4
|
-
|
|
5
|
-
function main() {
|
|
6
|
-
const devices = execFileSync('adb', ['devices'], { encoding: 'utf8' })
|
|
7
|
-
.split(/\r?\n/)
|
|
8
|
-
.map(line => line.match(/^(.+?)\tdevice\s*$/))
|
|
9
|
-
.filter(Boolean)
|
|
10
|
-
.map(match => match[1]);
|
|
11
|
-
const requestedSerial = process.env.ANDROID_SERIAL?.trim();
|
|
12
|
-
if (requestedSerial?.includes(',')) {
|
|
13
|
-
throw new Error('Set ANDROID_SERIAL to one device connection for Baseline Profile generation.');
|
|
14
|
-
}
|
|
15
|
-
const serial = requestedSerial || devices[0];
|
|
16
|
-
if (!serial || !devices.includes(serial)) {
|
|
17
|
-
throw new Error(requestedSerial
|
|
18
|
-
? `ADB device is not online: ${requestedSerial}`
|
|
19
|
-
: 'No online ADB device. Connect an Android device before generating a Baseline Profile.');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
console.log(`Generating Baseline Profile using one ADB connection: ${serial}`);
|
|
23
|
-
const args = [':app:generateBaselineProfile', '--console=plain'];
|
|
24
|
-
const result = spawnSync(
|
|
25
|
-
process.platform === 'win32' ? 'cmd.exe' : './gradlew',
|
|
26
|
-
process.platform === 'win32' ? ['/d', '/s', '/c', `gradlew.bat ${args.join(' ')}`] : args,
|
|
27
|
-
{
|
|
28
|
-
cwd: path.resolve(__dirname, '..', 'android'),
|
|
29
|
-
env: { ...process.env, ANDROID_SERIAL: serial },
|
|
30
|
-
stdio: 'inherit',
|
|
31
|
-
}
|
|
32
|
-
);
|
|
33
|
-
if (result.error) throw result.error;
|
|
34
|
-
if (result.signal) throw new Error(`Baseline Profile generation stopped by ${result.signal}.`);
|
|
35
|
-
process.exitCode = result.status ?? 1;
|
|
36
|
-
if (process.exitCode === 0) {
|
|
37
|
-
syncGeneratedProfileBackup({ backupOnly: true });
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
main();
|
|
43
|
-
} catch (error) {
|
|
44
|
-
console.error(`Baseline Profile generation failed: ${error.message}`);
|
|
45
|
-
process.exitCode = 1;
|
|
46
|
-
}
|
|
1
|
+
const { execFileSync, spawnSync } = require('child_process');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { syncGeneratedProfileBackup } = require('./setup-baseline-profile.js');
|
|
4
|
+
|
|
5
|
+
function main() {
|
|
6
|
+
const devices = execFileSync('adb', ['devices'], { encoding: 'utf8' })
|
|
7
|
+
.split(/\r?\n/)
|
|
8
|
+
.map(line => line.match(/^(.+?)\tdevice\s*$/))
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.map(match => match[1]);
|
|
11
|
+
const requestedSerial = process.env.ANDROID_SERIAL?.trim();
|
|
12
|
+
if (requestedSerial?.includes(',')) {
|
|
13
|
+
throw new Error('Set ANDROID_SERIAL to one device connection for Baseline Profile generation.');
|
|
14
|
+
}
|
|
15
|
+
const serial = requestedSerial || devices[0];
|
|
16
|
+
if (!serial || !devices.includes(serial)) {
|
|
17
|
+
throw new Error(requestedSerial
|
|
18
|
+
? `ADB device is not online: ${requestedSerial}`
|
|
19
|
+
: 'No online ADB device. Connect an Android device before generating a Baseline Profile.');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
console.log(`Generating Baseline Profile using one ADB connection: ${serial}`);
|
|
23
|
+
const args = [':app:generateBaselineProfile', '--console=plain'];
|
|
24
|
+
const result = spawnSync(
|
|
25
|
+
process.platform === 'win32' ? 'cmd.exe' : './gradlew',
|
|
26
|
+
process.platform === 'win32' ? ['/d', '/s', '/c', `gradlew.bat ${args.join(' ')}`] : args,
|
|
27
|
+
{
|
|
28
|
+
cwd: path.resolve(__dirname, '..', 'android'),
|
|
29
|
+
env: { ...process.env, ANDROID_SERIAL: serial },
|
|
30
|
+
stdio: 'inherit',
|
|
31
|
+
}
|
|
32
|
+
);
|
|
33
|
+
if (result.error) throw result.error;
|
|
34
|
+
if (result.signal) throw new Error(`Baseline Profile generation stopped by ${result.signal}.`);
|
|
35
|
+
process.exitCode = result.status ?? 1;
|
|
36
|
+
if (process.exitCode === 0) {
|
|
37
|
+
syncGeneratedProfileBackup({ backupOnly: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
main();
|
|
43
|
+
} catch (error) {
|
|
44
|
+
console.error(`Baseline Profile generation failed: ${error.message}`);
|
|
45
|
+
process.exitCode = 1;
|
|
46
|
+
}
|