@@ -7,7 +7,7 @@ import fs from 'fs';
7
7
import glob from 'glob' ;
8
8
import module from 'module' ;
9
9
import { dirname , join , relative } from 'path' ;
10
- import sass from 'sass' ;
10
+ import * as sass from 'sass' ;
11
11
import url from 'url' ;
12
12
import tsNode from 'ts-node' ;
13
13
@@ -86,22 +86,26 @@ async function main() {
86
86
*/
87
87
async function compileSassFiles ( ) {
88
88
const sassFiles = glob . sync ( 'src/**/!(_*|theme).scss' , { cwd : projectDir , absolute : true } ) ;
89
- const sassTasks = [ ] ;
89
+ const writeTasks = [ ] ;
90
90
91
+ let count = 0 ;
91
92
for ( const file of sassFiles ) {
92
93
const outRelativePath = relative ( projectDir , file ) . replace ( / \. s c s s $ / , '.css' ) ;
93
94
const outPath = join ( projectDir , outRelativePath ) ;
94
- const task = renderSassFileAsync ( file ) . then ( async content => {
95
+ const content = renderSassFile ( file ) . css ;
96
+
97
+ count ++ ;
98
+ console . error ( `Compiled ${ count } /${ sassFiles . length } files` ) ;
99
+
100
+ writeTasks . push ( async ( ) => {
95
101
console . info ( 'Compiled, now writing:' , outRelativePath ) ;
96
102
await fs . promises . mkdir ( dirname ( outPath ) , { recursive : true } ) ;
97
103
await fs . promises . writeFile ( outPath , content ) ;
98
104
} ) ;
99
-
100
- sassTasks . push ( task ) ;
101
105
}
102
106
103
- // Wait for all Sass compilations to finish.
104
- await Promise . all ( sassTasks ) ;
107
+ // Start all writes and wait for them to finish.
108
+ await Promise . all ( writeTasks . map ( task => task ( ) ) ) ;
105
109
}
106
110
107
111
/**
@@ -156,14 +160,12 @@ async function createEntryPointSpecFile() {
156
160
return specEntryPointFile ;
157
161
}
158
162
159
- /** Helper function to render a Sass file asynchronously using promises. */
160
- async function renderSassFileAsync ( inputFile ) {
161
- return sass
162
- . compileAsync ( inputFile , {
163
- loadPaths : [ nodeModulesDir , projectDir ] ,
164
- importers : [ localPackageSassImporter ] ,
165
- } )
166
- . then ( result => result . css ) ;
163
+ /** Helper function to render a Sass file. */
164
+ function renderSassFile ( inputFile ) {
165
+ return sass . compile ( inputFile , {
166
+ loadPaths : [ nodeModulesDir , projectDir ] ,
167
+ importers : [ localPackageSassImporter ] ,
168
+ } ) ;
167
169
}
168
170
169
171
/**
0 commit comments