Esempio n. 1
0
        private void DetectAdditionalSourceFilesJavaScript(string fileName, bool clear = true)
        {
            if (clear)
            {
                AdditionalSourceFiles.Clear();
            }
            if (!File.Exists(fileName))
            {
                return;
            }
            string filePath = Path.GetDirectoryName(fileName);

            using (var reader = new StreamReader(fileName))
            {
                while (!reader.EndOfStream)
                {
                    string line  = reader.ReadLine();
                    var    match = Regex.Match(line, @"^\s*import\s+.*?([""'])(.+?)\1");
                    if (match.Success)
                    {
                        string file = match.Groups[2].Value.Trim();
                        if (Path.GetExtension(file) != ".js")
                        {
                            file += ".js";
                        }
                        file = file.Replace("/", "\\");
                        file = Path.Combine(filePath, file);
                        if (AdditionalSourceFiles.Add(file))
                        {
                            DetectAdditionalSourceFilesJavaScript(file, clear: false);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void DetectAdditionalSourceFilesCss(string fileName, bool clear = true)
        {
            if (clear)
            {
                AdditionalSourceFiles.Clear();
            }
            if (!File.Exists(fileName))
            {
                return;
            }
            string filePath = Path.GetDirectoryName(fileName);

            using (var reader = new StreamReader(fileName))
            {
                while (!reader.EndOfStream)
                {
                    string line  = reader.ReadLine();
                    var    match = Regex.Match(line, @"^\s*@import\s+url\(\s*([""']?)(.+?)\1\s*\)");
                    if (!match.Success)
                    {
                        match = Regex.Match(line, @"^\s*@import\s+(""|')(.+?)\1");
                    }
                    if (match.Success)
                    {
                        string file = match.Groups[2].Value.Trim();
                        if (!file.StartsWith("http://") && !file.StartsWith("https://"))
                        {
                            file = file.Replace("/", "\\");
                            file = Path.Combine(filePath, file);
                            if (AdditionalSourceFiles.Add(file))
                            {
                                DetectAdditionalSourceFilesCss(file, clear: false);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void DetectAdditionalSourceFilesScss(string fileName, bool clear = true)
        {
            if (clear)
            {
                AdditionalSourceFiles.Clear();
            }
            if (!File.Exists(fileName))
            {
                return;
            }
            string filePath = Path.GetDirectoryName(fileName);

            using (var reader = new StreamReader(fileName))
            {
                while (!reader.EndOfStream)
                {
                    string line  = reader.ReadLine();
                    var    match = Regex.Match(line, @"^\s*@(?:forward|import|use)\s+(?:(""|')(.+?)\1\s*,?\s*)+");
                    if (match.Success)
                    {
                        foreach (Capture capture in match.Groups[2].Captures)
                        {
                            string file = capture.Value.Trim();
                            file = file.Replace("/", "\\");
                            file = Path.Combine(filePath, file);

                            switch (Path.GetExtension(file))
                            {
                            case ".css":
                            case ".scss":
                            case ".sass":
                                if (AdditionalSourceFiles.Add(file))
                                {
                                    DetectAdditionalSourceFilesScss(file, clear: false);
                                }
                                break;

                            default:
                                // Add all possible variants as they may exist or change later
                                if (AdditionalSourceFiles.Add(file + ".css"))
                                {
                                    DetectAdditionalSourceFilesScss(file + ".css", clear: false);
                                }
                                if (AdditionalSourceFiles.Add(file + ".scss"))
                                {
                                    DetectAdditionalSourceFilesScss(file + ".scss", clear: false);
                                }
                                if (AdditionalSourceFiles.Add(file + ".sass"))
                                {
                                    DetectAdditionalSourceFilesScss(file + ".sass", clear: false);
                                }

                                string partialFile = Path.Combine(Path.GetDirectoryName(file), "_" + Path.GetFileName(file));
                                if (AdditionalSourceFiles.Add(partialFile + ".css"))
                                {
                                    DetectAdditionalSourceFilesScss(partialFile + ".css", clear: false);
                                }
                                if (AdditionalSourceFiles.Add(partialFile + ".scss"))
                                {
                                    DetectAdditionalSourceFilesScss(partialFile + ".scss", clear: false);
                                }
                                if (AdditionalSourceFiles.Add(partialFile + ".sass"))
                                {
                                    DetectAdditionalSourceFilesScss(partialFile + ".sass", clear: false);
                                }
                                break;
                            }
                        }
                    }
                }
            }
        }