2017-04-05 21:38:15 +08:00
|
|
|
"use strict";
|
|
|
|
const path = require("path");
|
|
|
|
|
2017-04-07 21:37:38 +08:00
|
|
|
const looksLikeAbsolutePath = (maybeAbsolutePath) => {
|
2017-04-05 21:38:15 +08:00
|
|
|
return /^(?:[a-z]:\\|\/)/i.test(maybeAbsolutePath);
|
|
|
|
};
|
|
|
|
|
2017-04-07 21:37:38 +08:00
|
|
|
const normalizePathSeparator = (p) => p.replace(/\\/g, "/");
|
|
|
|
|
2017-04-05 21:38:15 +08:00
|
|
|
exports.makePathsRelative = (context, identifier) => {
|
|
|
|
return identifier
|
|
|
|
.split(/([|! ])/)
|
2017-04-07 21:37:38 +08:00
|
|
|
.map(str => looksLikeAbsolutePath(str) ?
|
|
|
|
normalizePathSeparator(path.relative(context, str)) : str)
|
2017-04-05 21:38:15 +08:00
|
|
|
.join("");
|
|
|
|
};
|