Skip to content

Commit 6cc1da3

Browse files
fix: cli --platform flag (#1416)
1 parent d4db17d commit 6cc1da3

File tree

5 files changed

+56
-12
lines changed

5 files changed

+56
-12
lines changed

.changeset/strange-bananas-switch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'style-dictionary': patch
3+
---
4+
5+
Add and check types to CLI file, fix typo for --platform flag.

bin/style-dictionary.js

+33-5
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,39 @@ import path from 'node:path';
66
import { fileURLToPath } from 'node:url';
77
import node_fs from 'node:fs';
88
import JSON5 from 'json5';
9-
import program from 'commander';
9+
import { Command } from 'commander';
1010
// usually also node:fs in this context, but can be customized by user
1111
import { fs } from 'style-dictionary/fs';
1212
import StyleDictionary from 'style-dictionary';
1313
import { logWarningLevels, logVerbosityLevels } from '../lib/enums/index.js';
1414

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();
1526
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1627
const { silent, verbose } = logVerbosityLevels;
1728
const pkg = JSON5.parse(node_fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
1829

30+
/**
31+
* @param {string} val
32+
* @param {string[]} arr
33+
*/
1934
function collect(val, arr) {
2035
arr.push(val);
2136
return arr;
2237
}
2338

39+
/**
40+
* @param {BuildOptions} options
41+
*/
2442
function getConfigPath(options) {
2543
let configPath = options.config;
2644

@@ -108,6 +126,10 @@ program.on('command:*', function () {
108126
process.exit(1);
109127
});
110128

129+
/**
130+
* @param {string} configPath
131+
* @param {BuildOptions} options
132+
*/
111133
function getSD(configPath, options) {
112134
let verbosity;
113135
let warnings;
@@ -120,27 +142,33 @@ function getSD(configPath, options) {
120142
return new StyleDictionary(configPath, { verbosity, warnings });
121143
}
122144

145+
/**
146+
* @param {BuildOptions} [options]
147+
*/
123148
async function styleDictionaryBuild(options) {
124149
options = options || {};
125150
const configPath = getConfigPath(options);
126151
const sd = getSD(configPath, options);
127152

128153
if (options.platform && options.platform.length > 0) {
129-
return Promise.all(options.platforms.map((platform) => sd.buildPlatform(platform)));
154+
await Promise.all(options.platform.map((platform) => sd.buildPlatform(platform)));
130155
} else {
131-
return sd.buildAllPlatforms();
156+
await sd.buildAllPlatforms();
132157
}
133158
}
134159

160+
/**
161+
* @param {BuildOptions} [options]
162+
*/
135163
async function styleDictionaryClean(options) {
136164
options = options || {};
137165
const configPath = getConfigPath(options);
138166
const sd = getSD(configPath, options);
139167

140168
if (options.platform && options.platform.length > 0) {
141-
return Promise.all(options.platforms.map((platform) => sd.cleanPlatform(platform)));
169+
await Promise.all(options.platform.map((platform) => sd.cleanPlatform(platform)));
142170
} else {
143-
return sd.cleanAllPlatforms();
171+
await sd.cleanAllPlatforms();
144172
}
145173
}
146174

package-lock.json

+16-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
"@zip.js/zip.js": "^2.7.44",
121121
"chalk": "^5.3.0",
122122
"change-case": "^5.3.0",
123-
"commander": "^8.3.0",
123+
"commander": "^12.1.0",
124124
"is-plain-obj": "^4.1.0",
125125
"json5": "^2.2.2",
126126
"patch-package": "^8.0.0",

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"skipLibCheck": true,
2323
"declaration": true
2424
},
25-
"include": ["lib/**/*.js", "**/*.ts"],
25+
"include": ["lib/**/*.js", "**/*.ts", "bin/**/*.js"],
2626
"exclude": ["node_modules", "**/coverage/*"]
2727
}

0 commit comments

Comments
 (0)