codeplay-common 1.0.4 → 1.0.5

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