@astro-paper/cli
Version:
A comprehensive CLI tool for AstroPaper blog theme management
28 lines (27 loc) • 1.06 kB
JavaScript
import path from 'path';
import fs from 'fs-extra';
import { handleError } from './handle-error.js';
const SITE_CONFIG_REGEX = /export const SITE = ({[\s\S]*?}) as const;/;
export async function getProjectInfo(projectRoot) {
try {
const configPath = path.join(projectRoot, 'src/config.ts');
// Check if config file exists
if (!(await fs.pathExists(configPath))) {
throw new Error('Could not find config.ts in your project.');
}
// Read the config file content
const configContent = await fs.readFile(configPath, 'utf-8');
// Extract SITE object using regex
const match = SITE_CONFIG_REGEX.exec(configContent);
if (!match) {
throw new Error('Could not find SITE config in config.ts');
}
// Convert the config to a safe JavaScript object
const configObj = new Function(`return ${match[1].trim()}`)();
console.log(configObj);
return { siteConfig: configObj };
}
catch (error) {
handleError(error);
}
}