forked from allenhwkim/angular-jsdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
69 lines (55 loc) · 1.88 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
'use strict';
var spawn = require('child_process').spawn;
var extend = require('util')._extend;
var path = require('path');
var Q = require('q');
var util = require("util");
/**
* execute shell command
*/
var runCommand = function(cmd, args) {
var deferred = Q.defer();
console.log("cwd is: " + __dirname);
console.log("angularJsdoc Running command\n", cmd, args.join(" "));
var child = (process.platform === "win32")
// For windows need to spawn a "cmd" instance and pass the command to it
? spawn("cmd", ["/C", cmd + " " + args.join(" ")], { cwd: process.env.PWD, env: process.env})
: spawn(cmd, args);
var 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 || util.format("node %s", 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;