From 231a7955cee5c6485aabb56d4f7ba1232eb25171 Mon Sep 17 00:00:00 2001 From: yarastqt Date: Sun, 26 Apr 2020 23:30:15 +0300 Subject: [PATCH] feat: support js format for config --- src/cli/build.ts | 7 ++++--- src/core/build.ts | 2 +- src/core/config.ts | 17 +++++++++++++++++ src/core/project-config.ts | 21 --------------------- 4 files changed, 22 insertions(+), 25 deletions(-) create mode 100644 src/core/config.ts delete mode 100644 src/core/project-config.ts diff --git a/src/cli/build.ts b/src/cli/build.ts index 2cd5e58..86e3c2a 100644 --- a/src/cli/build.ts +++ b/src/cli/build.ts @@ -1,8 +1,9 @@ +import { resolve } from 'path' import { Command, flags } from '@oclif/command' import createSpinner, { Ora as Spinner } from 'ora' import chalk from 'chalk' -import { getProjectConfig } from '../core/project-config' +import { loadConfig } from '../core/config' import { build } from '../core/build' type Flags = { config: string } @@ -12,14 +13,14 @@ export default class Build extends Command { config: flags.string({ char: 'c', description: 'Config path', - default: 'theme.config.json', + default: 'themekit.config.js', }), } async run() { let spinner: Spinner const { flags } = this.parse(Build) - const config = await getProjectConfig(process.cwd(), flags.config) + const config = await loadConfig(resolve(flags.config)) await build( config, (format) => { diff --git a/src/core/build.ts b/src/core/build.ts index 4f09aac..417e951 100644 --- a/src/core/build.ts +++ b/src/core/build.ts @@ -2,7 +2,7 @@ import { writeFile, ensureDir } from 'fs-extra' import { join, resolve, parse } from 'path' import deepmerge from 'deepmerge' -import { Config } from './project-config' +import { Config } from './config' import { getThemeLayers } from './theme-layers' import { flatTokens } from './flat-tokens' import { transformTokens } from './transforms' diff --git a/src/core/config.ts b/src/core/config.ts new file mode 100644 index 0000000..b7ac6ce --- /dev/null +++ b/src/core/config.ts @@ -0,0 +1,17 @@ +import { Platforms } from './platforms' + +export type Config = { + src: string + platforms?: Platforms + formats: { + [key: string]: { + outDir: string + transforms: string[] + options?: {} + } + } +} + +export async function loadConfig(path: string): Promise { + return await import(path) +} diff --git a/src/core/project-config.ts b/src/core/project-config.ts deleted file mode 100644 index a049fcc..0000000 --- a/src/core/project-config.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { join } from 'path' -import { readJsonSync } from 'fs-extra' - -import { Platforms } from './platforms' - -export type Config = { - src: string - platforms?: Platforms - formats: { - [key: string]: { - outDir: string - transforms: string[] - options?: {} - } - } -} - -// TODO: Support config with js format. -export async function getProjectConfig(source: string, configName: string): Promise { - return readJsonSync(join(source, configName)) -}