예제 #1
0
        public void Process()
        {
            Console.WriteLine("Sass");
            Colorizer.WriteLine($"  Output Style: [DarkCyan!{appSettings.ScssOutput}]");

            // get files
            var inFiles = util.GetFiles("scss", "sass");

            Colorizer.WriteLine($"  Processing [White!{inFiles.Count}] files...");

            foreach (var inFile in inFiles)
            {
                if (appSettings.Verbose)
                {
                    Colorizer.WriteLine($"    [DarkGray!{inFile.FullName.Replace(appSettings.Input, ".")}]");
                }
                try
                {
                    var outFile = new FileInfo(inFile.FullName
                                               .Replace(appSettings.Input, appSettings.Output)
                                               .Replace(".scss", ".css"));
                    // preprocess
                    var options = new ScssOptions
                    {
                        InputFile   = inFile.FullName,
                        OutputFile  = outFile.FullName,
                        OutputStyle = appSettings.ScssOutput,
                    };
                    var result = Scss.ConvertFileToCss(inFile.FullName, options);

                    // save result
                    outFile.Directory?.Create();
                    File.WriteAllText(outFile.FullName, result.Css);
                }
                catch (Exception ex)
                {
                    throw util.ProcessingException(inFile, ex);
                }
            }
        }
        public void Process()
        {
            Console.WriteLine("JavaScript Minify");

            // get files
            var inFiles = util.GetFiles("js");

            Colorizer.WriteLine($"  Processing [White!{inFiles.Count}] files...");

            foreach (var inFile in inFiles)
            {
                if (appSettings.Verbose)
                {
                    Colorizer.WriteLine($"    [DarkGray!{inFile.FullName.Replace(appSettings.Input, ".")}]");
                }
                try
                {
                    // process
                    var js = ProcessFile(inFile);

                    // minify
                    if (appSettings.MinifyJs && !inFile.Name.ToLowerInvariant().EndsWith(".min.js"))
                    {
                        js = Uglify.Js(js).Code;
                    }

                    // save result
                    var outFile = new FileInfo(inFile.FullName.Replace(appSettings.Input, appSettings.Output));
                    outFile.Directory?.Create();
                    File.WriteAllText(outFile.FullName, js);
                }
                catch (Exception ex)
                {
                    throw util.ProcessingException(inFile, ex);
                }
            }
        }
        public void Process()
        {
            Console.WriteLine("Static Files");

            // get files
            var extensions = new List <string> {
                "jpg", "jpeg", "gif", "png", "ico", "txt", "xml", "pdf"
            };

            extensions.AddRange(appSettings.AdditionalStaticFiles);
            var inFiles = util.GetFiles(extensions.ToArray());

            inFiles.AddRange(Directory.EnumerateFiles(appSettings.Input, "*.", SearchOption.AllDirectories)
                             .Where(x => Path.GetFileName(x)?.StartsWith("_") == false)
                             .Select(x => new FileInfo(x)));

            Colorizer.WriteLine($"  Processing [White!{inFiles.Count}] files...");

            foreach (var inFile in inFiles)
            {
                if (appSettings.Verbose)
                {
                    Colorizer.WriteLine($"    [DarkGray!{inFile.FullName.Replace(appSettings.Input, ".")}]");
                }
                try
                {
                    // copy
                    var outFile = new FileInfo(inFile.FullName.Replace(appSettings.Input, appSettings.Output));
                    outFile.Directory?.Create();
                    File.Copy(inFile.FullName, outFile.FullName, true);
                }
                catch (Exception ex)
                {
                    throw util.ProcessingException(inFile, ex);
                }
            }
        }
예제 #4
0
        public void Process()
        {
            Console.WriteLine("Razor");

            // metadata
            var siteMeta = new Dictionary <string, object>();
            var metaFile = new FileInfo($"{appSettings.Input}/shared/meta.yaml");

            if (metaFile.Exists)
            {
                Colorizer.WriteLine($"  Meta: [DarkCyan!{metaFile.FullName.Replace(appSettings.Input, ".")}]");
                siteMeta = new Deserializer().Deserialize <Dictionary <string, object> >(File.ReadAllText(metaFile.FullName));
                if (appSettings.Verbose)
                {
                    foreach (var m in siteMeta)
                    {
                        Colorizer.WriteLine($"    [DarkGray!{m.Key} = \"{m.Value}\"]");
                    }
                }
            }

            // get files
            var inFiles = util.GetFiles("cshtml");

            Colorizer.WriteLine($"  Processing [White!{inFiles.Count}] files...");

            // create razor engine
            var razor = RazorEngineService.Create(new TemplateServiceConfiguration
            {
                ////BaseTemplateType = typeof(SupportTemplateBase<>),
                TemplateManager = new ResolvePathTemplateManager(new[] { $"{appSettings.Input}/shared" }),
            });

            foreach (var inFile in inFiles)
            {
                if (appSettings.Verbose)
                {
                    Colorizer.WriteLine($"    [DarkGray!{inFile.FullName.Replace(appSettings.Input, ".")}]");
                }
                try
                {
                    // compile
                    var html = razor.RunCompile(inFile.FullName, null, null, new DynamicViewBag(siteMeta));
                    if (appSettings.MinifyHtml)
                    {
                        html = Uglify.Html(html).Code;
                    }

                    // save contents
                    var outFile = new FileInfo(inFile.FullName
                                               .Replace(appSettings.Input, appSettings.Output)
                                               .Replace(".cshtml", ".html"));
                    outFile.Directory?.Create();
                    File.WriteAllText(outFile.FullName, html);
                }
                catch (Exception ex)
                {
                    throw util.ProcessingException(inFile, ex);
                }
            }
        }
예제 #5
0
        public void Process()
        {
            Console.WriteLine("Html");

            // load metadata
            var siteMeta = new Dictionary <string, object>();
            var metaFile = new FileInfo($"{appSettings.Input}/shared/meta.yaml");

            if (metaFile.Exists)
            {
                Colorizer.WriteLine($"  Meta: [DarkCyan!{metaFile.FullName.Replace(appSettings.Input, ".")}]");
                siteMeta = new Deserializer().Deserialize <Dictionary <string, object> >(File.ReadAllText(metaFile.FullName));
                if (appSettings.Verbose)
                {
                    foreach (var m in siteMeta)
                    {
                        Colorizer.WriteLine($"    [DarkGray!{m.Key} = \"{m.Value}\"]");
                    }
                }
            }

            // get files
            var inFiles = util.GetFiles("htm", "html");

            Colorizer.WriteLine($"  Processing [White!{inFiles.Count}] files...");

            foreach (var inFile in inFiles)
            {
                if (appSettings.Verbose)
                {
                    Colorizer.WriteLine($"    [DarkGray!{inFile.FullName.Replace(appSettings.Input, ".")}]");
                }
                try
                {
                    // compile
                    var contents = ProcessFile(inFile);

                    // separate page meta
                    var separator = new[] { $"{Environment.NewLine}---{Environment.NewLine}" };
                    var parts     = contents.Split(separator, StringSplitOptions.RemoveEmptyEntries);
                    var meta      = parts.Length == 1 ? string.Empty : parts[0];
                    var html      = parts.Length == 1 ? parts[0] : parts[1];

                    // inject metadata
                    if (!string.IsNullOrEmpty(meta))
                    {
                        var pageMeta = new Deserializer().Deserialize <Dictionary <string, object> >(meta);
                        foreach (var m in pageMeta)
                        {
                            html = html.Replace($"{{{{ {m.Key} }}}}", m.Value.ToString());
                        }
                    }
                    foreach (var m in siteMeta)
                    {
                        html = html.Replace($"{{{{ {m.Key} }}}}", m.Value.ToString());
                    }

                    // minify
                    if (appSettings.MinifyHtml)
                    {
                        html = Uglify.Html(html).Code;
                    }

                    // save contents
                    var outFile = new FileInfo(inFile.FullName.Replace(appSettings.Input, appSettings.Output));
                    outFile.Directory?.Create();
                    File.WriteAllText(outFile.FullName, html);
                }
                catch (Exception ex)
                {
                    throw util.ProcessingException(inFile, ex);
                }
            }
        }