forked from nodegit/nodegit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean.js
More file actions
142 lines (127 loc) · 3.33 KB
/
clean.js
File metadata and controls
142 lines (127 loc) · 3.33 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
var fse = require("fs-extra");
var path = require("path");
var npm = require("npm");
var Promise = require("nodegit-promise");
var rooted = path.join.bind(path, __dirname, "..");
if (fse.existsSync(rooted(".didntcomefromthenpmregistry"))) {
console.error("[nodegit] We only clean when downloaded from the npm " +
"registry. Skipping clean.");
return;
}
npm.load({
"production": true
}, function() {
var filesToDelete = [
"build/Makefile",
"build/binding.Makefile",
"build/config.gypi",
"build/gyp-mac-tool",
"build/nodegit.target.mk",
"build/vendor",
"build/Release/.deps",
"build/Release/git2.a",
"build/Release/http_parser.a",
"build/Release/linker.lock",
"build/Release/obj.target",
"build/Release/openssl.a",
"build/Release/ssh2.a",
"build/Release/zlib.a",
"build/Debug/.deps",
"build/Debug/git2.a",
"build/Debug/http_parser.a",
"build/Debug/linker.lock",
"build/Debug/obj.target",
"build/Debug/openssl.a",
"build/Debug/ssh2.a",
"build/Debug/zlib.a",
"example",
"generate",
"include",
"lifecycleScripts",
"src",
"test",
"vendor",
".astylerc",
".editorconfig",
".gitingore",
".gitmodules",
".jshintrc",
".npmignore",
".travis.yml",
"appveyor.yml",
"binding.gyp",
"TESTING.md"
];
var modulesToPrune = [
"for-node-webkit",
"which-native-nodish",
"fs-extra",
"node-pre-gyp",
"npm"
];
console.info("[nodegit] Cleaning up after ourselves.");
Promise.all([
cleanFiles(),
pruneDevDependencies(),
pruneOtherDependencies()
]).then(
function success() {
console.info("[nodegit] Done cleaning, enjoy!");
},
function failure() {
console.error("[nodegit] Couldn't finish cleaning.");
}
);
function cleanFiles() {
console.info("[nodegit] Deleting unneeded files.");
return new Promise(function(resolve, reject) {
var failures = filesToDelete.some(function(deletable) {
try {
fse.removeSync(rooted(deletable));
return false;
}
catch (e) {
console.info("[nodegit] Error deleting files. Errored on " +
rooted(deletable) + ".");
console.error(e);
reject(e);
return true;
}
});
if (!failures) {
console.info("[nodegit] Finished deleting files.");
resolve();
}
});
}
function pruneDevDependencies() {
console.info("[nodegit] Pruning devdependencies.");
return new Promise(function (resolve, reject) {
npm.commands.prune(function(err) {
if (err) {
console.error("[nodegit] Failed pruning devdependencies.");
reject(err);
}
else {
console.info("[nodegit] Successfully pruned devdependencies.");
resolve();
}
});
});
}
function pruneOtherDependencies() {
console.info("[nodegit] Cleaning unneeded dependencies.");
return new Promise(function (resolve, reject) {
npm.commands.uninstall(modulesToPrune, function(err) {
if (err) {
console.error("[nodegit] Failed cleaning unneeded dependencies.");
reject(err);
}
else {
console.info("[nodegit] Successfully cleaned unneeded dependencies.");
resolve();
}
});
});
}
});