@enonic/mock-xp
Version:
Mock Enonic XP API JavaScript Library
41 lines (40 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.mockResolve = mockResolve;
var path_1 = require("path");
var ResourceKey_1 = require("../implementation/app/ResourceKey");
function _getCallerFile() {
var originalFunc = Error.prepareStackTrace;
var callerfile;
try {
var err = new Error();
Error.prepareStackTrace = function (_err, stack) { return stack; };
var v8StackArray = err.stack;
var currentfile = v8StackArray.shift().getFileName();
while (v8StackArray.length) {
callerfile = v8StackArray.shift().getFileName();
if (currentfile !== callerfile)
break;
}
}
catch (e) { }
Error.prepareStackTrace = originalFunc;
return callerfile;
}
function mockResolve(_a) {
var applicationKey = _a.applicationKey, basePath = _a.basePath;
return function (path) {
if (path.startsWith('/')) {
return new ResourceKey_1.ResourceKey({
applicationKey: applicationKey,
path: (0, path_1.join)(basePath, ".".concat(path))
});
}
var callerFile = _getCallerFile();
var dir = (0, path_1.dirname)(callerFile);
return new ResourceKey_1.ResourceKey({
applicationKey: applicationKey,
path: (0, path_1.join)(dir, path)
});
};
}