Exemple #1
0
        public ProjectBuilder BuildTypeScripts()
        {
            var tsc      = new TypeScriptCompiler();
            var uglifyJs = new JavascriptMinifier();
            var files    = ResourceMinifier.GetFiles(file =>
                                                     file.FullName.Contains(@"src\") &&
                                                     file.Extension == ".ts" &&
                                                     !file.Name.EndsWith(".d.ts")
                                                     );

            using (var cache = new BuildCache())
            {
                var changedFiles = files.Where(file => !cache.Contains(file)).ToArray();
                if (changedFiles.Any())
                {
                    changedFiles.ForEach(file =>
                    {
                        cache.AddCache(file);
                        WriteInfo($"TypeScript build: {file}");
                    });
                    Console.Write(tsc.Run().Trim());
                    Parallel.ForEach(changedFiles.Select(f => ".ts-output/" + f.Replace(".ts", ".js").Replace($"src{Path.DirectorySeparatorChar}", "")), file => {
                        var min     = uglifyJs.Minify(File.ReadAllText(file));
                        var minFile = ResourceMinifier.GetMinimizedFileName(file);
                        File.WriteAllText(minFile, min);
                        WriteHint($"\t=> {minFile}");
                    });
                }
                cache.SaveCache();
            }
            WriteSuccess("TypeScript build complete.");
            return(this);
        }
Exemple #2
0
        public ProjectBuilder BuildSass()
        {
            var sass     = new SassCompiler();
            var cleancss = new CssMinifier();
            var files    = ResourceMinifier.GetFiles(file =>
                                                     file.FullName.Contains("src" + Path.DirectorySeparatorChar) &&
                                                     file.Extension == ".scss"
                                                     );

            using (var cache = new BuildCache())
            {
                var changedFiles = files.Where(file => !cache.Contains(file)).ToArray();
                if (changedFiles.Any())
                {
                    changedFiles.ForEach(file =>
                    {
                        cache.AddCache(file);
                        WriteInfo($"Sass build: {file}");
                    });
                    Console.Write(sass.Run().Trim());
                    var results = ResourceMinifier.GetFiles(f => f.FullName.Contains(".sass-output" + Path.DirectorySeparatorChar));
                    Parallel.ForEach(results, file =>
                    {
                        var min     = cleancss.Minify(File.ReadAllText(file).Replace("@charset \"UTF-8\";", ""));
                        var minFile = ResourceMinifier.GetMinimizedFileName(file);
                        File.WriteAllText(minFile, min);
                        // WriteHint($"\t=> {minFile}");
                    });
                }
                cache.SaveCache();
            }
            WriteSuccess("Sass build complete.");
            return(this);
        }
        public ProjectBuilder BuildSass()
        {
            var sass     = new SassCompiler();
            var cleancss = new CssMinifier();
            var files    = ResourceMinifier.GetFiles(file =>
                                                     file.Extension == ".scss"
                                                     );

            using (var cache = new BuildCache())
            {
                var changedFiles = files.Where(file => !cache.Contains(file)).ToArray();
                if (changedFiles.Any())
                {
                    string getOutputCacheFilename(string f)
                    {
                        return(".sass-output/" + f
                               .Replace(".scss", ".css")
                               .Replace($"src{Path.DirectorySeparatorChar}", ""));
                    }

                    changedFiles.ForEach(file => {
                        cache.AddCache(file);
                        WriteInfo($"Sass build: {file}");
                    });
                    WriteInfo(sass.Run("").Trim());
                    Parallel.ForEach(changedFiles
                                     .Where(f => !Path.GetFileName(f).StartsWith("_")),
                                     f => {
                        // var sass = new SassSingleCompiler();
                        // var css = sass.Run(File.ReadAllText(file));
                        // File.WriteAllText(getOutputCacheFilename(file), css);
                        var file    = getOutputCacheFilename(f);
                        var min     = cleancss.Minify(File.ReadAllText(file).Replace("@charset \"UTF-8\";", ""));
                        var minFile = ResourceMinifier.GetMinimizedFileName(file);
                        File.WriteAllText(minFile, min);
                        UpdateCachedMinFile(minFile);
                        // WriteHint($"\t=> {minFile}");
                    });
                    // var results = ResourceMinifier.GetFiles(f => f.FullName.Contains(".sass-output" + Path.DirectorySeparatorChar));
                    // Parallel.ForEach(results, file =>
                    // {
                    //   var min = cleancss.Minify(File.ReadAllText(file).Replace("@charset \"UTF-8\";", ""));
                    //   var minFile = ResourceMinifier.GetMinimizedFileName(file);
                    //   File.WriteAllText(minFile, min);
                    // });
                }
                cache.SaveCache();
            }
            WriteSuccess("Sass build complete.");
            return(this);
        }
        public ProjectBuilder BuildTypeScripts()
        {
            var tsc      = new BabelCompiler();
            var uglifyJs = new JavascriptMinifier();
            var files    = ResourceMinifier.GetFiles(file =>
                                                     file.Extension == ".ts" &&
                                                     !file.Name.EndsWith(".d.ts")
                                                     );

            using (var cache = new BuildCache())
            {
                var changedFiles = files.Where(file => !cache.Contains(file)).ToArray();
                if (changedFiles.Any())
                {
                    string getOutputCacheFilename(string f)
                    {
                        return(".ts-output/" + f
                               .Replace(".ts", ".js")
                               .Replace($"src{Path.DirectorySeparatorChar}", ""));
                    }

                    changedFiles.ForEach(file => {
                        cache.AddCache(file);
                        WriteInfo($"TypeScript build: {file}");
                    });
                    WriteInfo(tsc.Run("").Trim());
                    Parallel.ForEach(changedFiles
                                     .Where(f => !f.EndsWith(".vue.ts")),
                                     f => {
                        // var tsc = new BabelSingleCompiler(file);
                        // var js = tsc.Run(File.ReadAllText(file));
                        // File.WriteAllText(getOutputCacheFilename(file), js);
                        var file = getOutputCacheFilename(f);
                        var text = RegexReplacer.Replace(File.ReadAllText(file), @"import\(\(\(\)\s*=>\s*(.*)\)\(\)\)", match =>
                        {
                            return($"import({match.Groups[1].Value})");
                        });
                        var min     = uglifyJs.Minify(text);
                        var minFile = ResourceMinifier.GetMinimizedFileName(file);
                        File.WriteAllText(minFile, min);
                        UpdateCachedMinFile(minFile);
                        // WriteHint($"\t=> {minFile}");
                    });
                }
                cache.SaveCache();
            }
            WriteSuccess("TypeScript build complete.");
            return(this);
        }