@@ -6,58 +6,60 @@ var sass = require('node-sass');
6
6
var glob = require ( 'glob' ) ;
7
7
8
8
function convert ( logger , projectDir , options ) {
9
- return new Promise ( function ( resolve , reject ) {
10
- options = options || { } ;
11
-
12
- var sassFilesPath = path . join ( projectDir , 'app/**/*.scss' ) ;
9
+ return new Promise ( function ( resolve , reject ) {
10
+ options = options || { } ;
11
+
12
+ var sassFilesPath = path . join ( projectDir , 'app/**/*.scss' ) ;
13
13
var sassImportPaths = [
14
- path . join ( projectDir , 'app/' ) ,
14
+ path . join ( projectDir , 'app/' ) ,
15
15
path . join ( projectDir , 'node_modules/' )
16
- ] ;
16
+ ] ;
17
17
//console.log("SASS Import Path", sassImportPaths);
18
-
19
- var sassFiles = glob . sync ( sassFilesPath , { follow : true } ) . filter ( function ( filePath ) {
20
- var path = filePath ;
21
- var parts = path . split ( '/' ) ;
18
+
19
+ var sassFiles = glob . sync ( sassFilesPath , { follow : true } ) . filter ( function ( filePath ) {
20
+ if ( ! ( sassImportPaths . find ( function ( element ) { return path . dirname ( filePath ) === element } ) ) ) {
21
+ sassImportPaths . push ( path . dirname ( filePath ) ) ;
22
+ }
23
+ var parts = filePath . split ( '/' ) ;
22
24
var filename = parts [ parts . length - 1 ] ;
23
- return path . indexOf ( "App_Resources" ) === - 1 && filename . indexOf ( "_" ) !== 0 ;
24
- } ) ;
25
-
26
- if ( sassFiles . length === 0 ) {
25
+ return filePath . indexOf ( "App_Resources" ) === - 1 && filename . indexOf ( "_" ) !== 0 ;
26
+ } ) ;
27
+
28
+ if ( sassFiles . length === 0 ) {
27
29
//No sass files in project; skip parsing
28
30
resolve ( ) ;
29
- } else {
31
+ } else {
30
32
var i = 0 ;
31
- var loopSassFilesAsync = function ( sassFiles ) {
32
- parseSass ( sassFiles [ i ] , sassImportPaths , function ( e ) {
33
- if ( e !== undefined ) {
33
+ var loopSassFilesAsync = function ( sassFiles ) {
34
+ parseSass ( sassFiles [ i ] , sassImportPaths , function ( e ) {
35
+ if ( e !== undefined ) {
34
36
//Error in the LESS parser; Reject promise
35
- reject ( Error ( sassFiles [ i ] + ' SASS CSS pre-processing failed. Error: ' + e ) ) ;
37
+ reject ( Error ( sassFiles [ i ] + ' SASS CSS pre-processing failed. Error: ' + e ) ) ;
36
38
}
37
-
39
+
38
40
i ++ ; //Increment loop counter
39
-
40
- if ( i < sassFiles . length ) {
41
+
42
+ if ( i < sassFiles . length ) {
41
43
loopSassFilesAsync ( sassFiles ) ;
42
44
} else {
43
45
//All files have been processed; Resolve promise
44
46
resolve ( ) ;
45
47
}
46
48
} ) ;
47
49
}
48
-
50
+
49
51
loopSassFilesAsync ( sassFiles ) ;
50
52
}
51
- } ) ;
53
+ } ) ;
52
54
}
53
55
54
- function parseSass ( filePath , importPaths , callback ) {
55
- var sassFileContent = fs . readFileSync ( filePath , { encoding : 'utf8' } ) ;
56
+ function parseSass ( filePath , importPaths , callback ) {
57
+ var sassFileContent = fs . readFileSync ( filePath , { encoding : 'utf8' } ) ;
56
58
var cssFilePath = filePath . replace ( '.scss' , '.css' ) ;
57
59
58
- if ( sassFileContent . trim ( ) . length === 0 ) {
60
+ if ( sassFileContent . trim ( ) . length === 0 ) {
59
61
// No SASS content write an empty file
60
- fs . writeFile ( cssFilePath , '' , 'utf8' , function ( ) {
62
+ fs . writeFile ( cssFilePath , '' , 'utf8' , function ( ) {
61
63
callback ( ) ;
62
64
} ) ;
63
65
return ;
@@ -69,18 +71,18 @@ function parseSass(filePath, importPaths, callback){
69
71
outFile : cssFilePath ,
70
72
outputStyle : 'compressed'
71
73
} , function ( e , output ) {
72
- if ( e ) {
74
+ if ( e ) {
73
75
//Callback with error
74
76
callback ( e ) ;
75
- }
76
-
77
- if ( output && output . css ) {
77
+ }
78
+
79
+ if ( output && output . css ) {
78
80
output = output . css ;
79
81
} else {
80
82
output = '' ;
81
83
}
82
84
83
- fs . writeFile ( cssFilePath , output , 'utf8' , function ( ) {
85
+ fs . writeFile ( cssFilePath , output , 'utf8' , function ( ) {
84
86
//File done writing
85
87
callback ( ) ;
86
88
} ) ;
0 commit comments