codeplay-common 1.8.6 → 1.8.7

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.
@@ -0,0 +1,188 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+ const { isStringObject } = require("util/types");
4
+
5
+ const configPath = path.join(process.cwd(), 'capacitor.config.json');
6
+
7
+ // Define file paths
8
+ const projectFolder = path.resolve(".");
9
+ const sourceSplashIcon = path.join(projectFolder, "resources", "splash_icon.png");
10
+ const destinationSplashIcon = path.join(
11
+ projectFolder,
12
+ "android",
13
+ "app",
14
+ "src",
15
+ "main",
16
+ "res",
17
+ "drawable-nodpi",
18
+ "splash_icon.png"
19
+ );
20
+ const sourceSplashXML = path.join(projectFolder,"buildCodeplay", "splashxml", "codeplay_splashScreen.xml");
21
+ const destinationSplashXML = path.join(
22
+ projectFolder,
23
+ "android",
24
+ "app",
25
+ "src",
26
+ "main",
27
+ "res",
28
+ "values",
29
+ "codeplay_splashScreen.xml"
30
+ );
31
+ const androidManifestPath = path.join(
32
+ projectFolder,
33
+ "android",
34
+ "app",
35
+ "src",
36
+ "main",
37
+ "AndroidManifest.xml"
38
+ );
39
+
40
+ // Helper function to copy files
41
+ function copyFile(source, destination) {
42
+ if (!fs.existsSync(source)) {
43
+ throw new Error(`Source file not found: ${source}`);
44
+ }
45
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
46
+ fs.copyFileSync(source, destination);
47
+ console.log(`Copied: ${source} -> ${destination}`);
48
+ }
49
+
50
+ // Helper function to update AndroidManifest.xml
51
+ function updateAndroidManifest() {
52
+ if (!fs.existsSync(androidManifestPath)) {
53
+ throw new Error(`AndroidManifest.xml not found: ${androidManifestPath}`);
54
+ }
55
+
56
+
57
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
58
+
59
+
60
+ const RESIZEABLE_ACTIVITY = config.android?.RESIZEABLE_ACTIVITY;
61
+
62
+ // 1️⃣ Check if it’s missing
63
+ if (RESIZEABLE_ACTIVITY === undefined) {
64
+ console.error('❌ Missing android.RESIZEABLE_ACTIVITY option in capacitor.config.json.');
65
+ process.exit(1);
66
+ }
67
+
68
+ // 2️⃣ Check if it’s not boolean (true/false only)
69
+ if (typeof RESIZEABLE_ACTIVITY !== 'boolean') {
70
+ console.error('❌ Invalid android.RESIZEABLE_ACTIVITY value. Please use only true or false (without quotes).');
71
+ process.exit(1);
72
+ }
73
+
74
+
75
+
76
+
77
+ let manifestContent = fs.readFileSync(androidManifestPath, "utf-8");
78
+
79
+ manifestContent = manifestContent.replace(
80
+ /<activity[^>]*?>/,
81
+ (match) => {
82
+ let updated = match;
83
+
84
+ // If android:theme is already present, update it
85
+ if (updated.includes('android:theme=')) {
86
+ updated = updated.replace(
87
+ /android:theme="[^"]*"/,
88
+ 'android:theme="@style/Theme.Codeplay.SplashScreen"'
89
+ );
90
+ }
91
+
92
+ // If android:resizeableActivity is already present, update it
93
+ if (updated.includes('android:resizeableActivity=')) {
94
+ updated = updated.replace(
95
+ /android:resizeableActivity="[^"]*"/,
96
+ `android:resizeableActivity="${RESIZEABLE_ACTIVITY}"`
97
+ );
98
+ } else {
99
+ // Add resizeableActivity attribute
100
+ updated = updated.replace(`<activity`, `<activity android:resizeableActivity="${RESIZEABLE_ACTIVITY}"`);
101
+ }
102
+
103
+
104
+ //const admobConfig = getAdMobConfig();
105
+
106
+
107
+
108
+
109
+
110
+
111
+ const orientation = config.android?.ORIENTATION;
112
+
113
+
114
+
115
+ if (!orientation) {
116
+ console.error('❌ Missing android.orientation option in capacitor.config.json.');
117
+ process.exit(1);
118
+ }
119
+
120
+ if(orientation!="portrait" && orientation!="landscape" && orientation!="auto")
121
+ {
122
+ console.error('❌ Spelling mistake in android.orientation option in capacitor.config.json. Please use only ["portrait" "landscape" "auto"]');
123
+ process.exit(1);
124
+ }
125
+
126
+
127
+ if(orientation=="portrait"){
128
+ // If android:screenOrientation is already present, update it
129
+ if (updated.includes('android:screenOrientation=')) {
130
+ updated = updated.replace(
131
+ /android:screenOrientation="[^"]*"/,
132
+ 'android:screenOrientation="portrait"'
133
+ );
134
+ } else {
135
+ updated = updated.replace(
136
+ '<activity',
137
+ '<activity android:screenOrientation="portrait"'
138
+ );
139
+ }
140
+ }
141
+
142
+
143
+
144
+ if(orientation=="landscape"){
145
+ // If android:screenOrientation is already present, update it
146
+ if (updated.includes('android:screenOrientation=')) {
147
+ updated = updated.replace(
148
+ /android:screenOrientation="[^"]*"/,
149
+ 'android:screenOrientation="landscape"'
150
+ );
151
+ } else {
152
+ updated = updated.replace(
153
+ '<activity',
154
+ '<activity android:screenOrientation="landscape"'
155
+ );
156
+ }
157
+ }
158
+
159
+
160
+ if (orientation === "auto") {
161
+ // Remove android:screenOrientation attribute if present
162
+ updated = updated.replace(/\s*android:screenOrientation="[^"]*"/, '');
163
+ }
164
+
165
+
166
+
167
+ return updated;
168
+ }
169
+ );
170
+
171
+ fs.writeFileSync(androidManifestPath, manifestContent, "utf-8");
172
+ console.log(`Updated AndroidManifest.xml: ensured resizeableActivity="false" and updated theme if present.`);
173
+ }
174
+
175
+ // Perform the tasks
176
+ try {
177
+ console.log("Starting splash screen setup...");
178
+ copyFile(sourceSplashIcon, destinationSplashIcon);
179
+ copyFile(sourceSplashXML, destinationSplashXML);
180
+ updateAndroidManifest();
181
+ console.log("Splash screen setup completed.");
182
+ } catch (error) {
183
+ console.error(`Error: ${error.message}`);
184
+ process.exit(1);
185
+ }
186
+
187
+
188
+
@@ -3,6 +3,11 @@ const path = require('path');
3
3
  const plist = require('plist');
4
4
 
5
5
 
6
+
7
+
8
+
9
+ const configPath = path.join(process.cwd(), 'capacitor.config.json');
10
+
6
11
  // Expected plugin list with minimum versions
7
12
  const requiredPlugins = [
8
13
  { pattern: /backbutton-(\d+\.\d+)\.js$/, minVersion: '1.4', required: true },
@@ -147,12 +152,24 @@ const os = require('os');
147
152
 
148
153
  const saveToGalleryAndSaveFileCheck_iOS = () => {
149
154
  const ROOT_DIR = path.resolve(__dirname, '../src');
155
+ const ANDROID_MANIFEST_PATH = path.resolve(__dirname, '../android/app/src/main/AndroidManifest.xml');
156
+
157
+
158
+ // Match iOS-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5-ios.js) not in comments
159
+ const IOS_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*-ios\.js['"]/m;
160
+
161
+ // Match Android-specific imports (e.g., saveToGalleryAndSaveAnyFile-2.5.js) not in comments
162
+ const ANDROID_FILE_REGEX = /^(?!\s*\/\/).*['"](?:.*\/)?saveToGalleryAndSaveAnyFile-\d+(\.\d+)*\.js['"]/m;
163
+
164
+
165
+
166
+
150
167
 
151
- const IOS_FILE_REGEX = /(?:import|require)?\s*\(?['"].*saveToGalleryAndSaveAnyFile-\d+(\.\d+)?-ios\.js['"]\)?/;
152
168
  const ALLOWED_EXTENSIONS = ['.js', '.f7'];
153
169
  const isMac = os.platform() === 'darwin';
154
170
 
155
171
  let iosImportFound = false;
172
+ let androidImportFound = false;
156
173
 
157
174
  function scanDirectory(dir) {
158
175
  const entries = fs.readdirSync(dir, { withFileTypes: true });
@@ -163,27 +180,28 @@ const saveToGalleryAndSaveFileCheck_iOS = () => {
163
180
  if (entry.isDirectory()) {
164
181
  if (entry.name === 'node_modules') continue;
165
182
  scanDirectory(fullPath);
166
- } else if (
167
- entry.isFile() &&
168
- ALLOWED_EXTENSIONS.some(ext => fullPath.endsWith(ext))
169
- ) {
183
+ } else if (entry.isFile() && ALLOWED_EXTENSIONS.some(ext => fullPath.endsWith(ext))) {
170
184
  const content = fs.readFileSync(fullPath, 'utf8');
171
- const matches = content.match(IOS_FILE_REGEX);
172
- if (matches) {
185
+
186
+ // Detect iOS version file imports
187
+ if (IOS_FILE_REGEX.test(content)) {
173
188
  iosImportFound = true;
174
- //console.error(`\n❌❌❌ BIG ERROR: iOS-specific import detected in: ${fullPath}`);
175
- //console.error(`🔍 Matched: ${matches[0]}\n`);
176
189
  if (!isMac) {
177
- console.error(`\n❌❌❌ BIG ERROR: iOS-specific import detected in: ${fullPath}`);
190
+ console.error(`\n ERROR: iOS-specific import detected in: ${fullPath}`);
178
191
  console.error(`🚫 STOPPED: This file should not be imported in Android/Windows/Linux builds.\n`);
179
192
  process.exit(1);
180
193
  }
181
194
  }
195
+
196
+ // Detect Android version file imports (but ignore iOS ones)
197
+ else if (ANDROID_FILE_REGEX.test(content) && !content.includes('-ios.js')) {
198
+ androidImportFound = true;
199
+ }
182
200
  }
183
201
  }
184
202
  }
185
203
 
186
- // Check if src folder exists first
204
+ // Check src folder
187
205
  if (!fs.existsSync(ROOT_DIR)) {
188
206
  console.warn(`⚠️ Warning: 'src' directory not found at: ${ROOT_DIR}`);
189
207
  return;
@@ -191,14 +209,45 @@ const saveToGalleryAndSaveFileCheck_iOS = () => {
191
209
 
192
210
  scanDirectory(ROOT_DIR);
193
211
 
212
+ // iOS Checks
194
213
  if (isMac && !iosImportFound) {
195
- console.warn(`\x1b[31m\n⚠️⚠️⚠️ WARNING: You're on macOS but no iOS-specific file (saveToGalleryAndSaveAnyFile-x.x-ios.js) was found.\x1b[0m`);
196
- console.warn(`👉 You may want to double-check your imports for the iOS platform.\n`);
214
+ console.warn(`⚠️ WARNING: You're on macOS but no iOS version (saveToGalleryAndSaveAnyFile-x.x-ios.js) found.`);
197
215
  process.exit(1);
198
216
  } else if (isMac && iosImportFound) {
199
- console.log('✅ iOS file detected as expected for macOS.');
217
+ console.log('✅ iOS version detected for macOS build.');
200
218
  } else if (!iosImportFound) {
201
- console.log('✅ No iOS-specific file imports detected for non-macOS.');
219
+ console.log('✅ No iOS-specific imports detected for non-macOS.');
220
+ }
221
+
222
+ // Android Checks
223
+ if (androidImportFound) {
224
+ console.log("📱 Android version of saveToGalleryAndSaveAnyFile detected. Checking AndroidManifest.xml...");
225
+
226
+ if (!fs.existsSync(ANDROID_MANIFEST_PATH)) {
227
+ console.error("❌ AndroidManifest.xml not found. Cannot add requestLegacyExternalStorage attribute.");
228
+ return;
229
+ }
230
+
231
+ let manifestContent = fs.readFileSync(ANDROID_MANIFEST_PATH, 'utf8');
232
+
233
+ if (!manifestContent.includes('android:requestLegacyExternalStorage="true"')) {
234
+ console.log("Adding android:requestLegacyExternalStorage=\"true\" to <application> tag...");
235
+
236
+ manifestContent = manifestContent.replace(
237
+ /<application([^>]*)>/,
238
+ (match, attrs) => {
239
+ if (attrs.includes('android:requestLegacyExternalStorage')) return match;
240
+ return `<application${attrs} android:requestLegacyExternalStorage="true">`;
241
+ }
242
+ );
243
+
244
+ fs.writeFileSync(ANDROID_MANIFEST_PATH, manifestContent, 'utf8');
245
+ console.log("✅ android:requestLegacyExternalStorage=\"true\" added successfully.");
246
+ } else {
247
+ console.log("ℹ️ android:requestLegacyExternalStorage already exists in AndroidManifest.xml.");
248
+ }
249
+ } else {
250
+ console.log("✅ No Android saveToGalleryAndSaveAnyFile imports detected.");
202
251
  }
203
252
  };
204
253
 
@@ -482,7 +531,9 @@ console.log('✅ Kotlin version updated in build.gradle.');
482
531
 
483
532
 
484
533
 
485
- const configPath = path.join(process.cwd(), 'capacitor.config.json');
534
+
535
+
536
+
486
537
  const androidPlatformPath = path.join(process.cwd(), 'android');
487
538
  const iosPlatformPath = path.join(process.cwd(), 'ios');
488
539
  const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
@@ -255,5 +255,4 @@ if(targetAppId=='apk.bulk.app.uninstaller' || targetAppId=='apk.extractor.instal
255
255
 
256
256
  // EXAMPLE USAGE
257
257
  addAndroidPermissions(permissions);
258
- }
259
-
258
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "1.8.6",
3
+ "version": "1.8.7",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",
@@ -1,113 +0,0 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- // Define file paths
5
- const projectFolder = path.resolve(".");
6
- const sourceSplashIcon = path.join(projectFolder, "resources", "splash_icon.png");
7
- const destinationSplashIcon = path.join(
8
- projectFolder,
9
- "android",
10
- "app",
11
- "src",
12
- "main",
13
- "res",
14
- "drawable-nodpi",
15
- "splash_icon.png"
16
- );
17
- const sourceSplashXML = path.join(projectFolder,"buildCodeplay", "splashxml", "codeplay_splashScreen.xml");
18
- const destinationSplashXML = path.join(
19
- projectFolder,
20
- "android",
21
- "app",
22
- "src",
23
- "main",
24
- "res",
25
- "values",
26
- "codeplay_splashScreen.xml"
27
- );
28
- const androidManifestPath = path.join(
29
- projectFolder,
30
- "android",
31
- "app",
32
- "src",
33
- "main",
34
- "AndroidManifest.xml"
35
- );
36
-
37
- // Helper function to copy files
38
- function copyFile(source, destination) {
39
- if (!fs.existsSync(source)) {
40
- throw new Error(`Source file not found: ${source}`);
41
- }
42
- fs.mkdirSync(path.dirname(destination), { recursive: true });
43
- fs.copyFileSync(source, destination);
44
- console.log(`Copied: ${source} -> ${destination}`);
45
- }
46
-
47
- // Helper function to update AndroidManifest.xml
48
- function updateAndroidManifest() {
49
- if (!fs.existsSync(androidManifestPath)) {
50
- throw new Error(`AndroidManifest.xml not found: ${androidManifestPath}`);
51
- }
52
-
53
- let manifestContent = fs.readFileSync(androidManifestPath, "utf-8");
54
-
55
- manifestContent = manifestContent.replace(
56
- /<activity[^>]*?>/,
57
- (match) => {
58
- let updated = match;
59
-
60
- // If android:theme is already present, update it
61
- if (updated.includes('android:theme=')) {
62
- updated = updated.replace(
63
- /android:theme="[^"]*"/,
64
- 'android:theme="@style/Theme.Codeplay.SplashScreen"'
65
- );
66
- }
67
-
68
- // If android:resizeableActivity is already present, update it
69
- if (updated.includes('android:resizeableActivity=')) {
70
- updated = updated.replace(
71
- /android:resizeableActivity="[^"]*"/,
72
- 'android:resizeableActivity="false"'
73
- );
74
- } else {
75
- // Add resizeableActivity attribute
76
- updated = updated.replace('<activity', '<activity android:resizeableActivity="false"');
77
- }
78
-
79
-
80
- // If android:screenOrientation is already present, update it
81
- if (updated.includes('android:screenOrientation=')) {
82
- updated = updated.replace(
83
- /android:screenOrientation="[^"]*"/,
84
- 'android:screenOrientation="portrait"'
85
- );
86
- } else {
87
- updated = updated.replace(
88
- '<activity',
89
- '<activity android:screenOrientation="portrait"'
90
- );
91
- }
92
-
93
-
94
-
95
- return updated;
96
- }
97
- );
98
-
99
- fs.writeFileSync(androidManifestPath, manifestContent, "utf-8");
100
- console.log(`Updated AndroidManifest.xml: ensured resizeableActivity="false" and updated theme if present.`);
101
- }
102
-
103
- // Perform the tasks
104
- try {
105
- console.log("Starting splash screen setup...");
106
- copyFile(sourceSplashIcon, destinationSplashIcon);
107
- copyFile(sourceSplashXML, destinationSplashXML);
108
- updateAndroidManifest();
109
- console.log("Splash screen setup completed.");
110
- } catch (error) {
111
- console.error(`Error: ${error.message}`);
112
- process.exit(1);
113
- }