-
Notifications
You must be signed in to change notification settings - Fork 5
/
nosync.js
executable file
·86 lines (79 loc) · 2.41 KB
/
nosync.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /usr/bin/env node
const shell = require("shelljs");
const minimist = require("minimist");
const args = minimist(process.argv.slice(2));
let step = 1;
shell.echo("\n🖕 iCloud: Congratulations iCloud is being fixed. Thx Apple 🙄");
// npm install if node_modules doesn't exist
const sym = shell.exec("find node_modules -type l", { silent: true }).stdout;
const install = shell.exec("find node_modules -type d", { silent: true })
.stdout;
if (install === "" && sym === "") {
shell.echo(
"\n🖕 iCloud - Step " +
step +
": Can't find node_modules - running `npm install`\n"
);
step++;
shell.exec("npm install");
shell.echo("\n🖕 iCloud - Step " + step + ": Done installing packages");
step++;
}
// if symlink not exists do the stuff
const nosync = shell.exec("find node_modules.nosync -type d", { silent: true })
.stdout;
if (nosync === "") {
shell.echo(
"\n🖕 iCloud - Step " +
step +
": modifying node_modules to node_modules.nosync"
);
step++;
shell.exec("mv node_modules node_modules.nosync");
shell.echo(
"\n🖕 iCloud - Step " +
step +
": adding node_modules -> node_modules.nosync symlink "
);
step++;
shell.exec("ln -s node_modules.nosync node_modules");
}
// add to git exclude maybe
const nogitexcludeline =
shell.exec(
'find .git/info/exclude -type f -print0 | xargs -0 grep -l "^# ignore node_modules symlink$"',
{ silent: true }
).stdout === "";
if (!args.n && nogitexcludeline) {
shell.echo(
"\n🖕 iCloud - Step " +
step +
": Modifying .git/info/exclude to ignore the node_modules .nosync folder and symlink"
);
step++;
shell.exec('echo "# ignore node_modules symlink" >> .git/info/exclude');
shell.exec('echo "node_modules.nosync/" >> .git/info/exclude');
shell.exec('echo "node_modules" >> .git/info/exclude');
shell.exec('echo "!node_modules/" >> .git/info/exclude');
}
// add to gitignore maybe
const nogitignoreline =
shell.exec(
'find .gitignore -type f -print0 | xargs -0 grep -lE "^node_modules/?$"',
{ silent: true }
).stdout === "";
if (!args.n && nogitignoreline) {
shell.echo(
"\n🖕 iCloud - Step " +
step +
": Modifying .gitignore to ignore the node_modules folder"
);
step++;
shell.exec('echo "node_modules/" >> .gitignore');
}
// done
shell.echo("\n.");
shell.echo("\n.");
shell.echo("\n.");
shell.echo("\n🖕 iCloud - Step " + step + ": Profit! 💰\n");
step++;