diff --git a/packages/style-dictionary/src/executors/build/lib/style-dictionary/clean-build-path.ts b/packages/style-dictionary/src/executors/build/lib/style-dictionary/clean-build-path.ts new file mode 100644 index 0000000..1222cdb --- /dev/null +++ b/packages/style-dictionary/src/executors/build/lib/style-dictionary/clean-build-path.ts @@ -0,0 +1,14 @@ +import { Platform } from 'style-dictionary'; +import { NormalizedBuildExecutorSchema } from '../../schema'; +import { rmSync, existsSync } from 'fs'; + +export function cleanPlatformBuildPath( + platform: Platform, + options: NormalizedBuildExecutorSchema +) { + if (platform.buildPath && platform.buildPath !== options.outputPath) { + if (existsSync(platform.buildPath)) { + rmSync(platform.buildPath); + } + } +} diff --git a/packages/style-dictionary/src/executors/build/lib/style-dictionary/run-build.ts b/packages/style-dictionary/src/executors/build/lib/style-dictionary/run-build.ts index 4ee2b92..a8070e7 100644 --- a/packages/style-dictionary/src/executors/build/lib/style-dictionary/run-build.ts +++ b/packages/style-dictionary/src/executors/build/lib/style-dictionary/run-build.ts @@ -2,6 +2,7 @@ import { ExecutorContext } from '@nx/devkit'; import * as styleDictionary from 'style-dictionary'; import { Config } from 'style-dictionary'; import { NormalizedBuildExecutorSchema } from '../../schema'; +import { cleanPlatformBuildPath } from './clean-build-path'; import { registerExtensions } from './register-extensions'; export function runBuild( @@ -16,9 +17,20 @@ export function runBuild( const { platform } = options; if (platform) { + const platformConfig = currentConfig.platforms[platform]; + if (options.deleteOutputPath) { + cleanPlatformBuildPath(platformConfig, options); + } instance.buildPlatform(platform); return; } + + if (options.deleteOutputPath) { + Object.values(currentConfig.platforms).forEach((platformConfig) => { + cleanPlatformBuildPath(platformConfig, options); + }); + } + instance.buildAllPlatforms(); }); }