@@ -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 program from 'commander' ;
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
- return Promise . all ( options . platforms . map ( ( platform ) => sd . buildPlatform ( platform ) ) ) ;
154
+ await Promise . all ( options . platform . map ( ( platform ) => sd . buildPlatform ( platform ) ) ) ;
130
155
} else {
131
- return sd . buildAllPlatforms ( ) ;
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
- return Promise . all ( options . platforms . map ( ( platform ) => sd . cleanPlatform ( platform ) ) ) ;
169
+ await Promise . all ( options . platform . map ( ( platform ) => sd . cleanPlatform ( platform ) ) ) ;
142
170
} else {
143
- return sd . cleanAllPlatforms ( ) ;
171
+ await sd . cleanAllPlatforms ( ) ;
144
172
}
145
173
}
146
174
0 commit comments