UNPKG

@forwardslashns/fws-cli

Version:

CLI meant to work together with other Forwardslash boilerplates.

24 lines (22 loc) 940 B
import { existsSync, readdirSync } from 'fs'; import { resolve } from 'path'; export const getPackageJsonAndRootPath = () => { try { if (existsSync(resolve(process.cwd(), 'wp-content', 'themes'))) { const themesDir = readdirSync(resolve(process.cwd(), 'wp-content', 'themes')); if (themesDir.length) { const theme = themesDir.find((dir) => dir.startsWith('fws-')); if (theme) { return { jsonPath: resolve(process.cwd(), 'wp-content', 'themes', theme, 'package.json'), rootPath: resolve(process.cwd(), 'wp-content', 'themes', theme), }; } } } return { jsonPath: resolve(process.cwd(), 'package.json'), rootPath: resolve(process.cwd()) }; } catch (err) { console.log(err); return { jsonPath: '', rootPath: '' }; } };