codeplay-common 1.2.0 → 1.2.2

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.
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Merbin Joe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # codeplay-common
2
+ Everything automatted in Capacitor apps, easy to maintain many apps in capacitor. It will reduce your 40% of work, with common file code.
3
+
4
+
5
+ Easy add splashscreen and set animation
6
+ Admob id automatically from capacitor.config.json file
7
+ Make three build file for different store as per our requirement
8
+ Based on store install various IAP plugins
9
+ Make it to ionic project
10
+
11
+ Donate to get full code including many common functions
12
+ https://ko-fi.com/codeplay
@@ -7,11 +7,44 @@ const androidPlatformPath = path.join(process.cwd(), 'android');
7
7
  const iosPlatformPath = path.join(process.cwd(), 'ios');
8
8
  const pluginPath = path.join(process.cwd(), 'node_modules', 'emi-indo-cordova-plugin-admob', 'plugin.xml');
9
9
  const infoPlistPath = path.join(process.cwd(), 'ios', 'App', 'App', 'Info.plist');
10
+ const resourcesPath = path.join(process.cwd(), 'resources', 'res');
11
+ const androidResPath = path.join(process.cwd(), 'android', 'app', 'src', 'main', 'res');
12
+ const localNotificationsPluginPath = path.join(process.cwd(), 'node_modules', '@capacitor', 'local-notifications');
10
13
 
11
14
  function fileExists(filePath) {
12
15
  return fs.existsSync(filePath);
13
16
  }
14
17
 
18
+ function copyFolderSync(source, target) {
19
+ if (!fs.existsSync(target)) {
20
+ fs.mkdirSync(target, { recursive: true });
21
+ }
22
+
23
+ fs.readdirSync(source).forEach(file => {
24
+ const sourceFile = path.join(source, file);
25
+ const targetFile = path.join(target, file);
26
+
27
+ if (fs.lstatSync(sourceFile).isDirectory()) {
28
+ copyFolderSync(sourceFile, targetFile);
29
+ } else {
30
+ fs.copyFileSync(sourceFile, targetFile);
31
+ }
32
+ });
33
+ }
34
+
35
+ function checkAndCopyResources() {
36
+ if (fileExists(resourcesPath)) {
37
+ copyFolderSync(resourcesPath, androidResPath);
38
+ console.log('Successfully copied resources/res to android/app/src/main/res.');
39
+ } else {
40
+ console.log('resources/res folder not found.');
41
+
42
+ if (fileExists(localNotificationsPluginPath)) {
43
+ throw new Error('resources/res is required for @capacitor/local-notifications. Stopping execution.');
44
+ }
45
+ }
46
+ }
47
+
15
48
  function getAdMobConfig() {
16
49
  if (!fileExists(configPath)) {
17
50
  throw new Error('capacitor.config.json not found. Ensure this is a Capacitor project.');
@@ -43,7 +76,6 @@ function updatePluginXml(admobConfig) {
43
76
  .replace(/<preference name="APP_ID_ANDROID" default=".*?" \/>/, `<preference name="APP_ID_ANDROID" default="${admobConfig.APP_ID_ANDROID}" />`)
44
77
  .replace(/<preference name="APP_ID_IOS" default=".*?" \/>/, `<preference name="APP_ID_IOS" default="${admobConfig.APP_ID_IOS}" />`);
45
78
 
46
-
47
79
  fs.writeFileSync(pluginPath, pluginContent, 'utf8');
48
80
  console.log('AdMob IDs successfully updated in plugin.xml');
49
81
  }
@@ -61,52 +93,6 @@ function updateInfoPlist(admobConfig) {
61
93
  plistData.NSUserTrackingUsageDescription = 'This identifier will be used to deliver personalized ads to you.';
62
94
  plistData.GADDelayAppMeasurementInit = true;
63
95
 
64
- // https://developers.google.com/admob/ios/quick-start
65
- plistData.SKAdNetworkItems = [
66
- { SKAdNetworkIdentifier: 'cstr6suwn9.skadnetwork' }, // Google
67
- { SKAdNetworkIdentifier: '4fzdc2evr5.skadnetwork' }, // Aarki
68
- { SKAdNetworkIdentifier: '2fnua5tdw4.skadnetwork' }, // Adform
69
- { SKAdNetworkIdentifier: 'ydx93a7ass.skadnetwork' }, // Adikteev
70
- { SKAdNetworkIdentifier: 'p78axxw29g.skadnetwork' }, // Amazon
71
- { SKAdNetworkIdentifier: 'v72qych5uu.skadnetwork' }, // Appier
72
- { SKAdNetworkIdentifier: 'ludvb6z3bs.skadnetwork' }, // Applovin
73
- { SKAdNetworkIdentifier: 'cp8zw746q7.skadnetwork' }, // Arpeely
74
- { SKAdNetworkIdentifier: '3sh42y64q3.skadnetwork' }, // Basis
75
- { SKAdNetworkIdentifier: 'c6k4g5qg8m.skadnetwork' }, // Beeswax.io
76
- { SKAdNetworkIdentifier: 's39g8k73mm.skadnetwork' }, // Bidease
77
- { SKAdNetworkIdentifier: '3qy4746246.skadnetwork' }, // Bigabid
78
- { SKAdNetworkIdentifier: 'hs6bdukanm.skadnetwork' }, // Criteo
79
- { SKAdNetworkIdentifier: 'mlmmfzh3r3.skadnetwork' }, // Digital Turbine DSP
80
- { SKAdNetworkIdentifier: 'v4nxqhlyqp.skadnetwork' }, // i-mobile
81
- { SKAdNetworkIdentifier: 'wzmmz9fp6w.skadnetwork' }, // InMobi
82
- { SKAdNetworkIdentifier: 'su67r6k2v3.skadnetwork' }, // ironSource Ads
83
- { SKAdNetworkIdentifier: 'yclnxrl5pm.skadnetwork' }, // Jampp
84
- { SKAdNetworkIdentifier: '7ug5zh24hu.skadnetwork' }, // Liftoff
85
- { SKAdNetworkIdentifier: 'gta9lk7p23.skadnetwork' }, // Liftoff Monetize
86
- { SKAdNetworkIdentifier: 'vutu7akeur.skadnetwork' }, // LINE
87
- { SKAdNetworkIdentifier: 'y5ghdn5j9k.skadnetwork' }, // Mediaforce
88
- { SKAdNetworkIdentifier: 'v9wttpbfk9.skadnetwork' }, // Meta (1 of 2)
89
- { SKAdNetworkIdentifier: 'n38lu8286q.skadnetwork' }, // Meta (2 of 2)
90
- { SKAdNetworkIdentifier: '47vhws6wlr.skadnetwork' }, // MicroAd
91
- { SKAdNetworkIdentifier: 'kbd757ywx3.skadnetwork' }, // Mintegral / Mobvista
92
- { SKAdNetworkIdentifier: '9t245vhmpl.skadnetwork' }, // Moloco
93
- { SKAdNetworkIdentifier: 'a2p9lx4jpn.skadnetwork' }, // Opera
94
- { SKAdNetworkIdentifier: '22mmun2rn5.skadnetwork' }, // Pangle
95
- { SKAdNetworkIdentifier: '4468km3ulz.skadnetwork' }, // Realtime Technologies GmbH
96
- { SKAdNetworkIdentifier: '2u9pt9hc89.skadnetwork' }, // Remerge
97
- { SKAdNetworkIdentifier: '8s468mfl3y.skadnetwork' }, // RTB House
98
- { SKAdNetworkIdentifier: 'ppxm28t8ap.skadnetwork' }, // Smadex
99
- { SKAdNetworkIdentifier: 'uw77j35x4d.skadnetwork' }, // The Trade Desk
100
- { SKAdNetworkIdentifier: 'pwa73g5rt2.skadnetwork' }, // Tremor
101
- { SKAdNetworkIdentifier: '578prtvx9j.skadnetwork' }, // Unicorn
102
- { SKAdNetworkIdentifier: '4dzt52r2t5.skadnetwork' }, // Unity Ads
103
- { SKAdNetworkIdentifier: 'tl55sbb4fm.skadnetwork' }, // Verve
104
- { SKAdNetworkIdentifier: 'e5fvkxwrpn.skadnetwork' }, // Yahoo!
105
- { SKAdNetworkIdentifier: '8c4e2ghe7u.skadnetwork' }, // Yahoo! Japan Ads
106
- { SKAdNetworkIdentifier: '3rd42ekr43.skadnetwork' }, // YouAppi
107
- { SKAdNetworkIdentifier: '3qcr597p9d.skadnetwork' }, // Zucks
108
- ];
109
-
110
96
  const updatedPlistContent = plist.build(plistData);
111
97
  fs.writeFileSync(infoPlistPath, updatedPlistContent, 'utf8');
112
98
  console.log('AdMob IDs and additional configurations successfully updated in Info.plist');
@@ -121,6 +107,8 @@ try {
121
107
  throw new Error('Neither Android nor iOS platforms are found. Ensure platforms are added to your Capacitor project.');
122
108
  }
123
109
 
110
+ checkAndCopyResources();
111
+
124
112
  const admobConfig = getAdMobConfig();
125
113
 
126
114
  if (fileExists(androidPlatformPath)) {
@@ -132,8 +120,5 @@ try {
132
120
  }
133
121
  } catch (error) {
134
122
  console.error(error.message);
123
+ process.exit(1); // Stop execution if there's a critical error
135
124
  }
136
-
137
-
138
-
139
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",
@@ -1,33 +1,19 @@
1
1
  // Define file prefixes to delete
2
2
  const filePrefixes = [
3
- "add-splash-screen",
4
- "setSplashAnimation",
5
- "codeplayBeforeBuild",
6
- "finalrelease"
7
- ];
8
-
9
-
10
-
11
-
12
-
13
-
3
+ "add-splash-screen",
4
+ "setSplashAnimation",
5
+ "codeplayBeforeBuild",
6
+ "finalrelease"
7
+ ];
14
8
 
15
9
  const fs = require("fs");
16
10
  const path = require("path");
17
11
 
18
12
  const projectRoot = path.resolve(__dirname, "../../../"); // Project root
19
13
  const commonBuildPath = path.join(__dirname, "../files"); // Path where files were copied from
20
-
21
-
22
-
23
-
24
14
  const splashXmlPath = path.join(projectRoot, "buildCodeplay"); // Path to splashxml folder
25
15
 
26
-
27
-
28
- process.stdout.write("🚀 Uninstalling: Removing old and copied files...");
29
-
30
-
16
+ process.stdout.write("🚀 Uninstalling: Removing old and copied files...\n");
31
17
 
32
18
  const removeDirectory = (dirPath) => {
33
19
  if (fs.existsSync(dirPath)) {
@@ -45,58 +31,30 @@ const removeDirectory = (dirPath) => {
45
31
  };
46
32
 
47
33
  removeDirectory(splashXmlPath);
34
+ removeDirectory(path.join(projectRoot, "splashxml")); // Remove old splashxml folder
48
35
 
36
+ // Step 1: Find all matching files in the project directory
37
+ const filePatternsToRemove = [
38
+ /^add-splash-screen-.*$/,
39
+ /^setSplashAnimation-.*$/,
40
+ /^codeplayBeforeBuild-.*$/,
41
+ /^modify-plugin-xml\.xml$/
42
+ ];
49
43
 
44
+ const filesInProject = fs.readdirSync(projectRoot);
50
45
 
51
-
52
- // Helper function to extract version from filename
53
- const extractVersion = (filename) => {
54
- const match = filename.match(/-(\d+\.\d+)\.js$/);
55
- return match ? parseFloat(match[1]) : null;
56
- };
57
-
58
- // Helper function to get base name without version
59
- const getBaseName = (filename) => filename.replace(/-\d+\.\d+\.js$/, "");
60
-
61
- // Step 1: Find all versioned files in the project directory
62
- const filesInProject = fs.readdirSync(projectRoot)
63
- .filter(file => file.match(/(add-splash-screen-|setSplashAnimation-|codeplayBeforeBuild-)-\d+\.\d+\.js/));
64
-
65
- const latestVersions = {};
66
-
67
- // Step 2: Determine the latest version for each file type
68
46
  filesInProject.forEach(file => {
69
- const baseName = getBaseName(file);
70
- const version = extractVersion(file);
71
-
72
- if (version !== null) {
73
- if (!latestVersions[baseName] || version > latestVersions[baseName].version) {
74
- latestVersions[baseName] = { file, version };
47
+ if (filePatternsToRemove.some(pattern => pattern.test(file))) {
48
+ const filePath = path.join(projectRoot, file);
49
+ try {
50
+ fs.unlinkSync(filePath);
51
+ process.stdout.write(`🗑️ Removed file: ${filePath}\n`);
52
+ } catch (error) {
53
+ process.stderr.write(`⚠️ Failed to remove ${filePath}: ${error.message}\n`);
75
54
  }
76
55
  }
77
56
  });
78
57
 
79
-
80
-
81
-
82
- // Step 1: Find all matching files in the project directory
83
- const filesInProject1 = fs.readdirSync(projectRoot)
84
- .filter(file => filePrefixes.some(prefix => file.startsWith(prefix)));
85
-
86
- filesInProject1.forEach(file => {
87
- const filePath = path.join(projectRoot, file);
88
- try {
89
- fs.unlinkSync(filePath);
90
- process.stdout.write(`🗑️ Removed file: ${filePath}`);
91
- } catch (error) {
92
- process.stderr.write(`⚠️ Failed to remove ${filePath}: ${error.message}`);
93
- }
94
- });
95
-
96
-
97
-
98
-
99
-
100
58
  // Remove files listed in commonBuildPath
101
59
  if (fs.existsSync(commonBuildPath)) {
102
60
  fs.readdirSync(commonBuildPath).forEach(file => {
@@ -104,12 +62,12 @@ if (fs.existsSync(commonBuildPath)) {
104
62
  if (fs.existsSync(destPath)) {
105
63
  try {
106
64
  fs.unlinkSync(destPath);
107
- process.stdout.write(`🗑️ Removed file: ${destPath}`);
65
+ process.stdout.write(`🗑️ Removed file: ${destPath}\n`);
108
66
  } catch (error) {
109
- process.stderr.write(`⚠️ Failed to remove ${destPath}: ${error.message}`);
67
+ process.stderr.write(`⚠️ Failed to remove ${destPath}: ${error.message}\n`);
110
68
  }
111
69
  }
112
70
  });
113
71
  }
114
72
 
115
- process.stdout.write("✅ Uninstall cleanup complete!");
73
+ process.stdout.write("✅ Uninstall cleanup complete!\n");