From 8eff2741068e2be0e4d1db6878115226cebda464 Mon Sep 17 00:00:00 2001 From: Thomas Gossmann Date: Tue, 5 Oct 2021 01:20:14 +0200 Subject: [PATCH] remove build command (#128) --- src/build/config.ts | 13 ------ src/build/index.ts | 16 ------- src/config.ts | 4 -- src/index.ts | 9 +--- src/theemo.ts | 55 ------------------------ src/tools/style-dictionary/builder.ts | 61 --------------------------- src/tools/style-dictionary/index.ts | 10 +---- src/tools/tool-factory.ts | 13 +----- src/tools/tool.ts | 15 ------- src/tools/unknown-tool.ts | 10 +---- 10 files changed, 6 insertions(+), 200 deletions(-) delete mode 100644 src/build/config.ts delete mode 100644 src/build/index.ts delete mode 100644 src/tools/style-dictionary/builder.ts diff --git a/src/build/config.ts b/src/build/config.ts deleted file mode 100644 index 5e757dc1..00000000 --- a/src/build/config.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Tools } from '../tools/tool'; - -/** - * The build config for theemo. - * - * Theemo tries to auto-detect your environment and choose the right tool. As - * such, you can omit the config here. - * Only if the environment cannot reliably be detected, theemo will let you - * know and kindly asks you to provide a configuration. - */ -export default interface BuildConfig { - tool: Tools; -} diff --git a/src/build/index.ts b/src/build/index.ts deleted file mode 100644 index 0d660443..00000000 --- a/src/build/index.ts +++ /dev/null @@ -1,16 +0,0 @@ -import ToolConfig from '../tools/config'; -import { BuilderTool } from '../tools/tool'; -import ToolFactory from '../tools/tool-factory'; -import BuildConfig from './config'; - -export default class BuildCommand { - private tool: BuilderTool; - - constructor(config: BuildConfig) { - this.tool = ToolFactory.createBuilder(config.tool, config as ToolConfig); - } - - execute() { - this.tool.build(); - } -} diff --git a/src/config.ts b/src/config.ts index 259792ed..5d84e4c5 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,4 +1,3 @@ -import BuildConfig from './build/config'; import GenerateConfig from './generate/config'; import SyncConfig from './sync/config'; @@ -13,9 +12,6 @@ export default interface TheemoConfig { /** Config for the sync command */ sync?: SyncConfig; - /** Config for the build command */ - build?: BuildConfig; - /** Config for the generate command */ generate?: GenerateConfig; } diff --git a/src/index.ts b/src/index.ts index f44f5fcd..bd93afe2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,13 +28,6 @@ async function main() { await theemo.sync(); }); - program - .command('build') - .description('runs the build of your token manager tool') - .action(() => { - theemo.build(); - }); - program .command('generate') .description('generates an adaptive CSS theme file') @@ -66,7 +59,7 @@ export type { default as WriterConfig } from './sync/writer/config'; export type { default as GenerateConfig } from './generate/config'; // tools -export type { Tools, ReaderTool, WriterTool, BuilderTool } from './tools/tool'; +export type { Tools, ReaderTool, WriterTool } from './tools/tool'; export type { FigmaReaderConfig, FigmaReferencerConfig, diff --git a/src/theemo.ts b/src/theemo.ts index f9db9db2..6b236ed7 100644 --- a/src/theemo.ts +++ b/src/theemo.ts @@ -1,53 +1,21 @@ -import BuildConfig from './build/config'; -import BuildCommand from './build/index'; import TheemoConfig from './config'; import GenerateConfig from './generate/config'; import GenerateCommand from './generate/index'; import SyncConfig from './sync/config'; import SyncCommand from './sync/index'; -import { Tools } from './tools/tool'; import { requireFile } from './utils'; -interface Package { - name: string; - dependencies: { - [key: string]: string; - }; - devDependencies: { - [key: string]: string; - }; -} - export default class Theemo { private config: TheemoConfig; - private package: Package; constructor() { this.config = this.loadConfig(); - this.package = this.loadPackage(); } private loadConfig(): TheemoConfig { return requireFile('theemo.js') as TheemoConfig; } - private loadPackage(): Package { - return requireFile('package.json') as Package; - } - - private detectBuildTool(): Tools { - const deps = { - ...this.package.dependencies, - ...this.package.devDependencies - }; - - if (Object.keys(deps).includes('style-dictionary')) { - return Tools.StyleDictionary; - } - - return Tools.Unknown; - } - /** * Executes the sync command * @@ -61,29 +29,6 @@ export default class Theemo { } } - /** - * Executes the build command - * - * @param config the config for build (if it cannot be auto-detected) - */ - async build(config?: BuildConfig): Promise { - let usedConfig = config ?? this.config.build; - - if (!usedConfig) { - const tool = this.detectBuildTool(); - if (tool !== Tools.Unknown) { - usedConfig = { - tool - }; - } - } - - if (usedConfig) { - const command = new BuildCommand(usedConfig); - command.execute(); - } - } - /** * Executes the generate command * diff --git a/src/tools/style-dictionary/builder.ts b/src/tools/style-dictionary/builder.ts deleted file mode 100644 index f4f4a5b7..00000000 --- a/src/tools/style-dictionary/builder.ts +++ /dev/null @@ -1,61 +0,0 @@ -import fs from 'fs'; - -import StyleDictionary, { Config } from 'style-dictionary'; - -import { requireFile } from '../../utils'; - -interface TheemoTransform { - matcher?: (property: Record) => boolean; - transformer: (property: Record) => string; -} - -interface TheemoTransforms { - value?: TheemoTransform; - attribute?: TheemoTransform; - name?: TheemoTransform; -} - -interface TheemoConfig extends Config { - transforms?: TheemoTransforms; -} - -export default class StyleDictionaryBuilder { - build(): void { - const config = this.loadConfig(); - if (config) { - const sd = StyleDictionary.extend(config); - - sd.buildAllPlatforms(); - } - } - - private loadConfig(): Config | undefined { - const file = this.findConfig(); - - if (file) { - return requireFile(file) as TheemoConfig; - } - - // eslint-disable-next-line unicorn/no-useless-undefined - return undefined; - } - - private findConfig() { - const files = [ - 'config.json', - 'config.json5', - 'config.js', - 'sd.config.js', - 'sd.config.json', - 'sd.config.json5' - ]; - for (const file of files) { - if (fs.existsSync(file)) { - return file; - } - } - - // eslint-disable-next-line unicorn/no-useless-undefined - return undefined; - } -} diff --git a/src/tools/style-dictionary/index.ts b/src/tools/style-dictionary/index.ts index 916624cd..659d2621 100644 --- a/src/tools/style-dictionary/index.ts +++ b/src/tools/style-dictionary/index.ts @@ -1,22 +1,16 @@ import TokenCollection from '../../token-collection'; import ToolConfig from '../config'; -import { BuilderTool, WriterTool } from '../tool'; -import StyleDictionaryBuilder from './builder'; +import { WriterTool } from '../tool'; import { StyleDictionaryConfig } from './config'; import StyleDictionaryWriter from './writer'; -export default class StyleDictionary implements WriterTool, BuilderTool { +export default class StyleDictionary implements WriterTool { private config: StyleDictionaryConfig; constructor(config: ToolConfig) { this.config = config as StyleDictionaryConfig; } - build() { - const builder = new StyleDictionaryBuilder(); - builder.build(); - } - write(tokens: TokenCollection) { const writer = new StyleDictionaryWriter(this.config.writer); writer.write(tokens); diff --git a/src/tools/tool-factory.ts b/src/tools/tool-factory.ts index a1fef834..6971b476 100644 --- a/src/tools/tool-factory.ts +++ b/src/tools/tool-factory.ts @@ -1,7 +1,7 @@ import ToolConfig from './config'; import Figma from './figma'; import StyleDictionary from './style-dictionary'; -import { BuilderTool, ReaderTool, Tools, WriterTool } from './tool'; +import { ReaderTool, Tools, WriterTool } from './tool'; import UnknownTool from './unknown-tool'; export default class ToolFactory { @@ -26,15 +26,4 @@ export default class ToolFactory { return new UnknownTool(); } } - - static createBuilder(tool: Tools, config: ToolConfig): BuilderTool { - switch (tool) { - case Tools.StyleDictionary: - return new StyleDictionary(config); - - case Tools.Unknown: - default: - return new UnknownTool(); - } - } } diff --git a/src/tools/tool.ts b/src/tools/tool.ts index 82e30dad..94445233 100644 --- a/src/tools/tool.ts +++ b/src/tools/tool.ts @@ -44,18 +44,3 @@ export interface WriterTool { */ write(tokens: TokenCollection): void; } - -/** - * This is for tools used during the `build` command and trigger the execution - * of that tool. - * - * @example - * - * Style Dictionary may be your builder tool and executes the build process - */ -export interface BuilderTool { - /** - * Executes the build of the tool - */ - build(): void; -} diff --git a/src/tools/unknown-tool.ts b/src/tools/unknown-tool.ts index 00b6f8fc..f1a67253 100644 --- a/src/tools/unknown-tool.ts +++ b/src/tools/unknown-tool.ts @@ -1,18 +1,12 @@ import TokenCollection from '../token-collection'; -import { ReaderTool, WriterTool, BuilderTool } from './tool'; +import { ReaderTool, WriterTool } from './tool'; -export default class UnknownTool - implements ReaderTool, WriterTool, BuilderTool -{ +export default class UnknownTool implements ReaderTool, WriterTool { async read() { const tokens = await new TokenCollection(); return tokens; } - build() { - // void implementation - } - write(_tokens: TokenCollection) { // void implementation }