Пример #1
0
        private void ShowOutput(CompilerResult result, string projectFolder)
        {
            string rel(string x) => (x == null ? "null" : string.Format("{0}\\{1}", Path.GetDirectoryName(x)?.Replace(projectFolder, string.Empty), Path.GetFileName(x)));

            _vsOutWindow.Writeline(
                "sass -> in:{0}  out:{1}  elapse:{2}",

                rel(result.SourceFile),
                (result.GeneratedFiles.Length > 1 ? string.Format("[{0}]", string.Join(" + ", result.GeneratedFiles.Select(x => rel(x)))) : rel(result.OutputFile)),
                result.Elapse.ToString("hh\\:mm\\:ss\\.fff")
                );
        }
Пример #2
0
        public async void Compile(string documentPath, IVsHierarchy hierarchy)
        {
            await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

            if (hierarchy == null)
            {
                return;
            }

            hierarchy.GetProperty(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID.VSHPROPID_ExtObject, out object objProj);
            string projectPath = (objProj as EnvDTE.Project)?.FullName;

            if (!File.Exists(projectPath) || !File.Exists(documentPath))
            {
                return;
            }

            string[] documents;
            if (Path.GetFileName(documentPath).StartsWith("_"))
            {
                documents = SassCompiler.GetSassFiles(Path.GetDirectoryName(projectPath)).ToArray();
            }
            else
            {
                documents = new string[] { documentPath }
            };

            string configPath = Path.Combine(Path.GetDirectoryName(projectPath), ConfigurationPage.ConfigurationFileDefaultName);
            var    options    = new CompilerOptions
            {
                ConfigurationFile  = (File.Exists(configPath) ? configPath : null),
                AddSourceComments  = ConfigurationPage.ShouldAddSourceMapComment,
                GenerateSourceMaps = ConfigurationPage.ShouldGenerateSourceMap,
                Minify             = ConfigurationPage.ShouldMinifyFile
            };

            for (int i = 0; i < documents.Length; i++)
            {
                CompilerResult result = await SassCompiler.CompileAsync(documents[i], options);

                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                ShowOutput(result, Path.GetDirectoryName(projectPath));
                ShowErrors(documents[i], result.Errors, hierarchy);
            }
        }