codeplay-common 1.0.4 → 1.0.6
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/package.json +1 -1
- package/scripts/sync-files.js +48 -13
package/package.json
CHANGED
package/scripts/sync-files.js
CHANGED
|
@@ -3,26 +3,61 @@ const path = require("path");
|
|
|
3
3
|
|
|
4
4
|
const projectRoot = process.cwd(); // Your project's root
|
|
5
5
|
const commonBuildPath = path.join(__dirname, "../files"); // Path to common files
|
|
6
|
+
const packageJsonPath = path.join(projectRoot, "package.json");
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
console.log("PROJECT ROOT IS ",projectRoot)
|
|
9
|
+
console.log("commonBuildPath IS ",projectRoot)
|
|
10
|
+
console.log("PROJECT ROOT IS PACKAGE.JSON",packageJsonPath)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
// Function to get the latest versioned file
|
|
14
|
+
function getLatestFile(prefix) {
|
|
15
|
+
const files = fs.readdirSync(commonBuildPath).filter(file => file.startsWith(prefix));
|
|
16
|
+
if (files.length === 0) return null;
|
|
17
|
+
files.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }));
|
|
18
|
+
return files[0];
|
|
15
19
|
}
|
|
16
20
|
|
|
17
|
-
// Ensure
|
|
18
|
-
if (
|
|
19
|
-
console.error("❌
|
|
21
|
+
// Ensure package.json exists
|
|
22
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
23
|
+
console.error("❌ package.json not found!");
|
|
20
24
|
process.exit(1);
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
// Copy all files to project root
|
|
27
|
+
// Copy all files from `common-build-files/files/` to the project root
|
|
24
28
|
fs.readdirSync(commonBuildPath).forEach(file => {
|
|
25
29
|
const sourcePath = path.join(commonBuildPath, file);
|
|
26
30
|
const destPath = path.join(projectRoot, file);
|
|
27
|
-
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
fs.copyFileSync(sourcePath, destPath);
|
|
34
|
+
console.log(`✅ Copied: ${file}`);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn(`⚠️ Failed to copy: ${file} - ${error.message}`);
|
|
37
|
+
}
|
|
28
38
|
});
|
|
39
|
+
|
|
40
|
+
// Detect latest script versions
|
|
41
|
+
const latestSplashScreen = getLatestFile("add-splash-screen-");
|
|
42
|
+
const latestSplashAnimation = getLatestFile("setSplashAnimation-");
|
|
43
|
+
const latestCodeplayBuild = getLatestFile("codeplayBeforeBuild-");
|
|
44
|
+
|
|
45
|
+
// Update package.json
|
|
46
|
+
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
|
|
47
|
+
|
|
48
|
+
if (latestSplashScreen) {
|
|
49
|
+
packageJson.scripts["capacitor:sync:after"] = packageJson.scripts["capacitor:sync:after"]
|
|
50
|
+
.replace(/add-splash-screen-\d+\.\d+\.js/, latestSplashScreen);
|
|
51
|
+
}
|
|
52
|
+
if (latestSplashAnimation) {
|
|
53
|
+
packageJson.scripts["capacitor:sync:after"] = packageJson.scripts["capacitor:sync:after"]
|
|
54
|
+
.replace(/setSplashAnimation-\d+\.\d+\.js/, latestSplashAnimation);
|
|
55
|
+
}
|
|
56
|
+
if (latestCodeplayBuild) {
|
|
57
|
+
packageJson.scripts["build"] = packageJson.scripts["build"]
|
|
58
|
+
.replace(/codeplayBeforeBuild-\d+\.\d+\.js/, latestCodeplayBuild);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Save changes
|
|
62
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
|
|
63
|
+
console.log("✅ package.json updated!");
|