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