@koobiq/tokens-builder 3.0.0-rc.8 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Tokens Builder
2
2
 
3
3
  ## Overview
4
+
4
5
  Tokens builder is a configuration script that utilizes Style Dictionary,
5
- a design-token platform for creating and maintaining consistent design tokens across various platforms.
6
+ a design-token platform for creating and maintaining consistent design tokens across various platforms.
6
7
 
7
8
  Overall, this script orchestrates the generation of design tokens by applying custom transformations,
8
9
  filters, and formats to the specified theme configuration for multiple platforms,
9
10
  facilitating a streamlined design token workflow compatible with
10
11
  various output formats like SCSS, CSS, and TypeScript.
11
-
package/build.js CHANGED
@@ -7,6 +7,7 @@ require('./transforms/attribute/typography')(StyleDictionary);
7
7
  require('./transforms/attribute/palette')(StyleDictionary);
8
8
  require('./transforms/attribute/prefix')(StyleDictionary);
9
9
  require('./transforms/attribute/font')(StyleDictionary);
10
+ require('./transforms/attribute/theme')(StyleDictionary);
10
11
 
11
12
  // ==== Include custom filters ====
12
13
  require('./filters/palette')(StyleDictionary);
@@ -23,12 +24,12 @@ require('./transformGroups/ts')(StyleDictionary);
23
24
  // ==== Include custom formats ====
24
25
  require('./formats/typography')(StyleDictionary);
25
26
  require('./formats/palette')(StyleDictionary);
27
+ require('./formats/variables')(StyleDictionary);
26
28
 
27
29
  // ==== Run build ====
28
30
  console.log('Build started...');
29
31
  console.log('==============================================');
30
32
 
31
-
32
33
  module.exports = (themeConfig) => {
33
34
  StyleDictionary.registerFileHeader({
34
35
  name: 'customHeader',
@@ -38,14 +39,14 @@ module.exports = (themeConfig) => {
38
39
 
39
40
  if (!themeConfig || themeConfig.length === 0) {
40
41
  console.error('Build Failed. Please set ThemeConfig, for example: ', {
41
- name: 'default-theme',
42
- buildPath: [
43
- `design-tokens/tokens/properties/**/*.json5`,
44
- `design-tokens/tokens/components/**/*.json5`
45
- ],
46
- outputPath: 'design-tokens/'
47
- }
48
- )
42
+ name: 'default-theme',
43
+ // prettier-ignore
44
+ buildPath: [
45
+ `design-tokens/tokens/properties/**/*.json5`,
46
+ `design-tokens/tokens/components/**/*.json5`
47
+ ],
48
+ outputPath: 'design-tokens/'
49
+ });
49
50
  process.exit(0);
50
51
  }
51
52
 
@@ -61,4 +62,4 @@ module.exports = (themeConfig) => {
61
62
 
62
63
  console.log('\n==============================================');
63
64
  console.log('\nBuild completed!');
64
- }
65
+ };
package/configs/css.js CHANGED
@@ -1,11 +1,40 @@
1
1
  module.exports = {
2
2
  css: {
3
3
  transformGroup: 'kbq/css',
4
- files: [{
5
- destination: 'css-tokens.css',
6
- format: 'css/variables',
7
- filter: 'css-variables',
8
- prefix: 'kbq'
9
- }]
4
+ files: [
5
+ {
6
+ destination: 'css-tokens.css',
7
+ format: 'css/variables',
8
+ filter: 'css-variables',
9
+ prefix: 'kbq'
10
+ },
11
+ {
12
+ destination: 'css-tokens-light.css',
13
+ format: 'kbq-css/variables',
14
+ filter: 'css-variables-light',
15
+ prefix: 'kbq',
16
+ options: {
17
+ selector: '.kbq-light'
18
+ }
19
+ },
20
+ {
21
+ destination: 'css-tokens-dark.css',
22
+ format: 'kbq-css/variables',
23
+ filter: 'css-variables-dark',
24
+ prefix: 'kbq',
25
+ options: {
26
+ selector: '.kbq-dark'
27
+ }
28
+ },
29
+ {
30
+ destination: 'css-tokens-font.css',
31
+ format: 'kbq-css/variables',
32
+ filter: 'css-variables-font',
33
+ prefix: 'kbq',
34
+ options: {
35
+ selector: '.kbq-font'
36
+ }
37
+ }
38
+ ]
10
39
  }
11
40
  };
package/configs/index.js CHANGED
@@ -13,14 +13,14 @@ const filterObj = {
13
13
  function filterOptions(platforms) {
14
14
  const platformObj = {};
15
15
 
16
- platforms.map(p => Object.assign(platformObj, p));
16
+ platforms.map((p) => Object.assign(platformObj, p));
17
17
 
18
18
  Object.keys(platformObj).forEach((p) => {
19
- platformObj[p].files = platformObj[p].files.map(f => ({
19
+ platformObj[p].files = platformObj[p].files.map((f) => ({
20
20
  ...f,
21
21
  ...filterObj,
22
22
  options: {
23
- ...f.options ?? {},
23
+ ...(f.options ?? {}),
24
24
  ...filterObj.options
25
25
  }
26
26
  }));
@@ -30,7 +30,7 @@ function filterOptions(platforms) {
30
30
  }
31
31
 
32
32
  function getSources(theme) {
33
- return theme.buildPath.map(pathName => {
33
+ return theme.buildPath.map((pathName) => {
34
34
  if (pathName.startsWith('@')) {
35
35
  return join('node_modules', pathName);
36
36
  }
@@ -48,7 +48,6 @@ function getConfigs(theme) {
48
48
  }
49
49
 
50
50
  module.exports = (theme) => {
51
-
52
51
  return {
53
52
  source: [...getSources(theme)],
54
53
  platforms: getConfigs(theme)
package/configs/js.js CHANGED
@@ -13,4 +13,3 @@ module.exports = {
13
13
  ]
14
14
  }
15
15
  };
16
-
package/filters/color.js CHANGED
@@ -1,9 +1,6 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerFilter({
4
3
  name: 'color',
5
- matcher: (prop) => !prop.attributes.palette &&
6
- !prop.attributes.typography &&
7
- !prop.attributes['md-typography']
8
- })
9
- }
4
+ matcher: (prop) => !prop.attributes.palette && !prop.attributes.typography && !prop.attributes['md-typography']
5
+ });
6
+ };
@@ -1,6 +1,29 @@
1
1
  module.exports = (StyleDictionary) => {
2
2
  StyleDictionary.registerFilter({
3
3
  name: 'css-variables',
4
- matcher: (prop) => !prop.attributes.font && !prop.attributes.palette
5
- })
6
- }
4
+ matcher: (prop) => {
5
+ return (
6
+ !prop.attributes.font &&
7
+ !prop.attributes.palette &&
8
+ !prop.attributes.light &&
9
+ !prop.attributes.dark &&
10
+ !prop.attributes.font
11
+ );
12
+ }
13
+ });
14
+
15
+ StyleDictionary.registerFilter({
16
+ name: 'css-variables-light',
17
+ matcher: (prop) => prop.attributes.light
18
+ });
19
+
20
+ StyleDictionary.registerFilter({
21
+ name: 'css-variables-dark',
22
+ matcher: (prop) => prop.attributes.dark
23
+ });
24
+
25
+ StyleDictionary.registerFilter({
26
+ name: 'css-variables-font',
27
+ matcher: (prop) => prop.attributes.font
28
+ });
29
+ };
@@ -1,7 +1,6 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerFilter({
4
3
  name: 'md-typography',
5
4
  matcher: (prop) => prop.attributes['md-typography']
6
- })
7
- }
5
+ });
6
+ };
@@ -1,7 +1,6 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerFilter({
4
3
  name: 'palette',
5
4
  matcher: (prop) => prop.attributes.palette
6
- })
7
- }
5
+ });
6
+ };
@@ -1,7 +1,6 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerFilter({
4
3
  name: 'typography',
5
4
  matcher: (prop) => prop.attributes.typography
6
- })
7
- }
5
+ });
6
+ };
@@ -1,25 +1,22 @@
1
-
2
1
  module.exports = (StyleDictionary) => {
3
2
  StyleDictionary.registerFormat({
4
3
  name: 'kbq-scss/palette',
5
4
  formatter: function (dictionary) {
6
- return dictionary.allProperties
7
- .map((prop) => `\$${prop.name}: ${getMapFromObj(prop.value)};\n`)
8
- .join('\n');
5
+ return dictionary.allProperties.map((prop) => `\$${prop.name}: ${getMapFromObj(prop.value)};\n`).join('\n');
9
6
  }
10
- })
7
+ });
11
8
  };
12
9
 
13
10
  function getMapFromObj(object) {
14
11
  const result = Object.keys(object)
15
12
  .map((key) => {
16
13
  if (key === 'contrast') {
17
- return `${key}: ${getMapFromObj(object[key])}`
14
+ return `${key}: ${getMapFromObj(object[key])}`;
18
15
  }
19
16
 
20
- return `${key}: ${object[key].value},\n`
17
+ return `${key}: ${object[key].value},\n`;
21
18
  })
22
19
  .join('');
23
20
 
24
- return `(\n${result}\n)`
21
+ return `(\n${result}\n)`;
25
22
  }
@@ -1,45 +1,45 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerFormat({
4
3
  name: 'kbq-scss/typography',
5
- formatter: function(dictionary) {
4
+ formatter: function (dictionary) {
6
5
  let string;
7
6
 
8
7
  string = dictionary.allProperties
9
8
  .map((prop) => {
10
9
  let output = '';
11
10
 
12
- const value = prop.attributes.category === 'asset' ? `"${ prop.value }"` : prop.value;
11
+ const value = prop.attributes.category === 'asset' ? `"${prop.value}"` : prop.value;
13
12
 
14
- output += `$${ prop.name }: ${ value };`
13
+ output += `$${prop.name}: ${value};`;
15
14
 
16
15
  if (prop.comment) {
17
- output += ` // ${ prop.comment }`;
16
+ output += ` // ${prop.comment}`;
18
17
  }
19
18
 
20
19
  return output + '\n';
21
20
  })
22
21
  .join('');
23
22
 
24
- return string + `\n$${this.mapName || 'tokens' }: ${processJsonNode(dictionary.properties, 0)};\n`;
23
+ return string + `\n$${this.mapName || 'tokens'}: ${processJsonNode(dictionary.properties, 0)};\n`;
25
24
  }
26
- })
25
+ });
27
26
  };
28
27
 
29
-
30
28
  function processJsonNode(obj, depth) {
31
29
  let output = '';
32
30
 
33
31
  if (obj.hasOwnProperty('value')) {
34
32
  output += `$${obj.name}`;
35
33
  } else {
36
- output += '(\n'
37
- output += Object.keys(obj).map((newKey) => {
38
- const newProp = obj[newKey];
39
- const indent = ' '.repeat(depth+1);
40
-
41
- return `${indent}'${newKey}': ${processJsonNode(newProp, depth + 1)}`;
42
- }).join(',\n');
34
+ output += '(\n';
35
+ output += Object.keys(obj)
36
+ .map((newKey) => {
37
+ const newProp = obj[newKey];
38
+ const indent = ' '.repeat(depth + 1);
39
+
40
+ return `${indent}'${newKey}': ${processJsonNode(newProp, depth + 1)}`;
41
+ })
42
+ .join(',\n');
43
43
 
44
44
  output += '\n' + ' '.repeat(depth) + ')';
45
45
  }
@@ -0,0 +1,22 @@
1
+ const { formatHelpers } = require('style-dictionary');
2
+
3
+ module.exports = (StyleDictionary) => {
4
+ StyleDictionary.registerFormat({
5
+ name: 'kbq-css/variables',
6
+ formatter: function ({ dictionary, options = {}, file }) {
7
+ const selector = options.selector ? options.selector : `:root`;
8
+ const { outputReferences } = options;
9
+
10
+ dictionary.allTokens.forEach((token) => {
11
+ token.name = token.name.replace(/(light|dark)-/, '');
12
+ });
13
+
14
+ return (
15
+ formatHelpers.fileHeader({ file }) +
16
+ `${selector} {\n` +
17
+ formatHelpers.formattedVariables({ format: 'css', dictionary, outputReferences }) +
18
+ `\n}\n`
19
+ );
20
+ }
21
+ });
22
+ };
package/package.json CHANGED
@@ -19,5 +19,5 @@
19
19
  "default": "./*"
20
20
  }
21
21
  },
22
- "version": "3.0.0-rc.8"
22
+ "version": "3.0.0"
23
23
  }
@@ -1,11 +1,12 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerTransformGroup({
4
3
  name: 'kbq/css',
5
4
  transforms: [
6
5
  'attribute/cti',
7
6
  'kbq-attribute/palette',
8
7
  'kbq-attribute/font',
8
+ 'kbq-attribute/light',
9
+ 'kbq-attribute/dark',
9
10
  'name/cti/kebab',
10
11
  'color/css',
11
12
  'kbq/prefix'
@@ -1,5 +1,4 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerTransformGroup({
4
3
  name: 'kbq/scss',
5
4
  transforms: [
@@ -10,4 +9,4 @@ module.exports = (StyleDictionary) => {
10
9
  'name/cti/kebab'
11
10
  ]
12
11
  });
13
- }
12
+ };
@@ -1,12 +1,6 @@
1
1
  module.exports = (StyleDictionary) => {
2
2
  StyleDictionary.registerTransformGroup({
3
3
  name: 'kbq/ts',
4
- transforms: [
5
- 'attribute/cti',
6
- 'name/cti/pascal',
7
- 'kbq-attribute/palette',
8
- 'size/px',
9
- 'color/hex'
10
- ]
4
+ transforms: ['attribute/cti', 'name/cti/pascal', 'kbq-attribute/palette', 'size/px', 'color/hex']
11
5
  });
12
- }
6
+ };
@@ -1,5 +1,4 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerTransform({
4
3
  name: 'kbq-attribute/md-typography',
5
4
  type: 'attribute',
@@ -1,5 +1,4 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerTransform({
4
3
  name: 'kbq-attribute/palette',
5
4
  type: 'attribute',
@@ -0,0 +1,19 @@
1
+ module.exports = (StyleDictionary) => {
2
+ StyleDictionary.registerTransform({
3
+ name: 'kbq-attribute/light',
4
+ type: 'attribute',
5
+ matcher: ({ attributes }) => {
6
+ return (attributes.category === 'markdown' && attributes.item === 'light') || attributes.type === 'light';
7
+ },
8
+ transformer: () => ({ light: true })
9
+ });
10
+
11
+ StyleDictionary.registerTransform({
12
+ name: 'kbq-attribute/dark',
13
+ type: 'attribute',
14
+ matcher: ({ attributes }) => {
15
+ return (attributes.category === 'markdown' && attributes.item === 'dark') || attributes.type === 'dark';
16
+ },
17
+ transformer: () => ({ dark: true })
18
+ });
19
+ };
@@ -1,5 +1,4 @@
1
1
  module.exports = (StyleDictionary) => {
2
-
3
2
  StyleDictionary.registerTransform({
4
3
  name: 'kbq-attribute/typography',
5
4
  type: 'attribute',