D
D
Developers
Search…
Contribution Point
In many cases, you would like to allow users to have fine-grained control over the exporter behavior, and maybe deeply integrate it with the Supernova interface as well. For this reason, exporters have access to contribution points, which allow them to directly integrate with Supernova.

Using contribution point

Contributions are done by expanding exporter.json with contributes key (object). For example, this is how you would expand exporter.json to contribute user configuration into Supernova interface:
1
{
2
"id": "io.supernova.html-preview",
3
"name": "HTML Preview",
4
"description": "Exporter for visual preview of design system elements",
5
....
6
"contributes": {
7
"configuration": [{
8
"default": true,
9
"key": "generateColors",
10
"label": "Generate color list page",
11
"type": "boolean"
12
}]
13
}
14
}
Copied!
To use specific functionality within the contribution point, simply add one of the following keys with their respective sub-definitions. Each key defines one specific area of contributions:
  • configuration - Allows to define configuration values that can be changed by the user, and then accessed inside blueprints or to modify which files should be produced by the exporter.

Contribution Point: Configuration

Configuration allows you to expose certain properties of the exporter to the user without them needing to clone or fork your exporter to make the change:
1
....
2
"contributes": {
3
"configuration": [{
4
"default": true,
5
"key": "booleanKey",
6
"label": "Boolean value you can set",
7
"type": "boolean"
8
},{
9
"default": "SN",
10
"key": "stringKey",
11
"label": "String value you can set",
12
"type": "string"
13
},{
14
"default": 42,
15
"key": "numericKey",
16
"label": "Numeric value you can set",
17
"type": "number"
18
}]
19
}
Copied!
There are three types of configuration options:
  • number forcing numeric input from the user of your exporter
  • string forcing string input from the user of your exporter
  • boolean forcing true/false input from the user of your exporter
Each of the entries in the configuration must define the following keys:
  • key that you will use to reference this configuration in your blueprints
  • label which is human-readable description that will show inside the interface
  • type which defines the type of the configuration - number, string or boolean
  • default value which is provided when the user doesn't override given values
You can declare an unlimited number of configuration keys, to give users as much flexibility as you want. User can override default values inside the settings for each exporter.

Using configuration inside blueprints

You can use configuration keys to decide the behavior from your code blueprints. To do that, simply call the configuration function @configuration() and access any of the declared configuration keys. For example, to generate class name with prefix provided by the user, you can declare the following:
1
....
2
"contributes": {
3
"configuration": [{
4
"default": "", // Empty prefix by default
5
"key": "classPrefix",
6
"label": "Prefix for all generated classes",
7
"type": "string"
8
}]
9
}
Copied!
Then, in your blueprint, simply retrieve that information:
1
{[ const className = "Colors".prefixed(@configuration.classPrefix) /]}
Copied!
The resulting variable will contain a prefixed value if user-provided one, or just Colors if they did not.

Using configuration inside javascript

The same configuration can also be accessed inside your javascript code. To do that, simply access the configuration through Pulsar.configuration property:
1
/**
2
* Convert group into properly formatted header
3
*/
4
Pulsar.registerFunction("formattedGroupHeader", function (tokenGroup, showSubpath) {
5
6
// Retrieve token group either including or not including the path to the group
7
if (tokenGroup.path.length > 0) {
8
let light = tokenGroup.path.join(" / ")
9
let dark = Pulsar.classPrefix + tokenGroup.name // Class prefix used for group name
10
return `<span class="light">${light} / </span>${dark}`
11
} else {
12
return tokenGroup.name
13
}
14
})
Copied!

Using configuration inside output.json

Lastly, you can use configuration to define the behavior of the file output. In this case, you can use your boolean keys to decide whether a file should be generated, or not. Simply add when to your output.json entry that defines one file:
1
{
2
"blueprints": [
3
{
4
"invoke": "colors.pr",
5
"write_to": "colors.html",
6
"when": "generateColors"
7
},
8
]
9
}
Copied!
In this case, when generateColors is true, colors.html will be generated, but otherwise, it will be ignored and won't show at the output.
You can also use negation to take the opposite value:
1
{
2
"blueprints": [
3
{
4
"invoke": "colors.pr",
5
"write_to": "colors.html",
6
"when": "!ignoreColors"
7
},
8
]
9
}
Copied!
This will generate colors.html only when ignoreColors is false. Note that in all cases, this key must be defined inside exporter.json in contributes.configuration, otherwise, an error will be thrown.
Behind the scenes: Right now, it is only possible to contribute dynamic configuration, but this feature will grow as we expand the capabilities of the system. Credits where due: Thanks to the VSCode developers for coming up with their contribution system in VSCode plugins, which inspired the creation of this system as well.
Last modified 7mo ago