codeplay-common 4.11.28 → 4.11.29
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/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -0
- package/files/buildCodeplay/codeplayBeforeBuild.js +1 -0
- 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/tests/huawei-privacy.test.cjs +49 -0
- package/files/buildCodeplay/tests/huawei-vite.test.cjs +35 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,7 @@ Files changed: `package.json`, `runtime/splash-ready.mjs`, `files/buildCodeplay/
|
|
|
15
15
|
|
|
16
16
|
## Unreleased
|
|
17
17
|
|
|
18
|
+
- Add a Huawei-only first-launch Simplified Chinese privacy consent gate from shared `buildCodeplay` files. Keep Firebase Analytics off by default in Huawei native builds, restore non-Huawei entries on the next build, and provide a Settings link and withdrawal control. Each app still needs its own published Chinese policy profile before submission.
|
|
18
19
|
- Add optional camera, autofocus and flash feature declarations after package-specific manifest updates. Warn about Amazon device exclusions for existing required camera features (including manual declarations); Enter or a 5-second timeout changes them to optional, while n/N preserves them. Avoid duplicate features on repeated builds and run package-ID preparation in every Android store build command.
|
|
19
20
|
- Invalidate the cached source-file inventory after removing replaced plugin folders or versioned files, so post-update validation scans the installed sources instead of deleted theme paths.
|
|
20
21
|
- Automatically migrate versioned save-file imports to `@saveGallery`, scan the script section of Framework7 pages, and add or refresh the Vite alias for the newest installed platform helper before and after plugin updates.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Huawei Mainland privacy setup
|
|
2
|
+
|
|
3
|
+
The shared before-build script activates `huawei-privacy-entry.js` for Android store ID 4. It uses `android.APP_UNIQUE_ID` from `capacitor.config.json` to link to `https://htmlcodeplay.com/privacy/ch/{id}`. The app entry waits for first-launch consent before importing the normal app bundle. The native manifest defaults Firebase Analytics collection to false. Other store builds restore the original app entry and any existing Analytics manifest value.
|
|
4
|
+
|
|
5
|
+
Publish this `codeplay-common` version, then update it in each app to copy the shared `buildCodeplay` files before running the normal Huawei build command. An older before-build process can download the new package while continuing its own old code, so run the build again after the package update and inspect the generated assets. Editing an app's `AGENTS.md` alone does not change a compiled build. This package does not deploy the privacy site or submit a release.
|
|
6
|
+
|
|
7
|
+
Before submitting each app, publish and review its own Simplified Chinese policy in the website's `data/privacy/ch/{id}.json`. Check that the policy matches the exact Huawei APK/AAB, including ads, analytics, permissions, server requests, accounts, and payment behavior. The website returns 503 if a Chinese profile is missing; do not submit that app until its page works publicly.
|
|
8
|
+
|
|
9
|
+
The shared hook expects one module script in `src/index.html`. It fails the Huawei build on unsupported layouts instead of silently bypassing consent. For apps with native services that collect information before the web app starts, audit and gate those services separately. The Analytics manifest setting is only one native collection control.
|
|
@@ -4728,6 +4728,7 @@ async function main() {
|
|
|
4728
4728
|
() => runNpmCommand(`npx cap sync ${buildPlatform}`));
|
|
4729
4729
|
}
|
|
4730
4730
|
ruAdsBuild.syncAndroidAdmobPolicy(process.cwd(), getCurrentStoreId(), buildPlatform);
|
|
4731
|
+
require('./huawei-privacy.cjs').syncHuaweiPrivacy(process.cwd(), getCurrentStoreId(), buildPlatform);
|
|
4731
4732
|
}
|
|
4732
4733
|
|
|
4733
4734
|
await main();
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Capacitor, registerPlugin } from '@capacitor/core';
|
|
2
|
+
import './huawei-privacy.css';
|
|
3
|
+
|
|
4
|
+
const consentKey = 'codeplayHuaweiPrivacyConsentV1';
|
|
5
|
+
const Analytics = registerPlugin('FirebaseAnalytics');
|
|
6
|
+
const Browser = registerPlugin('Browser');
|
|
7
|
+
const NativeApp = registerPlugin('App');
|
|
8
|
+
const RuAds = registerPlugin('CodeplayRuStoreAds');
|
|
9
|
+
|
|
10
|
+
function policyUrl(appId) {
|
|
11
|
+
return `https://htmlcodeplay.com/privacy/ch/${appId}`;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function openPolicy(appId) {
|
|
15
|
+
const url = policyUrl(appId);
|
|
16
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('Browser')) {
|
|
17
|
+
await Browser.open({ url });
|
|
18
|
+
} else {
|
|
19
|
+
window.open(url, '_blank', 'noopener,noreferrer');
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function setAnalyticsConsent(enabled) {
|
|
24
|
+
if (!Capacitor.isNativePlatform() || !Capacitor.isPluginAvailable('FirebaseAnalytics')) return;
|
|
25
|
+
try {
|
|
26
|
+
await Analytics.setConsent({ type: 'ANALYTICS_STORAGE', status: enabled ? 'GRANTED' : 'DENIED' });
|
|
27
|
+
await Analytics.setEnabled({ enabled });
|
|
28
|
+
} catch (error) {
|
|
29
|
+
// The manifest still defaults native analytics collection to disabled.
|
|
30
|
+
if (enabled) console.warn('Huawei analytics remains disabled:', error);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function button(label, className, action) {
|
|
35
|
+
const element = document.createElement('button');
|
|
36
|
+
element.type = 'button';
|
|
37
|
+
element.className = className;
|
|
38
|
+
element.textContent = label;
|
|
39
|
+
element.addEventListener('click', action);
|
|
40
|
+
return element;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function showGate({ appId, appName, startApp }) {
|
|
44
|
+
const gate = document.createElement('section');
|
|
45
|
+
gate.className = 'codeplay-huawei-privacy-gate';
|
|
46
|
+
gate.setAttribute('role', 'dialog');
|
|
47
|
+
gate.setAttribute('aria-modal', 'true');
|
|
48
|
+
gate.setAttribute('aria-label', '隐私政策');
|
|
49
|
+
const card = document.createElement('div');
|
|
50
|
+
card.className = 'codeplay-huawei-privacy-card';
|
|
51
|
+
const title = document.createElement('h1');
|
|
52
|
+
title.textContent = '请先阅读隐私政策';
|
|
53
|
+
const message = document.createElement('p');
|
|
54
|
+
message.textContent = `${appName} 会在您同意后启动应用服务。请先阅读简体中文隐私政策,了解个人信息处理、第三方服务及您的权利。`;
|
|
55
|
+
const link = button('阅读隐私政策', 'codeplay-huawei-privacy-policy', async () => {
|
|
56
|
+
try { await openPolicy(appId); }
|
|
57
|
+
catch { status.textContent = '无法打开隐私政策。请检查网络连接后重试。'; }
|
|
58
|
+
});
|
|
59
|
+
const status = document.createElement('p');
|
|
60
|
+
status.className = 'codeplay-huawei-privacy-status';
|
|
61
|
+
status.setAttribute('role', 'status');
|
|
62
|
+
const agree = button('同意并继续', 'codeplay-huawei-privacy-agree', async () => {
|
|
63
|
+
agree.disabled = true;
|
|
64
|
+
try {
|
|
65
|
+
localStorage.setItem(consentKey, 'agreed');
|
|
66
|
+
await setAnalyticsConsent(true);
|
|
67
|
+
gate.remove();
|
|
68
|
+
await startApp();
|
|
69
|
+
installSettingsControls(appId);
|
|
70
|
+
} catch {
|
|
71
|
+
localStorage.removeItem(consentKey);
|
|
72
|
+
status.textContent = '应用暂时无法启动。请重试。';
|
|
73
|
+
agree.disabled = false;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
const decline = button('不同意并退出', 'codeplay-huawei-privacy-decline', async () => {
|
|
77
|
+
await setAnalyticsConsent(false);
|
|
78
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('CodeplayRuStoreAds')) {
|
|
79
|
+
await RuAds.setEnabled({ enabled: false }).catch(() => {});
|
|
80
|
+
}
|
|
81
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('App')) {
|
|
82
|
+
await NativeApp.exitApp();
|
|
83
|
+
} else {
|
|
84
|
+
status.textContent = '您可以关闭此页面。再次打开时仍可选择是否同意。';
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
card.append(title, message, link, status, agree, decline);
|
|
88
|
+
gate.append(card);
|
|
89
|
+
document.body.append(gate);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function installSettingsControls(appId) {
|
|
93
|
+
function mount() {
|
|
94
|
+
const page = document.querySelector('.page-current[data-name="settings"] .page-content');
|
|
95
|
+
if (!page || page.querySelector('.codeplay-huawei-privacy-settings')) return;
|
|
96
|
+
const container = document.createElement('div');
|
|
97
|
+
container.className = 'codeplay-huawei-privacy-settings block';
|
|
98
|
+
const policy = button('简体中文隐私政策', 'button', async () => {
|
|
99
|
+
try { await openPolicy(appId); }
|
|
100
|
+
catch { policy.textContent = '无法打开,请重试'; }
|
|
101
|
+
});
|
|
102
|
+
const withdraw = button('撤回隐私同意', 'button', async () => {
|
|
103
|
+
const confirmed = window.confirm('撤回同意后,应用会关闭。再次打开时可重新选择。确定撤回吗?');
|
|
104
|
+
if (!confirmed) return;
|
|
105
|
+
localStorage.removeItem(consentKey);
|
|
106
|
+
await setAnalyticsConsent(false);
|
|
107
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('CodeplayRuStoreAds')) {
|
|
108
|
+
await RuAds.setEnabled({ enabled: false }).catch(() => {});
|
|
109
|
+
}
|
|
110
|
+
if (Capacitor.isNativePlatform() && Capacitor.isPluginAvailable('App')) await NativeApp.exitApp();
|
|
111
|
+
else location.reload();
|
|
112
|
+
});
|
|
113
|
+
container.append(policy, withdraw);
|
|
114
|
+
page.append(container);
|
|
115
|
+
}
|
|
116
|
+
document.addEventListener('page:afterin', mount);
|
|
117
|
+
document.addEventListener('page:init', mount);
|
|
118
|
+
mount();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function startHuaweiPrivacy(options) {
|
|
122
|
+
if (document.readyState === 'loading') {
|
|
123
|
+
await new Promise(resolve => document.addEventListener('DOMContentLoaded', resolve, { once: true }));
|
|
124
|
+
}
|
|
125
|
+
let agreed = false;
|
|
126
|
+
try { agreed = localStorage.getItem(consentKey) === 'agreed'; } catch { /* Ask again. */ }
|
|
127
|
+
if (agreed) {
|
|
128
|
+
await setAnalyticsConsent(true);
|
|
129
|
+
await options.startApp();
|
|
130
|
+
installSettingsControls(options.appId);
|
|
131
|
+
} else {
|
|
132
|
+
await setAnalyticsConsent(false);
|
|
133
|
+
showGate(options);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
const generatedEntry = '../buildCodeplay/huawei-privacy-generated.js';
|
|
5
|
+
const originalAttribute = 'data-codeplay-original-src';
|
|
6
|
+
const analyticsMarker = 'CODEPLAY HUAWEI ANALYTICS ORIGINAL';
|
|
7
|
+
|
|
8
|
+
function updateEntry(projectRoot, enabled, appId, appName) {
|
|
9
|
+
const indexPath = path.join(projectRoot, 'src/index.html');
|
|
10
|
+
if (!fs.existsSync(indexPath)) {
|
|
11
|
+
if (enabled) throw new Error('Huawei privacy: src/index.html was not found.');
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
const original = fs.readFileSync(indexPath, 'utf8');
|
|
15
|
+
const scripts = [...original.matchAll(/<script\b(?=[^>]*\btype\s*=\s*["']module["'])[^>]*\bsrc\s*=\s*["']([^"']+)["'][^>]*><\/script>/gi)];
|
|
16
|
+
const managed = scripts.filter(match => match[0].includes(originalAttribute));
|
|
17
|
+
if (managed.length > 1) throw new Error('Huawei privacy: more than one managed app entry was found.');
|
|
18
|
+
let target = managed[0];
|
|
19
|
+
if (!target && enabled) {
|
|
20
|
+
if (scripts.length !== 1) throw new Error('Huawei privacy: expected exactly one module app entry in src/index.html.');
|
|
21
|
+
target = scripts[0];
|
|
22
|
+
}
|
|
23
|
+
if (!target) return false;
|
|
24
|
+
const saved = target[0].match(new RegExp(`${originalAttribute}=["']([^"']+)["']`));
|
|
25
|
+
const entry = saved ? saved[1] : target[1];
|
|
26
|
+
if (!/^\.\/[\w./-]+\.js$/.test(entry) || entry.includes('..')) {
|
|
27
|
+
throw new Error(`Huawei privacy: unsupported app entry ${entry}`);
|
|
28
|
+
}
|
|
29
|
+
const entryPath = path.resolve(projectRoot, 'src', entry);
|
|
30
|
+
if (!fs.existsSync(entryPath)) throw new Error(`Huawei privacy: app entry ${entry} was not found.`);
|
|
31
|
+
const tag = enabled
|
|
32
|
+
? target[0].replace(/\ssrc\s*=\s*["'][^"']+["']/, ` src="${generatedEntry}"`)
|
|
33
|
+
.replace(/<script\b/, match => saved ? match : `${match} ${originalAttribute}="${entry}"`)
|
|
34
|
+
: target[0].replace(/\ssrc\s*=\s*["'][^"']+["']/, ` src="${entry}"`)
|
|
35
|
+
.replace(new RegExp(`\\s+${originalAttribute}=["'][^"']+["']`), '');
|
|
36
|
+
const next = original.replace(target[0], tag);
|
|
37
|
+
if (next !== original) fs.writeFileSync(indexPath, next);
|
|
38
|
+
if (enabled) {
|
|
39
|
+
const wrapperPath = path.join(projectRoot, 'buildCodeplay/huawei-privacy-generated.js');
|
|
40
|
+
const importPath = `../src/${entry.slice(2)}`;
|
|
41
|
+
const wrapper = `// Generated by codeplay-common for the Huawei build.\nimport { startHuaweiPrivacy } from './huawei-privacy-entry.js';\nstartHuaweiPrivacy({ appId: ${JSON.stringify(appId)}, appName: ${JSON.stringify(appName)}, startApp: () => import(${JSON.stringify(importPath)}) });\n`;
|
|
42
|
+
if (!fs.existsSync(wrapperPath) || fs.readFileSync(wrapperPath, 'utf8') !== wrapper) fs.writeFileSync(wrapperPath, wrapper);
|
|
43
|
+
}
|
|
44
|
+
return next !== original;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function updateAnalyticsDefault(projectRoot, enabled) {
|
|
48
|
+
const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
|
|
49
|
+
if (!fs.existsSync(manifestPath)) {
|
|
50
|
+
if (enabled) throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
const original = fs.readFileSync(manifestPath, 'utf8');
|
|
54
|
+
const newline = original.includes('\r\n') ? '\r\n' : '\n';
|
|
55
|
+
const marker = new RegExp(`(\\r?\\n)?[ \\t]*<!-- ${analyticsMarker} ([A-Za-z0-9+/=]*) -->\\r?\\n[ \\t]*<meta-data\\b(?=[^>]*\\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\\/\\s*>\\r?\\n?`);
|
|
56
|
+
let next = original;
|
|
57
|
+
if (marker.test(next)) {
|
|
58
|
+
if (!enabled) next = next.replace(marker, (_, leading, encoded) =>
|
|
59
|
+
encoded ? `${leading || ''}${Buffer.from(encoded, 'base64').toString('utf8')}` : '');
|
|
60
|
+
else next = next.replace(marker, match => match.replace(/android:value=["'][^"']*["']/, 'android:value="false"'));
|
|
61
|
+
} else if (enabled) {
|
|
62
|
+
const existing = /[ \t]*<meta-data\b(?=[^>]*\bandroid:name=["']firebase_analytics_collection_enabled["'])[^>]*\/\s*>\r?\n?/;
|
|
63
|
+
const prior = next.match(existing)?.[0] || '';
|
|
64
|
+
const block = ` <!-- ${analyticsMarker} ${Buffer.from(prior).toString('base64')} -->${newline} <meta-data android:name="firebase_analytics_collection_enabled" android:value="false" />${newline}`;
|
|
65
|
+
if (!/<application\b[^>]*>/.test(next)) throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
|
|
66
|
+
next = prior ? next.replace(existing, block) : next.replace(/<application\b[^>]*>/, match => `${match}${newline}${block}`);
|
|
67
|
+
}
|
|
68
|
+
if (next !== original) fs.writeFileSync(manifestPath, next);
|
|
69
|
+
return next !== original;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function syncHuaweiPrivacy(projectRoot, storeId, platform = 'android') {
|
|
73
|
+
const enabled = platform === 'android' && Number(storeId) === 4;
|
|
74
|
+
const config = JSON.parse(fs.readFileSync(path.join(projectRoot, 'capacitor.config.json'), 'utf8'));
|
|
75
|
+
const appId = Number(config.android?.APP_UNIQUE_ID);
|
|
76
|
+
if (enabled && (!Number.isInteger(appId) || appId < 1)) {
|
|
77
|
+
throw new Error('Huawei privacy: capacitor.config.json needs a valid android.APP_UNIQUE_ID.');
|
|
78
|
+
}
|
|
79
|
+
// Inspect both targets before writing either one, so unsupported app layouts fail early.
|
|
80
|
+
const manifestPath = path.join(projectRoot, 'android/app/src/main/AndroidManifest.xml');
|
|
81
|
+
if (enabled && !fs.existsSync(manifestPath)) {
|
|
82
|
+
throw new Error('Huawei privacy: AndroidManifest.xml was not found.');
|
|
83
|
+
}
|
|
84
|
+
if (enabled && !/<application\b[^>]*>/.test(fs.readFileSync(manifestPath, 'utf8'))) {
|
|
85
|
+
throw new Error('Huawei privacy: application element was not found in AndroidManifest.xml.');
|
|
86
|
+
}
|
|
87
|
+
updateEntry(projectRoot, enabled, appId, config.appName || 'App');
|
|
88
|
+
updateAnalyticsDefault(projectRoot, enabled);
|
|
89
|
+
if (enabled) console.log(`Huawei privacy consent enabled. Verify https://htmlcodeplay.com/privacy/ch/${appId} is published before submission.`);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
module.exports = { syncHuaweiPrivacy };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
.codeplay-huawei-privacy-gate {
|
|
2
|
+
position: fixed;
|
|
3
|
+
z-index: 2147483647;
|
|
4
|
+
inset: 0;
|
|
5
|
+
display: grid;
|
|
6
|
+
place-items: center;
|
|
7
|
+
overflow: auto;
|
|
8
|
+
padding: calc(24px + env(safe-area-inset-top, 0px)) calc(20px + env(safe-area-inset-right, 0px)) calc(24px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
|
|
9
|
+
box-sizing: border-box;
|
|
10
|
+
background: #fff;
|
|
11
|
+
color: #17212b;
|
|
12
|
+
font-family: system-ui, sans-serif;
|
|
13
|
+
}
|
|
14
|
+
.codeplay-huawei-privacy-card { width: min(100%, 420px); }
|
|
15
|
+
.codeplay-huawei-privacy-card h1 { margin: 0 0 16px; font-size: 24px; line-height: 1.3; }
|
|
16
|
+
.codeplay-huawei-privacy-card p { line-height: 1.6; }
|
|
17
|
+
.codeplay-huawei-privacy-card button { display: block; width: 100%; min-height: 48px; margin-top: 12px; border-radius: 8px; font: inherit; }
|
|
18
|
+
.codeplay-huawei-privacy-policy { border: 0; background: transparent; color: #155fc6; text-decoration: underline; }
|
|
19
|
+
.codeplay-huawei-privacy-agree { border: 0; background: #155fc6; color: #fff; }
|
|
20
|
+
.codeplay-huawei-privacy-decline { border: 1px solid #8a929c; background: #fff; color: #17212b; }
|
|
21
|
+
.codeplay-huawei-privacy-status { min-height: 1.5em; color: #9b2b20; }
|
|
22
|
+
.codeplay-huawei-privacy-settings { display: flex; flex-direction: column; gap: 8px; }
|
|
@@ -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
|
+
}
|