Ejemplo n.º 1
0
        /**
         * Note: the RazorMinifier.Core source code is embedded so that there will be
         * only 1 exe for deployment.
         * There is no need of RazorMinifier.Core.dll
         * */

        #region Main

        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please provide folder path or file(s) to process");
            }
            else
            {
                // Determine which features to enable or disable
                var features = new MinifyOptions(args);
                foreach (var arg in args)
                {
                    if (Directory.Exists(arg))
                    {
                        ProcessDirectory(features, arg);
                    }
                    else if (File.Exists(arg))
                    {
                        ProcessFile(features, arg);
                    }
                }
                Console.WriteLine("Razor Minifying Complete");
            }

            //Console.ReadLine();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Minifies the contents of the given view.
 /// </summary>
 /// <param name="filePath">The file path.</param>
 /// <param name="option">The features</param>
 /// <returns>
 /// The <see cref="string" />.
 /// </returns>
 public static string MinifyHtml(string filePath, MinifyOptions option)
 {
     using (StreamReader reader = new StreamReader(filePath))
     {
         return(RazorMinify.Minify(reader.ReadToEnd(), option));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Minify a given file
        /// </summary>
        /// <param name="features">Features object</param>
        /// <param name="filePath">The path to the file</param>
        public static void ProcessFile(MinifyOptions features, string filePath)
        {
            // Minify contents
            string minifiedContents = MinifyHtml(filePath, features);

            // Write to the same file
            File.WriteAllText(filePath, minifiedContents, Encoding.UTF8);
            Console.WriteLine("Minified file : " + filePath);
        }
Ejemplo n.º 4
0
        private static object Minify(MinifyOptions opts)
        {
            try
            {
                new MinifyCommand(opts).Execute().Wait();
            }
            catch (Exception ex)
            {
                MessageHelper.Error(ex.ToString());
                MessageHelper.Warning("Use \"nustore minify --help\" for help info...");
            }

            return(null);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Minify all files in a given file
        /// </summary>
        /// <param name="features">Features object</param>
        /// <param name="folderPath">The path to the folder</param>
        public static void ProcessDirectory(MinifyOptions features, string folderPath)
        {
            // Loop through the files in the folder and look for any of the following extensions
            var subFolders = GetDirectories(folderPath);

            foreach (string folder in subFolders)
            {
                var filePaths = Directory.GetFiles(folder);
                foreach (var filePath in filePaths)
                {
                    if (IsHtmlFile(filePath))
                    {
                        ProcessFile(features, filePath);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public MinifyCommand(MinifyOptions options)
 {
     _options = options;
 }