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