Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 feat(script): Gerenate themes imports #716

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ typings/
# Jetbrains IDEA
.idea

# Imports of the themes generated by the script generateThemesImports.js
themeImports.js

dist
build
Expand Down
21 changes: 12 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"scripts": {
"commit": "git-cz",
"clean": "lerna clean -y && lerna run prebuild --scope=@gympass/yoga-doc",
"test": "NODE_ENV=test jest --config=./jest/config/config.js",
"test": "yarn generateThemeImports && NODE_ENV=test jest --config=./jest/config/config.js",
"pretest": "lerna run prebuild --ignore=@gympass/yoga-doc",
"test:native": "NODE_ENV=test jest --config=./jest/config/native.js",
"test:helpers": "NODE_ENV=test jest --config=./jest/config/helpers.js",
"test:system": "NODE_ENV=test jest --config=./jest/config/system.js",
"test:web": "NODE_ENV=test jest --config=./jest/config/web.js",
"test:native": "yarn generateThemeImports && NODE_ENV=test jest --config=./jest/config/native.js",
"test:helpers": "yarn generateThemeImports && NODE_ENV=test jest --config=./jest/config/helpers.js",
"test:system": "yarn generateThemeImports && NODE_ENV=test jest --config=./jest/config/system.js",
"test:web": "yarn generateThemeImports && NODE_ENV=test jest --config=./jest/config/web.js",
"prettier": "prettier",
"dev:web": "lerna run dev --scope=@gympass/yoga-doc --stream",
"dev:native:android": "lerna run android --scope=@gympass/yoga-labnative --stream",
"dev:native:ios": "lerna run ios --scope=@gympass/yoga-labnative --stream",
"dev:web": "yarn generateThemeImports && lerna run dev --scope=@gympass/yoga-doc --stream",
"dev:native:android": "yarn generateThemeImports && lerna run android --scope=@gympass/yoga-labnative --stream",
"dev:native:ios": "yarn generateThemeImports && lerna run ios --scope=@gympass/yoga-labnative --stream",
"lint": "eslint --ext js,jsx,android.jsx,ios.jsx",
"lint:yoga": "NODE_ENV=test yarn lint packages/yoga",
"lint:doc": "NODE_ENV=test yarn lint packages/doc",
Expand All @@ -29,7 +29,8 @@
"build:packages": "lerna run build --ignore=@gympass/yoga-doc --stream",
"build:system": "lerna run build --scope=@gympass/yoga-system --stream",
"build": "lerna run build --stream --parallel",
"new": "node ./scripts/cli/index.js"
"new": "node ./scripts/cli/index.js && yarn generateThemeImports",
"generateThemeImports": "node ./scripts/generateThemesImports.js > ./packages/yoga/src/Theme/theme/themeImports.js"
},
"private": true,
"devDependencies": {
Expand All @@ -56,6 +57,7 @@
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "4.0.0",
"fs": "^0.0.1-security",
"fs-extra": "^8.1.0",
"git-last-commit": "^1.0.0",
"husky": "3.0.5",
Expand All @@ -65,6 +67,7 @@
"lerna": "^5.0.0",
"lint-staged": "9.2.5",
"metro-react-native-babel-preset": "^0.67.0",
"path": "^0.12.7",
"prettier": "2.6.2",
"react-dom": "^18.0.0",
"tsup": "^7.1.0",
Expand Down
5 changes: 3 additions & 2 deletions packages/yoga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
"build:web": "tsup src src/**/web !src/Fonts !**/*.test.jsx.snap !**/*.test.tsx.snap --outDir dist/cjs --format=cjs",
"build:esm": "tsup src src/**/web !src/Fonts !**/*.test.jsx.snap !**/*.test.tsx.snap --format=esm --legacy-output",
"build:native": "tsup src src/**/native !src/Fonts !**/*.test.jsx.snap !**/*.test.tsx.snap --outDir dist/cjs --format=cjs",
"prebuild": "rm -rf ./dist",
"prebuild": "rm -rf ./dist && yarn generateThemeImports",
"postbuild": "cp -r ./src/Fonts ./dist/fonts",
"prepublishOnly": "node ../../scripts/prepublish.js --rn"
"prepublishOnly": "node ../../scripts/prepublish.js --rn",
"generateThemeImports": "node ../../scripts/generateThemesImports.js > ./src/Theme/theme/themeImports.js"
},
"keywords": [
"Gympass",
Expand Down
83 changes: 0 additions & 83 deletions packages/yoga/src/Theme/theme/componentThemes.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/yoga/src/Theme/theme/theme.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable prefer-destructuring */
import { merge } from '@gympass/yoga-common';
import componentThemes from './componentThemes';
import componentThemes from './themeImports';

const getComponentThemes = tokens => {
const { colors, baseFont, baseFontSize } = tokens;
Expand Down
57 changes: 57 additions & 0 deletions scripts/generateThemesImports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');

const themeFiles = [];
const yogaPath = path.join(__dirname, '../packages/yoga/src');
const removeExt = /\.theme\.(js|ts)$/;

function findThemeFiles(directory) {
const files = fs.readdirSync(directory);

files.forEach(file => {
const filePath = path.join(directory, file);
const stats = fs.statSync(filePath);

if (stats.isDirectory()) {
findThemeFiles(filePath);
}

if (file.endsWith('.theme.js') || file.endsWith('.theme.ts')) {
themeFiles.push(filePath);
}
});
}

function toCamelCase(name) {
return name.replace(/[-_.](.)/g, (_, afterDot) => afterDot.toUpperCase());
}

function adjustPath(name) {
return name.replace('packages/yoga/src', '..');
}

findThemeFiles(yogaPath);

const importStatements = themeFiles.map(filePath => {
const componentName = toCamelCase(
path.basename(filePath).replace(removeExt, ''),
);
const componentPath = adjustPath(path.relative(__dirname, filePath));

return `import ${componentName} from '${componentPath}';`;
});

const exportStatements = themeFiles.map(filePath => {
const componentName = toCamelCase(
path.basename(filePath).replace(removeExt, ''),
);

return ` ${componentName},`;
});

console.log(importStatements.join('\n'));
console.log('\nconst componentThemes = {');
console.log(exportStatements.join('\n'));
console.log('};');
console.log('\nexport default componentThemes;');
22 changes: 21 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12745,6 +12745,11 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==

fs@^0.0.1-security:
version "0.0.1-security"
resolved "https://registry.yarnpkg.com/fs/-/fs-0.0.1-security.tgz#8a7bd37186b6dddf3813f23858b57ecaaf5e41d4"
integrity sha512-3XY9e1pP0CVEUCdj5BmfIZxRBTSDycnbqhIOGec9QYtmVH2fbLpj86CFWkrNOkt/Fvty4KZG5lTglL9j/gJ87w==

fsevents@^1.2.7:
version "1.2.13"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.2.13.tgz#f325cb0455592428bcf11b383370ef70e3bfcc38"
Expand Down Expand Up @@ -20439,6 +20444,14 @@ path-type@^4.0.0:
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

path@^0.12.7:
version "0.12.7"
resolved "https://registry.yarnpkg.com/path/-/path-0.12.7.tgz#d4dc2a506c4ce2197eb481ebfcd5b36c0140b10f"
integrity sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==
dependencies:
process "^0.11.1"
util "^0.10.3"

pbkdf2@^3.0.3:
version "3.1.2"
resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.1.2.tgz#dd822aa0887580e52f1a039dc3eda108efae3075"
Expand Down Expand Up @@ -21149,7 +21162,7 @@ process-nextick-args@~2.0.0:
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
integrity sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==

process@^0.11.10:
process@^0.11.1, process@^0.11.10:
version "0.11.10"
resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182"
integrity sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==
Expand Down Expand Up @@ -25487,6 +25500,13 @@ [email protected]:
dependencies:
inherits "2.0.1"

util@^0.10.3:
version "0.10.4"
resolved "https://registry.yarnpkg.com/util/-/util-0.10.4.tgz#3aa0125bfe668a4672de58857d3ace27ecb76901"
integrity sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==
dependencies:
inherits "2.0.3"

util@^0.11.0:
version "0.11.1"
resolved "https://registry.yarnpkg.com/util/-/util-0.11.1.tgz#3236733720ec64bb27f6e26f421aaa2e1b588d61"
Expand Down
Loading