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
57 lines (56 loc) • 2.16 kB
JavaScript
import { FileUtils } from '../utils/file-utils.js';
export class ProjectService {
static async getProjectConfig(cwd) {
return {
framework: 'rn',
componentsDir: FileUtils.join(cwd, 'components', 'ui'),
stylesDir: FileUtils.join(cwd, 'styles'),
libDir: FileUtils.join(cwd, 'lib'),
};
}
static async isReactNativeProject(cwd) {
const packageJsonPath = FileUtils.join(cwd, 'package.json');
if (!(await FileUtils.exists(packageJsonPath))) {
return false;
}
try {
const packageJson = await FileUtils.readJson(packageJsonPath);
const dependencies = {
...packageJson.dependencies,
...packageJson.devDependencies,
};
return !!(dependencies['react-native'] ||
dependencies['expo'] ||
dependencies['@expo/cli']);
}
catch {
return false;
}
}
static getPackagesPath(framework) {
const cliDir = FileUtils.dirname(FileUtils.dirname(new URL(import.meta.url).pathname));
return FileUtils.join(cliDir, 'packages', framework);
}
static getComponentPath(framework, componentName) {
return FileUtils.join(this.getPackagesPath(framework), 'components', 'ui', `${componentName}.tsx`);
}
static getStylesPath(framework) {
return FileUtils.join(this.getPackagesPath(framework), 'styles');
}
static getLibPath(framework) {
return FileUtils.join(this.getPackagesPath(framework), 'lib');
}
static getThemesPath(framework) {
return FileUtils.join(this.getStylesPath(framework), 'themes');
}
static async getAvailableThemes(framework) {
const themesPath = this.getThemesPath(framework);
if (!(await FileUtils.exists(themesPath))) {
return [];
}
const files = await FileUtils.listFiles(themesPath);
return files
.filter(file => file.endsWith('.ts') && file !== 'index.ts' && file !== 'common.ts')
.map(file => FileUtils.basename(file, '.ts'));
}
}