2017-09-03 21:31:33 +08:00
|
|
|
"use strict";
|
|
|
|
|
|
2020-03-21 22:07:52 +02:00
|
|
|
const replaceCWD = (text) => {
|
2019-11-08 20:51:51 +08:00
|
|
|
const cwd = process.cwd();
|
2020-01-23 10:34:53 +02:00
|
|
|
|
|
|
|
|
const variants = /^[a-z]:\\/i.test(cwd)
|
|
|
|
|
? [
|
|
|
|
|
cwd.charAt(0).toLowerCase() + cwd.slice(1),
|
2020-03-21 22:07:52 +02:00
|
|
|
cwd.charAt(0).toUpperCase() + cwd.slice(1),
|
2020-01-23 10:34:53 +02:00
|
|
|
]
|
|
|
|
|
: [cwd];
|
|
|
|
|
|
|
|
|
|
for (const variant of variants) {
|
|
|
|
|
while (text.includes(variant)) {
|
|
|
|
|
text = text.replace(variant, "<cwd>");
|
|
|
|
|
}
|
2019-11-08 20:51:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
};
|
|
|
|
|
|
2017-09-03 21:31:33 +08:00
|
|
|
module.exports = {
|
2020-03-21 22:07:52 +02:00
|
|
|
test: (value) =>
|
2017-09-28 19:30:51 +10:00
|
|
|
typeof value === "string" &&
|
2019-11-17 18:06:14 +08:00
|
|
|
(value.includes("\\") || value.includes(process.cwd())),
|
2017-09-03 21:31:33 +08:00
|
|
|
print: (value, serializer) =>
|
2020-03-21 22:07:52 +02:00
|
|
|
serializer(replaceCWD(value).replace(/\\/g, "/")),
|
2017-09-03 21:31:33 +08:00
|
|
|
};
|