@@ -17,28 +17,22 @@ type BemToBlockClassMap = WeakMap<BemSelector, BlockClassSelector>;
17
17
const EMPTY_ELEMENT_PLACEHOLDER = "EMPTY-ELEMENT-PLACEHOLDER" ;
18
18
const COMMON_PREFIXES_FOR_MODIFIERS = [ "is" ] ;
19
19
20
- export function convertBemToBlocks ( files : Array < string > ) : Promise < void > [ ] {
21
- let promises : Promise < void > [ ] = [ ] ;
22
- files . forEach ( file => {
23
- fs . readFile ( file , async ( _err , css ) => {
24
- postcss ( [
25
- // Using postcss-simple-vars to pass the fileName to the plugin
26
- vars ( {
27
- variables : ( ) => { return { fileName : path . relative ( process . cwd ( ) , file ) } ; } ,
28
- } ) ,
29
- bemToBlocksPlugin ,
30
- ] )
31
- . process ( css , { from : file } )
32
- . then ( output => {
33
- // rewrite the file with the processed output
34
- const parsedFilePath = path . parse ( file ) ;
35
- const blockFilePath = Object . assign ( parsedFilePath , { ext : `.block${ parsedFilePath . ext } ` , base : undefined } ) ;
36
- promises . push ( fs . writeFile ( path . format ( blockFilePath ) , output . toString ( ) ) ) ;
37
- } ) . catch ( e => { throw ( e ) ; } ) ;
38
-
39
- } ) ;
40
- } ) ;
41
- return promises ;
20
+ export async function convertBemToBlocks ( files : Array < string > ) : Promise < void > {
21
+ for ( let file of files ) {
22
+ let fileName = path . relative ( process . cwd ( ) , file ) ;
23
+ let processor = postcss ( [
24
+ // Using postcss-simple-vars to pass the fileName to the plugin
25
+ vars ( {
26
+ variables : ( ) => { return { fileName } ; } ,
27
+ } ) ,
28
+ bemToBlocksPlugin ,
29
+ ] ) ;
30
+ let css = fs . readFileSync ( file , "utf-8" ) ;
31
+ let result = await processor . process ( css , { from : fileName } ) ;
32
+ const parsedFilePath = path . parse ( file ) ;
33
+ const blockFilePath = Object . assign ( parsedFilePath , { ext : `.block${ parsedFilePath . ext } ` , base : undefined } ) ;
34
+ await fs . writeFile ( path . format ( blockFilePath ) , result . toString ( ) ) ;
35
+ }
42
36
}
43
37
44
38
/**
0 commit comments