From 7bddbbddcf9a6faf1f7891d260fa44f68f8f745a Mon Sep 17 00:00:00 2001 From: yarastqt Date: Sat, 25 Apr 2020 21:49:56 +0300 Subject: [PATCH] feat: support outDir for each format --- src/core/build.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/build.ts b/src/core/build.ts index 96ee428..71b4feb 100644 --- a/src/core/build.ts +++ b/src/core/build.ts @@ -1,5 +1,5 @@ import { writeFile, ensureDir } from 'fs-extra' -import { resolve } from 'path' +import { resolve, parse } from 'path' import deepmerge from 'deepmerge' import { Config } from './project-config' @@ -14,7 +14,7 @@ export async function build(config: Config): Promise { // TODO: Add header for generated files with date/ts. const themeLayers = await getThemeLayers(config.src, { platforms: config.platforms }) for (const format in config.formats) { - const { options, transforms } = config.formats[format] + const { outDir, options, transforms } = config.formats[format] const result = deepmerge(themeLayers, {}) for (const platform in themeLayers) { const xxx = themeLayers[platform] @@ -28,9 +28,10 @@ export async function build(config: Config): Promise { } const result_to_write = formats[format](result, options) for (const file of result_to_write) { - // TODO: build dir should be configurated - await ensureDir(resolve(process.cwd(), config.outDir, 'tokens')) - await writeFile(resolve(process.cwd(), config.outDir, 'tokens', file.fileName), file.content) + const destFilePath = resolve(process.cwd(), outDir, file.fileName) + const destFolder = parse(destFilePath).dir + await ensureDir(destFolder) + await writeFile(destFilePath, file.content) } } }