예제 #1
0
        public ProjectBuilder BuildTypeScripts()
        {
            var tsc   = new TypeScriptCompiler();
            var files = ResourceMinifier.GetFiles(file =>
                                                  (file.FullName.Contains(@"style\") ||
                                                   file.FullName.Contains(@"touch\") ||
                                                   file.FullName.Contains(@"utils\") ||
                                                   file.FullName.Contains(@"video\")) &&
                                                  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());
                    changedFiles.ForEach(file =>
                    {
                        WriteHint($"\t=> {file.Replace(".ts", ".js")}");
                    });
                }
                cache.SaveCache();
            }
            WriteSuccess("TypeScript build complete.");
            return(this);
        }
예제 #2
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);
        }