Skip to content

Commit

Permalink
Merge pull request #2399 from epam/fix/only_allow_to_generate_mixins_…
Browse files Browse the repository at this point in the history
…via_bin_script

Fix/only allow to generate mixins via bin script
  • Loading branch information
siarheiyelin authored Jul 2, 2024
2 parents bf6f1da + ff2e580 commit 160c2b4
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 15 deletions.
2 changes: 2 additions & 0 deletions uui-build/bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ if (process.argv.includes(BIN_SCRIPTS.ROLLUP_BUILD)) {
// eslint-disable-next-line import/extensions
const { main } = require('./themeTokens/main.js');
main();
} else {
console.error(`[ERROR] Unknown command. List of supported commands: ${Object.values(BIN_SCRIPTS).map((c) => `"${c}"`).join(', ')}.`);
}
3 changes: 1 addition & 2 deletions uui-build/bin/themeTokens/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ module.exports = {

function main() {
const spawn = require('cross-spawn');
// We only allow to generate mixins here
const args = [
'ts/scripts/themeTokensGen.ts',
getCliArgStartWith('--src-collection='),
getCliArgStartWith('--out-collection='),
getCliArgStartWith('--out-tokens='),
getCliArgStartWith('--out-mixins='),
];
spawn.sync('ts-node', args, { encoding: 'utf8', stdio: 'inherit' });
Expand Down
2 changes: 1 addition & 1 deletion uui-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "yarn build-module",
"build-module": "ts-node -T ts/scripts/buildUuiModule.ts",
"generate-components-api": "ts-node ts/scripts/docsGen.ts",
"generate-theme-tokens": "node ./bin/cli.js --theme-tokens --src-collection=../public/docs/figmaTokensGen/Theme.json --out-collection=../public/docs/figmaTokensGen/ThemeOutput.json --out-tokens=../public/docs/figmaTokensGen/ThemeTokens.json --out-mixins=../epam-assets/theme/tokens",
"generate-theme-tokens": "ts-node ts/scripts/themeTokensGen.ts --src-collection=../public/docs/figmaTokensGen/Theme.json --out-collection=../public/docs/figmaTokensGen/ThemeOutput.json --out-tokens=../public/docs/figmaTokensGen/ThemeTokens.json --out-mixins=../epam-assets/theme/tokens",
"compile-theme-scss": "ts-node ts/scripts/compileThemeScss.ts",
"track-bundle-size": "ts-node ts/scripts/trackBundleSize.ts",
"prepublish": "yarn build",
Expand Down
6 changes: 3 additions & 3 deletions uui-build/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

This package is a part of [EPAM UUI](https://github.com/epam/UUI) library.

`@epam/uui-build` consist scripts and tools to build UUI mono-repo. It contains scripts to run the repo as a single huge app (for development needs), and build each package separately for NPM.
Also, its contains some external scripts which can be used we UUI ecosystem.
`@epam/uui-build` consists of scripts and tools to build UUI monorepo. It contains scripts to run the repo as a single huge app (for development needs), and to build each package separately for NPM.
Also, it contains some external scripts that can be used within UUI ecosystem.

### CLI scripts
1. Build a project using Rollup
Expand All @@ -16,5 +16,5 @@ npx @epam/uui-build@latest --rollup-build --watch

2. Generate a set of SCSS mixins with theme tokens. A collection of variables exported from Figma (*.json) is used as input.
```shell
npx @epam/uui-build@latest --theme-tokens --src-collection=./input/Theme.json --out-collection=./input/ThemeOutput.json --out-tokens=./input/ThemeTokens.json --out-mixins=./input
npx @epam/uui-build@latest --theme-tokens --src-collection=./input/Theme.json --out-mixins=./input
```
22 changes: 13 additions & 9 deletions uui-build/ts/tasks/themeTokensGen/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,31 @@ export const taskConfig: ITaskConfig = {
main,
cliArgs: {
[ARGS.SRC_COLLECTION]: { format: 'NameValue', required: true },
[ARGS.OUT_COLLECTION]: { format: 'NameValue', required: true },
[ARGS.OUT_TOKENS]: { format: 'NameValue', required: true },
[ARGS.OUT_MIXINS]: { format: 'NameValue', required: true },
[ARGS.OUT_COLLECTION]: { format: 'NameValue', required: false },
[ARGS.OUT_TOKENS]: { format: 'NameValue', required: false },
},
};

async function main(params: TTaskParams) {
const {
[ARGS.SRC_COLLECTION]: { value: srcCollectionPath },
[ARGS.OUT_COLLECTION]: { value: outCollectionPath },
[ARGS.OUT_TOKENS]: { value: outTokensPath },
[ARGS.OUT_COLLECTION]: outCollection,
[ARGS.OUT_TOKENS]: outTokens,
[ARGS.OUT_MIXINS]: { value: outMixinsPath },
} = params.cliArgs;

const srcCollectionData = readFigmaVarCollection(srcCollectionPath as string);
const { outCollectionData, outTokensData } = generateTokens({ srcCollectionData });
if (outCollection?.value) {
const outCollectionPathAbs = path.resolve(outCollection.value as string);
writeFileSync(outCollectionPathAbs, JSON.stringify(outCollectionData, undefined, 2));
}
if (outTokens?.value) {
const outTokensPathAbs = path.resolve(outTokens.value as string);
writeFileSync(outTokensPathAbs, JSON.stringify(outTokensData, undefined, 2));
}

const outCollectionPathAbs = path.resolve(outCollectionPath as string);
const outTokensPathAbs = path.resolve(outTokensPath as string);

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

Expand Down

0 comments on commit 160c2b4

Please sign in to comment.