forked from allenhwkim/angular-jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
58 lines (50 loc) · 1.58 KB
/
index.js
File metadata and controls
58 lines (50 loc) · 1.58 KB
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
'use strict';
var spawn = require('child_process').spawn;
var extend = require('util')._extend;
var path = require('path');
var Q = require('q');
/**
* execute shell command
*/
var runCommand = function(cmd, args) {
var deferred = Q.defer();
console.log("angularJsdoc Running command\n", cmd, args.join(" "));
var child = spawn(cmd,args), result="";
child.stdout.on("data", function(data) {
result += data;
});
child.stderr.on("data", function(data) {result += data;});
child.stdout.on("end", function() {deferred.resolve(result);});
return deferred.promise;
};
/**
* main function
*/
var angularJsdoc = function(dirs, optionsArg, callback) {
optionsArg = optionsArg || {};
dirs = Array.isArray(dirs) ? dirs : dirs.split(" ");
//default values
var command =
optionsArg.command || path.join("node_modules", "jsdoc", "jsdoc.js");
var options = extend({
configure: path.join(__dirname, "common", "conf.json"),
template: path.join(__dirname, "default"),
destination: "docs",
readme: 'README.md'
}, optionsArg);
// if given template a single word including dash
if (optionsArg.template && optionsArg.template.match(/^[\w-]+$/i)) {
options.template = path.join(__dirname, optionsArg.template);
};
var args = [
'--configure', options.configure,
'--template', options.template,
'--destination', options.destination,
'--readme', options.readme
];
args = args.concat(['--recurse']).concat(dirs);
runCommand(command, args).then(function(output) {
callback && callback(output);
});
};
module.exports = angularJsdoc;