jingrow-ui/vite/utils.js
jingrow c7bac1a7a0
Some checks failed
Publish on NPM / publish (push) Has been cancelled
Build and Deploy Storybook / build (push) Has been cancelled
Tests / test (push) Has been cancelled
initial commit
2025-10-24 00:40:30 +08:00

43 lines
1.1 KiB
JavaScript

import path from 'path'
import fs from 'fs'
export function getConfig() {
let configPath = path.join(process.cwd(), 'jingrowui.json')
if (fs.existsSync(configPath)) {
return JSON.parse(fs.readFileSync(configPath))
}
}
export function getCommonSiteConfig() {
let currentDir = path.resolve('.')
// traverse up till we find jingrow-bench with sites directory
while (currentDir !== '/') {
if (
fs.existsSync(path.join(currentDir, 'sites')) &&
fs.existsSync(path.join(currentDir, 'apps'))
) {
let configPath = path.join(currentDir, 'sites', 'common_site_config.json')
if (fs.existsSync(configPath)) {
return JSON.parse(fs.readFileSync(configPath))
}
return null
}
currentDir = path.resolve(currentDir, '..')
}
return null
}
export function findAppsFolder() {
let currentDir = process.cwd()
while (currentDir !== '/') {
if (
fs.existsSync(path.join(currentDir, 'apps')) &&
fs.existsSync(path.join(currentDir, 'sites'))
) {
return path.join(currentDir, 'apps')
}
currentDir = path.resolve(currentDir, '..')
}
return null
}