Skip to content

Commit

Permalink
Merge pull request #2398 from epam/fix/fix_err_when_target_dir_not_ex…
Browse files Browse the repository at this point in the history
…ists

Fix error when destination dir does not exist
  • Loading branch information
siarheiyelin authored Jul 2, 2024
2 parents 37b4d10 + a6a3e61 commit bf6f1da
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 3 additions & 6 deletions uui-build/ts/tasks/themeTokensGen/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs';
import path from 'path';
import { readFigmaVarCollection, logFileCreated } from './utils/fileUtils';
import { readFigmaVarCollection, writeFileSync } from './utils/fileUtils';
import { getHiddenFromPublishingVarPlaceholder } from './constants';
import {
convertRawToken,
Expand Down Expand Up @@ -43,10 +42,8 @@ async function main(params: TTaskParams) {
const outCollectionPathAbs = path.resolve(outCollectionPath as string);
const outTokensPathAbs = path.resolve(outTokensPath as string);

fs.writeFileSync(outCollectionPathAbs, JSON.stringify(outCollectionData, undefined, 2));
logFileCreated(outCollectionPathAbs);
fs.writeFileSync(outTokensPathAbs, JSON.stringify(outTokensData, undefined, 2));
logFileCreated(outTokensPathAbs);
writeFileSync(outCollectionPathAbs, JSON.stringify(outCollectionData, undefined, 2));
writeFileSync(outTokensPathAbs, JSON.stringify(outTokensData, undefined, 2));
await mixinsGenerator(outTokensData, outMixinsPath as string);
}

Expand Down
11 changes: 11 additions & 0 deletions uui-build/ts/tasks/themeTokensGen/utils/fileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs';
import { IFigmaVarCollection } from '../types/sourceTypes';
import { logger } from '../../../utils/jsBridge';
import path from 'path';

export function readFigmaVarCollection(absPath: string): IFigmaVarCollection {
if (fs.existsSync(absPath)) {
Expand All @@ -17,3 +18,13 @@ export function forwardSlashes(pathStr: string): string {
export function logFileCreated(pathStr: string) {
logger.success(`File created: ${forwardSlashes(pathStr)}`);
}

export function writeFileSync(absPath: string, content: string) {
const dir = path.dirname(absPath);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}
// The file will be overwritten if it already exists
fs.writeFileSync(absPath, content);
logFileCreated(absPath);
}

0 comments on commit bf6f1da

Please sign in to comment.