/
njake.js
305 lines (231 loc) · 9.63 KB
/
njake.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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
(function () {
var
spawn = require('child_process').spawn,
path = require('path'),
fs = require('fs');
var extend = function (obj) {
var args = Array.prototype.slice.call(arguments);
if (args.length == 0) return {};
args.slice(1).forEach(function (source) {
for (var prop in source)
obj[prop] = source[prop];
});
return obj;
};
exports.exec = function (cmd, opts, callback) {
var command = spawn(cmd, opts || [], { customFds: [0, 1, 2] });
command.on('exit', function (code) { if (callback) callback(code); });
};
exports.msbuild = (function () {
var defaults = {
processor: 'x86',
version: 'net2.0'
};
var task = function (opts, callback) {
var opt = extend({}, defaults, opts),
args = [];
if (!opt.file) fail('msbuild failed - file required');
if (!opt._exe) {
if (!opt.processor) fail('msbuild failed - processor required');
if (!opt.version) fail('msbuild failed - version required');
opt._exe = exports.getDotNetVersionPath(opt.version, opt.processor) + 'MSBuild.exe';
}
args.push(opt.file);
if (opt.targets)
opts.targets.forEach(function (target) { args.push('/t:' + target); });
if (opt.properties) {
for (var key in opt.properties)
args.push('/p:' + key + '=' + opt.properties[key])
}
args.push.apply(args, opt._parameters || []);
exports.exec(opt._exe, args, function (code) {
if (code !== 0) fail('msbuild failed')
callback ? callback(code) : complete();
});
};
task.setDefaults = function (opts) {
extend(defaults, opts);
return defaults;
};
return task;
})();
exports.xunit = (function () {
var defaults = {};
var task = function (opts, callback) {
var opt = extend({}, defaults, opts),
args = [];
if (!opt._exe) fail('xunit failed - _exe required');
if (!opt.assembly) fail('xunit failed - assembly required');
args.push(opt.assembly);
args.push.apply(args, opt._parameters || []);
exports.exec(opt._exe, args, function (code) {
if (code !== 0) fail('xunit failed')
callback ? callback(code) : complete();
});
};
task.setDefaults = function (opts) {
extend(defaults, opts);
return defaults;
};
return task;
})();
exports.nunit = (function () {
var defaults = {};
var task = function (opts, callback) {
var opt = extend({}, defaults, opts),
args = [];
if (!opt._exe) fail('nunit failed - _exe required');
if (!opt.assemblies) failed('nunit failed - assemblies required');
opt.assemblies.forEach(function (assembly) { args.push(assembly); });
args.push.apply(args, opt._parameters || []);
exports.exec(opt._exe, args, function (code) {
if (code !== 0) fail('nunit failed');
callback ? callback(code) : complete();
});
};
task.setDefaults = function (opts) {
extend(defaults, opts);
return defaults;
};
return task;
})();
exports.nuget = (function () {
var defaults = {
_exe: 'NuGet.exe'
};
var task = {};
task.pack = function (opts, callback) {
var opt = extend({}, defaults, opts),
args = [];
args.push('pack');
if (!opt._exe) fail('nuget.pack failed - _exe required');
if (!opt.nuspec) fail('nuget.pack failed - nuspec required');
args.push(opt.nuspec);
if (opt.outputDirectory) {
args.push('-OutputDirectory')
args.push(opt.outputDirectory);
}
if (opt.verbose) args.push('-Verbose');
if (opt.version) {
args.push('-Version');
args.push(opt.version);
}
if (opt.properties) {
for (var key in opt.properties) {
args.push('-Properties');
args.push(key + '=' + opt.properties[key])
}
}
args.push.apply(args, opt._parameters || []);
exports.exec(opt._exe, args, function (code) {
if (code !== 0) fail('nuget.pack failed')
callback ? callback(code) : complete();
});
};
task.push = function (opts, callback) {
var opt = extend({}, defaults, opts),
args = [];
args.push('push');
if (!opt._exe) fail('nuget.push failed - _exe required');
if (!opt.package) fail('nuget.push failed - package required');
args.push(opt.package);
if (opt.apiKey) args.push(opt.apiKey);
if (opt.createOnly) args.push('-CreateOnly');
if (opt.source && opt.source !== '') {
args.push('-Source');
args.push(opt.source);
}
args.push.apply(args, opt._parameters || []);
exports.exec(opt._exe, args, function (code) {
if (code !== 0) fail('nuget.push failed');
callback ? callback(code) : complete();
});
};
task.setDefaults = function (opts) {
extend(defaults, opts);
return defaults;
};
task.sources = {
symbolSource: 'http://nuget.gw.symbolsource.org/Public/NuGet'
};
return task;
})();
exports.assemblyinfo = (function () {
var defaults = {
language: 'c#',
namespaces: ['System.Reflection', 'System.Runtime.InteropServices']
};
var supportedLangagues = ['c#'];
var task = function (opts, callback) {
var opt = extend({}, defaults, opts),
contents = '',
assemblyValue;
if (!opt.file) fail('assemblyinfo failed - file required');
if (!opt.language) fail('assemblyinfo failed - language required');
if (opt.language === 'c#') {
if (opt.namespaces) {
opt.namespaces.forEach(function (ns) {
contents += 'using ' + ns + ';\r\n';
});
}
if (opt.assembly) {
for (var key in opt.assembly) {
assemblyValue = opt.assembly[key];
if (typeof assemblyValue === 'function') {
contents += assemblyValue();
continue;
}
contents += '[assembly: ' + key + '(';
if (typeof assemblyValue === 'boolean')
contents += assemblyValue ? 'true' : 'false';
else
contents += '\"' + assemblyValue + '\"';
contents += ')]\r\n';
}
}
fs.writeFileSync(opt.file, contents);
} else {
fail('assemblyinfo failed - unsupported language. choose ' + supportedLangagues);
}
callback ? callback(0) : complete();
};
task.setDefaults = function (opts) {
extend(defaults, opts);
return defaults;
}
return task;
})();
exports.getWinDir = function () {
var winDir = process.env.WINDIR;
return path.normalize((winDir.substr(-1) === '/' || winDir.substr(-1) === '\\') ? winDir : (winDir + '/')); // append / if absent
};
exports.dotNetVersionMapper = {
'processor': {
'x86': 'Framework',
'x64': 'Framework64'
},
'version': {
'net1.0': '1.0.3705',
'net1.1': '1.1.4322',
'net2.0': '2.0.50727',
'net3.5': '3.5',
'net4.0': '4.0.30319'
}
};
exports.getDotNetVersionPath = function (version, processor) {
// http://msdn.microsoft.com/en-us/library/dd414023.aspx
// http://docs.nuget.org/docs/creating-packages/creating-and-publishing-a-package#Grouping_Assemblies_by_Framework_Version
// make it processor instead of bit, just incase MS releases FrameworkARM ;)
var actualProcessor = exports.dotNetVersionMapper['processor'][processor];
var actualVersion = exports.dotNetVersionMapper['version'][version];
if (typeof actualProcessor === 'undefined' || typeof actualVersion === 'undefined') {
fail('specified .NET framework is not supported : ' + version + '(' + processor + ')');
return;
}
var netFrameworkPath = exports.getWinDir() +
'Microsoft.Net\\' +
exports.dotNetVersionMapper['processor'][processor] + '\\v' +
exports.dotNetVersionMapper['version'][version] + '\\';
return netFrameworkPath;
};
})();