codeplay-common 4.3.8 → 4.3.9

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.
@@ -123,14 +123,57 @@ function getConnectedDevice() {
123
123
  return devices[0];
124
124
  }
125
125
 
126
- function stopScreenRecording(recording) {
127
- // Allocate a remote pseudo-terminal so Ctrl+C is delivered as an interrupt
128
- // to screenrecord. Without a PTY, adb treats it as ordinary pipe data.
126
+ function getScreenRecordingPids(deviceId) {
127
+ const result = spawnSync('adb', ['-s', deviceId, 'shell', 'pidof', 'screenrecord'], {
128
+ encoding: 'utf8',
129
+ windowsHide: true,
130
+ });
131
+
132
+ if (result.error) throw result.error;
133
+
134
+ const output = String(result.stdout || '').trim();
135
+ if (result.status === 1 && !output) return [];
136
+ if (result.status !== 0) {
137
+ throw new Error(
138
+ String(result.stderr || output || `adb exited with code ${result.status}.`).trim(),
139
+ );
140
+ }
141
+
142
+ return output.split(/\s+/).filter(Boolean);
143
+ }
144
+
145
+ function waitForScreenRecordingPid(deviceId) {
146
+ for (let attempt = 0; attempt < 50; attempt += 1) {
147
+ const pids = getScreenRecordingPids(deviceId);
148
+ if (pids.length === 1) return pids[0];
149
+ if (pids.length > 1) {
150
+ throw new Error(`Multiple screenrecord processes are running: ${pids.join(', ')}.`);
151
+ }
152
+ wait(100);
153
+ }
154
+
155
+ throw new Error('Android screenrecord did not start within 5 seconds.');
156
+ }
157
+
158
+ function stopScreenRecording(deviceId, recordingPid) {
159
+ // SIGINT lets screenrecord write the MP4 index before its adb shell exits.
160
+ run('adb', ['-s', deviceId, 'shell', 'kill', '-2', recordingPid]);
161
+ }
162
+
163
+ async function waitForRecordingFinalization(recordingCompletion) {
164
+ let timeout;
129
165
  try {
130
- recording.child.stdin.write('\u0003');
131
- recording.child.stdin.end();
132
- } catch {
133
- // The adb shell may already have closed its input stream.
166
+ await Promise.race([
167
+ recordingCompletion,
168
+ new Promise((resolve, reject) => {
169
+ timeout = setTimeout(
170
+ () => reject(new Error('The recorder did not finalize within 15 seconds.')),
171
+ 15000,
172
+ );
173
+ }),
174
+ ]);
175
+ } finally {
176
+ clearTimeout(timeout);
134
177
  }
135
178
  }
136
179
 
@@ -323,6 +366,7 @@ async function recordConnectedDevice(options, destinationPath) {
323
366
  );
324
367
 
325
368
  let recording;
369
+ let recordingPid = '';
326
370
  if (audio === 'with') {
327
371
  const scrcpyCommand = getScrcpyCommand();
328
372
  if (!scrcpyCommand) {
@@ -344,13 +388,21 @@ async function recordConnectedDevice(options, destinationPath) {
344
388
  }
345
389
  recording = runAsync(scrcpyCommand, scrcpyArguments);
346
390
  } else {
391
+ const existingPids = getScreenRecordingPids(deviceId);
392
+ if (existingPids.length) {
393
+ throw new Error(
394
+ `Android screenrecord is already running (PID ${existingPids.join(', ')}). Stop it before recording.`,
395
+ );
396
+ }
397
+ run('adb', ['-s', deviceId, 'shell', 'rm', '-f', deviceRecordingPath]);
347
398
  recording = runAsync('adb', [
348
399
  '-s', deviceId,
349
- 'shell', '-t', 'screenrecord',
400
+ 'shell', 'screenrecord',
350
401
  '--bit-rate', '12000000',
351
402
  '--time-limit', String(duration),
352
403
  deviceRecordingPath,
353
- ], { stdio: ['pipe', 'inherit', 'inherit'] });
404
+ ], { stdio: ['ignore', 'inherit', 'inherit'] });
405
+ recordingPid = waitForScreenRecordingPid(deviceId);
354
406
  }
355
407
 
356
408
  let manualStopRequested = false;
@@ -366,20 +418,13 @@ async function recordConnectedDevice(options, destinationPath) {
366
418
  'shell', 'pkill', '-TERM', '-f', 'com.genymobile.scrcpy.Server',
367
419
  ]);
368
420
  } else {
369
- stopScreenRecording(recording);
421
+ stopScreenRecording(deviceId, recordingPid);
370
422
  }
371
423
  } else if (stopReason === 'maximum-duration') {
372
424
  console.log(`Safety maximum reached after ${duration} seconds.`);
373
425
  }
374
426
 
375
- if (manualStopRequested) {
376
- // Vendor recorder services can leave adb.exe waiting after the recording
377
- // file has already been finalized. Give the device a moment, but do not
378
- // block the pull forever on that wrapper process.
379
- wait(2000);
380
- } else {
381
- await recording.completion;
382
- }
427
+ await waitForRecordingFinalization(recording.completion);
383
428
 
384
429
  if (audio === 'without') {
385
430
  try {
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
- {
2
- "name": "codeplay-common",
3
- "version": "4.3.8",
4
- "description": "Common build scripts and files",
5
- "scripts": {
6
- "postinstall": "node scripts/sync-files.js",
7
- "preinstall": "node scripts/uninstall.js"
8
- },
9
- "repository": {
10
- "type": "git",
11
- "url": "https://github.com/merbin2012/codeplay-common.git"
12
- },
13
- "author": "Codeplay Technologies",
14
- "license": "MIT"
15
- }
1
+ {
2
+ "name": "codeplay-common",
3
+ "version": "4.3.9",
4
+ "description": "Common build scripts and files",
5
+ "scripts": {
6
+ "postinstall": "node scripts/sync-files.js",
7
+ "preinstall": "node scripts/uninstall.js"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/merbin2012/codeplay-common.git"
12
+ },
13
+ "author": "Codeplay Technologies",
14
+ "license": "MIT"
15
+ }
@@ -1,104 +1,104 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
-
4
- const projectRoot = path.resolve(__dirname, "../../../"); // Your project's root
5
- const commonBuildPath = path.join(__dirname, "../files"); // Path to common files
6
- const buildCodeplayPath = path.join(commonBuildPath, "buildCodeplay"); // Correct path
7
- const packageJsonPath = path.join(projectRoot, "package.json");
8
-
9
- // Ensure package.json exists
10
- if (!fs.existsSync(packageJsonPath)) {
11
- process.stderr.write("❌ package.json not found!\n");
12
- process.exit(1);
13
- }
14
-
15
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
16
-
17
- function copyFolderSync(source, destination) {
18
- try {
19
- fs.cpSync(source, destination, { recursive: true });
20
- process.stdout.write(`✅ Copied folder: ${source} -> ${destination}\n`);
21
- } catch (error) {
22
- process.stderr.write(`⚠️ Failed to copy folder: ${source} - ${error.message}\n`);
23
- }
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}\n`);
37
- } catch (error) {
38
- process.stderr.write(`⚠️ Failed to copy file: ${file} - ${error.message}\n`);
39
- }
40
- }
41
- });
42
-
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ const projectRoot = path.resolve(__dirname, "../../../"); // Your project's root
5
+ const commonBuildPath = path.join(__dirname, "../files"); // Path to common files
6
+ const buildCodeplayPath = path.join(commonBuildPath, "buildCodeplay"); // Correct path
7
+ const packageJsonPath = path.join(projectRoot, "package.json");
8
+
9
+ // Ensure package.json exists
10
+ if (!fs.existsSync(packageJsonPath)) {
11
+ process.stderr.write("❌ package.json not found!\n");
12
+ process.exit(1);
13
+ }
14
+
15
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
16
+
17
+ function copyFolderSync(source, destination) {
18
+ try {
19
+ fs.cpSync(source, destination, { recursive: true });
20
+ process.stdout.write(`✅ Copied folder: ${source} -> ${destination}\n`);
21
+ } catch (error) {
22
+ process.stderr.write(`⚠️ Failed to copy folder: ${source} - ${error.message}\n`);
23
+ }
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}\n`);
37
+ } catch (error) {
38
+ process.stderr.write(`⚠️ Failed to copy file: ${file} - ${error.message}\n`);
39
+ }
40
+ }
41
+ });
42
+
43
43
  // Function to get the latest versioned file from files/buildCodeplay
44
- function getLatestFile(prefix) {
45
- if (!fs.existsSync(buildCodeplayPath)) return null; // Ensure directory exists
46
-
47
- const files = fs.readdirSync(buildCodeplayPath).filter(file => file.startsWith(prefix));
48
- if (files.length === 0) return null;
49
- files.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }));
50
- return files[0];
51
- }
52
-
53
- // Detect latest script versions
54
- const latestSplashScreen = getLatestFile("add-splash-screen-");
55
- const latestSplashAnimation = getLatestFile("setSplashAnimation-");
56
- const latestCodeplayBuild = getLatestFile("codeplayBeforeBuild-");
57
-
58
- const latestPackageIdModification = getLatestFile("packageidBaseModification-");
59
- const baselineProfileSetupScript = "node scripts/setup-baseline-profile.js";
60
- const baselineProfileGenerateScript = "cd android && gradlew.bat :app:generateBaselineProfile --console=plain";
61
-
62
- function appendIfMissing(base, suffix) {
63
- if (!suffix) return base;
64
- if (!base || typeof base !== "string") return suffix;
65
- if (base.includes(suffix)) return base;
66
- return `${base} && ${suffix}`;
67
- }
68
-
69
-
70
- // Ensure scripts object exists
71
- packageJson.scripts = packageJson.scripts || {};
72
-
73
- // Update or add necessary scripts
74
- if (latestCodeplayBuild) {
75
- packageJson.scripts["build"] = `node buildCodeplay/${latestCodeplayBuild} && node buildCodeplay/${latestPackageIdModification} && cross-env NODE_ENV=production vite build --logLevel warn`;
76
- }
77
- if (latestSplashScreen && latestSplashAnimation) {
78
- packageJson.scripts["capacitor:sync:after"] = appendIfMissing(
79
- `node buildCodeplay/${latestSplashScreen} && node buildCodeplay/${latestSplashAnimation} && node buildCodeplay/manifestModification.js`,
80
- baselineProfileSetupScript
81
- );
82
- //node buildCodeplay/ios-emi-admob-modification.js &&
83
- } else if (packageJson.scripts["capacitor:sync:after"]) {
84
- packageJson.scripts["capacitor:sync:after"] = appendIfMissing(
85
- packageJson.scripts["capacitor:sync:after"],
86
- baselineProfileSetupScript
87
- );
88
- }
89
- packageJson.scripts["baseline-profile:setup"] = baselineProfileSetupScript;
90
- packageJson.scripts["baseline-profile:generate"] = baselineProfileGenerateScript;
91
-
92
- packageJson.scripts["ionic:build"] = "npm run build";
93
- packageJson.scripts["ionic:serve"] = "cross-env NODE_ENV=development vite";
94
- packageJson.scripts["build:storeid1"] = "vite build --mode storeid1";
95
- packageJson.scripts["build:storeid2"] = "vite build --mode storeid2";
96
- packageJson.scripts["build:storeid3"] = "vite build --mode storeid3";
97
- packageJson.scripts["build:storeid4"] = "vite build --mode storeid4";
98
- packageJson.scripts["build:storeid5"] = "vite build --mode storeid5";
99
- //packageJson.scripts["build:storeid6"] = "vite build --mode storeid6";
100
- packageJson.scripts["build:storeid7"] = "vite build --mode storeid7";
101
- packageJson.scripts["build:storeid8"] = "vite build --mode storeid8";
102
- // Save changes
103
- fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
104
- process.stdout.write("✅ package.json updated!\n");
44
+ function getLatestFile(prefix) {
45
+ if (!fs.existsSync(buildCodeplayPath)) return null; // Ensure directory exists
46
+
47
+ const files = fs.readdirSync(buildCodeplayPath).filter(file => file.startsWith(prefix));
48
+ if (files.length === 0) return null;
49
+ files.sort((a, b) => b.localeCompare(a, undefined, { numeric: true }));
50
+ return files[0];
51
+ }
52
+
53
+ // Detect latest script versions
54
+ const latestSplashScreen = getLatestFile("add-splash-screen-");
55
+ const latestSplashAnimation = getLatestFile("setSplashAnimation-");
56
+ const latestCodeplayBuild = getLatestFile("codeplayBeforeBuild-");
57
+
58
+ const latestPackageIdModification = getLatestFile("packageidBaseModification-");
59
+ const baselineProfileSetupScript = "node scripts/setup-baseline-profile.js";
60
+ const baselineProfileGenerateScript = "cd android && gradlew.bat :app:generateBaselineProfile --console=plain";
61
+
62
+ function appendIfMissing(base, suffix) {
63
+ if (!suffix) return base;
64
+ if (!base || typeof base !== "string") return suffix;
65
+ if (base.includes(suffix)) return base;
66
+ return `${base} && ${suffix}`;
67
+ }
68
+
69
+
70
+ // Ensure scripts object exists
71
+ packageJson.scripts = packageJson.scripts || {};
72
+
73
+ // Update or add necessary scripts
74
+ if (latestCodeplayBuild) {
75
+ packageJson.scripts["build"] = `node buildCodeplay/${latestCodeplayBuild} && node buildCodeplay/${latestPackageIdModification} && cross-env NODE_ENV=production vite build --logLevel warn`;
76
+ }
77
+ if (latestSplashScreen && latestSplashAnimation) {
78
+ packageJson.scripts["capacitor:sync:after"] = appendIfMissing(
79
+ `node buildCodeplay/${latestSplashScreen} && node buildCodeplay/${latestSplashAnimation} && node buildCodeplay/manifestModification.js`,
80
+ baselineProfileSetupScript
81
+ );
82
+ //node buildCodeplay/ios-emi-admob-modification.js &&
83
+ } else if (packageJson.scripts["capacitor:sync:after"]) {
84
+ packageJson.scripts["capacitor:sync:after"] = appendIfMissing(
85
+ packageJson.scripts["capacitor:sync:after"],
86
+ baselineProfileSetupScript
87
+ );
88
+ }
89
+ packageJson.scripts["baseline-profile:setup"] = baselineProfileSetupScript;
90
+ packageJson.scripts["baseline-profile:generate"] = baselineProfileGenerateScript;
91
+
92
+ packageJson.scripts["ionic:build"] = "npm run build";
93
+ packageJson.scripts["ionic:serve"] = "cross-env NODE_ENV=development vite";
94
+ packageJson.scripts["build:storeid1"] = "vite build --mode storeid1";
95
+ packageJson.scripts["build:storeid2"] = "vite build --mode storeid2";
96
+ packageJson.scripts["build:storeid3"] = "vite build --mode storeid3";
97
+ packageJson.scripts["build:storeid4"] = "vite build --mode storeid4";
98
+ packageJson.scripts["build:storeid5"] = "vite build --mode storeid5";
99
+ //packageJson.scripts["build:storeid6"] = "vite build --mode storeid6";
100
+ packageJson.scripts["build:storeid7"] = "vite build --mode storeid7";
101
+ packageJson.scripts["build:storeid8"] = "vite build --mode storeid8";
102
+ // Save changes
103
+ fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2), "utf8");
104
+ process.stdout.write("✅ package.json updated!\n");
@@ -1,109 +1,109 @@
1
- // Define file prefixes to delete
2
- const filePrefixes = [
3
- "add-splash-screen",
4
- "setSplashAnimation",
5
- "codeplayBeforeBuild",
6
- "finalrelease"
7
- ];
8
-
9
- const fs = require("fs");
10
- const path = require("path");
11
-
12
- const projectRoot = path.resolve(__dirname, "../../../"); // Project root
13
- const commonBuildPath = path.join(__dirname, "../files"); // Path where files were copied from
14
- const splashXmlPath = path.join(projectRoot, "buildCodeplay"); // Path to splashxml folder
15
- const baselineProfileSetupScript = path.join(projectRoot, "scripts", "setup-baseline-profile.js");
16
- const baselineProfileBackup = path.join(projectRoot, "baselineProfiles", "baseline-prof.txt");
17
-
18
- const isAgentInstructionAsset = (file) => {
19
- const normalizedName = file.toLowerCase();
20
- return normalizedName === "agents" || normalizedName === "agents.md";
21
- };
22
-
23
- process.stdout.write("🚀 Uninstalling: Removing old and copied files...\n");
24
-
25
- const removeDirectory = (dirPath) => {
26
- if (fs.existsSync(dirPath)) {
27
- fs.readdirSync(dirPath).forEach(file => {
28
- const currentPath = path.join(dirPath, file);
29
- if (fs.lstatSync(currentPath).isDirectory()) {
30
- removeDirectory(currentPath);
31
- } else {
32
- fs.unlinkSync(currentPath);
33
- }
34
- });
35
- fs.rmdirSync(dirPath);
36
- process.stdout.write(`🗑️ Removed folder: ${dirPath}\n`);
37
- }
38
- };
39
-
40
- removeDirectory(splashXmlPath);
41
- removeDirectory(path.join(projectRoot, "splashxml")); // Remove old splashxml folder
42
-
43
- // Step 1: Find all matching files in the project directory
44
- const filePatternsToRemove = [
45
- /^add-splash-screen-.*$/,
46
- /^setSplashAnimation-.*$/,
47
- /^codeplayBeforeBuild-.*$/,
48
- /^modify-plugin-xml\.xml$/,
49
- /^finalrelease.*$/,
50
- /^iap-install-\d+(\.\d+)?\.js$/,
51
- /^\.env\.storeid[1-7]$/,
52
- /^modify-plugin-xml\.js$/
53
- ];
54
-
55
- const filesInProject = fs.readdirSync(projectRoot);
56
-
57
- filesInProject.forEach(file => {
58
- if (filePatternsToRemove.some(pattern => pattern.test(file))) {
59
- const filePath = path.join(projectRoot, file);
60
- try {
61
- fs.unlinkSync(filePath);
62
- process.stdout.write(`🗑️ Removed file: ${filePath}\n`);
63
- } catch (error) {
64
- process.stderr.write(`⚠️ Failed to remove ${filePath}: ${error.message}\n`);
65
- }
66
- }
67
- });
68
-
69
- // Remove files and folders listed in commonBuildPath
70
- if (fs.existsSync(commonBuildPath)) {
71
- fs.readdirSync(commonBuildPath).forEach(file => {
72
- const destPath = path.join(projectRoot, file);
73
- if (file === "scripts" || isAgentInstructionAsset(file)) {
74
- return;
75
- }
76
- if (fs.existsSync(destPath)) {
77
- try {
78
- if (fs.lstatSync(destPath).isDirectory()) {
79
- removeDirectory(destPath);
80
- } else {
81
- fs.unlinkSync(destPath);
82
- process.stdout.write(`🗑️ Removed file: ${destPath}\n`);
83
- }
84
- } catch (error) {
85
- process.stderr.write(`⚠️ Failed to remove ${destPath}: ${error.message}\n`);
86
- }
87
- }
88
- });
89
- }
90
-
91
- if (fs.existsSync(baselineProfileSetupScript)) {
92
- try {
93
- fs.unlinkSync(baselineProfileSetupScript);
94
- process.stdout.write(`🗑️ Removed file: ${baselineProfileSetupScript}\n`);
95
- } catch (error) {
96
- process.stderr.write(`⚠️ Failed to remove ${baselineProfileSetupScript}: ${error.message}\n`);
97
- }
98
- }
99
-
100
- if (fs.existsSync(baselineProfileBackup)) {
101
- try {
102
- fs.unlinkSync(baselineProfileBackup);
103
- process.stdout.write(`🗑️ Removed file: ${baselineProfileBackup}\n`);
104
- } catch (error) {
105
- process.stderr.write(`⚠️ Failed to remove ${baselineProfileBackup}: ${error.message}\n`);
106
- }
107
- }
108
-
109
- process.stdout.write("✅ Uninstall cleanup complete!\n");
1
+ // Define file prefixes to delete
2
+ const filePrefixes = [
3
+ "add-splash-screen",
4
+ "setSplashAnimation",
5
+ "codeplayBeforeBuild",
6
+ "finalrelease"
7
+ ];
8
+
9
+ const fs = require("fs");
10
+ const path = require("path");
11
+
12
+ const projectRoot = path.resolve(__dirname, "../../../"); // Project root
13
+ const commonBuildPath = path.join(__dirname, "../files"); // Path where files were copied from
14
+ const splashXmlPath = path.join(projectRoot, "buildCodeplay"); // Path to splashxml folder
15
+ const baselineProfileSetupScript = path.join(projectRoot, "scripts", "setup-baseline-profile.js");
16
+ const baselineProfileBackup = path.join(projectRoot, "baselineProfiles", "baseline-prof.txt");
17
+
18
+ const isAgentInstructionAsset = (file) => {
19
+ const normalizedName = file.toLowerCase();
20
+ return normalizedName === "agents" || normalizedName === "agents.md";
21
+ };
22
+
23
+ process.stdout.write("🚀 Uninstalling: Removing old and copied files...\n");
24
+
25
+ const removeDirectory = (dirPath) => {
26
+ if (fs.existsSync(dirPath)) {
27
+ fs.readdirSync(dirPath).forEach(file => {
28
+ const currentPath = path.join(dirPath, file);
29
+ if (fs.lstatSync(currentPath).isDirectory()) {
30
+ removeDirectory(currentPath);
31
+ } else {
32
+ fs.unlinkSync(currentPath);
33
+ }
34
+ });
35
+ fs.rmdirSync(dirPath);
36
+ process.stdout.write(`🗑️ Removed folder: ${dirPath}\n`);
37
+ }
38
+ };
39
+
40
+ removeDirectory(splashXmlPath);
41
+ removeDirectory(path.join(projectRoot, "splashxml")); // Remove old splashxml folder
42
+
43
+ // Step 1: Find all matching files in the project directory
44
+ const filePatternsToRemove = [
45
+ /^add-splash-screen-.*$/,
46
+ /^setSplashAnimation-.*$/,
47
+ /^codeplayBeforeBuild-.*$/,
48
+ /^modify-plugin-xml\.xml$/,
49
+ /^finalrelease.*$/,
50
+ /^iap-install-\d+(\.\d+)?\.js$/,
51
+ /^\.env\.storeid[1-7]$/,
52
+ /^modify-plugin-xml\.js$/
53
+ ];
54
+
55
+ const filesInProject = fs.readdirSync(projectRoot);
56
+
57
+ filesInProject.forEach(file => {
58
+ if (filePatternsToRemove.some(pattern => pattern.test(file))) {
59
+ const filePath = path.join(projectRoot, file);
60
+ try {
61
+ fs.unlinkSync(filePath);
62
+ process.stdout.write(`🗑️ Removed file: ${filePath}\n`);
63
+ } catch (error) {
64
+ process.stderr.write(`⚠️ Failed to remove ${filePath}: ${error.message}\n`);
65
+ }
66
+ }
67
+ });
68
+
69
+ // Remove files and folders listed in commonBuildPath
70
+ if (fs.existsSync(commonBuildPath)) {
71
+ fs.readdirSync(commonBuildPath).forEach(file => {
72
+ const destPath = path.join(projectRoot, file);
73
+ if (file === "scripts" || isAgentInstructionAsset(file)) {
74
+ return;
75
+ }
76
+ if (fs.existsSync(destPath)) {
77
+ try {
78
+ if (fs.lstatSync(destPath).isDirectory()) {
79
+ removeDirectory(destPath);
80
+ } else {
81
+ fs.unlinkSync(destPath);
82
+ process.stdout.write(`🗑️ Removed file: ${destPath}\n`);
83
+ }
84
+ } catch (error) {
85
+ process.stderr.write(`⚠️ Failed to remove ${destPath}: ${error.message}\n`);
86
+ }
87
+ }
88
+ });
89
+ }
90
+
91
+ if (fs.existsSync(baselineProfileSetupScript)) {
92
+ try {
93
+ fs.unlinkSync(baselineProfileSetupScript);
94
+ process.stdout.write(`🗑️ Removed file: ${baselineProfileSetupScript}\n`);
95
+ } catch (error) {
96
+ process.stderr.write(`⚠️ Failed to remove ${baselineProfileSetupScript}: ${error.message}\n`);
97
+ }
98
+ }
99
+
100
+ if (fs.existsSync(baselineProfileBackup)) {
101
+ try {
102
+ fs.unlinkSync(baselineProfileBackup);
103
+ process.stdout.write(`🗑️ Removed file: ${baselineProfileBackup}\n`);
104
+ } catch (error) {
105
+ process.stderr.write(`⚠️ Failed to remove ${baselineProfileBackup}: ${error.message}\n`);
106
+ }
107
+ }
108
+
109
+ process.stdout.write("✅ Uninstall cleanup complete!\n");