|
|
@ -119,6 +119,7 @@ export interface SiteConfig<ThemeConfig = any>
|
|
|
|
srcDir: string
|
|
|
|
srcDir: string
|
|
|
|
site: SiteData<ThemeConfig>
|
|
|
|
site: SiteData<ThemeConfig>
|
|
|
|
configPath: string | undefined
|
|
|
|
configPath: string | undefined
|
|
|
|
|
|
|
|
configDeps: string[]
|
|
|
|
themeDir: string
|
|
|
|
themeDir: string
|
|
|
|
outDir: string
|
|
|
|
outDir: string
|
|
|
|
tempDir: string
|
|
|
|
tempDir: string
|
|
|
@ -150,7 +151,11 @@ export async function resolveConfig(
|
|
|
|
command: 'serve' | 'build' = 'serve',
|
|
|
|
command: 'serve' | 'build' = 'serve',
|
|
|
|
mode = 'development'
|
|
|
|
mode = 'development'
|
|
|
|
): Promise<SiteConfig> {
|
|
|
|
): Promise<SiteConfig> {
|
|
|
|
const [userConfig, configPath] = await resolveUserConfig(root, command, mode)
|
|
|
|
const [userConfig, configPath, configDeps] = await resolveUserConfig(
|
|
|
|
|
|
|
|
root,
|
|
|
|
|
|
|
|
command,
|
|
|
|
|
|
|
|
mode
|
|
|
|
|
|
|
|
)
|
|
|
|
const site = await resolveSiteData(root, userConfig)
|
|
|
|
const site = await resolveSiteData(root, userConfig)
|
|
|
|
const srcDir = path.resolve(root, userConfig.srcDir || '.')
|
|
|
|
const srcDir = path.resolve(root, userConfig.srcDir || '.')
|
|
|
|
const outDir = userConfig.outDir
|
|
|
|
const outDir = userConfig.outDir
|
|
|
@ -183,6 +188,7 @@ export async function resolveConfig(
|
|
|
|
themeDir,
|
|
|
|
themeDir,
|
|
|
|
pages,
|
|
|
|
pages,
|
|
|
|
configPath,
|
|
|
|
configPath,
|
|
|
|
|
|
|
|
configDeps,
|
|
|
|
outDir,
|
|
|
|
outDir,
|
|
|
|
tempDir: resolve(root, '.temp'),
|
|
|
|
tempDir: resolve(root, '.temp'),
|
|
|
|
markdown: userConfig.markdown,
|
|
|
|
markdown: userConfig.markdown,
|
|
|
@ -206,32 +212,32 @@ async function resolveUserConfig(
|
|
|
|
root: string,
|
|
|
|
root: string,
|
|
|
|
command: 'serve' | 'build',
|
|
|
|
command: 'serve' | 'build',
|
|
|
|
mode: string
|
|
|
|
mode: string
|
|
|
|
): Promise<[UserConfig, string | undefined]> {
|
|
|
|
): Promise<[UserConfig, string | undefined, string[]]> {
|
|
|
|
// load user config
|
|
|
|
// load user config
|
|
|
|
const configPath = supportedConfigExtensions
|
|
|
|
const configPath = supportedConfigExtensions
|
|
|
|
.map((ext) => resolve(root, `config.${ext}`))
|
|
|
|
.map((ext) => resolve(root, `config.${ext}`))
|
|
|
|
.find(fs.pathExistsSync)
|
|
|
|
.find(fs.pathExistsSync)
|
|
|
|
|
|
|
|
|
|
|
|
const userConfig: RawConfigExports = configPath
|
|
|
|
let userConfig: RawConfigExports = {}
|
|
|
|
? ((
|
|
|
|
let configDeps: string[] = []
|
|
|
|
await loadConfigFromFile(
|
|
|
|
if (!configPath) {
|
|
|
|
{
|
|
|
|
|
|
|
|
command,
|
|
|
|
|
|
|
|
mode
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
configPath,
|
|
|
|
|
|
|
|
root
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)?.config as any)
|
|
|
|
|
|
|
|
: {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (configPath) {
|
|
|
|
|
|
|
|
debug(`loaded config at ${c.yellow(configPath)}`)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
debug(`no config file found.`)
|
|
|
|
debug(`no config file found.`)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
const configExports = await loadConfigFromFile(
|
|
|
|
|
|
|
|
{ command, mode },
|
|
|
|
|
|
|
|
configPath,
|
|
|
|
|
|
|
|
root
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
if (configExports) {
|
|
|
|
|
|
|
|
userConfig = configExports.config
|
|
|
|
|
|
|
|
configDeps = configExports.dependencies.map((file) =>
|
|
|
|
|
|
|
|
normalizePath(path.resolve(file))
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(`loaded config at ${c.yellow(configPath)}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return [await resolveConfigExtends(userConfig), configPath]
|
|
|
|
return [await resolveConfigExtends(userConfig), configPath, configDeps]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function resolveConfigExtends(
|
|
|
|
async function resolveConfigExtends(
|
|
|
|