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: create themes flag to build tokens #2357

Merged
merged 2 commits into from
Jun 7, 2023

Conversation

dcoa
Copy link
Contributor

@dcoa dcoa commented Jun 5, 2023

Description

This PR is a proposal to be able to build tokens of any custom theme throughout CLI. Also, add a function to create the index file for the output, understanding that the build-scss command needs this file.

  themes/ 
    light/
    │  ├─ index.css
    │  ├─ other_css_files
    dark/
    │  ├─ index.css
    │  ├─ other_css_files
    some_other_custom_theme/
    │  ├─ index.css
    │  ├─ other_css_files

The user can run something like build-design-tokens --build-dir ./<folder_path> --source /<folder_path> --themes custom_theme_a custom_theme_b light

Merge Checklist

  • If your update includes visual changes, have they been reviewed by a designer? Send them a link to the Netlify deploy preview, if applicable.
  • Does your change adhere to the documented style conventions?
  • Do any prop types have missing descriptions in the Props API tables in the documentation site (check deploy preview)?
  • Were your changes tested using all available themes (see theme switcher in the header of the deploy preview, under the "Settings" icon)?
  • Were your changes tested in the example app?
  • Is there adequate test coverage for your changes?
  • Consider whether this change needs to reviewed/QA'ed for accessibility (a11y). If so, please add wittjeff and adamstankiewicz as reviewers on this PR.

Post-merge Checklist

  • Verify your changes were released to NPM at the expected version.
  • If you'd like, share your contribution in #show-and-tell.
  • 🎉 🙌 Celebrate! Thanks for your contribution.

@adamstankiewicz

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Jun 5, 2023
@openedx-webhooks
Copy link

Thanks for the pull request, @dcoa! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@dcoa dcoa force-pushed the dcoa/paragon-css-variables branch from 6cb3004 to 88b1522 Compare June 6, 2023 00:01
Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing users of the CLI to pass in custom themes makes a lot of sense! @edx/brand packages could begin defining their own themes before upstream Paragon does. The @edx/frontend-build and @edx/frontend-platform PRs should be able to support any custom themes as well already, if that is a concern.

tokens/utils.js Outdated
@@ -162,7 +162,37 @@ async function transformInPath(location, variablesMap, transformType = 'definiti
}
}


function createIndexFile(buildDir, isTheme, themeVariant){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree having it programmatically create the index file makes sense! 🥇

// This line creates the index file for core folder, specially when buildDir is outside Paragon.
createIndexFile(buildDir,false);

const THEME_VARIANTS = themes ? themes : ['light'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
const THEME_VARIANTS = themes ? themes : ['light'];
const THEME_VARIANTS = themes || ['light'];

tokens/utils.js Outdated
@@ -162,7 +162,37 @@ async function transformInPath(location, variablesMap, transformType = 'definiti
}
}


function createIndexFile(buildDir, isTheme, themeVariant){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It may be worth changing the function signature here to be more like kwargs in python, e.g. function createIndexFile({ buildDir, isTheme, themeVariant }) {. Makes it more explicit what args you're passing in at first glance.


program
.version('0.0.1')
.description('CLI to build design tokens for various platforms (currently only CSS is supported) from Paragon Design Tokens.')
.option('--build-dir <char>', 'A path to directory where to put files with built tokens, must end with a /.', './build/')
.option('--source <char>', 'A path where to look for additional tokens that will get merged with Paragon ones, must be a path to root directory of the token files that contains "root" and "themes" subdirectories.')
.option('--source-tokens-only', 'If provided, only tokens from --source will be included in the output; Paragon tokens will be used for references but not included in the output.')
.option('--themes <themes...>', 'A list of all the themes do you want to build, by default Paragn build light theme.')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit grammar and typo. Perhaps something like:

Suggested change
.option('--themes <themes...>', 'A list of all the themes do you want to build, by default Paragn build light theme.')
.option('--themes <themes...>', 'A list of theme variants to build. By default, Paragon currently only supports a light theme.')

tokens/utils.js Outdated
@@ -162,7 +162,37 @@ async function transformInPath(location, variablesMap, transformType = 'definiti
}
}


function createIndexFile(buildDir, isTheme, themeVariant){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: tiny naming nit; perhaps something like createIndexCssFile just to be a tad bit more explicit in what type of file is being created by this function?

tokens/utils.js Outdated
return;
}

const jsonFiles = files.filter(file => file !== 'index.css');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[clarification] Is this variable named jsonFiles because the resulting file names are the output from building the JSON design tokens? If so, this wasn't immediately obvious where for awhile I was thinking the files contains file names with .json file extensions but I don't think that's the case? If we're solely working with CSS files here, I wonder if there's a clearer name here, e.g. nonIndexCssFiles or outputCssFiles, etc.

tokens/utils.js Outdated
}

const jsonFiles = files.filter(file => file !== 'index.css');
isTheme && jsonFiles.reverse();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be worth leaving a comment in the code explaining why the .reverse() is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add a comment, it's not exactly necessary, it's just to maintain the order, I mean variables first when run build-scss.

A more explicit approach could be the following:

outputCssFiles.sort((a,b) => a.includes('variables') ? -1 : 0)

@mphilbrick211 mphilbrick211 added the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Jun 7, 2023
@codecov
Copy link

codecov bot commented Jun 7, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.58%. Comparing base (73335b9) to head (95f1134).
Report is 878 commits behind head on alpha.

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #2357   +/-   ##
=======================================
  Coverage   91.58%   91.58%           
=======================================
  Files         214      214           
  Lines        3519     3519           
  Branches      852      852           
=======================================
  Hits         3223     3223           
  Misses        288      288           
  Partials        8        8           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@e0d e0d removed the needs test run Author's first PR to this repository, awaiting test authorization from Axim label Jun 7, 2023
Copy link
Member

@adamstankiewicz adamstankiewicz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, lgtm! Appreciate the contribution 🙌 💯

@adamstankiewicz adamstankiewicz merged commit 13c53d0 into openedx:alpha Jun 7, 2023
@openedx-webhooks
Copy link

@dcoa 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@edx-semantic-release
Copy link
Contributor

🎉 This PR is included in version 21.0.0-alpha.37 🎉

The release is available on:

Your semantic-release bot 📦🚀

monteri pushed a commit to raccoongang/paragon that referenced this pull request Aug 17, 2023
PKulkoRaccoonGang pushed a commit to raccoongang/paragon that referenced this pull request Aug 18, 2023
@edx-semantic-release
Copy link
Contributor

🎉 This PR is included in version 22.0.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@openedx-semantic-release-bot

🎉 This PR is included in version 23.0.0-alpha.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@openedx-semantic-release-bot

🎉 This PR is included in version 23.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

7 participants