don't show absolute paths
This commit is contained in:
parent
bbeea2717d
commit
914064ecdf
|
@ -5,18 +5,32 @@
|
|||
var fs = require("fs");
|
||||
var path = require("path");
|
||||
|
||||
function lessStrict(regExpStr) {
|
||||
regExpStr = regExpStr
|
||||
.replace(/node_modules/g, "(node_modules|~)")
|
||||
.replace(/(\\\/|\\\\)/g, "[\\/\\\\]")
|
||||
return regExpStr;
|
||||
}
|
||||
|
||||
module.exports = function(template, baseDir, stdout, prefix) {
|
||||
|
||||
var regexp = new RegExp("\\{\\{" + (prefix ? prefix+":" : "") + "([^:\\}]+)\\}\\}", "g")
|
||||
var cwd = process.cwd();
|
||||
cwd = cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
||||
var webpack = path.join(__dirname, "..");
|
||||
var webpackParent = path.join(__dirname, "..", "..");
|
||||
cwd = lessStrict(cwd.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
|
||||
cwd = new RegExp(cwd, "g");
|
||||
webpack = lessStrict(webpack.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
|
||||
webpack = new RegExp(webpack, "g");
|
||||
webpackParent = lessStrict(webpackParent.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
|
||||
console.log(webpackParent);
|
||||
webpackParent = new RegExp(webpackParent, "g");
|
||||
|
||||
return template.replace(regexp, function(match) {
|
||||
match = match.substr(2 + (prefix ? prefix.length+1 : 0), match.length - 4 - (prefix ? prefix.length+1 : 0));
|
||||
if(match === "stdout")
|
||||
return stdout;
|
||||
return fs.readFileSync(path.join(baseDir, match), "utf-8");
|
||||
}).replace(cwd, ".");
|
||||
}).replace(cwd, ".").replace(webpack, "(webpack)").replace(webpackParent, "(webpack)/~");
|
||||
|
||||
}
|
Loading…
Reference in New Issue