UNPKG

@omlet/cli

Version:

Omlet (https://omlet.dev) is a component analytics tool that uses a CLI to scan your codebase to detect components and their usage. Get real usage insights from customizable charts to measure adoption across all projects and identify opportunities to impr

49 lines (48 loc) 1.63 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.normalizeTrimPath = exports.resolvePath = exports.listDir = exports.readIfExists = exports.pathExists = void 0; const fs_1 = require("fs"); const os_1 = __importDefault(require("os")); const upath_1 = __importDefault(require("upath")); async function pathExists(p) { try { await fs_1.promises.access(p, fs_1.constants.F_OK); return true; } catch (_a) { return false; } } exports.pathExists = pathExists; async function readIfExists(filePath) { if (await pathExists(filePath)) { return await fs_1.promises.readFile(filePath, "utf8"); } } exports.readIfExists = readIfExists; async function listDir(path) { try { return await fs_1.promises.readdir(path, { withFileTypes: true }); } catch (err) { console.error(err); return []; } } exports.listDir = listDir; function resolvePath(path) { if (path.startsWith("~/")) { return upath_1.default.resolve(os_1.default.homedir(), path.slice(2)); } return upath_1.default.resolve(process.cwd(), path); } exports.resolvePath = resolvePath; function normalizeTrimPath(inputPath) { // normalize ensures forward-slahses used and removes unnecessary . at the beginning of the path // normalizeTrim removes trailing slashes return upath_1.default.normalizeTrim(upath_1.default.normalize(inputPath)); } exports.normalizeTrimPath = normalizeTrimPath;