-
Notifications
You must be signed in to change notification settings - Fork 566
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
How to include comments in build files #344
Comments
Yes, but you will need to create a custom format. Here is something I threw together quickly, let me know if it makes sense: const StyleDictionary = require('style-dictionary');
StyleDictionary.registerFormat({
name: 'scss/variables',
formatter: function(dictionary, config) {
const header = `/**\n` +
this.header.split('\n').map((line) => ` * ${line}`).join('\n') +
`\n */\n`;
return header +
dictionary.allProperties.map((prop) => `$${prop.name}: ${prop.value};`).join('\n');
}
});
module.exports = {
"source": ["properties/**/*.json"],
"platforms": {
"scss": {
"transformGroup": "scss",
"buildPath": "build/scss/",
"files": [{
"header": `@tokens Colors
@presenter Color`,
"destination": "_variables.scss",
"format": "scss/variables"
}]
},
}
} |
|
@davidrpoliti do you still need help with this? |
@dbanksdesign I do! I'm going to try to get this working tomorrow with one of my peers. Would I just add the commented out portion after |
Congrats! 🎉 I am about to do that myself. The custom format I created in that example will take what is in the |
@dbanksdesign this makes sense! and congrats to you as well! I'm pretty new at this, and I can't figure out where that snippet should live. Does it go in my storybook config? Happy to send you a coffee/venmo for helping me out. |
@davidrpoliti thanks! That snippet would live in your style dictionary configuration. If you have a repository you are working on I could take a look at I could tell you exactly where it goes. |
Hey @dbanksdesign, What if i want multiple headers in single file like for colors, border-radius, line-height, This just create one header at top level. |
To build on the comments above, I'd love to build a mixed This plays very nicely with the Storybook Design Token add-on. |
@avkvirtru having a storybook design token format would be awesome! |
I think this might answer the need: |
This is now part of 3.0 via #572 |
This shouldnt be closed, as the actual question is to work with the design-token-addon. Personally I think the addon lacks extendibility for custom tokens. Now you need to adhere to the available presenters provided by the addon. But if your CSS file has different token names, then the addon will break and throw an error instead. One thing I got to work is to create a custom Formatter in style dictionary: CC: @harrymansworth for helping me out on the final solution:
And then use this customFormat formatter in your config:
|
I'm using storybook to ingest the tokens built by style-dictionary. I need to include a commented-out header that gets added to the built scss.
Is there a way to add the header in my config, or base.json, so that the output build file looks like this?
The text was updated successfully, but these errors were encountered: