UNPKG

leshi-ui

Version:

Modern CLI for building and managing React Native UI components with copy-paste simplicity, custom theming, and open source design system support

42 lines (41 loc) 1.42 kB
import { FileUtils } from './file-utils.js'; export class VersionUtils { static version = null; static async getCliVersion() { if (this.version) { return this.version; } try { const cliDir = FileUtils.dirname(FileUtils.dirname(new URL(import.meta.url).pathname)); let packageJsonPath = FileUtils.join(cliDir, 'package.json'); if (!(await FileUtils.exists(packageJsonPath))) { packageJsonPath = FileUtils.join(FileUtils.dirname(cliDir), 'package.json'); } if (await FileUtils.exists(packageJsonPath)) { const packageJson = await FileUtils.readJson(packageJsonPath); this.version = packageJson.version; return this.version; } } catch (error) { } this.version = '0.0.15'; return this.version; } static versionToTag(version) { return version.startsWith('v') ? version : `v${version}`; } static async getGitHubRef() { const version = await this.getCliVersion(); if (version.includes('dev') || version.includes('local')) { return 'main'; } return this.versionToTag(version); } static isPreRelease(version) { return /-(alpha|beta|rc|dev|pre)/.test(version); } static clearCache() { this.version = null; } }