codeplay-common 1.8.7 → 1.8.9

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,188 +1,187 @@
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
-
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
+ let logErrorMessage="";
61
+
62
+ const RESIZEABLE_ACTIVITY = config.android?.RESIZEABLE_ACTIVITY;
63
+ const orientation = config.android?.ORIENTATION;
64
+
65
+ // 1️⃣ Check if it’s missing
66
+ if (RESIZEABLE_ACTIVITY === undefined) {
67
+ logErrorMessage+='❌ Missing android.RESIZEABLE_ACTIVITY option in capacitor.config.json.\n';
68
+ }
69
+
70
+ // 2️⃣ Check if it’s not boolean (true/false only)
71
+ else if (typeof RESIZEABLE_ACTIVITY !== 'boolean') {
72
+ logErrorMessage+='❌ Invalid android.RESIZEABLE_ACTIVITY value. Please use only true or false (without quotes).\n';
73
+ }
74
+
75
+
76
+
77
+ if (!orientation) {
78
+ logErrorMessage+='❌ Missing android.ORIENTATION option in capacitor.config.json.\n';
79
+ }
80
+
81
+ else if(orientation!="portrait" && orientation!="landscape" && orientation!="auto")
82
+ {
83
+ logErrorMessage+='❌ Spelling mistake in android.ORIENTATION option in capacitor.config.json. Please use only ["portrait" "landscape" "auto"]\n';
84
+ }
85
+
86
+ if(logErrorMessage!="")
87
+ {
88
+ console.error(logErrorMessage);
89
+ process.exit(1)
90
+ }
91
+
92
+
93
+ let manifestContent = fs.readFileSync(androidManifestPath, "utf-8");
94
+
95
+ manifestContent = manifestContent.replace(
96
+ /<activity[^>]*?>/,
97
+ (match) => {
98
+ let updated = match;
99
+
100
+ // If android:theme is already present, update it
101
+ if (updated.includes('android:theme=')) {
102
+ updated = updated.replace(
103
+ /android:theme="[^"]*"/,
104
+ 'android:theme="@style/Theme.Codeplay.SplashScreen"'
105
+ );
106
+ }
107
+
108
+ // If android:resizeableActivity is already present, update it
109
+ if (updated.includes('android:resizeableActivity=')) {
110
+ updated = updated.replace(
111
+ /android:resizeableActivity="[^"]*"/,
112
+ `android:resizeableActivity="${RESIZEABLE_ACTIVITY}"`
113
+ );
114
+ } else {
115
+ // Add resizeableActivity attribute
116
+ updated = updated.replace(`<activity`, `<activity android:resizeableActivity="${RESIZEABLE_ACTIVITY}"`);
117
+ }
118
+
119
+
120
+ //const admobConfig = getAdMobConfig();
121
+
122
+
123
+
124
+
125
+
126
+ if(orientation=="portrait"){
127
+ // If android:screenOrientation is already present, update it
128
+ if (updated.includes('android:screenOrientation=')) {
129
+ updated = updated.replace(
130
+ /android:screenOrientation="[^"]*"/,
131
+ 'android:screenOrientation="portrait"'
132
+ );
133
+ } else {
134
+ updated = updated.replace(
135
+ '<activity',
136
+ '<activity android:screenOrientation="portrait"'
137
+ );
138
+ }
139
+ }
140
+
141
+
142
+
143
+ if(orientation=="landscape"){
144
+ // If android:screenOrientation is already present, update it
145
+ if (updated.includes('android:screenOrientation=')) {
146
+ updated = updated.replace(
147
+ /android:screenOrientation="[^"]*"/,
148
+ 'android:screenOrientation="landscape"'
149
+ );
150
+ } else {
151
+ updated = updated.replace(
152
+ '<activity',
153
+ '<activity android:screenOrientation="landscape"'
154
+ );
155
+ }
156
+ }
157
+
158
+
159
+ if (orientation === "auto") {
160
+ // Remove android:screenOrientation attribute if present
161
+ updated = updated.replace(/\s*android:screenOrientation="[^"]*"/, '');
162
+ }
163
+
164
+
165
+
166
+ return updated;
167
+ }
168
+ );
169
+
170
+ fs.writeFileSync(androidManifestPath, manifestContent, "utf-8");
171
+ console.log(`Updated AndroidManifest.xml: ensured resizeableActivity="false" and updated theme if present.`);
172
+ }
173
+
174
+ // Perform the tasks
175
+ try {
176
+ console.log("Starting splash screen setup...");
177
+ copyFile(sourceSplashIcon, destinationSplashIcon);
178
+ copyFile(sourceSplashXML, destinationSplashXML);
179
+ updateAndroidManifest();
180
+ console.log("Splash screen setup completed.");
181
+ } catch (error) {
182
+ console.error(`Error: ${error.message}`);
183
+ process.exit(1);
184
+ }
185
+
186
+
187
+