Skip to content

Commit

Permalink
refactor: destructure and dedupe repeated enum members
Browse files Browse the repository at this point in the history
Update import enum paths for examples
  • Loading branch information
Dario Soller committed Oct 29, 2024
1 parent 87cb861 commit bea5162
Show file tree
Hide file tree
Showing 78 changed files with 808 additions and 638 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ StyleDictionary.buildAllPlatforms();
The `.extend()` method is an overloaded method that can also take an object with the configuration in the same format as a config.json file.

```javascript
import { fileFormats, transformGroups } from 'style-dictionary/enums';

const StyleDictionary = require('style-dictionary').extend({
source: ['tokens/**/*.json'],
platforms: {
Expand Down Expand Up @@ -294,6 +296,7 @@ The style dictionary build system is made to be extended. We don't know exactly

```javascript
const StyleDictionary = require('style-dictionary').extend('config.json');
import { transforms, transformTypes } from 'style-dictionary/enums';

StyleDictionary.registerTransform({
name: transforms.timeSeconds,
Expand Down
14 changes: 7 additions & 7 deletions __integration__/async.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { transforms, propertyFormatNames, transformTypes } from '../lib/enums/in
const sleep = async (time) => {
await new Promise((resolve) => setTimeout(resolve, time));
};

const { attributeCti, nameKebab, timeSeconds, htmlIcon, sizeRem, colorCss } = transforms;
const textFile = resolve(`${buildPath}text.txt`);

// Tests all hooks async, into a single config
Expand Down Expand Up @@ -101,12 +101,12 @@ describe('integration', async function () {
platforms: {
css: {
transforms: [
transforms.attributeCti,
transforms.nameKebab,
transforms.timeSeconds,
transforms.htmlIcon,
transforms.sizeRem,
transforms.colorCss,
attributeCti,
nameKebab,
timeSeconds,
htmlIcon,
sizeRem,
colorCss,
'foo-value-transform',
],
buildPath,
Expand Down
6 changes: 4 additions & 2 deletions __integration__/compose.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { buildPath } from './_constants.js';
import { clearOutput } from '../__tests__/__helpers.js';
import { fileFormats } from '../lib/enums/index.js';

const { composeObject } = fileFormats;

describe('integration', async () => {
before(async () => {
const sd = new StyleDictionary({
Expand All @@ -29,15 +31,15 @@ describe('integration', async () => {
files: [
{
destination: 'StyleDictionary.kt',
format: fileFormats.composeObject,
format: composeObject,
options: {
className: 'StyleDictionary',
packageName: 'com.example.tokens',
},
},
{
destination: 'StyleDictionaryWithReferences.kt',
format: fileFormats.composeObject,
format: composeObject,
options: {
outputReferences: true,
className: 'StyleDictionary',
Expand Down
12 changes: 7 additions & 5 deletions __integration__/css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { buildPath } from './_constants.js';
import { clearOutput } from '../__tests__/__helpers.js';
import { fileFormats, transformGroups } from '../lib/enums/index.js';

const { cssVariables } = fileFormats;

describe('integration', async () => {
before(async () => {
const sd = new StyleDictionary({
Expand All @@ -39,30 +41,30 @@ describe('integration', async () => {
files: [
{
destination: 'variables.css',
format: fileFormats.cssVariables,
format: cssVariables,
options: {
formatting: { indentation: ' ' },
},
},
{
destination: 'variablesWithReferences.css',
format: fileFormats.cssVariables,
format: cssVariables,
options: {
outputReferences: true,
outputReferenceFallbacks: false,
},
},
{
destination: 'variablesWithReferenceFallbacks.css',
format: fileFormats.cssVariables,
format: cssVariables,
options: {
outputReferences: true,
outputReferenceFallbacks: true,
},
},
{
destination: 'variablesWithSelector.css',
format: fileFormats.cssVariables,
format: cssVariables,
options: {
selector: '.test',
},
Expand All @@ -79,7 +81,7 @@ describe('integration', async () => {
});

describe('css', async () => {
describe(fileFormats.cssVariables, async () => {
describe(cssVariables, async () => {
it(`should match snapshot`, async () => {
const output = fs.readFileSync(resolve(`${buildPath}variables.css`), {
encoding: 'UTF-8',
Expand Down
6 changes: 4 additions & 2 deletions __integration__/customFormats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { buildPath } from './_constants.js';
import { clearOutput } from '../__tests__/__helpers.js';
import { transformGroups } from '../lib/enums/index.js';

const { js } = transformGroups;

describe('integration', async () => {
before(async () => {
const sd = new StyleDictionary({
Expand All @@ -35,7 +37,7 @@ describe('integration', async () => {
},
platforms: {
inlineCustomFormats: {
transformGroup: transformGroups.js,
transformGroup: js,
buildPath,
options: {
otherOption: `platform option`,
Expand All @@ -60,7 +62,7 @@ describe('integration', async () => {
],
},
customFormats: {
transformGroup: transformGroups.js,
transformGroup: js,
buildPath,
options: {
otherOption: `platform option`,
Expand Down
10 changes: 6 additions & 4 deletions __integration__/flutter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { buildPath } from './_constants.js';
import { clearOutput } from '../__tests__/__helpers.js';
import { fileFormats } from '../lib/enums/index.js';

const { flutterClassDart } = fileFormats;

describe('integration', async () => {
before(async () => {
const sd = new StyleDictionary({
Expand All @@ -29,14 +31,14 @@ describe('integration', async () => {
files: [
{
destination: 'style_dictionary.dart',
format: fileFormats.flutterClassDart,
format: flutterClassDart,
options: {
className: 'StyleDictionary',
},
},
{
destination: 'style_dictionary_with_references.dart',
format: fileFormats.flutterClassDart,
format: flutterClassDart,
options: {
outputReferences: true,
className: 'StyleDictionary',
Expand All @@ -50,7 +52,7 @@ describe('integration', async () => {
files: [
{
destination: 'style_dictionary_color.dart',
format: fileFormats.flutterClassDart,
format: flutterClassDart,
options: {
className: 'StyleDictionaryColor',
type: 'color',
Expand All @@ -61,7 +63,7 @@ describe('integration', async () => {
},
{
destination: 'style_dictionary_sizes.dart',
format: fileFormats.flutterClassDart,
format: flutterClassDart,
options: {
className: 'StyleDictionarySize',
type: 'float',
Expand Down
17 changes: 10 additions & 7 deletions __integration__/iOSObjectiveC.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { buildPath } from './_constants.js';
import { clearOutput } from '../__tests__/__helpers.js';
import { fileFormats } from '../lib/enums/index.js';

const { iosColorsH, iosColorsM, iosMacros, iosSingletonH, iosSingletonM, iosStaticH, iosStaticM } =
fileFormats;

describe('integration', async () => {
before(async () => {
const sd = new StyleDictionary({
Expand All @@ -29,21 +32,21 @@ describe('integration', async () => {
files: [
{
destination: 'singleton.m',
format: fileFormats.iosSingletonM,
format: iosSingletonM,
options: {
className: 'StyleDictionary',
},
},
{
destination: 'singleton.h',
format: fileFormats.iosSingletonH,
format: iosSingletonH,
options: {
className: 'StyleDictionary',
},
},
{
destination: 'color.h',
format: fileFormats.iosColorsH,
format: iosColorsH,
options: {
className: 'StyleDictionaryColor',
type: 'StyleDictionaryColorName',
Expand All @@ -52,7 +55,7 @@ describe('integration', async () => {
},
{
destination: 'color.m',
format: fileFormats.iosColorsM,
format: iosColorsM,
options: {
className: 'StyleDictionaryColor',
type: 'StyleDictionaryColorName',
Expand All @@ -61,11 +64,11 @@ describe('integration', async () => {
},
{
destination: 'macros.h',
format: fileFormats.iosMacros,
format: iosMacros,
},
{
destination: 'static.h',
format: fileFormats.iosStaticH,
format: iosStaticH,
options: {
className: 'StyleDictionaryStatic',
type: 'CGFloat',
Expand All @@ -74,7 +77,7 @@ describe('integration', async () => {
},
{
destination: 'static.m',
format: fileFormats.iosStaticM,
format: iosStaticM,
options: {
className: 'StyleDictionaryStatic',
type: 'CGFloat',
Expand Down
6 changes: 4 additions & 2 deletions __integration__/logging/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { buildPath, cleanConsoleOutput } from '../_constants.js';
import { clearOutput } from '../../__tests__/__helpers.js';
import { logWarningLevels, logVerbosityLevels } from '../../lib/enums/index.js';

const { error: errorLog, disabled } = logWarningLevels;

/**
* These integration tests will verify the behavior and logging at the *config*
* level. These messages happen when `.extend()` is called to verify
Expand Down Expand Up @@ -71,7 +73,7 @@ describe(`integration >`, () => {
it(`should not log anything if the log warnings is set to disabled`, async () => {
const sd = new StyleDictionary({
log: {
warnings: logWarningLevels.disabled,
warnings: disabled,
},
source: [
// including a specific file twice will throw value collision warnings
Expand All @@ -87,7 +89,7 @@ describe(`integration >`, () => {
it(`should not show warnings if given higher log level`, async () => {
const sd = new StyleDictionary(
{
log: { warnings: logWarningLevels.error },
log: { warnings: errorLog },
source: [
// including a specific file twice will throw value collision warnings
`__integration__/tokens/size/padding.json`,
Expand Down
Loading

0 comments on commit bea5162

Please sign in to comment.