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: add configuration for android jetpack compose output #223

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
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
110 changes: 110 additions & 0 deletions config/compose.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
const StyleDictionary = require('style-dictionary');
const Color = require('tinycolor2');

const { PREFIX, OUTPUT_PATH, OUTPUT_BASE_FILENAME } = process.env;
const WHITELABEL = process.env.WHITELABEL !== 'false';


StyleDictionary.registerTransform({
type: 'name',
name: 'name/camelCase',
matcher: (token) => token.original.type === 'color',
transformer: (token) => {
const formatted = token.path.map(el => format(el))
token.name = `Telekom${formatted.toString().replace(/,/g, '')}`
return token.name
}
});

StyleDictionary.registerTransform({
type: 'value',
name: 'color/composeColor',
matcher: (token) => token.original.type === 'color',
transformer: (token) => {
const hex8 = Color(token.value).toHex8();
return `Color(0x${hex8})`;
}
});

StyleDictionary.registerTransform({
type: 'value',
name: 'has-alpha',
transitive: true,
transformer: function (token) {
if (token.value?.alpha != null) {
const hex = Color(token.value.color.replace('Color(0x', '').slice(0, -3))
const hex8withAlpha = hex.setAlpha(token.value.alpha)
token.value = `Color(0x${hex8withAlpha.toHex8()})`;
return token.value
} else {
return token.value;
}
},
});

const composeObjectTransformGroup = [
'has-alpha',
'color/composeColor',
'name/camelCase',
// 'comment/composeStripComments'
];

function format(string){
const dashlessString = string.replace(/-(.)/g, (_, letter) => letter.toUpperCase());
const upperCasedString = dashlessString.charAt(0).toUpperCase() + dashlessString.slice(1);
const ampersandRemovedString = upperCasedString.replace(/&/g, 'And')
return ampersandRemovedString;
}


module.exports = {
include: ['src/core/**/*.json5'],
source: [
...(WHITELABEL === false ? ['src/telekom/core/**.json5'] : []),
'src/semantic/**/*.json5',
],
platforms: {
composeObjectLightOnlyData: {
transforms: ['mode-light', ...composeObjectTransformGroup],
prefix: PREFIX,
buildPath: OUTPUT_PATH + 'android-compose/',
files: [
{
destination: OUTPUT_BASE_FILENAME + '.light.kt',
format: 'compose/object',
packageName: 'de.telekom.tokens',
className: 'ScaleTokensLight',
filter: (token) => {
if (token.path[0] !== 'core' && !token.path.includes('experimental') && token.type === 'color') {
{
// delete token.comment
// delete token.original.comment
return token
}
}
}
},
],
},
composeObjectDarkOnlyData: {
transforms: ['mode-dark', ...composeObjectTransformGroup],
prefix: PREFIX,
buildPath: OUTPUT_PATH + 'android-compose/',
files: [
{
destination: OUTPUT_BASE_FILENAME + '.dark.kt',
format: 'compose/object',
packageName: 'de.telekom.tokens',
className: 'ScaleTokensDark',
filter: (token) => {
if (token.path[0] !== 'core' && token.original.value?.dark != null && token.type === 'color')
{
return token
}
}

},
],
},
},
};
2 changes: 1 addition & 1 deletion config/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Color = require('tinycolor2');

setDefaultEnvValue(
'CONFIG',
'css,js,figma,sketch,docs-json,tailwindcss-preset,csv'
'css,js,figma,sketch,docs-json,tailwindcss-preset,csv,compose'
);
setDefaultEnvValue('PREFIX', 'telekom');
setDefaultEnvValue('OUTPUT_PATH', 'dist/');
Expand Down