From e4305c5add78b74dddf896911528cfd7ca20b682 Mon Sep 17 00:00:00 2001 From: Eugene Date: Sun, 23 Aug 2020 17:37:06 +0300 Subject: [PATCH] feat: add autoload config with js, json and yml ext --- src/cli/build.ts | 2 +- src/core/config.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cli/build.ts b/src/cli/build.ts index 1240250..346eccf 100644 --- a/src/cli/build.ts +++ b/src/cli/build.ts @@ -16,7 +16,7 @@ export default class Build extends Command { config: flags.string({ char: 'c', description: 'The path to a themekit config file.', - default: 'themekit.config.json', + default: 'themekit.config.{js,json,yml}', }), watch: flags.boolean({ char: 'w', diff --git a/src/core/config.ts b/src/core/config.ts index 0454444..7cce524 100644 --- a/src/core/config.ts +++ b/src/core/config.ts @@ -1,4 +1,5 @@ import { Platform } from 'style-dictionary' +import fg from 'fast-glob' export type Config = { entry: Record @@ -6,5 +7,9 @@ export type Config = { } export async function loadConfig(path: string): Promise { - return require(path) + const resolvedPath = fg.sync(path) + if (resolvedPath.length === 0) { + throw new Error(`Cannot load config from "${path}", please check path or file are exists.`) + } + return require(resolvedPath[0]) }