-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-cli-permissions.js
43 lines (36 loc) · 1.29 KB
/
get-cli-permissions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fs = require('fs');
const os = require('os');
const path = require('path');
const username = os.userInfo().username; // Get the current user's username
const dynamicPath = `/Users/${username}/.npm/_npx/`; // Start path
const targetFile = 'pkg-helper'; // Name of the file to find
const targetDirectory = '/node_modules/.bin/'; // Target directory to look for the file
const changePermissions = (filePath) => {
fs.chmod(filePath, '755', (err) => {
if (err) {
console.error(`Error setting permissions for ${filePath}: ${err.message}`);
return;
}
console.log(`Permissions updated for ${filePath}`);
});
};
const searchFile = (dir) => {
fs.readdir(dir, { withFileTypes: true }, (err, files) => {
if (err) {
console.error(`Error reading directory ${dir}: ${err.message}`);
return;
}
files.forEach((file) => {
const filePath = path.join(dir, file.name);
if (file.isDirectory()) {
// Recurse into subdirectories
searchFile(filePath);
} else if (file.name === targetFile && dir.includes(targetDirectory)) {
// Check if the file is the target and in the correct directory
console.log(`Found ${targetFile} at ${filePath}`);
changePermissions(filePath);
}
});
});
};
searchFile(dynamicPath);