-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
82 lines (63 loc) · 2.16 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
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
const Drone = require('drone-node');
const plugin = new Drone.Plugin();
const Nuget = require('nuget-runner');
const path = require('path');
const shelljs = require('shelljs');
const do_push = function (nuget, workspace, vargs, file) {
var relative_path = path.relative('.', file);
console.log('Start pushing ' + file);
nuget.push(relative_path, {
source: vargs.source
}).then(function (stdout) {
console.log('Successfully pushed ' + file);
}).catch(function (err) {
console.log('An error happened while pushing: ' + err);
});
}
const do_pack_then_push = function (nuget, workspace, vargs, file) {
console.log('Start packing ' + file);
nuget.pack({
spec: file,
outputDirectory: path.dirname(file)
}).then(function(stdout) {
console.log('Successfully packed ' + file);
var package_path = file.replace('.nuspec', '*.nupkg')
var resolved_package_file = shelljs.ls(package_path)
do_push(nuget, workspace, vargs, resolved_package_file[0]);
}).catch(function (err) {
console.log('An error happened while packing: ' + err);
});
}
const do_upload = function (workspace, vargs) {
if (vargs.source) {
var nuget = new Nuget({
apiKey: vargs.api_key,
verbosity: vargs.verbosity,
nugetPath: '/usr/lib/nuget/NuGet.exe'
});
var resolved_files = [].concat.apply([], vargs.files.map((f) => { return shelljs.ls(workspace.path + '/' + f); }));
resolved_files.forEach((file) => {
if (path.extname(file) === '.nuspec') {
do_pack_then_push(nuget, workspace, vargs, file);
} else {
do_push(nuget, workspace, vargs, file);
}
});
} else {
console.log("Parameter missing: NuGet source URL");
process.exit(1)
}
}
plugin.parse().then((params) => {
// gets build and repository information for
// the current running build
const build = params.build;
const repo = params.repo;
const workspace = params.workspace;
// gets plugin-specific parameters defined in
// the .drone.yml file
const vargs = params.vargs;
vargs.verbosity || (vargs.verbosity = 'quiet');
vargs.files || (vargs.files = []);
do_upload(workspace, vargs);
});