style-dictionary 4.0.0-prerelease.1 → 4.0.0-prerelease.2

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.
Files changed (54) hide show
  1. package/bin/{style-dictionary → style-dictionary.js} +13 -13
  2. package/examples/advanced/auto-rebuild-watcher/package.json +1 -1
  3. package/examples/advanced/create-react-app/package.json +2 -1
  4. package/examples/advanced/create-react-native-app/package.json +5 -1
  5. package/examples/advanced/s3/upload.js +1 -1
  6. package/examples/advanced/yaml-tokens/sd.config.js +1 -1
  7. package/lib/StyleDictionary.js +451 -0
  8. package/lib/buildFile.js +46 -40
  9. package/lib/cleanDir.js +1 -1
  10. package/lib/cleanDirs.js +2 -2
  11. package/lib/cleanFile.js +1 -1
  12. package/lib/common/actions.js +12 -7
  13. package/lib/common/formatHelpers/getTypeScriptType.js +8 -7
  14. package/lib/common/formats.js +6 -6
  15. package/lib/common/templates/compose/object.kt.template.js +1 -1
  16. package/lib/common/templates/css/fonts.css.template.js +1 -1
  17. package/lib/common/templates/ios/singleton.m.template.js +10 -10
  18. package/lib/common/templates/scss/map-deep.template.js +3 -3
  19. package/lib/common/transforms.js +11 -1
  20. package/lib/filterTokens.js +76 -0
  21. package/lib/register/preprocessor.js +39 -0
  22. package/lib/register/transform.js +2 -1
  23. package/lib/register/transformGroup.js +1 -3
  24. package/lib/transform/config.js +26 -21
  25. package/lib/transform/object.js +18 -12
  26. package/lib/transform/{property.js → token.js} +1 -2
  27. package/lib/transform/{propertySetup.js → tokenSetup.js} +17 -17
  28. package/lib/utils/combineJSON.js +22 -12
  29. package/lib/utils/convertToBase64.js +3 -3
  30. package/lib/utils/createDictionary.js +10 -14
  31. package/lib/utils/createFormatArgs.js +1 -5
  32. package/lib/utils/deepExtend.js +15 -18
  33. package/lib/utils/deepmerge.js +14 -0
  34. package/lib/utils/{flattenProperties.js → flattenTokens.js} +10 -10
  35. package/lib/utils/preprocess.js +35 -0
  36. package/lib/utils/references/getName.js +2 -2
  37. package/lib/utils/references/getReferences.js +7 -7
  38. package/lib/utils/resolveObject.js +4 -5
  39. package/package.json +33 -20
  40. package/types/Config.d.ts +3 -2
  41. package/types/Dictionary.d.ts +0 -2
  42. package/types/FormatHelpers.d.ts +12 -23
  43. package/{lib/cleanAllPlatforms.js → types/Preprocessor.d.ts} +6 -17
  44. package/types/index.d.ts +23 -2
  45. package/types/index.test-d.ts +7 -0
  46. package/index-node.js +0 -7
  47. package/index.js +0 -84
  48. package/lib/buildAllPlatforms.js +0 -37
  49. package/lib/buildPlatform.js +0 -67
  50. package/lib/cleanPlatform.js +0 -59
  51. package/lib/exportPlatform.js +0 -131
  52. package/lib/extend.js +0 -162
  53. package/lib/filterProperties.js +0 -92
  54. package/lib/utils/es6_.js +0 -151
@@ -11,7 +11,6 @@
11
11
  * and limitations under the License.
12
12
  */
13
13
 
14
- import { cloneDeep } from './es6_.js';
15
14
  import GroupMessages from './groupMessages.js';
16
15
  import usesReference from './references/usesReference.js';
17
16
  import getName from './references/getName.js';
@@ -31,7 +30,7 @@ let updated_object, regex, options;
31
30
  export default function resolveObject(object, opts) {
32
31
  options = Object.assign({}, defaults, opts);
33
32
 
34
- updated_object = cloneDeep(object); // This object will be edited
33
+ updated_object = structuredClone(object); // This object will be edited
35
34
 
36
35
  regex = createReferenceRegex(options);
37
36
 
@@ -113,7 +112,7 @@ function compile_value(value, stack) {
113
112
 
114
113
  // Recursive, therefore we can compute multi-layer variables like a = b, b = c, eventually a = c
115
114
  if (usesReference(to_ret, regex)) {
116
- var reference = to_ret.slice(1, -1);
115
+ const reference = to_ret.slice(1, -1);
117
116
 
118
117
  // Compare to found circular references
119
118
  if (foundCirc.hasOwnProperty(reference)) {
@@ -123,10 +122,10 @@ function compile_value(value, stack) {
123
122
  // chop down only the circular part, save it to our circular reference info, and spit out an error
124
123
 
125
124
  // Get the position of the existing reference in the stack
126
- var stackIndexReference = stack.indexOf(reference);
125
+ const stackIndexReference = stack.indexOf(reference);
127
126
 
128
127
  // Get the portion of the stack that starts at the circular reference and brings you through until the end
129
- var circStack = stack.slice(stackIndexReference);
128
+ const circStack = stack.slice(stackIndexReference);
130
129
 
131
130
  // For all the references in this list, add them to the list of references that end up in a circular reference
132
131
  circStack.forEach(function (key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "style-dictionary",
3
- "version": "4.0.0-prerelease.1",
3
+ "version": "4.0.0-prerelease.2",
4
4
  "description": "Style once, use everywhere. A build system for creating cross-platform styles.",
5
5
  "keywords": [
6
6
  "style dictionary",
@@ -9,7 +9,6 @@
9
9
  "amazon",
10
10
  "css",
11
11
  "design",
12
- "properties",
13
12
  "tokens",
14
13
  "sass",
15
14
  "scss",
@@ -23,10 +22,12 @@
23
22
  "exports": {
24
23
  ".": {
25
24
  "types": "./types/index.d.ts",
26
- "node": "./index-node.js",
27
- "default": "./index.js"
25
+ "default": "./lib/StyleDictionary.js"
28
26
  },
29
- "./fs": "./fs.js"
27
+ "./fs": {
28
+ "node": "./fs-node.js",
29
+ "default": "./fs.js"
30
+ }
30
31
  },
31
32
  "bin": {
32
33
  "style-dictionary": "./bin/style-dictionary"
@@ -47,19 +48,23 @@
47
48
  ],
48
49
  "scripts": {
49
50
  "format": "run-p format:*",
50
- "format:eslint": "eslint --fix index.js \"lib/**/*.js\" \"__tests__/**/*.js\"",
51
+ "format:eslint": "eslint --fix \"**/*.js\"",
51
52
  "format:prettier": "prettier \"**/*.{js,md}\" \"package.json\" --write",
52
53
  "lint": "run-p lint:*",
53
- "lint:eslint": "eslint index.js \"lib/**/*.js\" \"__tests__/**/*.js\"",
54
+ "lint:eslint": "eslint \"**/*.js\"",
54
55
  "lint:prettier": "prettier \"**/*.{js,md}\" \"package.json\" --list-different || (echo '↑↑ these files are not prettier formatted ↑↑' && exit 1)",
55
- "test": "run-p test:*",
56
- "test:unit": "jest --runInBand --silent --coverage",
57
- "test:types": "tsd",
56
+ "test": "npm run test:browser && npm run test:node",
57
+ "test:browser": "web-test-runner --coverage",
58
+ "test:browser:coverage": "cd coverage/lcov-report && npx http-server -o -c-1",
59
+ "test:browser:watch": "web-test-runner --watch",
60
+ "test:browser:update-snapshots": "web-test-runner --update-snapshots",
61
+ "test:node": "mocha -r mocha-hooks.mjs './__integration__/**/*.test.js' './__tests__/**/*.test.js' './__node_tests__/**/*.test.js'",
58
62
  "generate-docs": "node ./scripts/generateDocs.js",
59
63
  "serve-docs": "docsify serve docs -p 3000 -P 12345",
60
64
  "install-cli": "npm install -g $(npm pack)",
61
65
  "release": "node scripts/inject-version.js && changeset publish",
62
- "prepare": "husky install"
66
+ "prepare": "husky install",
67
+ "postinstall": "patch-package"
63
68
  },
64
69
  "standard-version": {
65
70
  "scripts": {
@@ -88,7 +93,7 @@
88
93
  "/__tests__/__assets/",
89
94
  "/__tests__/__configs/",
90
95
  "/__tests__/__json_files/",
91
- "/__tests__/__properties/",
96
+ "/__tests__/__tokens/",
92
97
  "/__tests__/__output/",
93
98
  "/__tests__/formats/__constants.js"
94
99
  ],
@@ -134,6 +139,7 @@
134
139
  ],
135
140
  "homepage": "https://github.com/amzn/style-dictionary",
136
141
  "dependencies": {
142
+ "@bundled-es-modules/deepmerge": "^4.3.1",
137
143
  "@bundled-es-modules/glob": "^10.3.5",
138
144
  "@bundled-es-modules/memfs": "^4.2.3",
139
145
  "@bundled-es-modules/path-browserify": "^1.0.2",
@@ -141,6 +147,7 @@
141
147
  "change-case": "^4.1.2",
142
148
  "commander": "^8.3.0",
143
149
  "fs-extra": "^10.0.0",
150
+ "is-plain-object": "^5.0.0",
144
151
  "json5": "^2.2.2",
145
152
  "jsonc-parser": "^3.0.0",
146
153
  "lodash": "^4.17.15",
@@ -149,30 +156,36 @@
149
156
  "url": "^0.11.1"
150
157
  },
151
158
  "devDependencies": {
152
- "@babel/preset-env": "^7.16.11",
159
+ "@babel/plugin-proposal-private-property-in-object": "^7.21.11",
153
160
  "@changesets/cli": "^2.26.2",
154
161
  "@commitlint/cli": "^16.1.0",
155
162
  "@commitlint/config-conventional": "^16.0.0",
156
- "babel-jest": "^27.4.6",
157
- "babel-preset-env": "^1.7.0",
163
+ "@esm-bundle/chai-as-promised": "^7.1.1",
164
+ "@types/chai": "^4.3.9",
165
+ "@web/test-runner": "^0.18.0",
166
+ "@web/test-runner-commands": "^0.9.0",
167
+ "@web/test-runner-playwright": "^0.11.0",
168
+ "chai": "^5.0.0-alpha.2",
169
+ "chai-as-promised": "npm:@esm-bundle/chai-as-promised@^7.1.1",
158
170
  "docsify": "^4.12.2",
159
171
  "docsify-cli": "^4.4.3",
160
172
  "eslint": "^8.7.0",
173
+ "eslint-config-react-app": "^7.0.1",
161
174
  "eslint-plugin-jest": "^26.0.0",
175
+ "hanbi": "^1.0.1",
162
176
  "husky": "^8.0.3",
163
- "istanbul": "^0.4.5",
164
- "jest": "^27.4.7",
165
177
  "jsdoc-escape-at": "^1.0.1",
166
178
  "jsdoc-to-markdown": "^7.1.0",
167
179
  "json5-jest": "^1.0.1",
168
180
  "less": "^4.1.2",
169
181
  "lint-staged": "^12.3.1",
170
- "node-sass": "^9.0.0",
182
+ "mocha": "^10.2.0",
171
183
  "npm-run-all": "^4.1.5",
184
+ "patch-package": "^8.0.0",
172
185
  "prettier": "^3.0.3",
186
+ "sass": "^1.69.5",
173
187
  "standard-version": "^9.3.2",
174
188
  "stylus": "^0.56.0",
175
- "tsd": "^0.19.1",
176
- "yaml": "^1.10.2"
189
+ "yaml": "^2.3.4"
177
190
  }
178
191
  }
package/types/Config.d.ts CHANGED
@@ -12,6 +12,7 @@
12
12
  */
13
13
 
14
14
  import { Parser } from './Parser';
15
+ import { Preprocessor } from './Preprocessor';
15
16
  import { Transform } from './Transform';
16
17
  import { TransformGroup } from './TransformGroup';
17
18
  import { Filter } from './Filter';
@@ -23,6 +24,7 @@ import { DesignTokens } from './DesignToken';
23
24
 
24
25
  export interface Config {
25
26
  parsers?: Parser[];
27
+ preprocessors?: Record<string, Preprocessor>;
26
28
  transform?: Record<string, Transform>;
27
29
  transformGroup?: Record<string, TransformGroup['transforms']>;
28
30
  format?: Record<string, Formatter>;
@@ -32,6 +34,5 @@ export interface Config {
32
34
  include?: string[];
33
35
  source?: string[];
34
36
  tokens?: DesignTokens;
35
- properties?: DesignTokens;
36
37
  platforms: Record<string, Platform>;
37
- }
38
+ }
@@ -16,8 +16,6 @@ import { TransformedToken, TransformedTokens } from './TransformedToken';
16
16
  export interface Dictionary {
17
17
  allTokens: TransformedToken[];
18
18
  tokens: TransformedTokens;
19
- allProperties: TransformedToken[];
20
- properties: TransformedTokens;
21
19
  usesReference: (value: any) => boolean;
22
20
  getReferences: (value: any) => TransformedToken[];
23
21
  }
@@ -11,14 +11,15 @@
11
11
  * and limitations under the License.
12
12
  */
13
13
 
14
- import { Dictionary } from "./Dictionary";
15
- import { DesignToken } from "./DesignToken";
16
- import { TransformedToken } from "./TransformedToken";
17
- import { File } from "./File";
14
+ import { Dictionary } from './Dictionary';
15
+ import { DesignToken } from './DesignToken';
16
+ import { TransformedToken } from './TransformedToken';
17
+ import { File } from './File';
18
18
 
19
19
  export interface LineFormatting {
20
20
  prefix?: string;
21
- commentStyle?: "short" | "long" | "none";
21
+ commentStyle?: 'short' | 'long' | 'none';
22
+ commentPosition?: 'inline' | 'above';
22
23
  indentation?: string;
23
24
  separator?: string;
24
25
  suffix?: string;
@@ -27,7 +28,7 @@ export interface LineFormatting {
27
28
  export type TokenFormatterArgs = {
28
29
  outputReferences?: boolean;
29
30
  dictionary: Dictionary;
30
- format?: "css" | "sass" | "less" | "stylus";
31
+ format?: 'css' | 'sass' | 'less' | 'stylus';
31
32
  formatting?: LineFormatting;
32
33
  };
33
34
 
@@ -45,32 +46,20 @@ export interface FileHeaderArgs {
45
46
  }
46
47
 
47
48
  export interface FormattedVariablesArgs {
48
- format: "css" | "sass";
49
+ format: 'css' | 'sass';
49
50
  dictionary: Dictionary;
50
51
  outputReferences?: boolean;
51
52
  formatting?: LineFormatting;
52
53
  }
53
54
 
54
55
  export interface FormatHelpers {
55
- createPropertyFormatter: (
56
- args: TokenFormatterArgs
57
- ) => (token: TransformedToken) => string;
56
+ createPropertyFormatter: (args: TokenFormatterArgs) => (token: TransformedToken) => string;
58
57
  fileHeader: (args: FileHeaderArgs) => string;
59
58
  formattedVariables: (args: FormattedVariablesArgs) => string;
60
59
  minifyDictionary: (dictionary: object) => object;
61
60
  getTypeScriptType: (value: unknown) => string;
62
- iconsWithPrefix: (
63
- prefix: string,
64
- allTokens: DesignToken[],
65
- options: object
66
- ) => string;
67
- sortByReference: (
68
- dictionary: Dictionary
69
- ) => (a: TransformedToken, b: TransformedToken) => number;
61
+ iconsWithPrefix: (prefix: string, allTokens: DesignToken[], options: object) => string;
62
+ sortByReference: (dictionary: Dictionary) => (a: TransformedToken, b: TransformedToken) => number;
70
63
  sortByName: (a: DesignToken, b: DesignToken) => number;
71
- setSwiftFileProperties: (
72
- options: object,
73
- objectType: string,
74
- transformGroup: string
75
- ) => string;
64
+ setSwiftFileProperties: (options: object, objectType: string, transformGroup: string) => string;
76
65
  }
@@ -11,22 +11,11 @@
11
11
  * and limitations under the License.
12
12
  */
13
13
 
14
- /**
15
- * Does the reverse of [buildAllPlatforms](#buildAllPlatforms) by
16
- * performing a clean on each platform. This removes all the files
17
- * defined in the platform and calls the undo method on any actions.
18
- *
19
- * @static
20
- * @memberof module:style-dictionary
21
- * @returns {module:style-dictionary}
22
- */
23
- export default function cleanAllPlatforms() {
24
- const self = this;
14
+ import { DesignTokens } from './DesignToken';
25
15
 
26
- Object.keys(this.options.platforms).forEach(function (key) {
27
- self.cleanPlatform(key);
28
- });
16
+ export type Preprocessor = {
17
+ name: string;
18
+ preprocessor: preprocessor;
19
+ };
29
20
 
30
- // For chaining
31
- return this;
32
- }
21
+ export type preprocessor = (dictionary: DesignTokens) => DesignTokens | Promise<DesignTokens>;
package/types/index.d.ts CHANGED
@@ -25,6 +25,7 @@ import { FormatHelpers as _FormatHelpers } from './FormatHelpers';
25
25
  import { Matcher as _Matcher } from './Matcher';
26
26
  import { Options as _Options } from './Options';
27
27
  import { Parser as _Parser } from './Parser';
28
+ import { Preprocessor as _Preprocessor, preprocessor as _preprocessor } from './Preprocessor';
28
29
  import { Platform as _Platform } from './Platform';
29
30
  import { Transform as _Transform } from './Transform';
30
31
  import {
@@ -52,6 +53,8 @@ declare namespace StyleDictionary {
52
53
  type Matcher = _Matcher;
53
54
  type Options = _Options;
54
55
  type Parser = _Parser;
56
+ type Preprocessor = _Preprocessor;
57
+ type preprocessor = _preprocessor;
55
58
  type Platform<PlatformType = Record<string, any>> = _Platform<PlatformType>;
56
59
  type Transform<PlatformType = Record<string, any>> = _Transform<PlatformType>;
57
60
  type TransformedToken = _TransformedToken;
@@ -63,8 +66,6 @@ declare namespace StyleDictionary {
63
66
  VERSION: string;
64
67
  tokens: DesignTokens | TransformedTokens;
65
68
  allTokens: TransformedTokens[];
66
- properties: DesignTokens | TransformedTokens;
67
- allProperties: TransformedTokens[];
68
69
  options: Config;
69
70
 
70
71
  transform: Record<string, Transform>;
@@ -74,6 +75,7 @@ declare namespace StyleDictionary {
74
75
  filter: Record<string, Filter['matcher']>;
75
76
  fileHeader: Record<string, FileHeader>;
76
77
  parsers: Parser[];
78
+ preprocessors: Record<string, Preprocessor>;
77
79
 
78
80
  formatHelpers: FormatHelpers;
79
81
 
@@ -208,6 +210,25 @@ declare namespace StyleDictionary {
208
210
  */
209
211
  registerParser(parser: Parser): this;
210
212
 
213
+ /**
214
+ * Adds a custom preprocessor to preprocess dictionary object.
215
+ *
216
+ * @param {Preprocessor} Preprocessor
217
+ * @param {string} Preprocessor.name - name of the preprocessor
218
+ * @param {preprocessor} Preprocessor.preprocessor - Function to preprocess the dictionary. The function should return a plain Javascript object.
219
+ * @example
220
+ * ```js
221
+ * StyleDictionary.registerPreprocessor({
222
+ * name: 'strip-third-party-meta',
223
+ * preprocessor: (dictionary) => {
224
+ * delete dictionary.thirdPartyMetadata;
225
+ * return dictionary;
226
+ * },
227
+ * });
228
+ * ```
229
+ */
230
+ registerPreprocessor(preprocessor: Preprocessor): this;
231
+
211
232
  /**
212
233
  * Adds a custom action to Style Dictionary. Actions
213
234
  * are functions that can do whatever you need, such as: copying files,
@@ -136,6 +136,13 @@ expectType<StyleDictionary.Core>(
136
136
  }),
137
137
  );
138
138
 
139
+ expectType<StyleDictionary.Core>(
140
+ StyleDictionary.registerPreprocessor({
141
+ name: 'foo',
142
+ preprocessor: (dictionary) => dictionary,
143
+ }),
144
+ );
145
+
139
146
  const file: StyleDictionary.File = {
140
147
  destination: `somePath.json`,
141
148
  format: `css/variables`,
package/index-node.js DELETED
@@ -1,7 +0,0 @@
1
- import fs from 'node:fs';
2
- import StyleDictionary from './index.js';
3
- import { setFs } from './fs.js';
4
-
5
- setFs(fs);
6
-
7
- export default StyleDictionary;
package/index.js DELETED
@@ -1,84 +0,0 @@
1
- /*
2
- * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
13
-
14
- import extend from './lib/extend.js';
15
- import transform from './lib/common/transforms.js';
16
- import transformGroup from './lib/common/transformGroups.js';
17
- import format from './lib/common/formats.js';
18
- import action from './lib/common/actions.js';
19
- import * as formatHelpers from './lib/common/formatHelpers/index.js';
20
- import filter from './lib/common/filters.js';
21
- import registerTransform from './lib/register/transform.js';
22
- import registerTransformGroup from './lib/register/transformGroup.js';
23
- import registerFormat from './lib/register/format.js';
24
- import registerAction from './lib/register/action.js';
25
- import registerFilter from './lib/register/filter.js';
26
- import registerParser from './lib/register/parser.js';
27
- import registerFileHeader from './lib/register/fileHeader.js';
28
- import exportPlatform from './lib/exportPlatform.js';
29
- import buildPlatform from './lib/buildPlatform.js';
30
- import buildAllPlatforms from './lib/buildAllPlatforms.js';
31
- import cleanPlatform from './lib/cleanPlatform.js';
32
- import cleanAllPlatforms from './lib/cleanAllPlatforms.js';
33
-
34
- // const TEMPLATE_DEPRECATION_WARNINGS = GroupMessages.GROUP.TemplateDeprecationWarnings;
35
- // const REGISTER_TEMPLATE_DEPRECATION_WARNINGS = GroupMessages.GROUP.RegisterTemplateDeprecationWarnings;
36
- // const SASS_MAP_FORMAT_DEPRECATION_WARNINGS = GroupMessages.GROUP.SassMapFormatDeprecationWarnings;
37
-
38
- /**
39
- * Style Dictionary module
40
- *
41
- * @module style-dictionary
42
- * @typicalname StyleDictionary
43
- * @example
44
- * ```js
45
- * import StyleDictionary from 'style-dictionary';
46
- * (await StyleDictionary.extend('config.json')).buildAllPlatforms();
47
- * ```
48
- */
49
-
50
- export default {
51
- // Placeholder is transformed on prepublish -> see scripts/inject-version.js
52
- // Another option might be import pkg from './package.json' with { "type": "json" } which would work in both browser and node, but support is not there yet.
53
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
54
- VERSION: '4.0.0-prerelease.1',
55
- tokens: {},
56
- allTokens: [],
57
- options: {},
58
-
59
- transform,
60
- transformGroup,
61
- format,
62
- action,
63
- formatHelpers,
64
- filter,
65
- parsers: [], // we need to initialise the array, since we don't have built-in parsers
66
- fileHeader: {},
67
-
68
- registerTransform,
69
- registerTransformGroup,
70
- registerFormat,
71
- registerAction,
72
- registerFilter,
73
- registerParser,
74
- registerFileHeader,
75
-
76
- exportPlatform,
77
- buildPlatform,
78
- buildAllPlatforms,
79
-
80
- cleanPlatform,
81
- cleanAllPlatforms,
82
-
83
- extend,
84
- };
@@ -1,37 +0,0 @@
1
- /*
2
- * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
13
-
14
- /**
15
- * The only top-level method that needs to be called
16
- * to build the Style Dictionary.
17
- *
18
- * @static
19
- * @memberof module:style-dictionary
20
- * @returns {module:style-dictionary}
21
- * @example
22
- * ```js
23
- * import StyleDictionary from 'style-dictionary';
24
- * const StyleDictionary = await StyleDictionary.extend('config.json');
25
- * StyleDictionary.buildAllPlatforms();
26
- * ```
27
- */
28
- export default function buildAllPlatforms() {
29
- var self = this;
30
-
31
- Object.keys(this.options.platforms).forEach(function (key) {
32
- self.buildPlatform(key);
33
- });
34
-
35
- // For chaining
36
- return this;
37
- }
@@ -1,67 +0,0 @@
1
- /*
2
- * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
13
-
14
- import transformConfig from './transform/config.js';
15
- import buildFiles from './buildFiles.js';
16
- import performActions from './performActions.js';
17
- import createDictionary from './utils/createDictionary.js';
18
-
19
- /**
20
- * Takes a platform and performs all transforms to
21
- * the tokens object (non-mutative) then
22
- * builds all the files and performs any actions. This is useful if you only want to
23
- * build the artifacts of one platform to speed up the build process.
24
- *
25
- * This method is also used internally in [buildAllPlatforms](#buildAllPlatforms) to
26
- * build each platform defined in the config.
27
- *
28
- * @static
29
- * @memberof module:style-dictionary
30
- * @param {String} platform - Name of the platform you want to build.
31
- * @returns {module:style-dictionary}
32
- * @example
33
- * ```js
34
- * StyleDictionary.buildPlatform('web');
35
- * ```
36
- * ```bash
37
- * $ style-dictionary build --platform web
38
- * ```
39
- */
40
- export default function buildPlatform(platform) {
41
- console.log('\n' + platform);
42
-
43
- if (!this.options || !(platform in (this.options.platforms || {}))) {
44
- throw new Error(`Platform "${platform}" does not exist`);
45
- }
46
-
47
- let properties;
48
- // We don't want to mutate the original object
49
- const platformConfig = transformConfig(this.options.platforms[platform], this, platform);
50
-
51
- // We need to transform the object before we resolve the
52
- // variable names because if a value contains concatenated
53
- // values like "1px solid {color.border.base}" we want to
54
- // transform the original value (color.border.base) before
55
- // replacing that value in the string.
56
- properties = this.exportPlatform(platform);
57
-
58
- // This is the dictionary object we pass to the file
59
- // building and action methods.
60
- const dictionary = createDictionary({ properties });
61
-
62
- buildFiles(dictionary, platformConfig);
63
- performActions(dictionary, platformConfig);
64
-
65
- // For chaining
66
- return this;
67
- }
@@ -1,59 +0,0 @@
1
- /*
2
- * Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5
- * the License. A copy of the License is located at
6
- *
7
- * http://www.apache.org/licenses/LICENSE-2.0
8
- *
9
- * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10
- * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11
- * and limitations under the License.
12
- */
13
-
14
- import createDictionary from './utils/createDictionary.js';
15
- import transformConfig from './transform/config.js';
16
- import cleanFiles from './cleanFiles.js';
17
- import cleanDirs from './cleanDirs.js';
18
- import cleanActions from './cleanActions.js';
19
-
20
- /**
21
- * Takes a platform and performs all transforms to
22
- * the tokens object (non-mutative) then
23
- * cleans all the files and performs the undo method of any [actions](actions.md).
24
- *
25
- * @static
26
- * @memberof module:style-dictionary
27
- * @param {String} platform
28
- * @returns {module:style-dictionary}
29
- */
30
- export default function cleanPlatform(platform) {
31
- console.log('\n' + platform);
32
-
33
- if (!this.options || !(platform in (this.options.platforms || {}))) {
34
- throw new Error('Platform ' + platform + " doesn't exist");
35
- }
36
-
37
- let properties;
38
- // We don't want to mutate the original object
39
- const platformConfig = transformConfig(this.options.platforms[platform], this, platform);
40
-
41
- // We need to transform the object before we resolve the
42
- // variable names because if a value contains concatenated
43
- // values like "1px solid {color.border.base}" we want to
44
- // transform the original value (color.border.base) before
45
- // replacing that value in the string.
46
- properties = this.exportPlatform(platform);
47
-
48
- // This is the dictionary object we pass to the file
49
- // cleaning and action methods.
50
- const dictionary = createDictionary({ properties });
51
-
52
- // We clean files first, then actions, ...and then directories?
53
- cleanFiles(dictionary, platformConfig);
54
- cleanActions(dictionary, platformConfig);
55
- cleanDirs(dictionary, platformConfig);
56
-
57
- // For chaining
58
- return this;
59
- }