codeplay-common 3.0.6 → 3.0.8

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.
@@ -1,248 +1,248 @@
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
-
21
-
22
-
23
-
24
-
25
- const sourceSplashXML = path.join(projectFolder,"buildCodeplay", "splashxml", "codeplay_splashScreen.xml");
26
- const destinationSplashXML = path.join(
27
- projectFolder,
28
- "android",
29
- "app",
30
- "src",
31
- "main",
32
- "res",
33
- "values",
34
- "codeplay_splashScreen.xml"
35
- );
36
- const androidManifestPath = path.join(
37
- projectFolder,
38
- "android",
39
- "app",
40
- "src",
41
- "main",
42
- "AndroidManifest.xml"
43
- );
44
-
45
- // Helper function to copy files
46
- function copyFile(source, destination) {
47
- if (!fs.existsSync(source)) {
48
- throw new Error(`Source file not found: ${source}`);
49
- }
50
- fs.mkdirSync(path.dirname(destination), { recursive: true });
51
- fs.copyFileSync(source, destination);
52
- console.log(`Copied: ${source} -> ${destination}`);
53
- }
54
-
55
- // Helper function to update AndroidManifest.xml
56
- function updateAndroidManifest() {
57
- if (!fs.existsSync(androidManifestPath)) {
58
- throw new Error(`AndroidManifest.xml not found: ${androidManifestPath}`);
59
- }
60
-
61
-
62
-
63
-
64
-
65
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
66
-
67
-
68
- let logErrorMessage="";
69
-
70
- const RESIZEABLE_ACTIVITY = config.android?.RESIZEABLE_ACTIVITY;
71
- const orientation = config.android?.ORIENTATION;
72
-
73
- // 1️⃣ Check if it’s missing
74
- if (RESIZEABLE_ACTIVITY === undefined) {
75
- logErrorMessage+='❌ Missing android.RESIZEABLE_ACTIVITY option in capacitor.config.json.\n';
76
- }
77
-
78
- // 2️⃣ Check if it’s not boolean (true/false only)
79
- else if (typeof RESIZEABLE_ACTIVITY !== 'boolean') {
80
- logErrorMessage+='❌ Invalid android.RESIZEABLE_ACTIVITY value. Please use only true or false (without quotes).\n';
81
- }
82
-
83
-
84
-
85
- if (!orientation) {
86
- logErrorMessage+='❌ Missing android.ORIENTATION option in capacitor.config.json.\n';
87
- }
88
-
89
- else if(orientation!="portrait" && orientation!="landscape" && orientation!="auto")
90
- {
91
- logErrorMessage+='❌ Spelling mistake in android.ORIENTATION option in capacitor.config.json. Please use only ["portrait" "landscape" "auto"]\n';
92
- }
93
-
94
- if(logErrorMessage!="")
95
- {
96
- console.error(logErrorMessage);
97
- process.exit(1)
98
- }
99
-
100
-
101
- let manifestContent = fs.readFileSync(androidManifestPath, "utf-8");
102
-
103
- manifestContent = manifestContent.replace(
104
- /<activity[^>]*?>/,
105
- (match) => {
106
- let updated = match;
107
-
108
- // If android:theme is already present, update it
109
- if (updated.includes('android:theme=')) {
110
- updated = updated.replace(
111
- /android:theme="[^"]*"/,
112
- 'android:theme="@style/Theme.Codeplay.SplashScreen"'
113
- );
114
- }
115
-
116
- // If android:resizeableActivity is already present, update it
117
- if (updated.includes('android:resizeableActivity=')) {
118
- updated = updated.replace(
119
- /android:resizeableActivity="[^"]*"/,
120
- `android:resizeableActivity="${RESIZEABLE_ACTIVITY}"`
121
- );
122
- } else {
123
- // Add resizeableActivity attribute
124
- updated = updated.replace(`<activity`, `<activity android:resizeableActivity="${RESIZEABLE_ACTIVITY}"`);
125
- }
126
-
127
-
128
- //const admobConfig = getAdMobConfig();
129
-
130
-
131
-
132
-
133
-
134
- if(orientation=="portrait"){
135
- // If android:screenOrientation is already present, update it
136
- if (updated.includes('android:screenOrientation=')) {
137
- updated = updated.replace(
138
- /android:screenOrientation="[^"]*"/,
139
- 'android:screenOrientation="portrait"'
140
- );
141
- } else {
142
- updated = updated.replace(
143
- '<activity',
144
- '<activity android:screenOrientation="portrait"'
145
- );
146
- }
147
- }
148
-
149
-
150
-
151
- if(orientation=="landscape"){
152
- // If android:screenOrientation is already present, update it
153
- if (updated.includes('android:screenOrientation=')) {
154
- updated = updated.replace(
155
- /android:screenOrientation="[^"]*"/,
156
- 'android:screenOrientation="landscape"'
157
- );
158
- } else {
159
- updated = updated.replace(
160
- '<activity',
161
- '<activity android:screenOrientation="landscape"'
162
- );
163
- }
164
- }
165
-
166
-
167
- if (orientation === "auto") {
168
- // Remove android:screenOrientation attribute if present
169
- updated = updated.replace(/\s*android:screenOrientation="[^"]*"/, '');
170
- }
171
-
172
-
173
-
174
- return updated;
175
- }
176
- );
177
-
178
- fs.writeFileSync(androidManifestPath, manifestContent, "utf-8");
179
- console.log(`Updated AndroidManifest.xml: ensured resizeableActivity="false" and updated theme if present.`);
180
- }
181
-
182
-
183
- function removeOldSplashImages() {
184
- const drawableFolders = [
185
- "drawable",
186
- "drawable-land-hdpi",
187
- "drawable-land-mdpi",
188
- "drawable-land-xhdpi",
189
- "drawable-land-xxhdpi",
190
- "drawable-land-xxxhdpi",
191
- "drawable-port-hdpi",
192
- "drawable-port-mdpi",
193
- "drawable-port-xhdpi",
194
- "drawable-port-xxhdpi",
195
- "drawable-port-xxxhdpi"
196
- ];
197
-
198
- drawableFolders.forEach((folder) => {
199
- const filePath = path.join(projectFolder, "android", "app", "src", "main", "res", folder, "splash.png");
200
- if (fs.existsSync(filePath)) {
201
- fs.unlinkSync(filePath);
202
- console.log(`Removed: ${filePath}`);
203
- } else {
204
- console.log(`Not found (skipped): ${filePath}`);
205
- }
206
- });
207
- }
208
-
209
- function removeOldSplashStyle() {
210
- const stylesPath = path.join(projectFolder, "android", "app", "src", "main", "res", "values", "styles.xml");
211
-
212
- if (!fs.existsSync(stylesPath)) {
213
- console.log(`styles.xml not found: ${stylesPath}`);
214
- return;
215
- }
216
-
217
- let content = fs.readFileSync(stylesPath, "utf-8");
218
-
219
- // Remove the <style name="AppTheme.NoActionBarLaunch">...</style> block
220
- const regex = /<style\s+name="AppTheme\.NoActionBarLaunch"[\s\S]*?<\/style>/g;
221
- if (regex.test(content)) {
222
- content = content.replace(regex, "");
223
- fs.writeFileSync(stylesPath, content, "utf-8");
224
- console.log("Removed AppTheme.NoActionBarLaunch from styles.xml");
225
- } else {
226
- console.log("AppTheme.NoActionBarLaunch style not found, skipped");
227
- }
228
- }
229
-
230
- // Perform the tasks
231
- try {
232
- console.log("Starting splash screen setup...");
233
- copyFile(sourceSplashIcon, destinationSplashIcon);
234
- copyFile(sourceSplashXML, destinationSplashXML);
235
- updateAndroidManifest();
236
- console.log("Splash screen setup completed.");
237
-
238
- console.log("Removing default splash.png files...");
239
- removeOldSplashImages()
240
- removeOldSplashStyle()
241
-
242
- } catch (error) {
243
- console.error(`Error: ${error.message}`);
244
- process.exit(1);
245
- }
246
-
247
-
248
-
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
+
21
+
22
+
23
+
24
+
25
+ const sourceSplashXML = path.join(projectFolder,"buildCodeplay", "splashxml", "codeplay_splashScreen.xml");
26
+ const destinationSplashXML = path.join(
27
+ projectFolder,
28
+ "android",
29
+ "app",
30
+ "src",
31
+ "main",
32
+ "res",
33
+ "values",
34
+ "codeplay_splashScreen.xml"
35
+ );
36
+ const androidManifestPath = path.join(
37
+ projectFolder,
38
+ "android",
39
+ "app",
40
+ "src",
41
+ "main",
42
+ "AndroidManifest.xml"
43
+ );
44
+
45
+ // Helper function to copy files
46
+ function copyFile(source, destination) {
47
+ if (!fs.existsSync(source)) {
48
+ throw new Error(`Source file not found: ${source}`);
49
+ }
50
+ fs.mkdirSync(path.dirname(destination), { recursive: true });
51
+ fs.copyFileSync(source, destination);
52
+ console.log(`Copied: ${source} -> ${destination}`);
53
+ }
54
+
55
+ // Helper function to update AndroidManifest.xml
56
+ function updateAndroidManifest() {
57
+ if (!fs.existsSync(androidManifestPath)) {
58
+ throw new Error(`AndroidManifest.xml not found: ${androidManifestPath}`);
59
+ }
60
+
61
+
62
+
63
+
64
+
65
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
66
+
67
+
68
+ let logErrorMessage="";
69
+
70
+ const RESIZEABLE_ACTIVITY = config.android?.RESIZEABLE_ACTIVITY;
71
+ const orientation = config.android?.ORIENTATION;
72
+
73
+ // 1️⃣ Check if it’s missing
74
+ if (RESIZEABLE_ACTIVITY === undefined) {
75
+ logErrorMessage+='❌ Missing android.RESIZEABLE_ACTIVITY option in capacitor.config.json.\n';
76
+ }
77
+
78
+ // 2️⃣ Check if it’s not boolean (true/false only)
79
+ else if (typeof RESIZEABLE_ACTIVITY !== 'boolean') {
80
+ logErrorMessage+='❌ Invalid android.RESIZEABLE_ACTIVITY value. Please use only true or false (without quotes).\n';
81
+ }
82
+
83
+
84
+
85
+ if (!orientation) {
86
+ logErrorMessage+='❌ Missing android.ORIENTATION option in capacitor.config.json.\n';
87
+ }
88
+
89
+ else if(orientation!="portrait" && orientation!="landscape" && orientation!="auto")
90
+ {
91
+ logErrorMessage+='❌ Spelling mistake in android.ORIENTATION option in capacitor.config.json. Please use only ["portrait" "landscape" "auto"]\n';
92
+ }
93
+
94
+ if(logErrorMessage!="")
95
+ {
96
+ console.error(logErrorMessage);
97
+ process.exit(1)
98
+ }
99
+
100
+
101
+ let manifestContent = fs.readFileSync(androidManifestPath, "utf-8");
102
+
103
+ manifestContent = manifestContent.replace(
104
+ /<activity[^>]*?>/,
105
+ (match) => {
106
+ let updated = match;
107
+
108
+ // If android:theme is already present, update it
109
+ if (updated.includes('android:theme=')) {
110
+ updated = updated.replace(
111
+ /android:theme="[^"]*"/,
112
+ 'android:theme="@style/Theme.Codeplay.SplashScreen"'
113
+ );
114
+ }
115
+
116
+ // If android:resizeableActivity is already present, update it
117
+ if (updated.includes('android:resizeableActivity=')) {
118
+ updated = updated.replace(
119
+ /android:resizeableActivity="[^"]*"/,
120
+ `android:resizeableActivity="${RESIZEABLE_ACTIVITY}"`
121
+ );
122
+ } else {
123
+ // Add resizeableActivity attribute
124
+ updated = updated.replace(`<activity`, `<activity android:resizeableActivity="${RESIZEABLE_ACTIVITY}"`);
125
+ }
126
+
127
+
128
+ //const admobConfig = getAdMobConfig();
129
+
130
+
131
+
132
+
133
+
134
+ if(orientation=="portrait"){
135
+ // If android:screenOrientation is already present, update it
136
+ if (updated.includes('android:screenOrientation=')) {
137
+ updated = updated.replace(
138
+ /android:screenOrientation="[^"]*"/,
139
+ 'android:screenOrientation="portrait"'
140
+ );
141
+ } else {
142
+ updated = updated.replace(
143
+ '<activity',
144
+ '<activity android:screenOrientation="portrait"'
145
+ );
146
+ }
147
+ }
148
+
149
+
150
+
151
+ if(orientation=="landscape"){
152
+ // If android:screenOrientation is already present, update it
153
+ if (updated.includes('android:screenOrientation=')) {
154
+ updated = updated.replace(
155
+ /android:screenOrientation="[^"]*"/,
156
+ 'android:screenOrientation="landscape"'
157
+ );
158
+ } else {
159
+ updated = updated.replace(
160
+ '<activity',
161
+ '<activity android:screenOrientation="landscape"'
162
+ );
163
+ }
164
+ }
165
+
166
+
167
+ if (orientation === "auto") {
168
+ // Remove android:screenOrientation attribute if present
169
+ updated = updated.replace(/\s*android:screenOrientation="[^"]*"/, '');
170
+ }
171
+
172
+
173
+
174
+ return updated;
175
+ }
176
+ );
177
+
178
+ fs.writeFileSync(androidManifestPath, manifestContent, "utf-8");
179
+ console.log(`Updated AndroidManifest.xml: ensured resizeableActivity="false" and updated theme if present.`);
180
+ }
181
+
182
+
183
+ function removeOldSplashImages() {
184
+ const drawableFolders = [
185
+ "drawable",
186
+ "drawable-land-hdpi",
187
+ "drawable-land-mdpi",
188
+ "drawable-land-xhdpi",
189
+ "drawable-land-xxhdpi",
190
+ "drawable-land-xxxhdpi",
191
+ "drawable-port-hdpi",
192
+ "drawable-port-mdpi",
193
+ "drawable-port-xhdpi",
194
+ "drawable-port-xxhdpi",
195
+ "drawable-port-xxxhdpi"
196
+ ];
197
+
198
+ drawableFolders.forEach((folder) => {
199
+ const filePath = path.join(projectFolder, "android", "app", "src", "main", "res", folder, "splash.png");
200
+ if (fs.existsSync(filePath)) {
201
+ fs.unlinkSync(filePath);
202
+ console.log(`Removed: ${filePath}`);
203
+ } else {
204
+ console.log(`Not found (skipped): ${filePath}`);
205
+ }
206
+ });
207
+ }
208
+
209
+ function removeOldSplashStyle() {
210
+ const stylesPath = path.join(projectFolder, "android", "app", "src", "main", "res", "values", "styles.xml");
211
+
212
+ if (!fs.existsSync(stylesPath)) {
213
+ console.log(`styles.xml not found: ${stylesPath}`);
214
+ return;
215
+ }
216
+
217
+ let content = fs.readFileSync(stylesPath, "utf-8");
218
+
219
+ // Remove the <style name="AppTheme.NoActionBarLaunch">...</style> block
220
+ const regex = /<style\s+name="AppTheme\.NoActionBarLaunch"[\s\S]*?<\/style>/g;
221
+ if (regex.test(content)) {
222
+ content = content.replace(regex, "");
223
+ fs.writeFileSync(stylesPath, content, "utf-8");
224
+ console.log("Removed AppTheme.NoActionBarLaunch from styles.xml");
225
+ } else {
226
+ console.log("AppTheme.NoActionBarLaunch style not found, skipped");
227
+ }
228
+ }
229
+
230
+ // Perform the tasks
231
+ try {
232
+ console.log("Starting splash screen setup...");
233
+ copyFile(sourceSplashIcon, destinationSplashIcon);
234
+ copyFile(sourceSplashXML, destinationSplashXML);
235
+ updateAndroidManifest();
236
+ console.log("Splash screen setup completed.");
237
+
238
+ console.log("Removing default splash.png files...");
239
+ removeOldSplashImages()
240
+ removeOldSplashStyle()
241
+
242
+ } catch (error) {
243
+ console.error(`Error: ${error.message}`);
244
+ process.exit(1);
245
+ }
246
+
247
+
248
+