public virtual ProjectBuilder Build(ProjectBuilder builder)
        {
            var files = GetFiles(FileFilter);

            using (var cache = new BuildCache())
            {
                var changedFiles = files.Where(file => !cache.Contains(file));
                Parallel.ForEach(changedFiles, path =>
                {
                    builder.WriteInfo($"{ResourceType} minify: {path}");

                    var text   = File.ReadAllText(path);
                    var result = Minify(text);

                    var outputPath = GetMinimizedFileName(path);
                    File.WriteAllText(outputPath, result);
                    cache.AddCache(path);

                    builder.WriteHint($"\t=> {outputPath}");
                    // builder.WriteHint($"\t=> {outputPath.PadRight(48)}{(100.0 * result.Length / text.Length):0.##}%");
                });
                cache.SaveCache();
            }
            files.ForEach(file =>
            {
                builder.OriginalResourceLength  += new FileInfo(file).Length;
                builder.MinimizedResourceLength += new FileInfo(GetMinimizedFileName(file)).Length;
            });
            builder.WriteSuccess($"{ResourceType} minify complete.");
            return(builder);
        }
Example #2
0
        public static void Main(string[] args)
        {
            try
            {
                var configFile = new ConfigurationBuilder()
                                 .AddJsonFile(
                    Path.Combine(Environment.CurrentDirectory, "builder/builder-config.json"),
                    optional: false,
                    reloadOnChange: false)
                                 .Build();
                var config = new BuilderConfig();
                configFile.Bind(config);

                var builder = new ProjectBuilder(config);
                builder
                .BuildClient()
                .BuildPreview()
                .BuildMaster()
                .GetBundleFiles()
                .PrebuildVue()
                .BuildTypeScripts()
                .BuildSass()
                .BuildVue()
                .BuildResources()
                .BuildPreviewOffline()
                .BuildOffline()
                .BuildBundle()
                .BuildPreviewData()
                .BuildFinalOutput();

                if (config.CopyOnBuild)
                {
                    var text = File.ReadAllText(config.PreviewOffline);
                    TextCopy.Clipboard.SetText(text);
                    builder.WriteHint($"Copied {text.Length} characters");
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Error.WriteLine($"Unexpected Error: {ex.Message}");
                throw;
            }
        }