astro/src/config.ts
Matthew Phillips 3c24faa8ca
hmx ☞ astro (#22)
This changes all hmx files to astro files and updates all code to not reference hmx any more.
2021-03-24 11:45:38 -04:00

22 lines
801 B
TypeScript

import type { AstroConfig } from './@types/astro';
import { join as pathJoin, resolve as pathResolve } from 'path';
import { existsSync } from 'fs';
export async function loadConfig(rawRoot: string | undefined): Promise<AstroConfig | undefined> {
if (typeof rawRoot === 'undefined') {
rawRoot = process.cwd();
}
const root = pathResolve(rawRoot);
const fileProtocolRoot = `file://${root}/`;
const astroConfigPath = pathJoin(root, 'astro.config.mjs');
if (!existsSync(astroConfigPath)) {
return undefined;
}
const astroConfig: AstroConfig = (await import(astroConfigPath)).default;
astroConfig.projectRoot = new URL(astroConfig.projectRoot + '/', fileProtocolRoot);
astroConfig.astroRoot = new URL(astroConfig.astroRoot + '/', fileProtocolRoot);
return astroConfig;
}