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 CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Common build scripts and files",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
- "postinstall": "node scripts/sync-files.js"
7
+
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
@@ -1,67 +1,58 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
3
 
4
- const projectRoot = process.cwd(); // Project root where this package is installed
5
- const commonBuildPath = path.join(__dirname, "../files"); // Path to "Common Build File" folder
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("❌ Error: package.json not found in project.");
18
+ console.error("❌ package.json not found!");
11
19
  process.exit(1);
12
20
  }
13
21
 
14
- // Function to get the latest versioned file dynamically
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
- fs.copyFileSync(path.join(commonBuildPath, file), path.join(projectRoot, file));
32
- console.log(`✅ Copied: ${file}`);
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
- // Get the latest versions
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
- // Read and update package.json
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"].replace(
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"].replace(
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"].replace(
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
- // Write updated package.json
56
+ // Save changes
66
57
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
67
- console.log("✅ package.json updated successfully!");
58
+ console.log("✅ package.json updated!");