codeplay-common 1.1.64 → 1.1.66

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.1.64",
3
+ "version": "1.1.66",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",
@@ -1,10 +1,10 @@
1
1
  const fs = require("fs");
2
2
  const path = require("path");
3
3
 
4
- const projectRoot = path.resolve(__dirname, "../../../"); // Your project's root
4
+ const projectRoot = path.resolve(__dirname, "../../../");;//process.cwd(); // Your project's root
5
5
  const commonBuildPath = path.join(__dirname, "../files"); // Path to common files
6
6
  const packageJsonPath = path.join(projectRoot, "package.json");
7
- const buildCodeplayPath = path.join(projectRoot, "buildCodeplay");
7
+
8
8
 
9
9
  // Ensure package.json exists
10
10
  if (!fs.existsSync(packageJsonPath)) {
@@ -12,20 +12,37 @@ if (!fs.existsSync(packageJsonPath)) {
12
12
  process.exit(1);
13
13
  }
14
14
 
15
- // Ensure buildCodeplay directory exists
16
- if (!fs.existsSync(buildCodeplayPath)) {
17
- fs.mkdirSync(buildCodeplayPath, { recursive: true });
18
- }
19
15
 
20
16
  function copyFolderSync(source, destination) {
21
17
  try {
22
18
  fs.cpSync(source, destination, { recursive: true });
23
- process.stdout.write(`✅ Copied folder: ${source} -> ${destination}\n`);
19
+ process.stdout.write(`✅ Copied folder: ${source} -> ${destination}`);
24
20
  } catch (error) {
25
- process.stderr.write(`⚠️ Failed to copy folder: ${source} - ${error.message}\n`);
21
+ process.stderr.write(`⚠️ Failed to copy folder: ${source} - ${error.message}`);
26
22
  }
27
23
  }
28
24
 
25
+
26
+ // Copy all files from `common-build-files/files/` to the project root
27
+ fs.readdirSync(commonBuildPath).forEach(file => {
28
+ const sourcePath = path.join(commonBuildPath, file);
29
+ const destPath = path.join(projectRoot, file);
30
+
31
+ if (fs.statSync(sourcePath).isDirectory()) {
32
+ copyFolderSync(sourcePath, destPath);
33
+ } else {
34
+ try {
35
+ fs.copyFileSync(sourcePath, destPath);
36
+ process.stdout.write(`✅ Copied file: ${file}`);
37
+ }
38
+ catch (error) {
39
+ process.stderr.write(`⚠️ Failed to copy file: ${file} - ${error.message}`);
40
+ }
41
+ }
42
+ });
43
+
44
+
45
+
29
46
  // Function to get the latest versioned file
30
47
  function getLatestFile(prefix) {
31
48
  const files = fs.readdirSync(commonBuildPath).filter(file => file.startsWith(prefix));
@@ -34,73 +51,30 @@ function getLatestFile(prefix) {
34
51
  return files[0];
35
52
  }
36
53
 
37
- // List of file prefixes to be copied to buildCodeplay
38
- const filePrefixes = [
39
- "add-splash-screen-",
40
- "codeplayBeforeBuild-",
41
- "modify-plugin-xml",
42
- "setSplashAnimation-"
43
- ];
44
-
45
- const copiedFiles = new Set();
46
-
47
- // Copy required files to buildCodeplay
48
- filePrefixes.forEach(prefix => {
49
- const latestFile = getLatestFile(prefix);
50
- if (latestFile) {
51
- const sourcePath = path.join(commonBuildPath, latestFile);
52
- const destPath = path.join(buildCodeplayPath, latestFile);
53
- try {
54
- fs.copyFileSync(sourcePath, destPath);
55
- process.stdout.write(`✅ Copied file: ${latestFile} -> ${destPath}\n`);
56
- copiedFiles.add(latestFile);
57
- } catch (error) {
58
- process.stderr.write(`⚠️ Failed to copy file: ${latestFile} - ${error.message}\n`);
59
- }
60
- }
61
- });
62
54
 
63
- // Copy splashxml folder
64
- const splashXmlSource = path.join(commonBuildPath, "splashxml");
65
- const splashXmlDest = path.join(buildCodeplayPath, "splashxml");
66
- if (fs.existsSync(splashXmlSource)) {
67
- copyFolderSync(splashXmlSource, splashXmlDest);
68
- copiedFiles.add("splashxml");
69
- }
70
55
 
71
- // Copy remaining files to the project root
72
- fs.readdirSync(commonBuildPath).forEach(file => {
73
- const sourcePath = path.join(commonBuildPath, file);
74
- const destPath = path.join(projectRoot, file);
75
56
 
76
- if (!copiedFiles.has(file)) {
77
- if (fs.statSync(sourcePath).isDirectory()) {
78
- copyFolderSync(sourcePath, destPath);
79
- } else {
80
- try {
81
- fs.copyFileSync(sourcePath, destPath);
82
- process.stdout.write(`✅ Copied file: ${file} -> ${destPath}\n`);
83
- } catch (error) {
84
- process.stderr.write(`⚠️ Failed to copy file: ${file} - ${error.message}\n`);
85
- }
86
- }
87
- }
88
- });
89
57
 
90
- // Update package.json
91
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
92
- packageJson.scripts = packageJson.scripts || {};
58
+
59
+ //const packageJsonPath = path.join(projectRoot, "package.json");
93
60
 
94
61
  // Detect latest script versions
95
62
  const latestSplashScreen = getLatestFile("add-splash-screen-");
96
63
  const latestSplashAnimation = getLatestFile("setSplashAnimation-");
97
64
  const latestCodeplayBuild = getLatestFile("codeplayBeforeBuild-");
98
65
 
66
+ // Update package.json
67
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
68
+
69
+ // Ensure scripts object exists
70
+ packageJson.scripts = packageJson.scripts || {};
71
+
72
+ // Update or add necessary scripts
99
73
  if (latestCodeplayBuild) {
100
- packageJson.scripts["build"] = `node buildCodeplay/${latestCodeplayBuild} && cross-env NODE_ENV=production vite build`;
74
+ packageJson.scripts["build"] = `node ${latestCodeplayBuild} && cross-env NODE_ENV=production vite build`;
101
75
  }
102
76
  if (latestSplashScreen && latestSplashAnimation) {
103
- packageJson.scripts["capacitor:sync:after"] = `node buildCodeplay/${latestSplashScreen} && node buildCodeplay/${latestSplashAnimation}`;
77
+ packageJson.scripts["capacitor:sync:after"] = `node ${latestSplashScreen} && node ${latestSplashAnimation}`;
104
78
  }
105
79
 
106
80
  packageJson.scripts["ionic:build"] = "npm run build";
@@ -109,5 +83,6 @@ packageJson.scripts["build:storeid1"] = "vite build --mode storeid1";
109
83
  packageJson.scripts["build:storeid2"] = "vite build --mode storeid2";
110
84
  packageJson.scripts["build:storeid7"] = "vite build --mode storeid7";
111
85
 
86
+ // Save changes
112
87
  fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
113
- process.stdout.write("✅ package.json updated!\n");
88
+ process.stdout.write("✅ package.json updated!");
@@ -1,17 +1,34 @@
1
+ // Define file prefixes to delete
2
+ const filePrefixes = [
3
+ "add-splash-screen",
4
+ "setSplashAnimation",
5
+ "codeplayBeforeBuild",
6
+ "finalrelease"
7
+ ];
8
+
9
+
10
+ const splashXmlPath = path.join(projectRoot, "buildCodeplay"); // Path to splashxml folder
11
+
12
+
13
+
14
+
1
15
  const fs = require("fs");
2
16
  const path = require("path");
3
17
 
4
18
  const projectRoot = path.resolve(__dirname, "../../../"); // Project root
5
- const buildCodeplayPath = path.join(projectRoot, "buildCodeplay"); // Path to buildCodeplay folder
6
- const commonBuildPath = path.join(__dirname, "../files"); // Source folder (files to be copied)
7
- const filePrefixes = [
8
- "add-splash-screen",
9
- "setSplashAnimation",
10
- "codeplayBeforeBuild",
11
- "finalrelease"
12
- ];
19
+ const commonBuildPath = path.join(__dirname, "../files"); // Path where files were copied from
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+ process.stdout.write("🚀 Uninstalling: Removing old and copied files...");
29
+
30
+
13
31
 
14
- // Function to remove a directory and its contents
15
32
  const removeDirectory = (dirPath) => {
16
33
  if (fs.existsSync(dirPath)) {
17
34
  fs.readdirSync(dirPath).forEach(file => {
@@ -27,35 +44,72 @@ const removeDirectory = (dirPath) => {
27
44
  }
28
45
  };
29
46
 
30
- // Remove specific files from project root
31
- fs.readdirSync(projectRoot).forEach(file => {
32
- if (filePrefixes.some(prefix => file.startsWith(prefix))) {
33
- const filePath = path.join(projectRoot, file);
34
- try {
35
- fs.unlinkSync(filePath);
36
- process.stdout.write(`🗑️ Removed file: ${filePath}\n`);
37
- } catch (error) {
38
- process.stderr.write(`⚠️ Failed to remove ${filePath}: ${error.message}\n`);
47
+ removeDirectory(splashXmlPath);
48
+
49
+
50
+
51
+
52
+ // Helper function to extract version from filename
53
+ const extractVersion = (filename) => {
54
+ const match = filename.match(/-(\d+\.\d+)\.js$/);
55
+ return match ? parseFloat(match[1]) : null;
56
+ };
57
+
58
+ // Helper function to get base name without version
59
+ const getBaseName = (filename) => filename.replace(/-\d+\.\d+\.js$/, "");
60
+
61
+ // Step 1: Find all versioned files in the project directory
62
+ const filesInProject = fs.readdirSync(projectRoot)
63
+ .filter(file => file.match(/(add-splash-screen-|setSplashAnimation-|codeplayBeforeBuild-)-\d+\.\d+\.js/));
64
+
65
+ const latestVersions = {};
66
+
67
+ // Step 2: Determine the latest version for each file type
68
+ filesInProject.forEach(file => {
69
+ const baseName = getBaseName(file);
70
+ const version = extractVersion(file);
71
+
72
+ if (version !== null) {
73
+ if (!latestVersions[baseName] || version > latestVersions[baseName].version) {
74
+ latestVersions[baseName] = { file, version };
39
75
  }
40
76
  }
41
77
  });
42
78
 
43
- // Remove all files that were copied from commonBuildPath/files
79
+
80
+
81
+
82
+ // Step 1: Find all matching files in the project directory
83
+ const filesInProject1 = fs.readdirSync(projectRoot)
84
+ .filter(file => filePrefixes.some(prefix => file.startsWith(prefix)));
85
+
86
+ filesInProject1.forEach(file => {
87
+ const filePath = path.join(projectRoot, file);
88
+ try {
89
+ fs.unlinkSync(filePath);
90
+ process.stdout.write(`🗑️ Removed file: ${filePath}`);
91
+ } catch (error) {
92
+ process.stderr.write(`⚠️ Failed to remove ${filePath}: ${error.message}`);
93
+ }
94
+ });
95
+
96
+
97
+
98
+
99
+
100
+ // Remove files listed in commonBuildPath
44
101
  if (fs.existsSync(commonBuildPath)) {
45
102
  fs.readdirSync(commonBuildPath).forEach(file => {
46
- const projectFilePath = path.join(projectRoot, file);
47
- if (fs.existsSync(projectFilePath)) {
103
+ const destPath = path.join(projectRoot, file);
104
+ if (fs.existsSync(destPath)) {
48
105
  try {
49
- fs.unlinkSync(projectFilePath);
50
- process.stdout.write(`🗑️ Removed copied file: ${projectFilePath}\n`);
106
+ fs.unlinkSync(destPath);
107
+ process.stdout.write(`🗑️ Removed file: ${destPath}`);
51
108
  } catch (error) {
52
- process.stderr.write(`⚠️ Failed to remove ${projectFilePath}: ${error.message}\n`);
109
+ process.stderr.write(`⚠️ Failed to remove ${destPath}: ${error.message}`);
53
110
  }
54
111
  }
55
112
  });
56
113
  }
57
114
 
58
- // Remove all contents of buildCodeplay and delete the folder
59
- removeDirectory(buildCodeplayPath);
60
-
61
- process.stdout.write("✅ Uninstall cleanup complete!\n");
115
+ process.stdout.write("✅ Uninstall cleanup complete!");