Skip to content

Commit

Permalink
fixed regex for including external json files
Browse files Browse the repository at this point in the history
  • Loading branch information
media-square committed Feb 13, 2018
1 parent 5897e85 commit 6da3806
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/index.js
Expand Up @@ -128,7 +128,7 @@ module.exports = function(opts) {
}

function includeHandler(inst) {
var args = /[^)"']*["']([^"']*)["'](,\s*({[\s\S]*})){0,1}\s*/.exec(inst.args)
var args = /^['|"]([^'|"]*)['|"](,\s*({[\s\S]*}|['|"]([^'|"]*)['|"]|\s*)|)/.exec(inst.args)

if (args) {
var includePath = path.resolve(filebase, args[1])
Expand Down Expand Up @@ -158,7 +158,19 @@ module.exports = function(opts) {
contents: Buffer.from(includeContent)
})

recFile = include(recFile, includeContent, args[3] ? JSON.parse(args[3]) : {})
var data = {};
if(args[4]){
var jsonfile = file.base + args[4];
if (fs.existsSync(jsonfile)) {
data = require(jsonfile)
} else {
return console.error('JSON file not exists:', jsonfile)
}
}else if(args[3]) {
data = JSON.parse(args[3]);
}

recFile = include(recFile, includeContent, data)

return String(recFile.contents)
}
Expand Down

0 comments on commit 6da3806

Please sign in to comment.