diff --git a/bin/mustache b/bin/mustache index 430e8b937..442f2d07a 100755 --- a/bin/mustache +++ b/bin/mustache @@ -53,11 +53,20 @@ function run (/*args*/) { } function readView (cb) { - var view = isStdin(viewArg) ? process.openStdin() : fs.createReadStream(viewArg); - - streamToStr(view, function onDone (str) { - cb(parseView(str)); - }); + let view; + if (isJson(viewArg)) { + view = require(path.join(process.cwd(),viewArg)); + cb(view); + } else { + if (isStdin(viewArg)) { + view = process.openStdin(); + } else { + view = fs.createReadStream(viewArg); + } + streamToStr(view, function onDone (str) { + cb(parseView(str)); + }); + } } function parseView (str) { @@ -121,6 +130,10 @@ function isStdin (view) { return view === '-'; } +function isJson (view) { + return path.parse(view).ext === '.js'; +} + function wasNotFound (err) { return err.code && err.code === 'ENOENT'; }