codeplay-common 1.0.2 → 1.0.4

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.2",
3
+ "version": "1.0.4",
4
4
  "description": "Common build scripts and files",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
-
7
+ "postinstall": "node scripts/sync-files.js"
8
8
  },
9
9
  "repository": {
10
10
  "type": "git",
@@ -3,56 +3,26 @@ 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");
7
6
 
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];
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
+ }
14
15
  }
15
16
 
16
- // Ensure package.json exists
17
- if (!fs.existsSync(packageJsonPath)) {
18
- console.error("❌ package.json not found!");
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!");
19
20
  process.exit(1);
20
21
  }
21
22
 
22
- // Copy all files from `common-build-files/files/` to the project root
23
+ // Copy all files to project root
23
24
  fs.readdirSync(commonBuildPath).forEach(file => {
24
25
  const sourcePath = path.join(commonBuildPath, file);
25
26
  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
- }
27
+ safeCopyFile(sourcePath, destPath);
33
28
  });
34
-
35
- // Detect latest script versions
36
- const latestSplashScreen = getLatestFile("add-splash-screen-");
37
- const latestSplashAnimation = getLatestFile("setSplashAnimation-");
38
- const latestCodeplayBuild = getLatestFile("codeplayBeforeBuild-");
39
-
40
- // Update package.json
41
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
42
-
43
- if (latestSplashScreen) {
44
- packageJson.scripts["capacitor:sync:after"] = packageJson.scripts["capacitor:sync:after"]
45
- .replace(/add-splash-screen-\d+\.\d+\.js/, latestSplashScreen);
46
- }
47
- if (latestSplashAnimation) {
48
- packageJson.scripts["capacitor:sync:after"] = packageJson.scripts["capacitor:sync:after"]
49
- .replace(/setSplashAnimation-\d+\.\d+\.js/, latestSplashAnimation);
50
- }
51
- if (latestCodeplayBuild) {
52
- packageJson.scripts["build"] = packageJson.scripts["build"]
53
- .replace(/codeplayBeforeBuild-\d+\.\d+\.js/, latestCodeplayBuild);
54
- }
55
-
56
- // Save changes
57
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
58
- console.log("✅ package.json updated!");