From 5e4939d440a91690b25c2b4838508373b1deb166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Anton=20Bach=20Sj=C3=B8gren?= Date: Fri, 7 Oct 2016 12:26:28 +0200 Subject: [PATCH] fix: #10 bug: Throws an error if scss-file is empty * Will no longer throw an error for empty files * nativescript-angular: ng2 throws errors if css-files doesn't exist, to accommodate that write empty css-files if the sass-file is empty --- lib/converter.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/converter.js b/lib/converter.js index 717c9c9..a01dc1e 100644 --- a/lib/converter.js +++ b/lib/converter.js @@ -54,7 +54,15 @@ function convert(logger, projectDir, options) { function parseSass(filePath, importPaths, callback){ var sassFileContent = fs.readFileSync(filePath, { encoding: 'utf8'}); var cssFilePath = filePath.replace('.scss', '.css'); - + + if(sassFileContent.trim().length === 0) { + // No SASS content write an empty file + fs.writeFile(cssFilePath, '', 'utf8', function(){ + callback(); + }); + return; + } + sass.render({ data: sassFileContent, includePaths: importPaths, @@ -66,14 +74,15 @@ function parseSass(filePath, importPaths, callback){ callback(e); } - if(output === null){ - //No CSS content in converted scss file; No need to write file - callback(); + if(output && output.css){ + output = output.css; } else { - fs.writeFile(cssFilePath, output.css, 'utf8', function(){ - //File done writing - callback(); - }); - } + output = ''; + } + + fs.writeFile(cssFilePath, output, 'utf8', function(){ + //File done writing + callback(); + }); }); -} \ No newline at end of file +}