From 37da52e624405484c63be382448e159a08d7beb1 Mon Sep 17 00:00:00 2001 From: Kevin Kirchner Date: Wed, 25 Jan 2017 11:11:54 -0500 Subject: [PATCH] Add --include-path option for sass imports Fixes: #32 --- lib/compile.js | 9 +++++---- lib/index.js | 12 ++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/compile.js b/lib/compile.js index 9b53208..ea4d237 100644 --- a/lib/compile.js +++ b/lib/compile.js @@ -90,15 +90,16 @@ var compile = { parseCSS: function(filePath, outputFile, errorFunc) { compile.doParse(fs.readFileSync(filePath, 'utf-8'), filePath, outputFile, errorFunc); }, - parseSCSSLocally: function(filePath, outputFile, errorFunc) { + parseSCSSLocally: function(filePath, outputFile, includePath, errorFunc) { var css = require('node-sass').renderSync({ file: filePath, - outputStyle: 'compressed' + outputStyle: 'compressed', + includePath: includePath, }).css.toString(); compile.doParse(css, filePath, outputFile, errorFunc); }, - parseSCSSGlobally: function(filePath, outputFile, errorFunc) { + parseSCSSGlobally: function(filePath, outputFile, includePath, errorFunc) { var css, isWin = process.platform == 'win32', cmd = 'npm', @@ -145,7 +146,7 @@ var compile = { // create temporary file var tmp_file = path.join(os.tmpdir(),(new Date()).valueOf().toString()); - cmdConvert = path.join(pathToGlobalSCSS, 'bin', 'node-sass') + ' --output-style compressed ' + filePath + ' > '+ tmp_file; + cmdConvert = path.join(pathToGlobalSCSS, 'bin', 'node-sass') + ' --output-style compressed --include-path ' + includePath + ' ' + filePath + ' > ' + tmp_file; childProcess.execSync(cmdConvert, { env: envObj }); diff --git a/lib/index.js b/lib/index.js index a6cb48e..ac4a6f0 100644 --- a/lib/index.js +++ b/lib/index.js @@ -47,6 +47,13 @@ module.exports = { type: 'string', "default": './', order: 15 + }, + includePath: { + title: 'Include Paths', + description: 'Paths to include when importing files. See node-sass --include-path option.', + type: 'string', + "default": './', + order: 16 } }, installationDir: '', @@ -114,6 +121,7 @@ module.exports = { compileFile: function(filePath) { var file = path.parse(filePath); var outputFile = path.resolve(file.dir, atom.config.get(packageName + '.output'), path.parse(filePath).name + '.js').replace(/\\/g, '/'); + var includePath = path.resolve(atom.project.getPaths()[0], atom.config.get(packageName + '.includePath')) if (file.ext == '.css') { // Normal CSS file conversion @@ -127,7 +135,7 @@ module.exports = { }, 0); } else if (atom.config.get(packageName + '.useGlobalSass')) { // SASS/SCSS file conversion with global node-sass package - compile.parseSCSSGlobally(filePath, outputFile, function(message) { + compile.parseSCSSGlobally(filePath, outputFile, includePath, function(message) { atom.notifications.addError('Error', { detail: message, dismissable: false @@ -136,7 +144,7 @@ module.exports = { } else { // SASS/SCSS file conversion with locally installed node-sass package setTimeout(function() { - compile.parseSCSSLocally(filePath, outputFile, function(message) { + compile.parseSCSSLocally(filePath, outputFile, includePath, function(message) { atom.notifications.addError('Error', { detail: message, dismissable: false