Skip to content

Commit

Permalink
chore: update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenbroekema committed Nov 28, 2023
1 parent 1a7fcf9 commit e432d83
Show file tree
Hide file tree
Showing 28 changed files with 273 additions and 207 deletions.
1 change: 1 addition & 0 deletions docs/_coverpage.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
[Get Started](README.md)

[See what's new in 3.0!](version_3.md)
[See what's new in 4.0!](version_4.md)

![color](#D9F8F5)
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- [Overview](README.md)
- [What's new in 3.0](version_3.md)
- [What's new in 4.0](version_4.md)
- [Quick Start](quick_start.md)
- [Examples](examples.md)
- [Config](config.md)
Expand Down
193 changes: 107 additions & 86 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,108 @@
<!--
DO NOT EDIT THIS FILE DIRECTLY, THIS FILE IS GENERATED BY JSDOC!
EDIT scripts/handlebars/templates/api.hbs OR JSDOC COMMENT INSTEAD!
-->

# API

### buildAllPlatforms
## new StyleDictionary()

> new StyleDictionary() ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
Create a new StyleDictionary instance.

| Param | Type | Description |
| ------------ | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| config | [<code>Config</code>](#Config) | Configuration options to build your style dictionary. If you pass a string, it will be used as a path to a JSON config file. You can also pass an object with the configuration. |
| options | <code>Object</code> | Options object when creating a new StyleDictionary instance. |
| options.init | <code>Boolean</code> | `true` by default but can be disabled to delay initializing the dictionary. You can then call `sdInstance.init()` yourself, e.g. for testing or error handling purposes. |

**Example**

```js
import StyleDictionary from 'style-dictionary';

const sd = new StyleDictionary('config.json');
const sdTwo = new StyleDictionary({
source: ['tokens/*.json'],
platforms: {
scss: {
transformGroup: 'scss',
buildPath: 'build/',
files: [
{
destination: 'variables.scss',
format: 'scss/variables',
},
],
},
// ...
},
});
```

## init

> StyleDictionary.init() ⇒ [<code>Promise<style-dictionary></code>](#module_style-dictionary)
Called automatically when doing `new StyleDictionary(config)` unless passing a second argument with `init` property set to `false`. In this scenario, you can call `.init()` manually, e.g. for testing or error handling purposes.

## extend

> StyleDictionary.extend(config) ⇒ [<code>Promise<style-dictionary></code>](#module_style-dictionary)
Extend a Style Dictionary instance with a config object, to create an extension instance.

| Param | Type | Description |
| -------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| config | [<code>Config</code>](#Config) | Configuration options to build your style dictionary. If you pass a string, it will be used as a path to a JSON config file. You can also pass an object with the configuration. |
| mutateOriginal | [<code>Boolean</code>](#Config) | Whether or not the original SD instance should be mutated during extension. `false` by default. You will likely never need to set this to `true`, consider this argument private. |

**Example**

```js
import StyleDictionary from 'style-dictionary';

const sd = new StyleDictionary('config.json');

const sdExtended = await sd.extend({
source: ['tokens/*.json'],
platforms: {
scss: {
transformGroup: 'scss',
buildPath: 'build/',
files: [
{
destination: 'variables.scss',
format: 'scss/variables',
},
],
},
// ...
},
});
```

---

> StyleDictionary.buildAllPlatforms() ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
## buildAllPlatforms

> StyleDictionary.buildAllPlatforms() ⇒ [<code>Promise<style-dictionary></code>](#module_style-dictionary)
The only top-level method that needs to be called
to build the Style Dictionary.

**Example**

```js
const StyleDictionary = require('style-dictionary').extend('config.json');
StyleDictionary.buildAllPlatforms();
import StyleDictionary from 'style-dictionary';
const sd = new StyleDictionary('config.json');

// Async, so you can do `await` or .then() if you
// want to execute code after buildAllPlatforms has completed
await sd.buildAllPlatforms();
```

---

### buildPlatform
## buildPlatform

> StyleDictionary.buildPlatform(platform) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
> StyleDictionary.buildPlatform(platform) ⇒ [<code>Promise<style-dictionary></code>](#module_style-dictionary)
Takes a platform and performs all transforms to
the tokens object (non-mutative) then
Expand All @@ -40,7 +119,9 @@ build each platform defined in the config.
**Example**

```js
StyleDictionary.buildPlatform('web');
// Async, so you can do `await` or .then() if you
// want to execute code after buildAllPlatforms has completed
await sd.buildPlatform('web');
```

```bash
Expand All @@ -49,19 +130,19 @@ $ style-dictionary build --platform web

---

### cleanAllPlatforms
## cleanAllPlatforms

> StyleDictionary.cleanAllPlatforms() ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
> StyleDictionary.cleanAllPlatforms() ⇒ [<code>Promise<style-dictionary></code>](#module_style-dictionary)
Does the reverse of [buildAllPlatforms](#buildAllPlatforms) by
performing a clean on each platform. This removes all the files
defined in the platform and calls the undo method on any actions.

---

### cleanPlatform
## cleanPlatform

> StyleDictionary.cleanPlatform(platform) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
> StyleDictionary.cleanPlatform(platform) ⇒ [<code>Promise<style-dictionary></code>](#module_style-dictionary)
Takes a platform and performs all transforms to
the tokens object (non-mutative) then
Expand All @@ -73,9 +154,9 @@ cleans all the files and performs the undo method of any [actions](actions.md).

---

### exportPlatform
## exportPlatform

> StyleDictionary.exportPlatform(platform) ⇒ <code>Object</code>
> StyleDictionary.exportPlatform(platform) ⇒ <code>Promise<Object></code>
Exports a tokens object with applied
platform transforms.
Expand All @@ -89,42 +170,7 @@ dictionary in JS build tools like webpack.

---

### extend

> StyleDictionary.extend(config) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
Create a Style Dictionary

| Param | Type | Description |
| ------ | ------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| config | [<code>Config</code>](#Config) | Configuration options to build your style dictionary. If you pass a string, it will be used as a path to a JSON config file. You can also pass an object with the configuration. |

**Example**

```js
const StyleDictionary = require('style-dictionary').extend('config.json');

const StyleDictionary = require('style-dictionary').extend({
source: ['tokens/*.json'],
platforms: {
scss: {
transformGroup: 'scss',
buildPath: 'build/',
files: [
{
destination: 'variables.scss',
format: 'scss/variables',
},
],
},
// ...
},
});
```

---

### registerAction
## registerAction

> StyleDictionary.registerAction(action) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
Expand Down Expand Up @@ -165,7 +211,7 @@ StyleDictionary.registerAction({

---

### registerFileHeader
## registerFileHeader

> StyleDictionary.registerFileHeader(options) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
Expand All @@ -191,7 +237,7 @@ StyleDictionary.registerFileHeader({

---

### registerFilter
## registerFilter

> StyleDictionary.registerFilter(filter) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
Expand All @@ -216,7 +262,7 @@ StyleDictionary.registerFilter({

---

### registerFormat
## registerFormat

> StyleDictionary.registerFormat(format) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
Expand All @@ -241,7 +287,7 @@ StyleDictionary.registerFormat({

---

### registerParser
## registerParser

> StyleDictionary.registerParser(pattern, parse) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
Expand All @@ -265,7 +311,7 @@ StyleDictionary.registerParser({

---

### registerPreprocessor
## registerPreprocessor

> StyleDictionary.registerPreprocessor({ name, preprocessor }) => [<code>style-dictionary</code>](#module_style-dictionary)
Expand All @@ -291,32 +337,7 @@ StyleDictionary.registerPreprocessor({

---

### registerTemplate

> ~~StyleDictionary.registerTemplate(template) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)~~
**_Deprecated_**

Add a custom template to the Style Dictionary

| Param | Type | Description |
| ----------------- | ------------------- | --------------------------------------------------------------------------- |
| template | <code>Object</code> | |
| template.name | <code>String</code> | The name of your template. You will refer to this in your config.json file. |
| template.template | <code>String</code> | Path to your lodash template |

**Example**

```js
StyleDictionary.registerTemplate({
name: 'Swift/colors',
template: __dirname + '/templates/swift/colors.template',
});
```

---

### registerTransform
## registerTransform

> StyleDictionary.registerTransform(transform) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
Expand Down Expand Up @@ -352,7 +373,7 @@ StyleDictionary.registerTransform({

---

### registerTransformGroup
## registerTransformGroup

> StyleDictionary.registerTransformGroup(transformGroup) ⇒ [<code>style-dictionary</code>](#module_style-dictionary)
Expand Down
12 changes: 6 additions & 6 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Here is an example using a CommonJS module for configuration:

```javascript
// config.js
module.exports = {
export default {
source: [`tokens/**/*.json`],
// If you don't want to call the registerTransform method a bunch of times
// you can override the whole transform object directly. This works because
Expand Down Expand Up @@ -116,20 +116,20 @@ You can also use Style Dictionary as an [npm module](using_the_npm_module.md) an

```javascript
// build.js
const StyleDictionary = require('style-dictionary');
import StyleDictionary from 'style-dictionary';

const myStyleDictionary = StyleDictionary.extend({
const myStyleDictionary = new StyleDictionary({
// configuration
});

myStyleDictionary.buildAllPlatforms();
await myStyleDictionary.buildAllPlatforms();

// You can also extend Style Dictionary multiple times:
const myOtherStyleDictionary = myStyleDictionary.extend({
const myOtherStyleDictionary = await myStyleDictionary.extend({
// new configuration
});

myOtherStyleDictionary.buildAllPlatforms();
await myOtherStyleDictionary.buildAllPlatforms();
```

You would then change your npm script or CLI command to run that file with Node:
Expand Down
14 changes: 9 additions & 5 deletions docs/extending.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ There is a straightforward way to extend Style Dictionary to meet your needs - s
Importing a configuration, defining a new `time/seconds` transform, and building the style dictionary.

```javascript
const StyleDictionary = require('style-dictionary').extend('config.json');
import StyleDictionary from 'style-dictionary';

StyleDictionary.registerTransform({
name: 'time/seconds',
Expand All @@ -31,14 +31,16 @@ StyleDictionary.registerTransform({
},
});

StyleDictionary.buildAllPlatforms();
const sd = new StyleDictionary('config.json');
await sd.buildAllPlatforms();
```

Export your extended style dictionary as a node module (without building) if you need other projects to depend on it.

```javascript
// package a
const StyleDictionary = require('style-dictionary').extend('config.json');
import StyleDictionary from 'style-dictionary';

StyleDictionary.registerTransform({
name: 'name/uppercase',
type: 'name',
Expand All @@ -47,8 +49,10 @@ StyleDictionary.registerTransform({
},
});

module.exports = StyleDictionary;
const sd = new StyleDictionary('config.json');

export default sd;

// package b
const StyleDictionary = require('package-a');
import sd from 'package-a';
```
Loading

0 comments on commit e432d83

Please sign in to comment.