forked from workshopper/workshopper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
print-text.js
48 lines (36 loc) · 1.11 KB
/
print-text.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
const fs = require('fs')
, path = require('path')
, colorsTmpl = require('colors-tmpl')
, msee = require('msee')
, mseeOptions = {
paragraphStart: ''
, paragraphEnd: '\n\n'
}
function printText (appName, appDir, filetype, contents) {
var variables = {
appname : appName
, rootdir : appDir
}
contents = colorsTmpl(contents)
contents = contents.replace(/\{([^}]+)\}/gi, function (match, k) {
return variables[k] || ('{' + k + '}')
})
// proper path resolution
contents = contents.replace(/\{rootdir:([^}]+)\}/gi, function (match, subpath) {
return 'file://' + path.join(appDir, subpath)
})
if (filetype == 'md') {
// convert Markdown to ANSI
contents = msee.parse(contents, mseeOptions)
}
console.log(contents)
}
function printFile (appName, appDir, file, callback) {
fs.readFile(file, 'utf8', function (err, contents) {
if (err)
throw err
printText(appName, appDir, path.extname(file).replace(/^\./, ''), contents, callback)
})
}
module.exports.text = printText
module.exports.file = printFile