|
1 | | -var fse = require("fs-extra"); |
| 1 | +var cleanForPublish = require("clean-for-publish"); |
2 | 2 | var path = require("path"); |
3 | | -var npm = require("npm"); |
4 | | -var Promise = require("nodegit-promise"); |
5 | 3 |
|
6 | | -var rooted = path.join.bind(path, __dirname, ".."); |
7 | | -if (fse.existsSync(rooted(".didntcomefromthenpmregistry"))) { |
8 | | - console.error("[nodegit] We only clean when downloaded from the npm " + |
9 | | - "registry. Skipping clean."); |
10 | | - return; |
11 | | -} |
12 | | - |
13 | | -npm.load({ |
14 | | - "production": true |
15 | | -}, function() { |
16 | | - |
17 | | - var filesToDelete = [ |
18 | | - "build/Makefile", |
19 | | - "build/binding.Makefile", |
20 | | - "build/config.gypi", |
21 | | - "build/gyp-mac-tool", |
22 | | - "build/nodegit.target.mk", |
23 | | - "build/vendor", |
24 | | - |
25 | | - "build/Release/.deps", |
26 | | - "build/Release/git2.a", |
27 | | - "build/Release/http_parser.a", |
28 | | - "build/Release/linker.lock", |
29 | | - "build/Release/obj.target", |
30 | | - "build/Release/openssl.a", |
31 | | - "build/Release/ssh2.a", |
32 | | - "build/Release/zlib.a", |
33 | | - |
34 | | - "build/Debug/.deps", |
35 | | - "build/Debug/git2.a", |
36 | | - "build/Debug/http_parser.a", |
37 | | - "build/Debug/linker.lock", |
38 | | - "build/Debug/obj.target", |
39 | | - "build/Debug/openssl.a", |
40 | | - "build/Debug/ssh2.a", |
41 | | - "build/Debug/zlib.a", |
42 | | - |
43 | | - "example", |
44 | | - "generate", |
45 | | - "include", |
46 | | - "lifecycleScripts", |
47 | | - "src", |
48 | | - "test", |
49 | | - "vendor", |
50 | | - |
51 | | - ".astylerc", |
52 | | - ".editorconfig", |
53 | | - ".gitingore", |
54 | | - ".gitmodules", |
55 | | - ".jshintrc", |
56 | | - ".npmignore", |
57 | | - ".travis.yml", |
58 | | - "appveyor.yml", |
59 | | - "binding.gyp", |
60 | | - "TESTING.md" |
61 | | - ]; |
62 | | - |
63 | | - var modulesToPrune = [ |
64 | | - "for-node-webkit", |
65 | | - "which-native-nodish", |
66 | | - "fs-extra", |
67 | | - "node-pre-gyp", |
68 | | - "npm" |
69 | | - ]; |
70 | | - |
71 | | - console.info("[nodegit] Cleaning up after ourselves."); |
72 | | - |
73 | | - Promise.all([ |
74 | | - cleanFiles(), |
75 | | - pruneDevDependencies(), |
76 | | - pruneOtherDependencies() |
77 | | - ]).then( |
78 | | - function success() { |
79 | | - console.info("[nodegit] Done cleaning, enjoy!"); |
80 | | - }, |
81 | | - function failure() { |
82 | | - console.error("[nodegit] Couldn't finish cleaning."); |
83 | | - } |
84 | | - ); |
85 | | - |
86 | | - function cleanFiles() { |
87 | | - console.info("[nodegit] Deleting unneeded files."); |
88 | | - return new Promise(function(resolve, reject) { |
89 | | - var failures = filesToDelete.some(function(deletable) { |
90 | | - try { |
91 | | - fse.removeSync(rooted(deletable)); |
92 | | - return false; |
93 | | - } |
94 | | - catch (e) { |
95 | | - console.info("[nodegit] Error deleting files. Errored on " + |
96 | | - rooted(deletable) + "."); |
97 | | - console.error(e); |
98 | | - |
99 | | - reject(e); |
100 | | - return true; |
101 | | - } |
102 | | - }); |
103 | | - |
104 | | - if (!failures) { |
105 | | - console.info("[nodegit] Finished deleting files."); |
106 | | - resolve(); |
107 | | - } |
108 | | - }); |
109 | | - } |
110 | | - |
111 | | - function pruneDevDependencies() { |
112 | | - console.info("[nodegit] Pruning devdependencies."); |
113 | | - return new Promise(function (resolve, reject) { |
114 | | - npm.commands.prune(function(err) { |
115 | | - if (err) { |
116 | | - console.error("[nodegit] Failed pruning devdependencies."); |
117 | | - reject(err); |
118 | | - } |
119 | | - else { |
120 | | - console.info("[nodegit] Successfully pruned devdependencies."); |
121 | | - resolve(); |
122 | | - } |
123 | | - }); |
124 | | - }); |
125 | | - } |
126 | | - |
127 | | - function pruneOtherDependencies() { |
128 | | - console.info("[nodegit] Cleaning unneeded dependencies."); |
129 | | - return new Promise(function (resolve, reject) { |
130 | | - npm.commands.uninstall(modulesToPrune, function(err) { |
131 | | - if (err) { |
132 | | - console.error("[nodegit] Failed cleaning unneeded dependencies."); |
133 | | - reject(err); |
134 | | - } |
135 | | - else { |
136 | | - console.info("[nodegit] Successfully cleaned unneeded dependencies."); |
137 | | - resolve(); |
138 | | - } |
139 | | - }); |
140 | | - }); |
141 | | - } |
142 | | -}); |
| 4 | +var location = path.join(__dirname, ".."); |
| 5 | +cleanForPublish(location); |
0 commit comments