chore(examples): modify RegExp in template-common

This commit is contained in:
Yuta Hiroto 2019-04-04 22:14:54 +01:00
parent eb7d7ea678
commit 83b0013209
No known key found for this signature in database
GPG Key ID: E03998F3E2B165C2
1 changed files with 3 additions and 3 deletions

View File

@ -51,15 +51,15 @@ exports.replaceBase = (template) => {
};
exports.needResults = (template, prefix) => {
const regExp = prefix ? new RegExp(`\\{\\{${prefix}:`) : /\{\{/;
const regExp = prefix ? new RegExp(`_\\{\\{${prefix}:`) : /_\{\{/;
return regExp.test(template);
};
exports.replaceResults = (template, baseDir, stdout, prefix) => {
const regexp = new RegExp("\\{\\{" + (prefix ? prefix + ":" : "") + "([^:\\}]+)\\}\\}", "g");
const regexp = new RegExp("_\\{\\{" + (prefix ? prefix + ":" : "") + "([^:\\}]+)\\}\\}_", "g");
return template.replace(regexp, function(match) {
match = match.substr(2 + (prefix ? prefix.length + 1 : 0), match.length - 4 - (prefix ? prefix.length + 1 : 0));
match = match.substr(3 + (prefix ? prefix.length + 1 : 0), match.length - 6 - (prefix ? prefix.length + 1 : 0));
if(match === "stdout")
return stdout;
return fs.readFileSync(path.join(baseDir, match), "utf-8").replace(/[\r\n]*$/, "");