1
1
exports . convert = convert ;
2
+ exports . getSassProcess = getSassProcess ;
2
3
3
4
var spawn = require ( 'child_process' ) . spawn ;
4
5
var fs = require ( 'fs' ) ;
5
6
var path = require ( 'path' ) ;
7
+ var currentSassProcess = null ;
6
8
7
9
function convert ( logger , projectDir , options ) {
8
10
return new Promise ( function ( resolve , reject ) {
@@ -12,7 +14,7 @@ function convert(logger, projectDir, options) {
12
14
var sassPath = path . join ( peerSassPath , 'bin/node-sass' ) ;
13
15
var appDir = path . join ( projectDir , "app" ) ;
14
16
var importerPath = path . join ( __dirname , "importer.js" ) ;
15
-
17
+
16
18
if ( fs . existsSync ( sassPath ) ) {
17
19
try {
18
20
logger . info ( 'Found peer node-sass' ) ;
@@ -34,16 +36,16 @@ function convert(logger, projectDir, options) {
34
36
}
35
37
36
38
logger . trace ( process . execPath , nodeArgs . join ( ' ' ) ) ;
37
- var sass = spawn ( process . execPath , nodeArgs ) ;
39
+ currentSassProcess = spawn ( process . execPath , nodeArgs ) ;
38
40
39
41
var isResolved = false ;
40
42
var watchResolveTimeout ;
41
- sass . stdout . on ( 'data' , function ( data ) {
43
+ currentSassProcess . stdout . on ( 'data' , function ( data ) {
42
44
var stringData = data . toString ( ) ;
43
45
logger . info ( stringData ) ;
44
46
} ) ;
45
47
46
- sass . stderr . on ( 'data' , function ( err ) {
48
+ currentSassProcess . stderr . on ( 'data' , function ( err ) {
47
49
var message = '' ;
48
50
var stringData = err . toString ( ) ;
49
51
@@ -58,7 +60,7 @@ function convert(logger, projectDir, options) {
58
60
logger . info ( message ) ;
59
61
} ) ;
60
62
61
- sass . on ( 'error' , function ( err ) {
63
+ currentSassProcess . on ( 'error' , function ( err ) {
62
64
logger . info ( err . message ) ;
63
65
if ( ! isResolved ) {
64
66
isResolved = true ;
@@ -67,7 +69,8 @@ function convert(logger, projectDir, options) {
67
69
} ) ;
68
70
69
71
// TODO: Consider using close event instead of exit
70
- sass . on ( 'exit' , function ( code , signal ) {
72
+ currentSassProcess . on ( 'exit' , function ( code , signal ) {
73
+ currentSassProcess = null ;
71
74
if ( ! isResolved ) {
72
75
isResolved = true ;
73
76
if ( code === 0 ) {
@@ -78,10 +81,14 @@ function convert(logger, projectDir, options) {
78
81
}
79
82
} ) ;
80
83
81
- // SASS does not recompile on watch, so directly resolve.
84
+ // SASS does not recompile on watch, so directly resolve.
82
85
if ( options . watch && ! isResolved ) {
83
86
isResolved = true ;
84
87
resolve ( ) ;
85
88
}
86
89
} ) ;
87
90
}
91
+
92
+ function getSassProcess ( ) {
93
+ return currentSassProcess ;
94
+ }
0 commit comments