@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
58 lines (56 loc) • 2.16 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
const NodeFolder_1 = require("./NodeFolder");
const StorageBase_1 = require("../storage/StorageBase");
const path = require("path");
class NodeStorage extends StorageBase_1.default {
get folderDelimiter() {
return path.sep;
}
constructor(incomingPath, name) {
super();
if (NodeStorage.platformFolderDelimiter === "\\") {
incomingPath = incomingPath.replace(/\//gi, NodeStorage.platformFolderDelimiter);
incomingPath = incomingPath.replace(/\\\\/gi, "\\");
}
else if (NodeStorage.platformFolderDelimiter === "/") {
incomingPath = incomingPath.replace(/\\/gi, NodeStorage.platformFolderDelimiter);
incomingPath = incomingPath.replace(/\/\//gi, NodeStorage.platformFolderDelimiter);
}
this.rootPath = incomingPath;
this.name = name;
this.rootFolder = new NodeFolder_1.default(this, null, incomingPath, name);
}
joinPath(pathA, pathB) {
let fullPath = pathA;
if (!fullPath.endsWith(NodeStorage.platformFolderDelimiter)) {
fullPath += NodeStorage.platformFolderDelimiter;
}
fullPath += pathB;
return fullPath;
}
static getParentFolderPath(parentPath) {
const lastDelim = parentPath.lastIndexOf(this.platformFolderDelimiter);
if (lastDelim < 0) {
return parentPath;
}
return parentPath.substring(0, lastDelim);
}
static ensureEndsWithDelimiter(pth) {
if (!pth.endsWith(NodeStorage.platformFolderDelimiter)) {
pth = pth + NodeStorage.platformFolderDelimiter;
}
return pth;
}
static ensureStartsWithDelimiter(pth) {
if (!pth.startsWith(NodeStorage.platformFolderDelimiter)) {
pth = NodeStorage.platformFolderDelimiter + pth;
}
return pth;
}
}
exports.default = NodeStorage;
NodeStorage.platformFolderDelimiter = path.sep;
//# sourceMappingURL=../maps/local/NodeStorage.js.map