codeplay-common 4.11.34 → 4.11.37

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +115 -115
  2. package/LICENSE +21 -21
  3. package/README.md +6 -0
  4. package/RELEASE_NOTES.md +110 -110
  5. package/files/buildCodeplay/HUAWEI-PRIVACY.md +9 -9
  6. package/files/buildCodeplay/add-splash-screen.js +256 -256
  7. package/files/buildCodeplay/apk-store-builder.js +97 -97
  8. package/files/buildCodeplay/fix-onesignal-plugin.js +96 -96
  9. package/files/buildCodeplay/fix-optimize-builld/android-r8-rules.cjs +31 -31
  10. package/files/buildCodeplay/fix-optimize-builld/ffmpeg-jni-rules.cjs +28 -28
  11. package/files/buildCodeplay/fix-optimize-builld/fix-optimize-build.gradle +9 -9
  12. package/files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs +30 -30
  13. package/files/buildCodeplay/huawei-privacy.cjs +102 -92
  14. package/files/buildCodeplay/iap-alias.cjs +116 -108
  15. package/files/buildCodeplay/ios-emi-admob-modification.js +24 -24
  16. package/files/buildCodeplay/manifestModification.js +38 -38
  17. package/files/buildCodeplay/migrate-system-bars.cjs +122 -122
  18. package/files/buildCodeplay/packageidBaseModification.js +528 -528
  19. package/files/buildCodeplay/project-scripts.cjs +69 -69
  20. package/files/buildCodeplay/ruads.cjs +10 -1
  21. package/files/buildCodeplay/setSplashAnimation.js +228 -228
  22. package/files/buildCodeplay/setup-ruads.cjs +9 -2
  23. package/files/buildCodeplay/splash-setup.cjs +88 -88
  24. package/files/buildCodeplay/splashxml/codeplay_splashScreen.xml +11 -11
  25. package/files/buildCodeplay/sync-admob-nextgen.js +219 -219
  26. package/files/buildCodeplay/tests/huawei-live-reload.test.cjs +60 -0
  27. package/files/buildCodeplay/tests/huawei-multiple-entries.test.cjs +80 -0
  28. package/files/buildCodeplay/tests/huawei-vite.test.cjs +38 -35
  29. package/files/buildCodeplay/versions.json +28 -28
  30. package/files/finalrelease +1365 -1365
  31. package/files/generate-ai-promo-video.js +23 -23
  32. package/files/ionic.config.json +6 -6
  33. package/files/scripts-common/run-codeplay-sync-after.js +21 -21
  34. package/files/scripts-common/screenshot/background-decorations.js +120 -120
  35. package/files/scripts-common/screenshot/frame-samples.js +117 -117
  36. package/files/scripts-common/setup-baseline-profile.js +291 -291
  37. package/files/take-screen-video.js +644 -644
  38. package/package.json +1 -1
  39. package/runtime/splash-ready.mjs +52 -52
  40. package/scripts/iap-alias.test.cjs +117 -78
  41. package/scripts/ruads-install.test.cjs +20 -3
  42. package/scripts/splash-setup.test.cjs +142 -142
  43. package/scripts/sync-files.js +119 -119
  44. package/scripts/system-bars-package.test.cjs +37 -37
  45. package/scripts/system-bars.test.cjs +93 -93
  46. package/scripts/uninstall.js +2 -2
  47. package/scripts/vite-build-settings.test.cjs +1 -0
@@ -1,142 +1,142 @@
1
- const { test } = require('node:test');
2
- const assert = require('node:assert/strict');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const { execFileSync } = require('child_process');
6
- const { readSplashOptions, migrateSplashTheme, migrateReadinessSource, syncSplashSetup } = require('../files/buildCodeplay/splash-setup.cjs');
7
-
8
- function fixture(t) {
9
- const base = path.resolve(process.env.CODEPLAY_TEST_ROOT || path.join(__dirname, '../agent-temp'));
10
- fs.mkdirSync(base, { recursive: true });
11
- const root = fs.mkdtempSync(path.join(base, 'splash-'));
12
- t.after(() => {
13
- if (path.dirname(path.resolve(root)) !== base) throw new Error('Unsafe fixture cleanup');
14
- fs.rmSync(root, { recursive: true, force: true });
15
- });
16
- return root;
17
- }
18
- const legacy = `var capacitorApp = {
19
- handleSplashscreen: function () {
20
- if (!window.Capacitor) return;
21
- setTimeout(() => { if (window.Capacitor.Plugins?.SplashScreen) window.Capacitor.Plugins.SplashScreen.hide(); }, 2000);
22
- },
23
- };`;
24
- const options = readSplashOptions({ plugins: { CodeplaySplashScreen: { migrateLegacyReadiness: true } } });
25
-
26
- test('duration defaults to1000 and preserves explicit0;invalid values fail', () => {
27
- assert.equal(readSplashOptions({}).duration, 1000);
28
- assert.equal(readSplashOptions({ plugins: { CodeplaySplashScreen: { exitAnimationDuration: 0 } } }).duration, 0);
29
- for (const duration of [-1, '0', 1.5, 10001]) assert.throws(() => readSplashOptions({ plugins: { CodeplaySplashScreen: { exitAnimationDuration: duration } } }));
30
- });
31
- test('repair known legacy theme,idempotently preserve app-specific themes', () => {
32
- const before = '<item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>';
33
- const after = migrateSplashTheme(before);
34
- assert.ok(after.includes('Theme.AppCompat.DayNight.NoActionBar'));
35
- assert.equal(migrateSplashTheme(after), after);
36
- assert.equal(migrateSplashTheme(before.replace('Theme.AppCompat.NoActionBar', 'MyCustomTheme')), before.replace('Theme.AppCompat.NoActionBar', 'MyCustomTheme'));
37
- });
38
- test('legacy handler migration requires opt-in,is idempotent,and preserves custom handlers', () => {
39
- assert.equal(migrateReadinessSource(legacy, readSplashOptions({})).source, legacy);
40
- const migrated = migrateReadinessSource(legacy, options);
41
- assert.equal(migrated.status, 'managed');
42
- assert.equal(migrateReadinessSource(migrated.source, options).source, migrated.source);
43
- const custom = migrated.source.replace(' if (!window.Capacitor)', ' customStartup();\n if (!window.Capacitor)');
44
- assert.equal(migrateReadinessSource(custom, options).source, custom);
45
- const customAfter = migrated.source.replace(' });', ' });\n customStartup();');
46
- assert.equal(migrateReadinessSource(customAfter, options).source, customAfter);
47
- });
48
- test('migration keeps legacy native-disabled config and custom theme intact', t => {
49
- const root = fixture(t);
50
- fs.mkdirSync(path.join(root, 'src/js'), { recursive: true });
51
- fs.mkdirSync(path.join(root, 'buildCodeplay/splashxml'), { recursive: true });
52
- fs.writeFileSync(path.join(root, 'src/js/capacitor-app.js'), legacy);
53
- fs.writeFileSync(path.join(root, 'buildCodeplay/splashxml/codeplay_splashScreen.xml'), '<item name="postSplashScreenTheme">@style/Custom</item>');
54
- fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify({ plugins: { SplashScreen: { launchShowDuration: 0 }, CodeplaySplashScreen: { migrateLegacyReadiness: true } } }));
55
- const log = [];
56
- syncSplashSetup(root, { log: value => log.push(value) });
57
- assert.equal(fs.readFileSync(path.join(root, 'src/js/capacitor-app.js'), 'utf8'), legacy);
58
- assert.ok(log.some(value => value.includes('native fallback')));
59
- });
60
- test('generator emits0ms without changing launchShowDuration', t => {
61
- const root = fixture(t);
62
- const java = path.join(root, 'android/app/src/main/java/example/app/MainActivity.java');
63
- fs.mkdirSync(path.dirname(java), { recursive: true });
64
- fs.writeFileSync(java, 'package example.app;');
65
- const config = { appId: 'example.app', plugins: { SplashScreen: { launchShowDuration: 8000 }, CodeplaySplashScreen: { exitAnimationDuration: 0 } } };
66
- fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify(config));
67
- execFileSync(process.execPath, [path.resolve(__dirname, '../files/buildCodeplay/setSplashAnimation.js')], { cwd: root, stdio: 'pipe' });
68
- assert.ok(fs.readFileSync(java, 'utf8').includes('.setDuration(0)'));
69
- assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capacitor.config.json'))), config);
70
- });
71
- test('complete migration requires fallback and plugin dependency;repeat preparation is stable', t => {
72
- const root = fixture(t);
73
- fs.mkdirSync(path.join(root, 'src/js'), { recursive: true });
74
- const app = path.join(root, 'src/js/capacitor-app.js');
75
- fs.writeFileSync(app, legacy);
76
- const config = { plugins: { SplashScreen: { launchShowDuration: 8000, launchAutoHide: true }, CodeplaySplashScreen: { migrateLegacyReadiness: true } } };
77
- fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify(config));
78
- fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ dependencies: {} }));
79
- syncSplashSetup(root, { log() {} });
80
- assert.equal(fs.readFileSync(app, 'utf8'), legacy);
81
- fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ dependencies: { '@capacitor/splash-screen': '^8.0.0' } }));
82
- syncSplashSetup(root, { log() {} });
83
- const result = fs.readFileSync(app, 'utf8');
84
- assert.ok(result.includes('return hideSplashWhenReady('));
85
- syncSplashSetup(root, { log() {} });
86
- assert.equal(fs.readFileSync(app, 'utf8'), result);
87
- assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capacitor.config.json'))), config);
88
- });
89
-
90
- function framework(image, cached = false) {
91
- const handlers = new Map();
92
- const page = { closest: () => true, querySelector: () => image };
93
- return { page, handlers, f7: { on: (name, fn) => handlers.set(name, fn), off: name => handlers.delete(name), views: { main: { router: { currentPageEl: cached ? page : null } } } } };
94
- }
95
- test('wait for main-page image decode,hide once,and detach listeners', async () => {
96
- const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
97
- let decoded, count = 0;
98
- const listeners = new Map();
99
- const image = { complete: false, naturalWidth: 100, decode: () => new Promise(resolve => { decoded = resolve; }), addEventListener: (name, fn) => listeners.set(name, fn), removeEventListener: name => listeners.delete(name) };
100
- const { f7, handlers, page } = framework(image);
101
- const finish = hideSplashWhenReady({ f7, hide: () => { count++; } });
102
- handlers.get('pageAfterIn')({ el: { closest: () => false } });
103
- assert.equal(count, 0);
104
- handlers.get('pageAfterIn')({ el: page });
105
- listeners.get('load')();
106
- await Promise.resolve();
107
- assert.equal(count, 0);
108
- decoded();
109
- await new Promise(resolve => setImmediate(resolve));
110
- finish();
111
- assert.equal(count, 1);
112
- assert.equal(handlers.size, 0);
113
- assert.equal(listeners.size, 0);
114
- });
115
- test('cached page without hero hides immediately and repeated setup is safe', async () => {
116
- const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
117
- const { f7 } = framework(null, true);
118
- let count = 0;
119
- hideSplashWhenReady({ f7, hide: () => { count++; } });
120
- hideSplashWhenReady({ f7, hide: () => { count++; } });
121
- assert.equal(count, 1);
122
- });
123
- test('broken image and failed decode release splash', async () => {
124
- const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
125
- for (const naturalWidth of [0, 100]) {
126
- let count = 0;
127
- const image = { complete: true, naturalWidth, decode: () => Promise.reject(new Error('decode failed')), removeEventListener() {} };
128
- const { f7 } = framework(image, true);
129
- hideSplashWhenReady({ f7, hide: () => { count++; } });
130
- await new Promise(resolve => setImmediate(resolve));
131
- assert.equal(count, 1);
132
- }
133
- });
134
- test('timeout releases stuck page and consumes native plugin rejection', async () => {
135
- const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
136
- const { f7, handlers } = framework(null);
137
- let count = 0;
138
- hideSplashWhenReady({ f7, timeout: 10, hide: () => { count++; return Promise.reject(new Error('native unavailable')); } });
139
- await new Promise(resolve => setTimeout(resolve, 30));
140
- assert.equal(count, 1);
141
- assert.equal(handlers.size, 0);
142
- });
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { execFileSync } = require('child_process');
6
+ const { readSplashOptions, migrateSplashTheme, migrateReadinessSource, syncSplashSetup } = require('../files/buildCodeplay/splash-setup.cjs');
7
+
8
+ function fixture(t) {
9
+ const base = path.resolve(process.env.CODEPLAY_TEST_ROOT || path.join(__dirname, '../agent-temp'));
10
+ fs.mkdirSync(base, { recursive: true });
11
+ const root = fs.mkdtempSync(path.join(base, 'splash-'));
12
+ t.after(() => {
13
+ if (path.dirname(path.resolve(root)) !== base) throw new Error('Unsafe fixture cleanup');
14
+ fs.rmSync(root, { recursive: true, force: true });
15
+ });
16
+ return root;
17
+ }
18
+ const legacy = `var capacitorApp = {
19
+ handleSplashscreen: function () {
20
+ if (!window.Capacitor) return;
21
+ setTimeout(() => { if (window.Capacitor.Plugins?.SplashScreen) window.Capacitor.Plugins.SplashScreen.hide(); }, 2000);
22
+ },
23
+ };`;
24
+ const options = readSplashOptions({ plugins: { CodeplaySplashScreen: { migrateLegacyReadiness: true } } });
25
+
26
+ test('duration defaults to1000 and preserves explicit0;invalid values fail', () => {
27
+ assert.equal(readSplashOptions({}).duration, 1000);
28
+ assert.equal(readSplashOptions({ plugins: { CodeplaySplashScreen: { exitAnimationDuration: 0 } } }).duration, 0);
29
+ for (const duration of [-1, '0', 1.5, 10001]) assert.throws(() => readSplashOptions({ plugins: { CodeplaySplashScreen: { exitAnimationDuration: duration } } }));
30
+ });
31
+ test('repair known legacy theme,idempotently preserve app-specific themes', () => {
32
+ const before = '<item name="postSplashScreenTheme">@style/Theme.AppCompat.NoActionBar</item>';
33
+ const after = migrateSplashTheme(before);
34
+ assert.ok(after.includes('Theme.AppCompat.DayNight.NoActionBar'));
35
+ assert.equal(migrateSplashTheme(after), after);
36
+ assert.equal(migrateSplashTheme(before.replace('Theme.AppCompat.NoActionBar', 'MyCustomTheme')), before.replace('Theme.AppCompat.NoActionBar', 'MyCustomTheme'));
37
+ });
38
+ test('legacy handler migration requires opt-in,is idempotent,and preserves custom handlers', () => {
39
+ assert.equal(migrateReadinessSource(legacy, readSplashOptions({})).source, legacy);
40
+ const migrated = migrateReadinessSource(legacy, options);
41
+ assert.equal(migrated.status, 'managed');
42
+ assert.equal(migrateReadinessSource(migrated.source, options).source, migrated.source);
43
+ const custom = migrated.source.replace(' if (!window.Capacitor)', ' customStartup();\n if (!window.Capacitor)');
44
+ assert.equal(migrateReadinessSource(custom, options).source, custom);
45
+ const customAfter = migrated.source.replace(' });', ' });\n customStartup();');
46
+ assert.equal(migrateReadinessSource(customAfter, options).source, customAfter);
47
+ });
48
+ test('migration keeps legacy native-disabled config and custom theme intact', t => {
49
+ const root = fixture(t);
50
+ fs.mkdirSync(path.join(root, 'src/js'), { recursive: true });
51
+ fs.mkdirSync(path.join(root, 'buildCodeplay/splashxml'), { recursive: true });
52
+ fs.writeFileSync(path.join(root, 'src/js/capacitor-app.js'), legacy);
53
+ fs.writeFileSync(path.join(root, 'buildCodeplay/splashxml/codeplay_splashScreen.xml'), '<item name="postSplashScreenTheme">@style/Custom</item>');
54
+ fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify({ plugins: { SplashScreen: { launchShowDuration: 0 }, CodeplaySplashScreen: { migrateLegacyReadiness: true } } }));
55
+ const log = [];
56
+ syncSplashSetup(root, { log: value => log.push(value) });
57
+ assert.equal(fs.readFileSync(path.join(root, 'src/js/capacitor-app.js'), 'utf8'), legacy);
58
+ assert.ok(log.some(value => value.includes('native fallback')));
59
+ });
60
+ test('generator emits0ms without changing launchShowDuration', t => {
61
+ const root = fixture(t);
62
+ const java = path.join(root, 'android/app/src/main/java/example/app/MainActivity.java');
63
+ fs.mkdirSync(path.dirname(java), { recursive: true });
64
+ fs.writeFileSync(java, 'package example.app;');
65
+ const config = { appId: 'example.app', plugins: { SplashScreen: { launchShowDuration: 8000 }, CodeplaySplashScreen: { exitAnimationDuration: 0 } } };
66
+ fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify(config));
67
+ execFileSync(process.execPath, [path.resolve(__dirname, '../files/buildCodeplay/setSplashAnimation.js')], { cwd: root, stdio: 'pipe' });
68
+ assert.ok(fs.readFileSync(java, 'utf8').includes('.setDuration(0)'));
69
+ assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capacitor.config.json'))), config);
70
+ });
71
+ test('complete migration requires fallback and plugin dependency;repeat preparation is stable', t => {
72
+ const root = fixture(t);
73
+ fs.mkdirSync(path.join(root, 'src/js'), { recursive: true });
74
+ const app = path.join(root, 'src/js/capacitor-app.js');
75
+ fs.writeFileSync(app, legacy);
76
+ const config = { plugins: { SplashScreen: { launchShowDuration: 8000, launchAutoHide: true }, CodeplaySplashScreen: { migrateLegacyReadiness: true } } };
77
+ fs.writeFileSync(path.join(root, 'capacitor.config.json'), JSON.stringify(config));
78
+ fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ dependencies: {} }));
79
+ syncSplashSetup(root, { log() {} });
80
+ assert.equal(fs.readFileSync(app, 'utf8'), legacy);
81
+ fs.writeFileSync(path.join(root, 'package.json'), JSON.stringify({ dependencies: { '@capacitor/splash-screen': '^8.0.0' } }));
82
+ syncSplashSetup(root, { log() {} });
83
+ const result = fs.readFileSync(app, 'utf8');
84
+ assert.ok(result.includes('return hideSplashWhenReady('));
85
+ syncSplashSetup(root, { log() {} });
86
+ assert.equal(fs.readFileSync(app, 'utf8'), result);
87
+ assert.deepEqual(JSON.parse(fs.readFileSync(path.join(root, 'capacitor.config.json'))), config);
88
+ });
89
+
90
+ function framework(image, cached = false) {
91
+ const handlers = new Map();
92
+ const page = { closest: () => true, querySelector: () => image };
93
+ return { page, handlers, f7: { on: (name, fn) => handlers.set(name, fn), off: name => handlers.delete(name), views: { main: { router: { currentPageEl: cached ? page : null } } } } };
94
+ }
95
+ test('wait for main-page image decode,hide once,and detach listeners', async () => {
96
+ const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
97
+ let decoded, count = 0;
98
+ const listeners = new Map();
99
+ const image = { complete: false, naturalWidth: 100, decode: () => new Promise(resolve => { decoded = resolve; }), addEventListener: (name, fn) => listeners.set(name, fn), removeEventListener: name => listeners.delete(name) };
100
+ const { f7, handlers, page } = framework(image);
101
+ const finish = hideSplashWhenReady({ f7, hide: () => { count++; } });
102
+ handlers.get('pageAfterIn')({ el: { closest: () => false } });
103
+ assert.equal(count, 0);
104
+ handlers.get('pageAfterIn')({ el: page });
105
+ listeners.get('load')();
106
+ await Promise.resolve();
107
+ assert.equal(count, 0);
108
+ decoded();
109
+ await new Promise(resolve => setImmediate(resolve));
110
+ finish();
111
+ assert.equal(count, 1);
112
+ assert.equal(handlers.size, 0);
113
+ assert.equal(listeners.size, 0);
114
+ });
115
+ test('cached page without hero hides immediately and repeated setup is safe', async () => {
116
+ const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
117
+ const { f7 } = framework(null, true);
118
+ let count = 0;
119
+ hideSplashWhenReady({ f7, hide: () => { count++; } });
120
+ hideSplashWhenReady({ f7, hide: () => { count++; } });
121
+ assert.equal(count, 1);
122
+ });
123
+ test('broken image and failed decode release splash', async () => {
124
+ const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
125
+ for (const naturalWidth of [0, 100]) {
126
+ let count = 0;
127
+ const image = { complete: true, naturalWidth, decode: () => Promise.reject(new Error('decode failed')), removeEventListener() {} };
128
+ const { f7 } = framework(image, true);
129
+ hideSplashWhenReady({ f7, hide: () => { count++; } });
130
+ await new Promise(resolve => setImmediate(resolve));
131
+ assert.equal(count, 1);
132
+ }
133
+ });
134
+ test('timeout releases stuck page and consumes native plugin rejection', async () => {
135
+ const { hideSplashWhenReady } = await import('../runtime/splash-ready.mjs');
136
+ const { f7, handlers } = framework(null);
137
+ let count = 0;
138
+ hideSplashWhenReady({ f7, timeout: 10, hide: () => { count++; return Promise.reject(new Error('native unavailable')); } });
139
+ await new Promise(resolve => setTimeout(resolve, 30));
140
+ assert.equal(count, 1);
141
+ assert.equal(handlers.size, 0);
142
+ });
@@ -1,120 +1,120 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const { updateBuildScripts, removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
4
- const { syncAndroidR8Rules } = require('../files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs');
5
-
6
- function migrateAppScripts(projectRoot) {
7
- const root = path.resolve(projectRoot);
8
- const source = path.resolve(root, 'scripts');
9
- const destination = path.resolve(root, 'scripts-common');
10
- if (path.dirname(source) !== root || path.dirname(destination) !== root) throw new Error('Invalid app scripts path.');
11
- if (!fs.existsSync(source)) return;
12
- // Preflight the entire tree before moving anything. Never overwrite a
13
- // different existing file or follow a linked directory.
14
- function check(from, to) {
15
- if (fs.lstatSync(from).isSymbolicLink() || (fs.existsSync(to) && fs.lstatSync(to).isSymbolicLink())) throw new Error('Cannot migrate linked script paths.');
16
- if (!fs.existsSync(to)) return;
17
- if (fs.statSync(from).isDirectory() && fs.statSync(to).isDirectory()) {
18
- for (const name of fs.readdirSync(from)) check(path.join(from, name), path.join(to, name));
19
- } else if (!fs.statSync(from).isFile() || !fs.statSync(to).isFile() || !fs.readFileSync(from).equals(fs.readFileSync(to))) {
20
- throw new Error(`Scripts folder conflict; both files preserved: ${to}`);
21
- }
22
- }
23
- function move(from, to) {
24
- if (!fs.existsSync(to)) { fs.renameSync(from, to); return; }
25
- if (fs.statSync(from).isDirectory()) {
26
- for (const name of fs.readdirSync(from)) move(path.join(from, name), path.join(to, name));
27
- fs.rmdirSync(from);
28
- } else fs.unlinkSync(from); // Identical existing file, verified above.
29
- }
30
- check(source, destination);
31
- move(source, destination);
32
- }
33
-
34
- function migrateAppConfigurator(projectRoot) {
35
- const filePath = path.join(projectRoot, 'scripts-common', 'configure-codeplay-common.js');
36
- if (!fs.existsSync(filePath)) return;
37
- const original = fs.readFileSync(filePath, 'utf8');
38
- let updated = original;
39
- // Preserve app-specific configuration; extend only the known legacy lookups.
40
- for (const [variable, script] of [
41
- ['buildFile', 'codeplayBeforeBuild.js'],
42
- ['packageIdFile', 'packageidBaseModification.js'],
43
- ]) {
44
- updated = updated.replace(
45
- `const ${variable} = fs.readdirSync(buildDir)`,
46
- `const ${variable} = fs.existsSync(path.join(buildDir, '${script}'))\n` +
47
- ` ? '${script}'\n` +
48
- ` : fs.readdirSync(buildDir)`
49
- );
50
- }
51
- updated = updated.replace(
52
- "packageJson.scripts['capacitor:sync:after'] = 'node scripts/run-codeplay-sync-after.js';",
53
- "packageJson.scripts['capacitor:sync:after'] = 'node scripts-common/run-codeplay-sync-after.js';"
54
- );
55
- if (updated !== original) fs.writeFileSync(filePath, updated, 'utf8');
56
- }
57
-
58
- function findProjectRoot() {
59
- // npm may execute a file: dependency's lifecycle in its source directory.
60
- // INIT_CWD identifies the app that invoked npm in that case.
61
- for (const candidate of [process.env.INIT_CWD, path.join(__dirname, '../../..')]) {
62
- if (!candidate) continue;
63
- const root = path.resolve(candidate);
64
- const file = path.join(root, 'package.json');
65
- if (!fs.existsSync(file)) continue;
66
- if (JSON.parse(fs.readFileSync(file, 'utf8')).name !== 'codeplay-common' && fs.existsSync(path.join(root, 'capacitor.config.json'))) return root;
67
- }
68
- return null;
69
- }
70
-
71
- function install(options = {}) {
72
- const resolved = options.projectRoot || findProjectRoot();
73
- if (!resolved) {
74
- console.log('codeplay-common: no consuming Capacitor app found; skipping source-package setup.');
75
- return null;
76
- }
77
- const projectRoot = path.resolve(resolved);
78
- const commonFiles = path.resolve(__dirname, '../files');
79
- const packagePath = path.join(projectRoot, 'package.json');
80
- if (!fs.existsSync(packagePath)) throw new Error('Consuming application package.json was not found.');
81
- const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
82
- const scripts = updateBuildScripts(pkg.scripts || {});
83
- migrateAppScripts(projectRoot);
84
- // Copy the common templates into each application for local testing.
85
- const buildSource = path.join(commonFiles, 'buildCodeplay');
86
- const buildTarget = path.join(projectRoot, 'buildCodeplay');
87
- fs.mkdirSync(buildTarget, { recursive: true });
88
- for (const name of fs.readdirSync(buildSource)) {
89
- const target = path.join(buildTarget, name);
90
- if ((name === 'release-sync.config.json' || name === 'splashxml') && fs.existsSync(target)) continue;
91
- fs.cpSync(path.join(buildSource, name), target, { recursive: true });
92
- }
93
- fs.copyFileSync(path.join(commonFiles, 'finalrelease'), path.join(projectRoot, 'finalrelease'));
94
- if (options.copyAssets !== false) {
95
- for (const name of fs.readdirSync(commonFiles)) {
96
- if (name === 'buildCodeplay' || name === 'scripts-screenshot') continue;
97
- fs.cpSync(path.join(commonFiles, name), path.join(projectRoot, name), { recursive: true });
98
- }
99
- }
100
- require('../files/buildCodeplay/splash-setup.cjs').syncSplashSetup(projectRoot);
101
- require('../files/buildCodeplay/setup-ruads.cjs').syncRuAdsSetup(projectRoot, {
102
- runtimeRoot: path.resolve(__dirname, '../runtime/vk-ads'),
103
- });
104
- require('../files/buildCodeplay/iap-alias.cjs').syncIapAliases(projectRoot);
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { updateBuildScripts, removeVersionedBuildScripts } = require('../files/buildCodeplay/project-scripts.cjs');
4
+ const { syncAndroidR8Rules } = require('../files/buildCodeplay/fix-optimize-builld/restore-android-r8-rules.cjs');
5
+
6
+ function migrateAppScripts(projectRoot) {
7
+ const root = path.resolve(projectRoot);
8
+ const source = path.resolve(root, 'scripts');
9
+ const destination = path.resolve(root, 'scripts-common');
10
+ if (path.dirname(source) !== root || path.dirname(destination) !== root) throw new Error('Invalid app scripts path.');
11
+ if (!fs.existsSync(source)) return;
12
+ // Preflight the entire tree before moving anything. Never overwrite a
13
+ // different existing file or follow a linked directory.
14
+ function check(from, to) {
15
+ if (fs.lstatSync(from).isSymbolicLink() || (fs.existsSync(to) && fs.lstatSync(to).isSymbolicLink())) throw new Error('Cannot migrate linked script paths.');
16
+ if (!fs.existsSync(to)) return;
17
+ if (fs.statSync(from).isDirectory() && fs.statSync(to).isDirectory()) {
18
+ for (const name of fs.readdirSync(from)) check(path.join(from, name), path.join(to, name));
19
+ } else if (!fs.statSync(from).isFile() || !fs.statSync(to).isFile() || !fs.readFileSync(from).equals(fs.readFileSync(to))) {
20
+ throw new Error(`Scripts folder conflict; both files preserved: ${to}`);
21
+ }
22
+ }
23
+ function move(from, to) {
24
+ if (!fs.existsSync(to)) { fs.renameSync(from, to); return; }
25
+ if (fs.statSync(from).isDirectory()) {
26
+ for (const name of fs.readdirSync(from)) move(path.join(from, name), path.join(to, name));
27
+ fs.rmdirSync(from);
28
+ } else fs.unlinkSync(from); // Identical existing file, verified above.
29
+ }
30
+ check(source, destination);
31
+ move(source, destination);
32
+ }
33
+
34
+ function migrateAppConfigurator(projectRoot) {
35
+ const filePath = path.join(projectRoot, 'scripts-common', 'configure-codeplay-common.js');
36
+ if (!fs.existsSync(filePath)) return;
37
+ const original = fs.readFileSync(filePath, 'utf8');
38
+ let updated = original;
39
+ // Preserve app-specific configuration; extend only the known legacy lookups.
40
+ for (const [variable, script] of [
41
+ ['buildFile', 'codeplayBeforeBuild.js'],
42
+ ['packageIdFile', 'packageidBaseModification.js'],
43
+ ]) {
44
+ updated = updated.replace(
45
+ `const ${variable} = fs.readdirSync(buildDir)`,
46
+ `const ${variable} = fs.existsSync(path.join(buildDir, '${script}'))\n` +
47
+ ` ? '${script}'\n` +
48
+ ` : fs.readdirSync(buildDir)`
49
+ );
50
+ }
51
+ updated = updated.replace(
52
+ "packageJson.scripts['capacitor:sync:after'] = 'node scripts/run-codeplay-sync-after.js';",
53
+ "packageJson.scripts['capacitor:sync:after'] = 'node scripts-common/run-codeplay-sync-after.js';"
54
+ );
55
+ if (updated !== original) fs.writeFileSync(filePath, updated, 'utf8');
56
+ }
57
+
58
+ function findProjectRoot() {
59
+ // npm may execute a file: dependency's lifecycle in its source directory.
60
+ // INIT_CWD identifies the app that invoked npm in that case.
61
+ for (const candidate of [process.env.INIT_CWD, path.join(__dirname, '../../..')]) {
62
+ if (!candidate) continue;
63
+ const root = path.resolve(candidate);
64
+ const file = path.join(root, 'package.json');
65
+ if (!fs.existsSync(file)) continue;
66
+ if (JSON.parse(fs.readFileSync(file, 'utf8')).name !== 'codeplay-common' && fs.existsSync(path.join(root, 'capacitor.config.json'))) return root;
67
+ }
68
+ return null;
69
+ }
70
+
71
+ function install(options = {}) {
72
+ const resolved = options.projectRoot || findProjectRoot();
73
+ if (!resolved) {
74
+ console.log('codeplay-common: no consuming Capacitor app found; skipping source-package setup.');
75
+ return null;
76
+ }
77
+ const projectRoot = path.resolve(resolved);
78
+ const commonFiles = path.resolve(__dirname, '../files');
79
+ const packagePath = path.join(projectRoot, 'package.json');
80
+ if (!fs.existsSync(packagePath)) throw new Error('Consuming application package.json was not found.');
81
+ const pkg = JSON.parse(fs.readFileSync(packagePath, 'utf8'));
82
+ const scripts = updateBuildScripts(pkg.scripts || {});
83
+ migrateAppScripts(projectRoot);
84
+ // Copy the common templates into each application for local testing.
85
+ const buildSource = path.join(commonFiles, 'buildCodeplay');
86
+ const buildTarget = path.join(projectRoot, 'buildCodeplay');
87
+ fs.mkdirSync(buildTarget, { recursive: true });
88
+ for (const name of fs.readdirSync(buildSource)) {
89
+ const target = path.join(buildTarget, name);
90
+ if ((name === 'release-sync.config.json' || name === 'splashxml') && fs.existsSync(target)) continue;
91
+ fs.cpSync(path.join(buildSource, name), target, { recursive: true });
92
+ }
93
+ fs.copyFileSync(path.join(commonFiles, 'finalrelease'), path.join(projectRoot, 'finalrelease'));
94
+ if (options.copyAssets !== false) {
95
+ for (const name of fs.readdirSync(commonFiles)) {
96
+ if (name === 'buildCodeplay' || name === 'scripts-screenshot') continue;
97
+ fs.cpSync(path.join(commonFiles, name), path.join(projectRoot, name), { recursive: true });
98
+ }
99
+ }
100
+ require('../files/buildCodeplay/splash-setup.cjs').syncSplashSetup(projectRoot);
101
+ require('../files/buildCodeplay/setup-ruads.cjs').syncRuAdsSetup(projectRoot, {
102
+ runtimeRoot: path.resolve(__dirname, '../runtime/vk-ads'),
103
+ });
104
+ require('../files/buildCodeplay/iap-alias.cjs').syncIapAliases(projectRoot);
105
105
  migrateAppConfigurator(projectRoot);
106
- require('../files/buildCodeplay/migrate-system-bars.cjs').migrateSystemBars(projectRoot);
107
- syncAndroidR8Rules(projectRoot, { installGradleHook: true });
108
- pkg.scripts = scripts;
109
- require('../files/buildCodeplay/saf-mediastore-dependency.cjs').syncSafMediastoreDependency(projectRoot);
110
- fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
111
- // Cleanup happens only after replacement assets and package commands exist.
112
- removeVersionedBuildScripts(projectRoot);
113
- console.log('codeplay-common: unversioned build scripts copied to app buildCodeplay; app-owned settings preserved.');
114
- // Coupled IAP/AdMob/Home migrations run together during before-build.
115
- return pkg;
116
- }
117
- module.exports = { install, findProjectRoot, migrateAppScripts, migrateAppConfigurator };
118
- if (require.main === module) {
119
- try { install(); } catch (error) { console.error(error.message); process.exitCode = 1; }
120
- }
106
+ require('../files/buildCodeplay/migrate-system-bars.cjs').migrateSystemBars(projectRoot);
107
+ syncAndroidR8Rules(projectRoot, { installGradleHook: true });
108
+ pkg.scripts = scripts;
109
+ require('../files/buildCodeplay/saf-mediastore-dependency.cjs').syncSafMediastoreDependency(projectRoot);
110
+ fs.writeFileSync(packagePath, JSON.stringify(pkg, null, 2) + '\n');
111
+ // Cleanup happens only after replacement assets and package commands exist.
112
+ removeVersionedBuildScripts(projectRoot);
113
+ console.log('codeplay-common: unversioned build scripts copied to app buildCodeplay; app-owned settings preserved.');
114
+ // Coupled IAP/AdMob/Home migrations run together during before-build.
115
+ return pkg;
116
+ }
117
+ module.exports = { install, findProjectRoot, migrateAppScripts, migrateAppConfigurator };
118
+ if (require.main === module) {
119
+ try { install(); } catch (error) { console.error(error.message); process.exitCode = 1; }
120
+ }
@@ -1,38 +1,38 @@
1
- const { test } = require('node:test');
2
- const assert = require('node:assert/strict');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const vm = require('vm');
6
-
7
- const source = fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/codeplayBeforeBuild.js'), 'utf8');
8
- const start = source.indexOf('const syncCodeplaySystemBarsPackage =');
9
- const code = source.slice(start, source.indexOf('\n};', start) + 3);
10
-
11
- function run({ installed = '1.0.1', latest = '1.0.2', declared = '^1.0.1', offline = false, fail = false } = {}) {
12
- const commands = [];
13
- let queries = 0;
14
- const context = {
15
- fs: { existsSync: () => true, readFileSync: () => JSON.stringify({ dependencies: { 'capacitor-codeplay-system-bars': declared } }) },
16
- packageJsonPath: 'package.json',
17
- CODEPLAY_SYSTEM_BARS_PLUGIN: 'capacitor-codeplay-system-bars',
18
- getInstalledVersion: () => installed,
19
- getLatestVersion: () => { queries++; return latest; },
20
- compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }),
21
- runNpmCommand: command => { if (fail) throw new Error('install failed'); commands.push(command); },
22
- skipOnlineVersionChecks: offline,
23
- console: { log() {}, warn() {} }
24
- };
25
- vm.runInNewContext(code + '\nsyncCodeplaySystemBarsPackage();', context);
26
- return { commands, queries };
27
- }
28
-
29
- test('updates an older installed release', () => {
30
- assert.deepEqual(run(), { commands: ['npm install capacitor-codeplay-system-bars@latest'], queries: 1 });
31
- });
32
- test('keeps the latest installed release', () => assert.deepEqual(run({ installed: '1.0.2' }).commands, []));
33
- test('does not downgrade a newer installed release', () => assert.deepEqual(run({ installed: '1.0.3' }).commands, []));
34
- test('installs a missing package', () => assert.equal(run({ installed: null }).commands.length, 1));
35
- test('replaces a local plugin reference', () => assert.equal(run({ declared: 'file:../plugin' }).commands.length, 1));
36
- test('offline builds skip the registry check', () => assert.deepEqual(run({ offline: true }), { commands: [], queries: 0 }));
37
- test('registry failure preserves the installed package', () => assert.deepEqual(run({ latest: null }).commands, []));
1
+ const { test } = require('node:test');
2
+ const assert = require('node:assert/strict');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const vm = require('vm');
6
+
7
+ const source = fs.readFileSync(path.join(__dirname, '../files/buildCodeplay/codeplayBeforeBuild.js'), 'utf8');
8
+ const start = source.indexOf('const syncCodeplaySystemBarsPackage =');
9
+ const code = source.slice(start, source.indexOf('\n};', start) + 3);
10
+
11
+ function run({ installed = '1.0.1', latest = '1.0.2', declared = '^1.0.1', offline = false, fail = false } = {}) {
12
+ const commands = [];
13
+ let queries = 0;
14
+ const context = {
15
+ fs: { existsSync: () => true, readFileSync: () => JSON.stringify({ dependencies: { 'capacitor-codeplay-system-bars': declared } }) },
16
+ packageJsonPath: 'package.json',
17
+ CODEPLAY_SYSTEM_BARS_PLUGIN: 'capacitor-codeplay-system-bars',
18
+ getInstalledVersion: () => installed,
19
+ getLatestVersion: () => { queries++; return latest; },
20
+ compareVersionStrings: (a, b) => a.localeCompare(b, undefined, { numeric: true }),
21
+ runNpmCommand: command => { if (fail) throw new Error('install failed'); commands.push(command); },
22
+ skipOnlineVersionChecks: offline,
23
+ console: { log() {}, warn() {} }
24
+ };
25
+ vm.runInNewContext(code + '\nsyncCodeplaySystemBarsPackage();', context);
26
+ return { commands, queries };
27
+ }
28
+
29
+ test('updates an older installed release', () => {
30
+ assert.deepEqual(run(), { commands: ['npm install capacitor-codeplay-system-bars@latest'], queries: 1 });
31
+ });
32
+ test('keeps the latest installed release', () => assert.deepEqual(run({ installed: '1.0.2' }).commands, []));
33
+ test('does not downgrade a newer installed release', () => assert.deepEqual(run({ installed: '1.0.3' }).commands, []));
34
+ test('installs a missing package', () => assert.equal(run({ installed: null }).commands.length, 1));
35
+ test('replaces a local plugin reference', () => assert.equal(run({ declared: 'file:../plugin' }).commands.length, 1));
36
+ test('offline builds skip the registry check', () => assert.deepEqual(run({ offline: true }), { commands: [], queries: 0 }));
37
+ test('registry failure preserves the installed package', () => assert.deepEqual(run({ latest: null }).commands, []));
38
38
  test('installation failure stops the build', () => assert.throws(() => run({ fail: true }), /install failed/));