style-dictionary 4.3.0 → 4.3.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.
- package/bin/style-dictionary.d.ts +8 -0
- package/bin/style-dictionary.js +33 -5
- package/examples/advanced/assets-base64-embed/package.json +1 -1
- package/examples/advanced/create-react-app/package.json +1 -1
- package/examples/advanced/create-react-native-app/package.json +1 -1
- package/examples/advanced/custom-parser/package.json +1 -1
- package/examples/advanced/custom-transforms/package.json +1 -1
- package/examples/advanced/font-face-rules/package.json +1 -1
- package/examples/advanced/format-helpers/package.json +1 -1
- package/examples/advanced/matching-build-files/package.json +1 -1
- package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
- package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
- package/examples/advanced/npm-module/package.json +1 -1
- package/examples/advanced/referencing_aliasing/package.json +1 -1
- package/examples/advanced/s3/package.json +1 -1
- package/examples/advanced/tailwind-preset/package.json +1 -1
- package/examples/advanced/tokens-deprecation/package.json +1 -1
- package/examples/advanced/transitive-transforms/package.json +1 -1
- package/examples/advanced/variables-in-outputs/package.json +1 -1
- package/examples/advanced/yaml-tokens/package.json +1 -1
- package/lib/StyleDictionary.js +1 -1
- package/lib/common/formats.js +1 -0
- package/lib/common/transforms.js +1 -1
- package/package.json +2 -2
package/bin/style-dictionary.js
CHANGED
|
@@ -6,21 +6,39 @@ import path from 'node:path';
|
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import node_fs from 'node:fs';
|
|
8
8
|
import JSON5 from 'json5';
|
|
9
|
-
import
|
|
9
|
+
import { Command } from 'commander';
|
|
10
10
|
// usually also node:fs in this context, but can be customized by user
|
|
11
11
|
import { fs } from 'style-dictionary/fs';
|
|
12
12
|
import StyleDictionary from 'style-dictionary';
|
|
13
13
|
import { logWarningLevels, logVerbosityLevels } from '../lib/enums/index.js';
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* @typedef {{
|
|
17
|
+
* config?: string;
|
|
18
|
+
* platform?: string[];
|
|
19
|
+
* verbose?: boolean;
|
|
20
|
+
* warn?: boolean;
|
|
21
|
+
* silent?: boolean;
|
|
22
|
+
* }} BuildOptions
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const program = new Command();
|
|
15
26
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
16
27
|
const { silent, verbose } = logVerbosityLevels;
|
|
17
28
|
const pkg = JSON5.parse(node_fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
|
|
18
29
|
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} val
|
|
32
|
+
* @param {string[]} arr
|
|
33
|
+
*/
|
|
19
34
|
function collect(val, arr) {
|
|
20
35
|
arr.push(val);
|
|
21
36
|
return arr;
|
|
22
37
|
}
|
|
23
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @param {BuildOptions} options
|
|
41
|
+
*/
|
|
24
42
|
function getConfigPath(options) {
|
|
25
43
|
let configPath = options.config;
|
|
26
44
|
|
|
@@ -108,6 +126,10 @@ program.on('command:*', function () {
|
|
|
108
126
|
process.exit(1);
|
|
109
127
|
});
|
|
110
128
|
|
|
129
|
+
/**
|
|
130
|
+
* @param {string} configPath
|
|
131
|
+
* @param {BuildOptions} options
|
|
132
|
+
*/
|
|
111
133
|
function getSD(configPath, options) {
|
|
112
134
|
let verbosity;
|
|
113
135
|
let warnings;
|
|
@@ -120,27 +142,33 @@ function getSD(configPath, options) {
|
|
|
120
142
|
return new StyleDictionary(configPath, { verbosity, warnings });
|
|
121
143
|
}
|
|
122
144
|
|
|
145
|
+
/**
|
|
146
|
+
* @param {BuildOptions} [options]
|
|
147
|
+
*/
|
|
123
148
|
async function styleDictionaryBuild(options) {
|
|
124
149
|
options = options || {};
|
|
125
150
|
const configPath = getConfigPath(options);
|
|
126
151
|
const sd = getSD(configPath, options);
|
|
127
152
|
|
|
128
153
|
if (options.platform && options.platform.length > 0) {
|
|
129
|
-
|
|
154
|
+
await Promise.all(options.platform.map((platform) => sd.buildPlatform(platform)));
|
|
130
155
|
} else {
|
|
131
|
-
|
|
156
|
+
await sd.buildAllPlatforms();
|
|
132
157
|
}
|
|
133
158
|
}
|
|
134
159
|
|
|
160
|
+
/**
|
|
161
|
+
* @param {BuildOptions} [options]
|
|
162
|
+
*/
|
|
135
163
|
async function styleDictionaryClean(options) {
|
|
136
164
|
options = options || {};
|
|
137
165
|
const configPath = getConfigPath(options);
|
|
138
166
|
const sd = getSD(configPath, options);
|
|
139
167
|
|
|
140
168
|
if (options.platform && options.platform.length > 0) {
|
|
141
|
-
|
|
169
|
+
await Promise.all(options.platform.map((platform) => sd.cleanPlatform(platform)));
|
|
142
170
|
} else {
|
|
143
|
-
|
|
171
|
+
await sd.cleanAllPlatforms();
|
|
144
172
|
}
|
|
145
173
|
}
|
|
146
174
|
|
package/lib/StyleDictionary.js
CHANGED
|
@@ -80,7 +80,7 @@ export default class StyleDictionary extends Register {
|
|
|
80
80
|
// Placeholder is transformed on prepublish -> see scripts/inject-version.js
|
|
81
81
|
// 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.
|
|
82
82
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
|
|
83
|
-
static VERSION = '4.3.
|
|
83
|
+
static VERSION = '4.3.2';
|
|
84
84
|
|
|
85
85
|
/** @returns {Config} */
|
|
86
86
|
get options() {
|
package/lib/common/formats.js
CHANGED
|
@@ -1655,6 +1655,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1655
1655
|
* @typedef {Object} flutterClassOpts
|
|
1656
1656
|
* @property {boolean} [flutterClassOpts.showFileHeader=true] - Whether or not to include a comment that has the build date
|
|
1657
1657
|
* @property {OutputReferences} [flutterClassOpts.outputReferences=false] - Whether or not to keep [references](/#/formats?id=references-in-output-files) (a -> b -> c) in the output.
|
|
1658
|
+
* @property {String} [flutterClassOpts.className] - The name of the generated Dart Class
|
|
1658
1659
|
* @param {FormatArgs & { options?: flutterClassOpts }} options
|
|
1659
1660
|
* @example
|
|
1660
1661
|
* ```dart
|
package/lib/common/transforms.js
CHANGED
|
@@ -829,7 +829,7 @@ export default {
|
|
|
829
829
|
transform: function (token, _, options) {
|
|
830
830
|
const nonParsed = options.usesDtcg ? token.$value : token.value;
|
|
831
831
|
// if the dimension already has a unit (non-digit / . period character)
|
|
832
|
-
if (`${nonParsed}`.match(/[^0-9
|
|
832
|
+
if (`${nonParsed}`.match(/[^0-9.-]+$/)) {
|
|
833
833
|
return nonParsed;
|
|
834
834
|
}
|
|
835
835
|
const parsedVal = parseFloat(nonParsed);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "style-dictionary",
|
|
3
|
-
"version": "4.3.
|
|
3
|
+
"version": "4.3.2",
|
|
4
4
|
"description": "Style once, use everywhere. A build system for creating cross-platform styles.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"style dictionary",
|
|
@@ -120,7 +120,7 @@
|
|
|
120
120
|
"@zip.js/zip.js": "^2.7.44",
|
|
121
121
|
"chalk": "^5.3.0",
|
|
122
122
|
"change-case": "^5.3.0",
|
|
123
|
-
"commander": "^
|
|
123
|
+
"commander": "^12.1.0",
|
|
124
124
|
"is-plain-obj": "^4.1.0",
|
|
125
125
|
"json5": "^2.2.2",
|
|
126
126
|
"patch-package": "^8.0.0",
|