-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
53 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,24 @@ | ||
import { resolve } from 'path' | ||
import { Command, flags } from '@oclif/command' | ||
|
||
import { getProjectConfig } from '../core/project-config' | ||
import { build } from '../core/build' | ||
|
||
type Flags = { config: string } | ||
type Args = { source: string } | ||
|
||
export default class Build extends Command { | ||
static flags = { | ||
config: flags.string({ | ||
char: 'c', | ||
description: 'Config path', | ||
default: 'theme.config.json', | ||
}), | ||
} | ||
|
||
async run() { | ||
this.log('build command') | ||
const { flags, args } = this.parse<Flags, Args>(Build) | ||
const config = await getProjectConfig(process.cwd(), flags.config) | ||
await build(config) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { writeFile, ensureDir } from 'fs-extra' | ||
import { resolve } from 'path' | ||
import deepmerge from 'deepmerge' | ||
|
||
import { Config } from './project-config' | ||
import { getThemeLayers } from './theme-layers' | ||
import { flatTokens } from './flat-tokens' | ||
import { transformTokens } from './transforms' | ||
import { formats } from './formats' | ||
|
||
export async function build(options: Config): Promise<any> { | ||
// TODO: Add tokens validate. | ||
// TODO: Add avalible transforms validate. | ||
const themeLayers = await getThemeLayers(options.rootDir, { platforms: options.platforms, exclude: options.exclude }) | ||
for (const format in options.formats) { | ||
// @ts-ignore | ||
const { options, transforms } = options.formats[format] | ||
const result = deepmerge(themeLayers, {}) | ||
for (const platform in themeLayers) { | ||
const xxx = themeLayers[platform] | ||
for (const q in xxx) { | ||
const uuu = xxx[q] | ||
const yyy = flatTokens(uuu.tokens) | ||
const hhh = transformTokens(yyy, { transforms, ...options }) | ||
// @ts-ignore | ||
result[platform][q].tokens = hhh | ||
} | ||
} | ||
const result_to_write = formats[format](result, options) | ||
for (const file of result_to_write) { | ||
await ensureDir(resolve(process.cwd(), options.rootDir, 'build')) | ||
await writeFile(resolve(process.cwd(), options.rootDir, 'build', file.fileName), file.content) | ||
} | ||
} | ||
} |