-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.js
87 lines (73 loc) · 2.62 KB
/
main.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
#!/usr/bin/env node
require("./global/all");
var sys = require('sys')
var execSync = require('child_process').exec;
var CLASS = global.CLASS;
var docmaster = new CLASS.docmaster();
if (process.argv.length <= 2){
console.log("Please set input and output file path!");
process.exit(-1);
}
var defaultParams = {
"-o": {description:"Output file", varName:"output"},
"-i": {description:"Input file", varName:"input"},
"-env": {description:"Postman environment", varName:"environment"},
"-req": {description:"Call all api requests with defined methods (GET,POST,PUT,DEL) (default is '-req GET')", varName:"apiRequestMethods"},
"--iformat": {description:"Input format", varName:"inputFormat"},
"-apidocCollection": {description:"Set apidoc input collection name", varName:"apidocCollection"},
"-apidocOutput": {description:"Set apidoc output path", varName:"apidocOutput"},
};
var params = {
"environment": null,
"inputFormat": "postman",
"apiRequestMethods": "GET",
// "apidocCollection": false,
// "apidocOutput": false
// "apiRequestMethods": "GET,POST"
};
for (var i = 2; i<process.argv.length; i++){
var param = process.argv[i];
if (defaultParams.hasOwnProperty(param)){
i = i+1;
if (process.argv.length <= i){
console.log("Missing parameter ("+param+")");
process.exit(-1);
}
param = defaultParams[param].varName;
params[param] = process.argv[i];
}
}
if (!params["input"] || !params["output"]){
console.log("Missing parameter!");
process.exit(-1);
}
docmaster.setEnvironment(params.environment);
docmaster.setInputPath(params.input);
docmaster.setOutputPath(params.output);
docmaster.setFormat(params.inputFormat);
docmaster.setApiRequestMethods(params.apiRequestMethods);
docmaster.export(done);
function done(err, res){
if (err){
console.log("Error! - ", err);
}else{
console.log("");
console.log("Finished!");
console.log("");
if (params.apidocOutput && params.apidocCollection){
var apidocCommand = "apidoc -i "+params.output+ params.apidocCollection +" -o " +params.apidocOutput;
// var apidocCommand = "pwd";
console.log("");
console.log("Command: ", apidocCommand);
execSync(apidocCommand, function (error, stdout, stderr) {
console.log("");
console.log("");
console.log(stdout, stderr)
if (error !== null) {
console.log('exec error: ' + error);
}
});
// execSync("clear")
}
}
}