codeplay-common 1.3.2 → 1.3.4

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,308 +1,312 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const plist = require('plist');
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
- //Check codeplay-common latest version installed or not Start
21
- const { execSync } = require('child_process');
22
-
23
- function getInstalledVersion(packageName) {
24
- try {
25
- const packageJsonPath = path.join(process.cwd(), 'node_modules', packageName, 'package.json');
26
- if (fs.existsSync(packageJsonPath)) {
27
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
28
- return packageJson.version;
29
- }
30
- } catch (error) {
31
- return null;
32
- }
33
- return null;
34
- }
35
-
36
- function getLatestVersion(packageName) {
37
- try {
38
- return execSync(`npm view ${packageName} version`).toString().trim();
39
- } catch (error) {
40
- console.error(`Failed to fetch latest version for ${packageName}`);
41
- return null;
42
- }
43
- }
44
-
45
- function checkPackageVersion() {
46
- const packageName = 'codeplay-common';
47
- const installedVersion = getInstalledVersion(packageName);
48
- const latestVersion = getLatestVersion(packageName);
49
-
50
- if (!installedVersion) {
51
- console.error(`${packageName} is not installed. Please install it using "npm install ${packageName}".`);
52
- process.exit(1);
53
- }
54
-
55
- if (installedVersion !== latestVersion) {
56
- console.error(`\x1b[31m${packageName} is outdated (installed: ${installedVersion}, latest: ${latestVersion}). Please update it.\x1b[0m\n\x1b[33mUse 'npm uninstall codeplay-common ; npm i codeplay-common'\x1b[0m`);
57
- process.exit(1);
58
- }
59
-
60
- console.log(`${packageName} is up to date (version ${installedVersion}).`);
61
- }
62
-
63
- // Run package version check before executing the main script
64
- try {
65
- checkPackageVersion();
66
- } catch (error) {
67
- console.error(error.message);
68
- process.exit(1);
69
- }
70
-
71
- //Check codeplay-common latest version installed or not End
72
-
73
-
74
-
75
-
76
- // Run package version check before executing the main script
77
- try {
78
- checkPackageVersion();
79
- } catch (error) {
80
- console.error(error.message);
81
- process.exit(1);
82
- }
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
- // Clean up AppleDouble files (._*) created by macOS START
92
- try {
93
- console.log('🧹 Cleaning up AppleDouble files (._*)...');
94
- execSync(`find . -name '._*' -delete`);
95
- console.log('✅ AppleDouble files removed.');
96
- } catch (err) {
97
- console.warn('⚠️ Failed to remove AppleDouble files:', err.message);
98
- }
99
-
100
- // Clean up AppleDouble files (._*) created by macOS END
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
- //In routes.js file check static import START
109
-
110
- const routesPath = path.join(process.cwd(), 'src', 'js', 'routes.js');
111
- const routesContent = fs.readFileSync(routesPath, 'utf-8');
112
-
113
- let inBlockComment = false;
114
- const lines = routesContent.split('\n');
115
-
116
- const allowedImport = `import HomePage from '../pages/home.f7';`;
117
- const badImportRegex = /^[ \t]*import\s+[\w{}*,\s]*\s+from\s+['"].+\.f7['"]\s*;/;
118
- const badImports = [];
119
-
120
- lines.forEach((line, index) => {
121
- const trimmed = line.trim();
122
-
123
- // Handle block comment start and end
124
- if (trimmed.startsWith('/*')) inBlockComment = true;
125
- if (inBlockComment && trimmed.endsWith('*/')) {
126
- inBlockComment = false;
127
- return;
128
- }
129
-
130
- // Skip if inside block comment or line comment
131
- if (inBlockComment || trimmed.startsWith('//')) return;
132
-
133
- // Match static .f7 import
134
- if (badImportRegex.test(trimmed) && trimmed !== allowedImport) {
135
- badImports.push({ line: trimmed, number: index + 1 });
136
- }
137
- });
138
-
139
- if (badImports.length > 0) {
140
- console.error('\n❌ ERROR: Detected disallowed static imports of .f7 files in routes.js\n');
141
- console.error(`⚠️ Only this static import is allowed:\n ${allowedImport}\n`);
142
- console.error(`🔧 Please convert other imports to async dynamic imports like this:\n`);
143
- console.error(`
144
-
145
- import HomePage from '../pages/home.f7';
146
-
147
- const routes = [
148
- {
149
- path: '/',
150
- component:HomePage,
151
- },
152
- {
153
- path: '/ProfilePage/',
154
- async async({ resolve }) {
155
- const page = await import('../pages/profile.f7');
156
- resolve({ component: page.default });
157
- },
158
- }]
159
- `);
160
-
161
- badImports.forEach(({ line, number }) => {
162
- console.error(`${number}: ${line}`);
163
- });
164
-
165
- process.exit(1);
166
- } else {
167
- console.log('✅ routes.js passed the .f7 import check.');
168
- }
169
-
170
- //In routes.js file check static import END
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
- const configPath = path.join(process.cwd(), 'capacitor.config.json');
190
- const androidPlatformPath = path.join(process.cwd(), 'android');
191
- const iosPlatformPath = path.join(process.cwd(), 'ios');
192
- const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
193
- const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
194
- const resourcesPath = path.join(process.cwd(), 'resources', 'res');
195
- const androidResPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'res');
196
- const localNotificationsPluginPath = path.join(process.cwd(), 'node_modules', '@capacitor', 'local-notifications');
197
-
198
- function fileExists(filePath) {
199
- return fs.existsSync(filePath);
200
- }
201
-
202
- function copyFolderSync(source, target) {
203
- if (!fs.existsSync(target)) {
204
- fs.mkdirSync(target, { recursive: true });
205
- }
206
-
207
- fs.readdirSync(source).forEach(file => {
208
- const sourceFile = path.join(source, file);
209
- const targetFile = path.join(target, file);
210
-
211
- if (fs.lstatSync(sourceFile).isDirectory()) {
212
- copyFolderSync(sourceFile, targetFile);
213
- } else {
214
- fs.copyFileSync(sourceFile, targetFile);
215
- }
216
- });
217
- }
218
-
219
- function checkAndCopyResources() {
220
- if (fileExists(resourcesPath)) {
221
- copyFolderSync(resourcesPath, androidResPath);
222
- console.log('Successfully copied resources/res to android/app/src/main/res.');
223
- } else {
224
- console.log('resources/res folder not found.');
225
-
226
- if (fileExists(localNotificationsPluginPath)) {
227
- throw new Error('resources/res is required for @capacitor/local-notifications. Stopping execution.');
228
- }
229
- }
230
- }
231
-
232
- function getAdMobConfig() {
233
- if (!fileExists(configPath)) {
234
- throw new Error('capacitor.config.json not found. Ensure this is a Capacitor project.');
235
- }
236
-
237
- const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
238
- const admobConfig = config.plugins?.AdMob;
239
-
240
- if (!admobConfig || !admobConfig.APP_ID_ANDROID || !admobConfig.APP_ID_IOS) {
241
- throw new Error('AdMob configuration is missing in capacitor.config.json. Ensure APP_ID_ANDROID and APP_ID_IOS are defined.');
242
- }
243
-
244
- return {
245
- APP_ID_ANDROID: admobConfig.APP_ID_ANDROID,
246
- APP_ID_IOS: admobConfig.APP_ID_IOS,
247
- USE_LITE_ADS: admobConfig.USE_LITE_ADS === "lite",
248
- };
249
- }
250
-
251
- function updatePluginXml(admobConfig) {
252
- if (!fileExists(pluginPath)) {
253
- console.error('plugin.xml not found. Ensure the plugin is installed.');
254
- return;
255
- }
256
-
257
- let pluginContent = fs.readFileSync(pluginPath, 'utf8');
258
-
259
- pluginContent = pluginContent
260
- .replace(/<preference name="APP_ID_ANDROID" default=".*?" \/>/, `<preference name="APP_ID_ANDROID" default="${admobConfig.APP_ID_ANDROID}" />`)
261
- .replace(/<preference name="APP_ID_IOS" default=".*?" \/>/, `<preference name="APP_ID_IOS" default="${admobConfig.APP_ID_IOS}" />`);
262
-
263
- fs.writeFileSync(pluginPath, pluginContent, 'utf8');
264
- console.log('AdMob IDs successfully updated in plugin.xml');
265
- }
266
-
267
- function updateInfoPlist(admobConfig) {
268
- if (!fileExists(infoPlistPath)) {
269
- console.error('Info.plist not found. Ensure you have built the iOS project.');
270
- return;
271
- }
272
-
273
- const plistContent = fs.readFileSync(infoPlistPath, 'utf8');
274
- const plistData = plist.parse(plistContent);
275
-
276
- plistData.GADApplicationIdentifier = admobConfig.APP_ID_IOS;
277
- plistData.NSUserTrackingUsageDescription = 'This identifier will be used to deliver personalized ads to you.';
278
- plistData.GADDelayAppMeasurementInit = true;
279
-
280
- const updatedPlistContent = plist.build(plistData);
281
- fs.writeFileSync(infoPlistPath, updatedPlistContent, 'utf8');
282
- console.log('AdMob IDs and additional configurations successfully updated in Info.plist');
283
- }
284
-
285
- try {
286
- if (!fileExists(configPath)) {
287
- throw new Error('capacitor.config.json not found. Skipping setup.');
288
- }
289
-
290
- if (!fileExists(androidPlatformPath) && !fileExists(iosPlatformPath)) {
291
- throw new Error('Neither Android nor iOS platforms are found. Ensure platforms are added to your Capacitor project.');
292
- }
293
-
294
- checkAndCopyResources();
295
-
296
- const admobConfig = getAdMobConfig();
297
-
298
- if (fileExists(androidPlatformPath)) {
299
- updatePluginXml(admobConfig);
300
- }
301
-
302
- if (fileExists(iosPlatformPath)) {
303
- updateInfoPlist(admobConfig);
304
- }
305
- } catch (error) {
306
- console.error(error.message);
307
- process.exit(1); // Stop execution if there's a critical error
308
- }
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const plist = require('plist');
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+ //Check codeplay-common latest version installed or not Start
21
+ const { execSync } = require('child_process');
22
+
23
+ function getInstalledVersion(packageName) {
24
+ try {
25
+ const packageJsonPath = path.join(process.cwd(), 'node_modules', packageName, 'package.json');
26
+ if (fs.existsSync(packageJsonPath)) {
27
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
28
+ return packageJson.version;
29
+ }
30
+ } catch (error) {
31
+ return null;
32
+ }
33
+ return null;
34
+ }
35
+
36
+ function getLatestVersion(packageName) {
37
+ try {
38
+ return execSync(`npm view ${packageName} version`).toString().trim();
39
+ } catch (error) {
40
+ console.error(`Failed to fetch latest version for ${packageName}`);
41
+ return null;
42
+ }
43
+ }
44
+
45
+ function checkPackageVersion() {
46
+ const packageName = 'codeplay-common';
47
+ const installedVersion = getInstalledVersion(packageName);
48
+ const latestVersion = getLatestVersion(packageName);
49
+
50
+ if (!installedVersion) {
51
+ console.error(`${packageName} is not installed. Please install it using "npm install ${packageName}".`);
52
+ process.exit(1);
53
+ }
54
+
55
+ if (installedVersion !== latestVersion) {
56
+ console.error(`\x1b[31m${packageName} is outdated (installed: ${installedVersion}, latest: ${latestVersion}). Please update it.\x1b[0m\n\x1b[33mUse 'npm uninstall codeplay-common ; npm i codeplay-common'\x1b[0m`);
57
+ process.exit(1);
58
+ }
59
+
60
+ console.log(`${packageName} is up to date (version ${installedVersion}).`);
61
+ }
62
+
63
+ // Run package version check before executing the main script
64
+ try {
65
+ checkPackageVersion();
66
+ } catch (error) {
67
+ console.error(error.message);
68
+ process.exit(1);
69
+ }
70
+
71
+ //Check codeplay-common latest version installed or not End
72
+
73
+
74
+
75
+
76
+ // Run package version check before executing the main script
77
+ try {
78
+ checkPackageVersion();
79
+ } catch (error) {
80
+ console.error(error.message);
81
+ process.exit(1);
82
+ }
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+ // Clean up AppleDouble files (._*) created by macOS START
92
+ if (process.platform === 'darwin') {
93
+ try {
94
+ console.log('🧹 Cleaning up AppleDouble files (._*)...');
95
+ execSync(`find . -name '._*' -delete`);
96
+ console.log('✅ AppleDouble files removed.');
97
+ } catch (err) {
98
+ console.warn('⚠️ Failed to remove AppleDouble files:', err.message);
99
+ }
100
+ } else {
101
+ console.log('ℹ️ Skipping AppleDouble cleanup — not a macOS machine.');
102
+ }
103
+
104
+ // Clean up AppleDouble files (._*) created by macOS END
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+ //In routes.js file check static import START
113
+
114
+ const routesPath = path.join(process.cwd(), 'src', 'js', 'routes.js');
115
+ const routesContent = fs.readFileSync(routesPath, 'utf-8');
116
+
117
+ let inBlockComment = false;
118
+ const lines = routesContent.split('\n');
119
+
120
+ const allowedImport = `import HomePage from '../pages/home.f7';`;
121
+ const badImportRegex = /^[ \t]*import\s+[\w{}*,\s]*\s+from\s+['"].+\.f7['"]\s*;/;
122
+ const badImports = [];
123
+
124
+ lines.forEach((line, index) => {
125
+ const trimmed = line.trim();
126
+
127
+ // Handle block comment start and end
128
+ if (trimmed.startsWith('/*')) inBlockComment = true;
129
+ if (inBlockComment && trimmed.endsWith('*/')) {
130
+ inBlockComment = false;
131
+ return;
132
+ }
133
+
134
+ // Skip if inside block comment or line comment
135
+ if (inBlockComment || trimmed.startsWith('//')) return;
136
+
137
+ // Match static .f7 import
138
+ if (badImportRegex.test(trimmed) && trimmed !== allowedImport) {
139
+ badImports.push({ line: trimmed, number: index + 1 });
140
+ }
141
+ });
142
+
143
+ if (badImports.length > 0) {
144
+ console.error('\n❌ ERROR: Detected disallowed static imports of .f7 files in routes.js\n');
145
+ console.error(`⚠️ Only this static import is allowed:\n ${allowedImport}\n`);
146
+ console.error(`🔧 Please convert other imports to async dynamic imports like this:\n`);
147
+ console.error(`
148
+
149
+ import HomePage from '../pages/home.f7';
150
+
151
+ const routes = [
152
+ {
153
+ path: '/',
154
+ component:HomePage,
155
+ },
156
+ {
157
+ path: '/ProfilePage/',
158
+ async async({ resolve }) {
159
+ const page = await import('../pages/profile.f7');
160
+ resolve({ component: page.default });
161
+ },
162
+ }]
163
+ `);
164
+
165
+ badImports.forEach(({ line, number }) => {
166
+ console.error(`${number}: ${line}`);
167
+ });
168
+
169
+ process.exit(1);
170
+ } else {
171
+ console.log('✅ routes.js passed the .f7 import check.');
172
+ }
173
+
174
+ //In routes.js file check static import END
175
+
176
+
177
+
178
+
179
+
180
+
181
+
182
+
183
+
184
+
185
+
186
+
187
+
188
+
189
+
190
+
191
+
192
+
193
+ const configPath = path.join(process.cwd(), 'capacitor.config.json');
194
+ const androidPlatformPath = path.join(process.cwd(), 'android');
195
+ const iosPlatformPath = path.join(process.cwd(), 'ios');
196
+ const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
197
+ const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
198
+ const resourcesPath = path.join(process.cwd(), 'resources', 'res');
199
+ const androidResPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'res');
200
+ const localNotificationsPluginPath = path.join(process.cwd(), 'node_modules', '@capacitor', 'local-notifications');
201
+
202
+ function fileExists(filePath) {
203
+ return fs.existsSync(filePath);
204
+ }
205
+
206
+ function copyFolderSync(source, target) {
207
+ if (!fs.existsSync(target)) {
208
+ fs.mkdirSync(target, { recursive: true });
209
+ }
210
+
211
+ fs.readdirSync(source).forEach(file => {
212
+ const sourceFile = path.join(source, file);
213
+ const targetFile = path.join(target, file);
214
+
215
+ if (fs.lstatSync(sourceFile).isDirectory()) {
216
+ copyFolderSync(sourceFile, targetFile);
217
+ } else {
218
+ fs.copyFileSync(sourceFile, targetFile);
219
+ }
220
+ });
221
+ }
222
+
223
+ function checkAndCopyResources() {
224
+ if (fileExists(resourcesPath)) {
225
+ copyFolderSync(resourcesPath, androidResPath);
226
+ console.log('Successfully copied resources/res to android/app/src/main/res.');
227
+ } else {
228
+ console.log('resources/res folder not found.');
229
+
230
+ if (fileExists(localNotificationsPluginPath)) {
231
+ throw new Error('resources/res is required for @capacitor/local-notifications. Stopping execution.');
232
+ }
233
+ }
234
+ }
235
+
236
+ function getAdMobConfig() {
237
+ if (!fileExists(configPath)) {
238
+ throw new Error('capacitor.config.json not found. Ensure this is a Capacitor project.');
239
+ }
240
+
241
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
242
+ const admobConfig = config.plugins?.AdMob;
243
+
244
+ if (!admobConfig || !admobConfig.APP_ID_ANDROID || !admobConfig.APP_ID_IOS) {
245
+ throw new Error('AdMob configuration is missing in capacitor.config.json. Ensure APP_ID_ANDROID and APP_ID_IOS are defined.');
246
+ }
247
+
248
+ return {
249
+ APP_ID_ANDROID: admobConfig.APP_ID_ANDROID,
250
+ APP_ID_IOS: admobConfig.APP_ID_IOS,
251
+ USE_LITE_ADS: admobConfig.USE_LITE_ADS === "lite",
252
+ };
253
+ }
254
+
255
+ function updatePluginXml(admobConfig) {
256
+ if (!fileExists(pluginPath)) {
257
+ console.error('plugin.xml not found. Ensure the plugin is installed.');
258
+ return;
259
+ }
260
+
261
+ let pluginContent = fs.readFileSync(pluginPath, 'utf8');
262
+
263
+ pluginContent = pluginContent
264
+ .replace(/<preference name="APP_ID_ANDROID" default=".*?" \/>/, `<preference name="APP_ID_ANDROID" default="${admobConfig.APP_ID_ANDROID}" />`)
265
+ .replace(/<preference name="APP_ID_IOS" default=".*?" \/>/, `<preference name="APP_ID_IOS" default="${admobConfig.APP_ID_IOS}" />`);
266
+
267
+ fs.writeFileSync(pluginPath, pluginContent, 'utf8');
268
+ console.log('AdMob IDs successfully updated in plugin.xml');
269
+ }
270
+
271
+ function updateInfoPlist(admobConfig) {
272
+ if (!fileExists(infoPlistPath)) {
273
+ console.error('Info.plist not found. Ensure you have built the iOS project.');
274
+ return;
275
+ }
276
+
277
+ const plistContent = fs.readFileSync(infoPlistPath, 'utf8');
278
+ const plistData = plist.parse(plistContent);
279
+
280
+ plistData.GADApplicationIdentifier = admobConfig.APP_ID_IOS;
281
+ plistData.NSUserTrackingUsageDescription = 'This identifier will be used to deliver personalized ads to you.';
282
+ plistData.GADDelayAppMeasurementInit = true;
283
+
284
+ const updatedPlistContent = plist.build(plistData);
285
+ fs.writeFileSync(infoPlistPath, updatedPlistContent, 'utf8');
286
+ console.log('AdMob IDs and additional configurations successfully updated in Info.plist');
287
+ }
288
+
289
+ try {
290
+ if (!fileExists(configPath)) {
291
+ throw new Error('capacitor.config.json not found. Skipping setup.');
292
+ }
293
+
294
+ if (!fileExists(androidPlatformPath) && !fileExists(iosPlatformPath)) {
295
+ throw new Error('Neither Android nor iOS platforms are found. Ensure platforms are added to your Capacitor project.');
296
+ }
297
+
298
+ checkAndCopyResources();
299
+
300
+ const admobConfig = getAdMobConfig();
301
+
302
+ if (fileExists(androidPlatformPath)) {
303
+ updatePluginXml(admobConfig);
304
+ }
305
+
306
+ if (fileExists(iosPlatformPath)) {
307
+ updateInfoPlist(admobConfig);
308
+ }
309
+ } catch (error) {
310
+ console.error(error.message);
311
+ process.exit(1); // Stop execution if there's a critical error
312
+ }