Example #1
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);
        }
Example #2
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;
                }
            }
        }
Example #3
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);
        }