Exemplo n.º 1
0
        public string GetPathForMinimised(string path)
        {
            path = MakePathAbsolute(path);
            FileType type = PathParser.GetFileType(path);

            return(GenerateOutPathForMinimised(path, type));
        }
Exemplo n.º 2
0
        /// <summary>
        /// reads from a standard Web Essentials stlye bundle file
        /// </summary>
        /// <param name="bundleBaseDirPath">the base directory, in which to look for the files that the bundle will contain.</param>
        /// <param name="bundlePath">The path to the .custombundle file.</param>
        /// <returns></returns>
        internal static BundleInfo LoadFromXmlFile(string bundleBaseDirPath, string bundlePath)
        {
            BundleInfo bundle = new BundleInfo(PathParser.GetFileType(bundlePath));

            XmlDocument doc = new XmlDocument();

            doc.Load(bundlePath);

            XmlNode node        = doc.SelectSingleNode("/bundle");
            string  outFilename = GenerateOutFilename(bundlePath);

            foreach (XmlAttribute attr in node.Attributes)
            {
                if (attr.Name == "minify")
                {
                    bundle.isMinimising = attr.Value == "true";
                }
                if (attr.Name == "output")
                {
                    outFilename = attr.Value;
                }
            }

            bundle.outFilepath = Path.Combine(Path.GetDirectoryName(bundlePath), outFilename);

            XmlNodeList fileNodes = doc.SelectNodes("/bundle/file");

            foreach (XmlNode fileNode in fileNodes)
            {
                string relPath = fileNode.InnerText;
                if (relPath.StartsWith("/"))
                {
                    relPath = relPath.Substring(1);
                }
                relPath = relPath.Replace("/", "\\");

                //get the absolute path to the file:
                string absPath = Path.Combine(bundleBaseDirPath, relPath);
                bundle.filePaths.Add(absPath);

                //check that type of the file, matches the type of the bundle:
                FileType typeOfFile = PathParser.GetFileType(absPath);
                FileTypeValidator.ValidateBundleMatches(bundle.Type, typeOfFile);
            }

            return(bundle);
        }
Exemplo n.º 3
0
        public void MinimiseFileToFile(string path, out string outPath)
        {
            Output.WriteLine("Minimising the file " + path);

            path = MakePathAbsolute(path);
            if (!File.Exists(path))
            {
                throw new ArgumentException("Could not find the path:" + path);
            }

            string text = ReadTextFromFile(path);

            FileType      fileType = PathParser.GetFileType(path);
            StringBuilder sb       = MinimiseTextToText(text, fileType);

            outPath = GenerateOutPathForMinimised(path, fileType);

            WriteTextToFile(sb.ToString(), outPath);

            Output.WriteLine("Minimised to: " + outPath);
        }
Exemplo n.º 4
0
        private ICompressor CreateCompressor(string path, out FileType fileType)
        {
            fileType = PathParser.GetFileType(path);

            return(CreateCompressor(fileType));
        }