codeplay-common 2.1.13 → 2.1.15
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 +2 -2
- package/LICENSE +21 -21
- package/README.md +11 -11
- package/files/buildCodeplay/add-splash-screen-1.6.js +248 -248
- package/files/buildCodeplay/codeplayBeforeBuild-5.1.js +1258 -1230
- package/files/buildCodeplay/ios-emi-admob-modification.js +52 -52
- package/files/buildCodeplay/modify-plugin-xml.js +36 -36
- package/files/buildCodeplay/packageidBaseModification-1.3.js +270 -270
- package/files/buildCodeplay/setSplashAnimation-1.2.js +170 -170
- package/files/buildCodeplay/splashxml/codeplay_splashScreen.xml +11 -11
- package/files/finalrelease +835 -835
- package/files/iap-install-2.js +145 -145
- package/files/ionic.config.json +6 -6
- package/package.json +16 -16
- package/scripts/sync-files.js +86 -86
- package/scripts/uninstall.js +77 -77
package/files/iap-install-2.js
CHANGED
|
@@ -1,145 +1,145 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const androidManifestPath = path.join("android", "app", "src", "main", "AndroidManifest.xml");
|
|
7
|
-
|
|
8
|
-
// Find the vite config file
|
|
9
|
-
const possibleConfigFiles = ['vite.config.mjs', 'vite.config.js'];
|
|
10
|
-
let viteConfigPath;
|
|
11
|
-
|
|
12
|
-
for (const configFile of possibleConfigFiles) {
|
|
13
|
-
const fullPath = path.resolve(configFile);
|
|
14
|
-
if (fs.existsSync(fullPath)) {
|
|
15
|
-
viteConfigPath = fullPath;
|
|
16
|
-
break;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (!viteConfigPath) {
|
|
21
|
-
console.error('Error: No vite.config.mjs or vite.config.js file found.');
|
|
22
|
-
process.exit(1);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
try {
|
|
26
|
-
// Read vite config file
|
|
27
|
-
const viteConfigContent = fs.readFileSync(viteConfigPath, 'utf-8');
|
|
28
|
-
|
|
29
|
-
// Extract @common alias path
|
|
30
|
-
const aliasPattern = /'@common':\s*path\.resolve\(__dirname,\s*'(.+?)'\)/;
|
|
31
|
-
const match = viteConfigContent.match(aliasPattern);
|
|
32
|
-
|
|
33
|
-
if (!match) {
|
|
34
|
-
console.error(`Error: @common alias not found in ${viteConfigPath}`);
|
|
35
|
-
process.exit(1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const commonFilePath = match[1];
|
|
39
|
-
const resolvedCommonPath = path.resolve(__dirname, commonFilePath);
|
|
40
|
-
|
|
41
|
-
// Read the common file content
|
|
42
|
-
if (!fs.existsSync(resolvedCommonPath)) {
|
|
43
|
-
console.error(`Error: Resolved common file does not exist: ${resolvedCommonPath}`);
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const commonFileContent = fs.readFileSync(resolvedCommonPath, 'utf-8');
|
|
48
|
-
|
|
49
|
-
// Extract _storeid value
|
|
50
|
-
const storeIdPattern = /export\s+let\s+_storeid\s*=\s*import\.meta\.env\.VITE_STORE_ID\s*\|\|\s*(\d+)\s*;/;
|
|
51
|
-
|
|
52
|
-
const storeMatch = commonFileContent.match(storeIdPattern);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (!storeMatch) {
|
|
56
|
-
console.error(`Error: _storeid not found in ${resolvedCommonPath}`);
|
|
57
|
-
process.exit(1);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const _storeid = parseInt(storeMatch[1], 10);
|
|
61
|
-
|
|
62
|
-
// Determine the store name based on _storeid
|
|
63
|
-
let storeName = "";
|
|
64
|
-
if (_storeid === 1) {
|
|
65
|
-
storeName = "PlayStore";
|
|
66
|
-
} else if (_storeid === 2) {
|
|
67
|
-
storeName = "SamsungStore";
|
|
68
|
-
} else if (_storeid === 7) {
|
|
69
|
-
storeName = "AmazonStore";
|
|
70
|
-
} else {
|
|
71
|
-
console.error(`Error: Unsupported _storeid value: ${_storeid}`);
|
|
72
|
-
process.exit(1);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
// Call managePackages with the determined store name
|
|
77
|
-
managePackages(storeName);
|
|
78
|
-
|
|
79
|
-
console.log(commonFilePath, `Success - _storeid found: ${_storeid}, Store: ${storeName}`);
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error('Error:', error);
|
|
82
|
-
process.exit(1);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function managePackages(store) {
|
|
86
|
-
console.log(`Managing packages for store: ${store}`);
|
|
87
|
-
|
|
88
|
-
let install = "";
|
|
89
|
-
let uninstall = "";
|
|
90
|
-
|
|
91
|
-
//let androidManifestPath = "path/to/AndroidManifest.xml"; // Update this path
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
let manifestContent = fs.readFileSync(androidManifestPath, 'utf-8');
|
|
95
|
-
|
|
96
|
-
const permissionsToRemove = [
|
|
97
|
-
'com.android.vending.BILLING',
|
|
98
|
-
'com.samsung.android.iap.permission.BILLING'
|
|
99
|
-
];
|
|
100
|
-
|
|
101
|
-
permissionsToRemove.forEach(permission => {
|
|
102
|
-
const permissionRegex = new RegExp(`^\\s*<uses-permission\\s+android:name="${permission}"\\s*/?>\\s*[\r\n]?`, 'm');
|
|
103
|
-
if (permissionRegex.test(manifestContent)) {
|
|
104
|
-
manifestContent = manifestContent.replace(permissionRegex, '');
|
|
105
|
-
console.log(`Removed <uses-permission android:name="${permission}" /> from AndroidManifest.xml`);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
// Write the updated content back to the file
|
|
110
|
-
fs.writeFileSync(androidManifestPath, manifestContent, 'utf-8');
|
|
111
|
-
|
|
112
|
-
if (store === "PlayStore") {
|
|
113
|
-
install = '@revenuecat/purchases-capacitor';
|
|
114
|
-
uninstall = 'cordova-plugin-samsungiap';
|
|
115
|
-
} else if (store === "AmazonStore") {
|
|
116
|
-
install = '@revenuecat/purchases-capacitor';
|
|
117
|
-
uninstall = 'cordova-plugin-samsungiap';
|
|
118
|
-
} else if (store === "SamsungStore") {
|
|
119
|
-
install = 'cordova-plugin-samsungiap';
|
|
120
|
-
uninstall = '@revenuecat/purchases-capacitor';
|
|
121
|
-
} else {
|
|
122
|
-
console.log("No valid store specified. Uninstalling both plugins.");
|
|
123
|
-
try {
|
|
124
|
-
require('child_process').execSync(`npm uninstall cordova-plugin-samsungiap`, { stdio: 'inherit' });
|
|
125
|
-
require('child_process').execSync(`npm uninstall @revenuecat/purchases-capacitor`, { stdio: 'inherit' });
|
|
126
|
-
console.log("Both plugins uninstalled successfully.");
|
|
127
|
-
} catch (err) {
|
|
128
|
-
console.error("Error uninstalling plugins:", err);
|
|
129
|
-
}
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
console.log(`Installing ${install} and uninstalling ${uninstall} for ${store}...`);
|
|
134
|
-
try {
|
|
135
|
-
if (install) {
|
|
136
|
-
require('child_process').execSync(`npm install ${install}`, { stdio: 'inherit' });
|
|
137
|
-
}
|
|
138
|
-
if (uninstall) {
|
|
139
|
-
require('child_process').execSync(`npm uninstall ${uninstall}`, { stdio: 'inherit' });
|
|
140
|
-
}
|
|
141
|
-
console.log(`${install} installed and ${uninstall} uninstalled successfully.`);
|
|
142
|
-
} catch (err) {
|
|
143
|
-
console.error(`Error managing packages for ${store}:`, err);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const androidManifestPath = path.join("android", "app", "src", "main", "AndroidManifest.xml");
|
|
7
|
+
|
|
8
|
+
// Find the vite config file
|
|
9
|
+
const possibleConfigFiles = ['vite.config.mjs', 'vite.config.js'];
|
|
10
|
+
let viteConfigPath;
|
|
11
|
+
|
|
12
|
+
for (const configFile of possibleConfigFiles) {
|
|
13
|
+
const fullPath = path.resolve(configFile);
|
|
14
|
+
if (fs.existsSync(fullPath)) {
|
|
15
|
+
viteConfigPath = fullPath;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!viteConfigPath) {
|
|
21
|
+
console.error('Error: No vite.config.mjs or vite.config.js file found.');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
// Read vite config file
|
|
27
|
+
const viteConfigContent = fs.readFileSync(viteConfigPath, 'utf-8');
|
|
28
|
+
|
|
29
|
+
// Extract @common alias path
|
|
30
|
+
const aliasPattern = /'@common':\s*path\.resolve\(__dirname,\s*'(.+?)'\)/;
|
|
31
|
+
const match = viteConfigContent.match(aliasPattern);
|
|
32
|
+
|
|
33
|
+
if (!match) {
|
|
34
|
+
console.error(`Error: @common alias not found in ${viteConfigPath}`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const commonFilePath = match[1];
|
|
39
|
+
const resolvedCommonPath = path.resolve(__dirname, commonFilePath);
|
|
40
|
+
|
|
41
|
+
// Read the common file content
|
|
42
|
+
if (!fs.existsSync(resolvedCommonPath)) {
|
|
43
|
+
console.error(`Error: Resolved common file does not exist: ${resolvedCommonPath}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const commonFileContent = fs.readFileSync(resolvedCommonPath, 'utf-8');
|
|
48
|
+
|
|
49
|
+
// Extract _storeid value
|
|
50
|
+
const storeIdPattern = /export\s+let\s+_storeid\s*=\s*import\.meta\.env\.VITE_STORE_ID\s*\|\|\s*(\d+)\s*;/;
|
|
51
|
+
|
|
52
|
+
const storeMatch = commonFileContent.match(storeIdPattern);
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if (!storeMatch) {
|
|
56
|
+
console.error(`Error: _storeid not found in ${resolvedCommonPath}`);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const _storeid = parseInt(storeMatch[1], 10);
|
|
61
|
+
|
|
62
|
+
// Determine the store name based on _storeid
|
|
63
|
+
let storeName = "";
|
|
64
|
+
if (_storeid === 1) {
|
|
65
|
+
storeName = "PlayStore";
|
|
66
|
+
} else if (_storeid === 2) {
|
|
67
|
+
storeName = "SamsungStore";
|
|
68
|
+
} else if (_storeid === 7) {
|
|
69
|
+
storeName = "AmazonStore";
|
|
70
|
+
} else {
|
|
71
|
+
console.error(`Error: Unsupported _storeid value: ${_storeid}`);
|
|
72
|
+
process.exit(1);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
// Call managePackages with the determined store name
|
|
77
|
+
managePackages(storeName);
|
|
78
|
+
|
|
79
|
+
console.log(commonFilePath, `Success - _storeid found: ${_storeid}, Store: ${storeName}`);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Error:', error);
|
|
82
|
+
process.exit(1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function managePackages(store) {
|
|
86
|
+
console.log(`Managing packages for store: ${store}`);
|
|
87
|
+
|
|
88
|
+
let install = "";
|
|
89
|
+
let uninstall = "";
|
|
90
|
+
|
|
91
|
+
//let androidManifestPath = "path/to/AndroidManifest.xml"; // Update this path
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
let manifestContent = fs.readFileSync(androidManifestPath, 'utf-8');
|
|
95
|
+
|
|
96
|
+
const permissionsToRemove = [
|
|
97
|
+
'com.android.vending.BILLING',
|
|
98
|
+
'com.samsung.android.iap.permission.BILLING'
|
|
99
|
+
];
|
|
100
|
+
|
|
101
|
+
permissionsToRemove.forEach(permission => {
|
|
102
|
+
const permissionRegex = new RegExp(`^\\s*<uses-permission\\s+android:name="${permission}"\\s*/?>\\s*[\r\n]?`, 'm');
|
|
103
|
+
if (permissionRegex.test(manifestContent)) {
|
|
104
|
+
manifestContent = manifestContent.replace(permissionRegex, '');
|
|
105
|
+
console.log(`Removed <uses-permission android:name="${permission}" /> from AndroidManifest.xml`);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Write the updated content back to the file
|
|
110
|
+
fs.writeFileSync(androidManifestPath, manifestContent, 'utf-8');
|
|
111
|
+
|
|
112
|
+
if (store === "PlayStore") {
|
|
113
|
+
install = '@revenuecat/purchases-capacitor';
|
|
114
|
+
uninstall = 'cordova-plugin-samsungiap';
|
|
115
|
+
} else if (store === "AmazonStore") {
|
|
116
|
+
install = '@revenuecat/purchases-capacitor';
|
|
117
|
+
uninstall = 'cordova-plugin-samsungiap';
|
|
118
|
+
} else if (store === "SamsungStore") {
|
|
119
|
+
install = 'cordova-plugin-samsungiap';
|
|
120
|
+
uninstall = '@revenuecat/purchases-capacitor';
|
|
121
|
+
} else {
|
|
122
|
+
console.log("No valid store specified. Uninstalling both plugins.");
|
|
123
|
+
try {
|
|
124
|
+
require('child_process').execSync(`npm uninstall cordova-plugin-samsungiap`, { stdio: 'inherit' });
|
|
125
|
+
require('child_process').execSync(`npm uninstall @revenuecat/purchases-capacitor`, { stdio: 'inherit' });
|
|
126
|
+
console.log("Both plugins uninstalled successfully.");
|
|
127
|
+
} catch (err) {
|
|
128
|
+
console.error("Error uninstalling plugins:", err);
|
|
129
|
+
}
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
console.log(`Installing ${install} and uninstalling ${uninstall} for ${store}...`);
|
|
134
|
+
try {
|
|
135
|
+
if (install) {
|
|
136
|
+
require('child_process').execSync(`npm install ${install}`, { stdio: 'inherit' });
|
|
137
|
+
}
|
|
138
|
+
if (uninstall) {
|
|
139
|
+
require('child_process').execSync(`npm uninstall ${uninstall}`, { stdio: 'inherit' });
|
|
140
|
+
}
|
|
141
|
+
console.log(`${install} installed and ${uninstall} uninstalled successfully.`);
|
|
142
|
+
} catch (err) {
|
|
143
|
+
console.error(`Error managing packages for ${store}:`, err);
|
|
144
|
+
}
|
|
145
|
+
}
|
package/files/ionic.config.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "merbin-test-app",
|
|
3
|
-
"integrations": {
|
|
4
|
-
"capacitor": {}
|
|
5
|
-
},
|
|
6
|
-
"type": "custom"
|
|
1
|
+
{
|
|
2
|
+
"name": "merbin-test-app",
|
|
3
|
+
"integrations": {
|
|
4
|
+
"capacitor": {}
|
|
5
|
+
},
|
|
6
|
+
"type": "custom"
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "codeplay-common",
|
|
3
|
-
"version": "2.1.
|
|
4
|
-
"description": "Common build scripts and files",
|
|
5
|
-
"scripts": {
|
|
6
|
-
"postinstall": "node scripts/sync-files.js",
|
|
7
|
-
"preinstall": "node scripts/uninstall.js"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "https://github.com/merbin2012/codeplay-common.git"
|
|
12
|
-
},
|
|
13
|
-
"author": "Codeplay Technologies",
|
|
14
|
-
"license": "MIT"
|
|
15
|
-
}
|
|
16
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "codeplay-common",
|
|
3
|
+
"version": "2.1.15",
|
|
4
|
+
"description": "Common build scripts and files",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"postinstall": "node scripts/sync-files.js",
|
|
7
|
+
"preinstall": "node scripts/uninstall.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/merbin2012/codeplay-common.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "Codeplay Technologies",
|
|
14
|
+
"license": "MIT"
|
|
15
|
+
}
|
|
16
|
+
|
package/scripts/sync-files.js
CHANGED
|
@@ -1,86 +1,86 @@
|
|
|
1
|
-
const fs = require("fs");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
|
|
4
|
-
const projectRoot = path.resolve(__dirname, "../../../"); // Your project's root
|
|
5
|
-
const commonBuildPath = path.join(__dirname, "../files"); // Path to common files
|
|
6
|
-
const buildCodeplayPath = path.join(commonBuildPath, "buildCodeplay"); // Correct path
|
|
7
|
-
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
8
|
-
|
|
9
|
-
// Ensure package.json exists
|
|
10
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
11
|
-
process.stderr.write("❌ package.json not found!\n");
|
|
12
|
-
process.exit(1);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function copyFolderSync(source, destination) {
|
|
16
|
-
try {
|
|
17
|
-
fs.cpSync(source, destination, { recursive: true });
|
|
18
|
-
process.stdout.write(`✅ Copied folder: ${source} -> ${destination}\n`);
|
|
19
|
-
} catch (error) {
|
|
20
|
-
process.stderr.write(`⚠️ Failed to copy folder: ${source} - ${error.message}\n`);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Copy all files from `common-build-files/files/` to the project root
|
|
25
|
-
fs.readdirSync(commonBuildPath).forEach(file => {
|
|
26
|
-
const sourcePath = path.join(commonBuildPath, file);
|
|
27
|
-
const destPath = path.join(projectRoot, file);
|
|
28
|
-
|
|
29
|
-
if (fs.statSync(sourcePath).isDirectory()) {
|
|
30
|
-
copyFolderSync(sourcePath, destPath);
|
|
31
|
-
} else {
|
|
32
|
-
try {
|
|
33
|
-
fs.copyFileSync(sourcePath, destPath);
|
|
34
|
-
process.stdout.write(`✅ Copied file: ${file}\n`);
|
|
35
|
-
} catch (error) {
|
|
36
|
-
process.stderr.write(`⚠️ Failed to copy file: ${file} - ${error.message}\n`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
// Function to get the latest versioned file from files/buildCodeplay
|
|
42
|
-
function getLatestFile(prefix) {
|
|
43
|
-
if (!fs.existsSync(buildCodeplayPath)) return null; // Ensure directory exists
|
|
44
|
-
|
|
45
|
-
const files = fs.readdirSync(buildCodeplayPath).filter(file => file.startsWith(prefix));
|
|
46
|
-
if (files.length === 0) return null;
|
|
47
|
-
files.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }));
|
|
48
|
-
return files[0];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Detect latest script versions
|
|
52
|
-
const latestSplashScreen = getLatestFile("add-splash-screen-");
|
|
53
|
-
const latestSplashAnimation = getLatestFile("setSplashAnimation-");
|
|
54
|
-
const latestCodeplayBuild = getLatestFile("codeplayBeforeBuild-");
|
|
55
|
-
|
|
56
|
-
const latestPackageIdModification = getLatestFile("packageidBaseModification-");
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// Update package.json
|
|
60
|
-
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
61
|
-
|
|
62
|
-
// Ensure scripts object exists
|
|
63
|
-
packageJson.scripts = packageJson.scripts || {};
|
|
64
|
-
|
|
65
|
-
// Update or add necessary scripts
|
|
66
|
-
if (latestCodeplayBuild) {
|
|
67
|
-
packageJson.scripts["build"] = `node buildCodeplay/${latestCodeplayBuild} && node buildCodeplay/${latestPackageIdModification} && cross-env NODE_ENV=production vite build --logLevel warn`;
|
|
68
|
-
}
|
|
69
|
-
if (latestSplashScreen && latestSplashAnimation) {
|
|
70
|
-
packageJson.scripts["capacitor:sync:after"] = ` node buildCodeplay/${latestSplashScreen} && node buildCodeplay/${latestSplashAnimation}`;
|
|
71
|
-
//node buildCodeplay/ios-emi-admob-modification.js &&
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
packageJson.scripts["ionic:build"] = "npm run build";
|
|
75
|
-
packageJson.scripts["ionic:serve"] = "npm run start";
|
|
76
|
-
packageJson.scripts["build:storeid1"] = "vite build --mode storeid1";
|
|
77
|
-
packageJson.scripts["build:storeid2"] = "vite build --mode storeid2";
|
|
78
|
-
packageJson.scripts["build:storeid3"] = "vite build --mode storeid3";
|
|
79
|
-
packageJson.scripts["build:storeid4"] = "vite build --mode storeid4";
|
|
80
|
-
packageJson.scripts["build:storeid5"] = "vite build --mode storeid5";
|
|
81
|
-
//packageJson.scripts["build:storeid6"] = "vite build --mode storeid6";
|
|
82
|
-
packageJson.scripts["build:storeid7"] = "vite build --mode storeid7";
|
|
83
|
-
packageJson.scripts["build:storeid8"] = "vite build --mode storeid8";
|
|
84
|
-
// Save changes
|
|
85
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
|
|
86
|
-
process.stdout.write("✅ package.json updated!\n");
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const path = require("path");
|
|
3
|
+
|
|
4
|
+
const projectRoot = path.resolve(__dirname, "../../../"); // Your project's root
|
|
5
|
+
const commonBuildPath = path.join(__dirname, "../files"); // Path to common files
|
|
6
|
+
const buildCodeplayPath = path.join(commonBuildPath, "buildCodeplay"); // Correct path
|
|
7
|
+
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
8
|
+
|
|
9
|
+
// Ensure package.json exists
|
|
10
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
11
|
+
process.stderr.write("❌ package.json not found!\n");
|
|
12
|
+
process.exit(1);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function copyFolderSync(source, destination) {
|
|
16
|
+
try {
|
|
17
|
+
fs.cpSync(source, destination, { recursive: true });
|
|
18
|
+
process.stdout.write(`✅ Copied folder: ${source} -> ${destination}\n`);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
process.stderr.write(`⚠️ Failed to copy folder: ${source} - ${error.message}\n`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Copy all files from `common-build-files/files/` to the project root
|
|
25
|
+
fs.readdirSync(commonBuildPath).forEach(file => {
|
|
26
|
+
const sourcePath = path.join(commonBuildPath, file);
|
|
27
|
+
const destPath = path.join(projectRoot, file);
|
|
28
|
+
|
|
29
|
+
if (fs.statSync(sourcePath).isDirectory()) {
|
|
30
|
+
copyFolderSync(sourcePath, destPath);
|
|
31
|
+
} else {
|
|
32
|
+
try {
|
|
33
|
+
fs.copyFileSync(sourcePath, destPath);
|
|
34
|
+
process.stdout.write(`✅ Copied file: ${file}\n`);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
process.stderr.write(`⚠️ Failed to copy file: ${file} - ${error.message}\n`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Function to get the latest versioned file from files/buildCodeplay
|
|
42
|
+
function getLatestFile(prefix) {
|
|
43
|
+
if (!fs.existsSync(buildCodeplayPath)) return null; // Ensure directory exists
|
|
44
|
+
|
|
45
|
+
const files = fs.readdirSync(buildCodeplayPath).filter(file => file.startsWith(prefix));
|
|
46
|
+
if (files.length === 0) return null;
|
|
47
|
+
files.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }));
|
|
48
|
+
return files[0];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Detect latest script versions
|
|
52
|
+
const latestSplashScreen = getLatestFile("add-splash-screen-");
|
|
53
|
+
const latestSplashAnimation = getLatestFile("setSplashAnimation-");
|
|
54
|
+
const latestCodeplayBuild = getLatestFile("codeplayBeforeBuild-");
|
|
55
|
+
|
|
56
|
+
const latestPackageIdModification = getLatestFile("packageidBaseModification-");
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
// Update package.json
|
|
60
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
61
|
+
|
|
62
|
+
// Ensure scripts object exists
|
|
63
|
+
packageJson.scripts = packageJson.scripts || {};
|
|
64
|
+
|
|
65
|
+
// Update or add necessary scripts
|
|
66
|
+
if (latestCodeplayBuild) {
|
|
67
|
+
packageJson.scripts["build"] = `node buildCodeplay/${latestCodeplayBuild} && node buildCodeplay/${latestPackageIdModification} && cross-env NODE_ENV=production vite build --logLevel warn`;
|
|
68
|
+
}
|
|
69
|
+
if (latestSplashScreen && latestSplashAnimation) {
|
|
70
|
+
packageJson.scripts["capacitor:sync:after"] = ` node buildCodeplay/${latestSplashScreen} && node buildCodeplay/${latestSplashAnimation}`;
|
|
71
|
+
//node buildCodeplay/ios-emi-admob-modification.js &&
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
packageJson.scripts["ionic:build"] = "npm run build";
|
|
75
|
+
packageJson.scripts["ionic:serve"] = "npm run start";
|
|
76
|
+
packageJson.scripts["build:storeid1"] = "vite build --mode storeid1";
|
|
77
|
+
packageJson.scripts["build:storeid2"] = "vite build --mode storeid2";
|
|
78
|
+
packageJson.scripts["build:storeid3"] = "vite build --mode storeid3";
|
|
79
|
+
packageJson.scripts["build:storeid4"] = "vite build --mode storeid4";
|
|
80
|
+
packageJson.scripts["build:storeid5"] = "vite build --mode storeid5";
|
|
81
|
+
//packageJson.scripts["build:storeid6"] = "vite build --mode storeid6";
|
|
82
|
+
packageJson.scripts["build:storeid7"] = "vite build --mode storeid7";
|
|
83
|
+
packageJson.scripts["build:storeid8"] = "vite build --mode storeid8";
|
|
84
|
+
// Save changes
|
|
85
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
|
|
86
|
+
process.stdout.write("✅ package.json updated!\n");
|