@@ -68,8 +68,7 @@ async function createFilesFromURL(project) {
68
68
snackbar . show (
69
69
"Flate could not be loaded to decode the URL to project files.\nCreating default tokens studio template instead."
70
70
) ;
71
- createConfig ( ) ;
72
- createStudioTokens ( ) ;
71
+ await Promise . all ( [ createConfig ( ) , createStudioTokens ( ) ] ) ;
73
72
return ;
74
73
}
75
74
@@ -85,111 +84,19 @@ async function createFilesFromURL(project) {
85
84
return fs . promises . writeFile ( file , content ) ;
86
85
} )
87
86
) ;
87
+ await sdState . determineRootFolder ( ) ;
88
88
}
89
89
90
90
export async function createStudioTokens ( ) {
91
91
const tokens = await (
92
92
await fetch ( new URL ( "./core.json" , import . meta. url ) . href )
93
93
) . json ( ) ;
94
94
95
- fs . writeFileSync ( "studio.json" , JSON . stringify ( tokens , null , 2 ) ) ;
95
+ fs . promises . writeFile ( "studio.json" , JSON . stringify ( tokens , null , 2 ) ) ;
96
96
}
97
97
98
- export function createStandardTokens ( ) {
99
- fs . mkdirSync ( `color` ) ;
100
- fs . mkdirSync ( `card` ) ;
101
- fs . mkdirSync ( `radii` ) ;
102
- fs . writeFileSync (
103
- path . join ( `color` , "base.json" ) ,
104
- JSON . stringify (
105
- {
106
- color : {
107
- base : {
108
- gray : {
109
- light : { value : "#CCCCCC" } ,
110
- medium : { value : "#999999" } ,
111
- dark : { value : "#111111" } ,
112
- } ,
113
- red : { value : "#FF0000" } ,
114
- green : { value : "#00FF00" } ,
115
- } ,
116
- } ,
117
- } ,
118
- null ,
119
- 2
120
- )
121
- ) ;
122
-
123
- fs . writeFileSync (
124
- path . join ( `color` , "font.json" ) ,
125
- JSON . stringify (
126
- {
127
- color : {
128
- font : {
129
- base : { value : "{color.base.red}" } ,
130
- secondary : { value : "{color.base.green}" } ,
131
- tertiary : { value : "{color.base.gray.dark}" } ,
132
- } ,
133
- } ,
134
- } ,
135
- null ,
136
- 2
137
- )
138
- ) ;
139
-
140
- fs . writeFileSync (
141
- path . join ( `card` , "card.json" ) ,
142
- JSON . stringify (
143
- {
144
- card : {
145
- border : {
146
- radius : {
147
- mobile : {
148
- value : "{radii.none}" ,
149
- } ,
150
- desktop : {
151
- value : "{radii.sm}" ,
152
- } ,
153
- } ,
154
- } ,
155
- heading : {
156
- color : {
157
- value : "{color.font.base}" ,
158
- } ,
159
- } ,
160
- text : {
161
- color : {
162
- value : "{color.font.tertiary}" ,
163
- } ,
164
- } ,
165
- } ,
166
- } ,
167
- null ,
168
- 2
169
- )
170
- ) ;
171
-
172
- fs . writeFileSync (
173
- path . join ( `radii` , "base.json" ) ,
174
- JSON . stringify (
175
- {
176
- radii : {
177
- none : {
178
- value : "0" ,
179
- } ,
180
- sm : {
181
- value : "8px" ,
182
- } ,
183
- } ,
184
- } ,
185
- null ,
186
- 2
187
- )
188
- ) ;
189
- }
190
-
191
- export function createConfig ( ) {
192
- fs . writeFileSync (
98
+ export async function createConfig ( ) {
99
+ fs . promises . writeFile (
193
100
// take the .js by default
194
101
SD_CONFIG_PATH ,
195
102
JSON . stringify (
@@ -221,7 +128,8 @@ export function createConfig() {
221
128
} ,
222
129
null ,
223
130
2
224
- )
131
+ ) ,
132
+ "utf-8"
225
133
) ;
226
134
}
227
135
@@ -253,6 +161,8 @@ export async function replaceSource(files, { clear = true, run = true } = {}) {
253
161
await switchToFile ( findUsedConfigPath ( ) , editorConfig ) ;
254
162
resizeMonacoLayout ( ) ;
255
163
if ( run ) {
164
+ // reset rootDir
165
+ await sdState . determineRootFolder ( ) ;
256
166
await sdState . runStyleDictionary ( { force : true } ) ;
257
167
}
258
168
await openAllFolders ( ) ;
@@ -263,8 +173,7 @@ export async function createInputFiles() {
263
173
if ( urlSplit . length > 1 && window . __configurator_standalone__ ) {
264
174
await createFilesFromURL ( urlSplit [ 1 ] ) ;
265
175
} else {
266
- createConfig ( ) ;
267
- createStudioTokens ( ) ;
176
+ await Promise . all ( [ createConfig ( ) , createStudioTokens ( ) ] ) ;
268
177
}
269
178
}
270
179
@@ -282,12 +191,12 @@ export async function createFolder(foldername) {
282
191
resolve ( ) ;
283
192
} ) ;
284
193
} ) ;
194
+ await sdState . determineRootFolder ( ) ;
285
195
}
286
196
287
197
export async function editFileName ( filePath , newName , isFolder = false ) {
288
198
const newPath = path . join ( path . dirname ( filePath ) , newName ) ;
289
199
fs . renameSync ( filePath , newPath ) ;
290
- // await sdState.runStyleDictionary();
291
200
}
292
201
293
202
export async function removeFile ( file ) {
0 commit comments