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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Common build scripts and files",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- // 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("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 we are not copying inside node_modules
18
- if (__dirname.includes("node_modules")) {
19
- console.error("❌ Error: Do not copy files inside node_modules!");
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
- safeCopyFile(sourcePath, destPath);
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!");