-
Notifications
You must be signed in to change notification settings - Fork 733
/
generate-docs.js
executable file
·36 lines (26 loc) · 1.01 KB
/
generate-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
#!/usr/bin/env node
/* globals cat, cd, echo, grep, sed, ShellString */
require('../global');
var path = require('path');
echo('Appending docs to README.md');
cd(path.join(__dirname, '..'));
// Extract docs from shell.js
var docs = grep('^//@', 'shell.js');
// Insert the docs for all the registered commands
docs = docs.replace(/\/\/@commands\n/g, function () {
return require('../commands').map(function (commandName) {
var file = './src/' + commandName + '.js';
return grep('^//@', file) + '\n';
}).join('');
});
// Now extract docs from the remaining src/*.js files
docs = docs.replace(/\/\/@include (.+)/g, function (match, filename) {
return grep('^//@', filename);
});
// Remove '//@'
docs = docs.replace(/\/\/@ ?/g, '');
// Wipe out the old docs
ShellString(cat('README.md').replace(/## Command reference(.|\n)*\n## Team/, '## Command reference\n## Team')).to('README.md');
// Append new docs to README
sed('-i', /## Command reference/, '## Command reference\n\n' + docs, 'README.md');
echo('All done.');