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

Need examples of registerFilter for documentation update #303

Closed
gearsandcode opened this issue Jul 2, 2019 · 1 comment
Closed

Need examples of registerFilter for documentation update #303

gearsandcode opened this issue Jul 2, 2019 · 1 comment

Comments

@gearsandcode
Copy link

I'd be happy to take care of the #286, but wasn't able to get filter working. If anyone can provide working examples of filter in use, that would be awesome.

Here's my pseudo code that I couldn't get working:

"platforms": {
    "web/scss": {
            "transformGroup": "tokens-scss",
            "buildPath": `dist/${brand}/web/`,
            "prefix": "",
            "files": [
                {
                    "destination": `scss/${category}-tokens.scss`,
                    "format": "scss/variables",
                    "filter": "filter-alias"
                }
            ]
        }
}...

StyleDictionaryPackage.registerFilter({
    name: 'filter-alias',
    matcher: function(prop) {
        return prop.attributes.type !== 'alias';
    }
})
@dbanksdesign
Copy link
Member

I made this quick example (simplified from your code a bit):

const StyleDictionary = require('style-dictionary');

StyleDictionary.registerFilter({
  name: 'filter-alias',
  matcher: function(prop) {
    return prop.attributes.type !== 'alias';
  }
});

StyleDictionary.extend({
  "source": ["tokens/**/*.json"],
  "platforms": {
    "web/scss": {
      "transformGroup": "scss",
      "buildPath": "dist/",
      "prefix": "",
      "files": [
        {
          "destination": "scss/variables.scss",
          "format": "scss/variables",
          "filter": "filter-alias"
        }
      ]
    }
  }
}).buildAllPlatforms();

And it works. One thing to note is the filter will include only when the matcher returns true. This is definitely something we should add to the docs though, filtering is not very well documented yet.

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

No branches or pull requests

2 participants