-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathindex.js
89 lines (75 loc) · 2.99 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
83
84
85
86
87
88
89
'use strict';
var log = require('npmlog')
, rmrf = require('rimraf')
, runnel = require('runnel')
, cloneWiki = require('./lib/clone-wiki')
, runJsdoc = require('./lib/run-jsdoc')
, wikify = require('./lib/wikify')
, sidebar = require('./lib/sidebar')
, commitWiki = require('./lib/commit-wiki')
, runDoctoc = require('./lib/run-doctoc')
function clean(tmpdir, cb) {
log.info('wicked', 'Cleaning up ...');
log.verbose('wicked', 'Removing tmp dir', tmpdir);
rmrf(tmpdir, cb);
}
function tellmeWhere(repodir, cb) {
log.info('wicked', 'Wiki cloned to and upated at', repodir);
cb();
}
/** @namespace Public
* @desc Public wicked API
*/
/**
* Generates jsdoc wiki pages for project of current working directory and updates github wiki with them.
*
* ##### Note
*
* It is assumed that this is run from the root of the project whose wiki should be generated.
* Additionally the currently checked out branch will be used when generating blob urls to link source examples.
*
* However the github remote and branch can also be set via environment vars as explained in the
* [documentation of jsdoc-githubify]{@link https://github.com/thlorenz/jsdoc-githubify#note} which is used
* by wicked under the hood.
*
* @name wicked
* @memberof Public
* @function
* @param {Object} args consumed by wicked
* @param {Boolean=} args.noclean (false) if true, the temp directory into which wiki is checked out will **not be removed** when done
* @param {Boolean=} args.nocommit (false) if true, the updated wiki will **not be committed automatically**
* @param {Boolean=} args.toc (false) if true, a table of contents is added to each generated wiki
* @param {String=} args.loglevel (info) level at which to log: silly|verbose|info|warn|error|silent
* @param {Array.<String>} jsdocargs consumed by jsdoc
* @param {Function(Error)} cb called back when wicked finished generating the wiki page
*/
var go = module.exports = function wicked(args, jsdocargs, cb) {
args = args || {};
jsdocargs = jsdocargs || [];
log.level = args.loglevel || 'info';
// Not ideal to use cwd here, but resolve-github-(remote|branch) run git in current dir
// So before we can actually override the root properly those tools need a PR
var projectRoot = process.cwd();
function updateWiki(info, cb) {
var tasks = [
runJsdoc.bind(null, projectRoot, info.root, jsdocargs)
, wikify.bind(null, info.repo.dir)
, sidebar.bind(null, info.repo.dir)
];
if (args.toc) tasks.push(function (cb_) {
runDoctoc(info.repo.dir, cb_);
})
tasks.push(args.nocommit ? tellmeWhere.bind(null, info.repo.dir) : commitWiki.bind(null, info.repo));
if (!args.noclean && !args.nocommit) tasks.push(clean.bind(null, info.root));
tasks.push(cb);
runnel(tasks);
}
cloneWiki(function (err, info) {
if (err) return cb(err);
updateWiki(info, cb);
})
};
/** @namespace Internal
* @desc Internal wicked functions
* @private
*/