UNPKG

1.14 kBJavaScriptView Raw
1const fs = require('fs')
2 , path = require('path')
3 , colorsTmpl = require('colors-tmpl')
4 , msee = require('msee')
5 , mseeOptions = {
6 paragraphStart: ''
7 , paragraphEnd: '\n\n'
8 }
9
10
11function printText (appName, appDir, filetype, contents) {
12 var variables = {
13 appname : appName
14 , rootdir : appDir
15 }
16
17 contents = colorsTmpl(contents)
18
19 contents = contents.replace(/\{([^}]+)\}/gi, function (match, k) {
20 return variables[k] || ('{' + k + '}')
21 })
22
23 // proper path resolution
24 contents = contents.replace(/\{rootdir:([^}]+)\}/gi, function (match, subpath) {
25 return 'file://' + path.join(appDir, subpath)
26 })
27
28 if (filetype == 'md') {
29 // convert Markdown to ANSI
30 contents = msee.parse(contents, mseeOptions)
31 }
32
33 console.log(contents)
34}
35
36
37function printFile (appName, appDir, file, callback) {
38 fs.readFile(file, 'utf8', function (err, contents) {
39 if (err)
40 throw err
41
42 printText(appName, appDir, path.extname(file).replace(/^\./, ''), contents, callback)
43 })
44}
45
46
47module.exports.text = printText
48module.exports.file = printFile