forked from tmackness/dropbox-ignore-node_modules
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
executable file
·53 lines (48 loc) · 1.53 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env node
const { exec } = require('child_process');
const fs = require('fs');
const glob = require('glob');
const isWsl = require('is-wsl');
try {
const cwd = process.cwd();
const modulesResults = glob.sync(`${cwd}/**/node_modules`);
modulesResults.forEach((modulesPath) => {
if (
modulesPath.indexOf('node_modules') ===
modulesPath.lastIndexOf('node_modules')
) {
// shell command
const platform = process.platform;
const command = () => {
switch (platform) {
case 'win32':
return `Set-Content -Path '${modulesPath}' -Stream com.dropbox.ignored -Value 1`;
case 'darwin':
return `xattr -w com.dropbox.ignored 1 "${modulesPath}"`;
case 'linux':
return isWsl
? `powershell.exe -Command "Set-Content -Path '${modulesPath.replace(
`/mnt/${modulesPath.split('/')[2]}`,
`${modulesPath.split('/')[2]}:`
)}' -Stream com.dropbox.ignored -Value 1"`
: `attr -s com.dropbox.ignored -V 1 ${modulesPath}`;
default:
throw new Error('Could not identify your OS');
}
};
// execute shell command
exec(command(), (error, _stdout, stderr) => {
if (error) {
throw error;
}
if (stderr) {
throw stderr;
}
console.log(`Dropbox is now ignoring ${modulesPath}`);
});
}
});
console.log('Complete.');
} catch (error) {
console.log(`Error: ${error.message}`);
}