Skip to content

Commit

Permalink
feat: add autoload config with js, json and yml ext
Browse files Browse the repository at this point in the history
  • Loading branch information
yarastqt committed Aug 23, 2020
1 parent 64352aa commit e4305c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
7 changes: 6 additions & 1 deletion src/core/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { Platform } from 'style-dictionary'
import fg from 'fast-glob'

export type Config = {
entry: Record<string, string>
output: Record<string, Platform>
}

export async function loadConfig(path: string): Promise<Config> {
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])
}

0 comments on commit e4305c5

Please sign in to comment.