@@ -22,6 +22,21 @@ const sass = (function() {
22
22
return null ;
23
23
} ) ( ) ;
24
24
25
+ /**
26
+ * Check if file exists
27
+ * @param {String } filePath
28
+ * @return {Boolean }
29
+ */
30
+ const fileExists = function ( filePath ) {
31
+ try {
32
+ return fs . statSync ( filePath ) . isFile ( ) ;
33
+ }
34
+ catch ( err )
35
+ {
36
+ return false ;
37
+ }
38
+ }
39
+
25
40
const TAG = 'mailer-utils' ;
26
41
27
42
// This package assumes that assets (templates, SCSS, CSS ..) are
@@ -37,7 +52,6 @@ const TAG = 'mailer-utils';
37
52
// /var/www/app/bundle
38
53
//
39
54
// For Modulus, you need to use the `APP_DIR` variable, which you do NOT need to set.
40
-
41
55
const developmentPrivateDir = ( ) => {
42
56
if ( ! isDevEnv ) {
43
57
return '' ;
@@ -154,7 +168,21 @@ Utils = {
154
168
} ,
155
169
156
170
readFile ( relativePathFromApp ) {
157
- const file = Path . join ( ROOT , relativePathFromApp ) ;
171
+ let file
172
+ if ( Meteor . isAppTest
173
+ || Meteor . isTest ) {
174
+ // note:
175
+ // * this DOES WORK with Meteor.isTest (=unit test mode)
176
+ // * Meteor.isAppTest is NOT TESTED yet (=in-app test mode)
177
+ //
178
+ // background-info: we had NO luck with "Assets.absoluteFilePath(relativePathFromApp)",
179
+ // so lets build the path ourselves.
180
+ // see discussion https://github.com/lookback/meteor-emails/issues/76
181
+ file = Path . join ( process . cwd ( ) , 'assets' , 'app' , relativePathFromApp ) ;
182
+ } else {
183
+ // = standard mode (development || production)
184
+ file = Path . join ( ROOT , relativePathFromApp ) ;
185
+ }
158
186
159
187
try {
160
188
return fs . readFileSync ( file , {
@@ -178,17 +206,29 @@ ${packageToRecommend}`, TAG);
178
206
return Utils . readFile ( scss ) ;
179
207
}
180
208
181
- const file = Path . join ( ROOT , scss ) ;
209
+ let file
210
+ if ( Meteor . isAppTest
211
+ || Meteor . isTest ) {
212
+ // note:
213
+ // * this DOES WORK with Meteor.isTest (=unit test mode)
214
+ // * Meteor.isAppTest is NOT TESTED yet (=in-app test mode)
215
+ file = Path . join ( process . cwd ( ) , 'assets' , 'app' , scss ) ;
216
+ } else {
217
+ // = standard mode (development || production)
218
+ file = Path . join ( ROOT , scss ) ;
219
+ }
182
220
183
- try {
184
- return sass . renderSync ( {
185
- file : file ,
186
- sourceMap : false
187
- } ) . css . toString ( ) ;
188
- } catch ( ex ) {
189
- console . error ( `Sass failed to compile: ${ ex . message } ` ) ;
190
- console . error ( `In ${ ex . file || scss } at line ${ ex . line } , column ${ ex . column } ` ) ;
191
- return '' ;
221
+ if ( fileExists ( file ) ) {
222
+ try {
223
+ return sass . renderSync ( {
224
+ file : file ,
225
+ sourceMap : false
226
+ } ) . css . toString ( ) ;
227
+ } catch ( ex ) {
228
+ console . error ( `Sass failed to compile: ${ ex . message } ` ) ;
229
+ console . error ( `In ${ ex . file || scss } at line ${ ex . line } , column ${ ex . column } ` ) ;
230
+ }
192
231
}
232
+ return '' ; // fallback: on error, or if file does NOT exist
193
233
}
194
234
} ;
0 commit comments