public void IncludeSourceCommentsAsString()
        {
            var configs = ConfigHandler.GetConfigs("../../artifacts/options/scss/scssconfigincludesourcecommentsasstring.json");
            var result  = new WebCompiler.SassOptions(configs.ElementAt(0));

            Assert.IsTrue(result.IncludeSourceComments);
        }
        public void OutputStyleEcho()
        {
            var configs = ConfigHandler.GetConfigs("../../artifacts/options/scss/scssconfigecho.json");
            var result  = new WebCompiler.SassOptions(configs.ElementAt(0));

            Assert.AreEqual(OutputStyle.Echo, result.OutputStyle);
        }
        public void Precision()
        {
            var configs = ConfigHandler.GetConfigs("../../artifacts/options/scss/scssconfigprecision.json");
            var result  = new WebCompiler.SassOptions(configs.ElementAt(0));

            Assert.AreEqual(3, result.Precision);
        }
Beispiel #4
0
        private static string ConstructArguments(Config config)
        {
            string arguments = "";

            if (config.SourceMap)
            {
                arguments += " --source-map=false --source-map-embed=true";
            }

            SassOptions options = SassOptions.FromConfig(config);

            arguments += " --precision=" + options.Precision;

            if (!string.IsNullOrEmpty(options.OutputStyle))
            {
                arguments += " --output-style=" + options.OutputStyle;
            }

            if (!string.IsNullOrEmpty(options.IndentType))
            {
                arguments += " --indent-type=" + options.IndentType;
            }

            if (options.IndentWidth > -1)
            {
                arguments += " --indent-width=" + options.IndentWidth;
            }

            return(arguments);
        }
Beispiel #5
0
        private void RunCompilerProcess(Config config, FileInfo info)
        {
            string arguments = ConstructArguments(config);

            ProcessStartInfo start = new ProcessStartInfo
            {
                WorkingDirectory       = new FileInfo(config.FileName).DirectoryName, // use config's directory to fix source map relative paths
                UseShellExecute        = false,
                WindowStyle            = ProcessWindowStyle.Hidden,
                CreateNoWindow         = true,
                FileName               = "cmd.exe",
                Arguments              = $"/c \"\"{Path.Combine(_path, "node_modules\\.bin\\node-sass.cmd")}\" {arguments} \"{info.FullName}\" \"",
                StandardOutputEncoding = Encoding.UTF8,
                StandardErrorEncoding  = Encoding.UTF8,
                RedirectStandardOutput = true,
                RedirectStandardError  = true,
            };

            // Pipe output from node-sass to postcss if autoprefix option is set
            SassOptions options = SassOptions.FromConfig(config);

            if (!string.IsNullOrEmpty(options.AutoPrefix))
            {
                string postCssArguments = "--use autoprefixer";

                if (!options.SourceMap && !config.SourceMap)
                {
                    postCssArguments += " --no-map";
                }

                start.Arguments = start.Arguments.TrimEnd('"') + $" | \"{Path.Combine(_path, "node_modules\\.bin\\postcss.cmd")}\" {postCssArguments}\"";
                start.EnvironmentVariables.Add("BROWSERSLIST", options.AutoPrefix);
            }

            start.EnvironmentVariables["PATH"] = _path + ";" + start.EnvironmentVariables["PATH"];

            using (Process p = Process.Start(start))
            {
                var stdout = p.StandardOutput.ReadToEndAsync();
                var stderr = p.StandardError.ReadToEndAsync();
                p.WaitForExit();

                _output = stdout.Result;
                // postcss outputs "√ Finished stdin (##ms)" to stderr for some reason
                if (!stderr.Result.StartsWith("√"))
                {
                    _error = stderr.Result;
                }
            }
        }
Beispiel #6
0
        public CompilerResult Compile(Config config)
        {
            string baseFolder = Path.GetDirectoryName(config.FileName);
            string inputFile  = Path.Combine(baseFolder, config.InputFile);

            FileInfo info    = new FileInfo(inputFile);
            string   content = File.ReadAllText(info.FullName);

            string sourceMap = config.SourceMap ? config.GetAbsoluteOutputFile() + ".map" : null;

            CompilerResult result = new CompilerResult
            {
                FileName        = info.FullName,
                OriginalContent = content,
            };

            SassOptions options = new SassOptions(config);

            try
            {
                LibSassNet.SassCompiler compiler = new LibSassNet.SassCompiler();
                var compilerResult = compiler.CompileFile(inputFile, (LibSassNet.OutputStyle)options.OutputStyle, sourceMap, options.IncludeSourceComments, options.Precision);
                result.CompiledContent = compilerResult.CSS;
                result.SourceMap       = compilerResult.SourceMap;
            }
            catch (Exception ex)
            {
                CompilerError error = new CompilerError
                {
                    FileName = info.FullName,
                    Message  = ex.Message.Replace("/", "\\").Replace(info.FullName, string.Empty).Trim()
                };

                if (error.Message.StartsWith(":"))
                {
                    int end  = error.Message.IndexOf(':', 1);
                    int line = 0;
                    if (int.TryParse(error.Message.Substring(1, end - 1), out line))
                    {
                        error.LineNumber = line;
                        error.Message    = error.Message.Substring(end + 1).Trim();
                    }
                }

                result.Errors.Add(error);
            }

            return(result);
        }
        public CompilerResult Compile(Config config)
        {
            string baseFolder = Path.GetDirectoryName(config.FileName);
            string inputFile = Path.Combine(baseFolder, config.InputFile);

            FileInfo info = new FileInfo(inputFile);
            string content = File.ReadAllText(info.FullName);

            string sourceMap = config.SourceMap ? config.GetAbsoluteOutputFile() + ".map" : null;

            CompilerResult result = new CompilerResult
            {
                FileName = info.FullName,
                OriginalContent = content,
            };

            SassOptions options = new SassOptions(config);

            try
            {
                LibSassNet.SassCompiler compiler = new LibSassNet.SassCompiler();
                var compilerResult = compiler.CompileFile(inputFile, (LibSassNet.OutputStyle)options.OutputStyle, sourceMap, options.IncludeSourceComments, options.Precision);
                result.CompiledContent = compilerResult.CSS;
                result.SourceMap = compilerResult.SourceMap;
            }
            catch (Exception ex)
            {
                CompilerError error = new CompilerError
                {
                    FileName = info.FullName,
                    Message = ex.Message.Replace("/", "\\").Replace(info.FullName, string.Empty).Trim()
                };

                if (error.Message.StartsWith(":"))
                {
                    int end = error.Message.IndexOf(':', 1);
                    int line = 0;
                    if (int.TryParse(error.Message.Substring(1, end - 1), out line))
                    {
                        error.LineNumber = line;
                        error.Message = error.Message.Substring(end + 1).Trim();
                    }
                }

                result.Errors.Add(error);
            }

            return result;
        }
Beispiel #8
0
        private static string ConstructArguments(Config config)
        {
            string arguments = "";

            SassOptions options = SassOptions.FromConfig(config);

            if (options.SourceMap || config.SourceMap)
            {
                arguments += " --source-map=false --source-map-embed=true";
            }

            arguments += " --precision=" + options.Precision;

            if (!string.IsNullOrEmpty(options.OutputStyle))
            {
                arguments += " --output-style=" + options.OutputStyle;
            }

            if (!string.IsNullOrEmpty(options.IndentType))
            {
                arguments += " --indent-type=" + options.IndentType;
            }

            if (options.IndentWidth > -1)
            {
                arguments += " --indent-width=" + options.IndentWidth;
            }

            if (!string.IsNullOrEmpty(options.IncludePath))
            {
                arguments += " --include-path=" + options.IncludePath;
            }

            if (!string.IsNullOrEmpty(options.SourceMapRoot))
            {
                arguments += " --source-map-root=" + options.SourceMapRoot;
            }

            if (!string.IsNullOrEmpty(options.LineFeed))
            {
                arguments += " --linefeed=" + options.LineFeed;
            }

            return(arguments);
        }
 public void Precision()
 {
     var configs = ConfigHandler.GetConfigs("../../artifacts/options/scss/scssconfigprecision.json");
     var result = new WebCompiler.SassOptions(configs.ElementAt(0));
     Assert.AreEqual(3, result.Precision);
 }
 public void OutputStyleNested()
 {
     var configs = ConfigHandler.GetConfigs("../../artifacts/options/scss/scssconfignested.json");
     var result = new WebCompiler.SassOptions(configs.ElementAt(0));
     Assert.AreEqual(OutputStyle.Nested, result.OutputStyle);
 }
 public void IncludeSourceCommentsAsString()
 {
     var configs = ConfigHandler.GetConfigs("../../artifacts/options/scss/scssconfigincludesourcecommentsasstring.json");
     var result = new WebCompiler.SassOptions(configs.ElementAt(0));
     Assert.IsTrue(result.IncludeSourceComments);
 }