forked from finn-no/maven-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·71 lines (61 loc) · 1.98 KB
/
cli.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
#!/usr/bin/env node
/**
* Module dependencies.
*/
var program = require('commander');
var package = require('./package.json');
var maven = require('./');
var path = require('path');
var callback = function(err, stdout, stderr, verbose){
if (err){
console.error(verbose ? stderr : err.message);
return false;
}else{
console.log(verbose ? stdout : 'done');
return true;
}
};
function parseConfigPath(config){
console.log('PARSE', config);
return path.isAbsolute(config) ? path.normalize(config) : path.normalize(path.join(process.cwd(),config));
}
program
.version(package.version)
.option('-c, --config <path>', 'Path of config file',parseConfigPath,path.normalize(path.join(process.cwd(),'.mvnconfig.json')))
.option('-v, --verbose', 'Prints all logs', 0);
program.command('package').action(function (options) {
try {
var config = require(options.parent.config);
maven.config(config);
maven.package(callback);
} catch (e) {
console.error('ERROR:');
console.error(e.message);
}
});
program.command('install').action(function (options) {
try {
var config = require(options.parent.config);
maven.config(config);
maven.package(function (err, stdout, stderr) {
if (callback(err,stdout,stderr, options.parent.verbose)){
maven.install(callback);
}
});
} catch (e) {
console.error('ERROR:');
console.error(e.message);
}
});
program.command('deploy <repoid>')
.option('-s, --snapshot', 'flags the artifact as SNAPSHOT', 0)
.action(function (repoid, options) {
var config = require(options.parent.config);
maven.config(config);
maven.package(function (err, stdout, stderr) {
if (callback(err, stdout, stderr,options.parent.verbose)) {
maven.deploy(repoid, !!options.snapshot, callback);
}
});
});
program.parse(process.argv);