-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-docs.js
102 lines (99 loc) · 3.47 KB
/
build-docs.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
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Build jsdocs and make github wiki pages
* TODO may cancel this
*/
var conf = require('./conf.json'),
fs = require('fs'),
path = require('path'),
exec = require('child_process').exec,
color = require('colors'),
child,
bodyRegex = /<body>[\s\S]*<\/body>/,
isHTML = /\.html$/,
destination = conf.opts.destination,
openHandles = 0,
i = 0,
jsRegex = /\.js$/,
filterHTML = function (filepath) {
return isHTML.test(filepath);
},
parse = function (filepath) {
var matches;
console.log('parsing filepath ' + filepath);
fs.readFile(filepath, function (err, data) {
if (err) {
console.log(err);
} else {
matches = data.toString().match(bodyRegex);
if (null !== matches && matches.length > 0) {
//sloppy scrunch
//matches = matches[1].replace(/[\n\r]+/gm, '').replace(/ +/gm, ' ');
matches = matches[0].replace(/\.html/gm, '');
filepath = path.basename(filepath, '.html');
if (filepath === 'index') {
var homepath = path.join(
destination,
'wiki',
'Home.textile'
);
fs.writeFile(homepath, matches, function (err) {
if (err) {
console.log(err);
} else {
console.log('wiki home file saved: ' + homepath.green);
}
});
} else {
filepath = path.join(
destination,
'wiki',
filepath + '.textile'
);
console.log('creating wiki file: ' + filepath.cyan);
fs.writeFile(filepath, matches, function (err) {
if (err) {
console.log(err);
} else {
console.log('wiki file saved: ' + filepath.green);
}
});
}
}
}
});
},
parseDirectory = function (filepaths) {
console.log('parsing directory'.green, filepaths);
filepaths = filepaths.filter(filterHTML);
if (filepaths.length > 0) {
var i = 0;
for (i; i < filepaths.length; i++) {
parse(path.join(destination, filepaths[i]));
}
}
},
readDestination = function () {
var read = function (err, filepaths) {
if (err) {
console.log(err);
} else {
parseDirectory(filepaths);
}
};
fs.readdir(destination, read);
};
/**
for (i; i < paths.length; i++) {
statFile(paths[i]);
}*/
var buildDocs = './node_modules/jsdoc/jsdoc.js -c ./conf.json',
execHandler = function (err, stdout, stderr) {
if (err) {
console.log(err);
} else {
//make sure wiki directory exists
fs.mkdir(path.join(destination, 'wiki'), readDestination);
}
};
child = exec(buildDocs, execHandler);
//EOF build-docs.js