-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·52 lines (40 loc) · 1.56 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
#! /usr/bin/env node
const args = require('chen.js').args();
const config = require('./lib/config');
const glob = require('glob');
const md_only = require('./lib/predicate_md_files');
const build_document = require('./lib/document_builder');
const debug = require('./lib/debug').extend('main');
if(args.v || args.version || args.h || args.help){
const package_info = require('./package.json');
console.log(`${package_info.name} \t v.${package_info.version}`);
console.log(``);
console.log(`\t* npm: \t\t https://npmjs.org/package/${package_info.name}`);
console.log(`\t* github: \t ${package_info.repository.url}`);
console.log(`\t* readme: \t ${package_info.repository.url.split('.git')[0]}/blob/master/readme.md`);
console.log(`\t* author: \t ${package_info.author}`);
return;
}
const markdown_files = args._
.map(pattern => glob.sync(pattern))
.reduce((a, b) => a.concat(b), [])
.filter(md_only);
debug("Searching for md files", markdown_files);
const targets = markdown_files.length ? markdown_files : glob.sync('*.md');
debug("Found target files", targets);
const types = [args.type || args.t || config.type || 'pdf'].reduce((a, b) => a.concat(b), []);
debug("Build types", types);
const errorHandler = r => {
if(r.stderr)
console.error(r.stderr);
if(r.stdout)
console.log(r.stdout);
else
console.error(r);
process.exit(1);
};
types.forEach(type => {
debug("Building type", type, targets);
build_document(type, targets).catch(errorHandler);
});
process.on('unhandledRejection', errorHandler);