liferay-npm-bundler-preset-reactjs
Version:
liferay npm bundler preset react
70 lines (69 loc) • 2.3 kB
JavaScript
"use strict";
/**
* SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
class FilePath {
constructor(nativePath, { posix = false } = {}) {
if (posix && !FilePath.nativeIsPosix) {
nativePath = nativePath.replace(/\//g, '\\');
}
this._nativePath = nativePath;
if (FilePath.nativeIsPosix) {
this._posixPath = nativePath;
this._windowsPath = nativePath.replace(/\//g, '\\');
}
else {
this._posixPath = nativePath.replace(/\\/g, '/');
this._windowsPath = nativePath;
}
}
toString() {
return this.asNative;
}
get asNative() {
return this._nativePath;
}
get asPosix() {
return this._posixPath;
}
get asWindows() {
return this._windowsPath;
}
basename() {
return new FilePath(path_1.default.basename(this.asNative));
}
dirname() {
return new FilePath(path_1.default.dirname(this.asNative));
}
is(anyPath) {
if (typeof anyPath === 'string') {
anyPath = new FilePath(anyPath);
}
return anyPath.resolve().asNative === this.resolve().asNative;
}
join(...anyPathFragments) {
const join = FilePath.nativeIsPosix ? path_1.default.posix.join : path_1.default.win32.join;
return new FilePath(join(this.toString(), ...anyPathFragments.map((nativePathFragment) => nativePathFragment.toString())));
}
normalize() {
return new FilePath(path_1.default.normalize(this.asNative));
}
relative(anyPath) {
return new FilePath(path_1.default.relative(this.asNative, anyPath.toString()));
}
resolve() {
const resolvedPath = path_1.default.resolve(this.asNative);
if (resolvedPath === this.asNative) {
return this;
}
return new FilePath(resolvedPath);
}
}
exports.default = FilePath;
FilePath.nativeIsPosix = path_1.default.sep === '/';