コード例 #1
0
        public static string Minify(string fullFileName, string outputText, ProjectItem projectItem, MinifyType mode, string customArgument)
        {
            if (mode == MinifyType.Unspecified)
            {
                mode = Settings.Instance(fullFileName).DefaultJavaScriptMinifier;
            }

            switch (mode)
            {
            case MinifyType.gctAdvanced:
                return(ClosureCompilerEngine.Minify(fullFileName, outputText, projectItem, ClosureCompilerCompressMode.ADVANCED_OPTIMIZATIONS, customArgument));

            case MinifyType.gctSimple:
                return(ClosureCompilerEngine.Minify(fullFileName, outputText, projectItem, ClosureCompilerCompressMode.SIMPLE_OPTIMIZATIONS, customArgument));

            case MinifyType.gctWhiteSpaceOnly:
                return(ClosureCompilerEngine.Minify(fullFileName, outputText, projectItem, ClosureCompilerCompressMode.WHITESPACE_ONLY, customArgument));

            case MinifyType.msAjax:
                return(MsJsEngine.Minify(fullFileName, outputText, projectItem));

            case MinifyType.uglify:
                return(UglifyEngine.Minify(fullFileName, outputText, projectItem));

            case MinifyType.jsBeautifier:
                return(UglifyEngine.Beautify(outputText));

            default:
                return(YuiJsEngine.Minify(fullFileName, outputText, projectItem));
            }
        }
コード例 #2
0
ファイル: Chirp.cs プロジェクト: cbilson/chirpy
        public void LoadActions()
        {
            if (this.engineManager == null || this.engineManager.IsDisposed) {
                this.engineManager = new EngineManager(this);
            }

            this.engineManager.Clear();
            this.engineManager.Add(YuiCssEngine = new YuiCssEngine());
            this.engineManager.Add(YuiJsEngine = new YuiJsEngine());
            this.engineManager.Add(DeanEdwardsPackerEngine = new DeanEdwardsPackerEngine());
            this.engineManager.Add(ClosureCompilerEngine = new ClosureCompilerEngine());
            this.engineManager.Add(LessEngine = new LessEngine());
            this.engineManager.Add(MsJsEngine = new MsJsEngine());
            this.engineManager.Add(MsCssEngine = new MsCssEngine());
            this.engineManager.Add(ConfigEngine = new ConfigEngine());
            this.engineManager.Add(ViewEngine = new ViewEngine());
            this.engineManager.Add(T4Engine = new T4Engine());
            this.engineManager.Add(CoffeeScriptEngine = new CoffeeScriptEngine());
            this.engineManager.Add(UglifyEngine = new UglifyEngine());
            this.engineManager.Add(JSHintEngine = new JSHintEngine());
            this.engineManager.Add(CSSLintEngine = new CSSLintEngine());
            this.engineManager.Add(SassEngine = new SassEngine());
        }
コード例 #3
0
        public override void Run(string fullFileName, ProjectItem projectItem)
        {
            var    fileGroups         = this.LoadConfigFileGroups(fullFileName);
            string directory          = Path.GetDirectoryName(fullFileName);
            var    productionFileText = new StringBuilder();

            using (var manager = new Manager.VSProjectItemManager(this.Chirp != null ? this.Chirp.App : null, projectItem))
            {
                foreach (var fileGroup in fileGroups)
                {
                    productionFileText.Clear();

                    bool isJS  = this.IsJsFile(fileGroup.GetName);
                    bool isCSS = this.IsCssFile(fileGroup.GetName);

                    string fullPath = directory + @"\" + fileGroup.Name;
                    if (!string.IsNullOrEmpty(fileGroup.Path))
                    {
                        fullPath = fileGroup.Path;
                    }
                    string fullPathMin = Utilities.GetBaseFileName(fullPath) + (isJS ? this.Settings.OutputExtensionJS : this.Settings.OutputExtensionCSS);
                    if (TaskList.Instance != null)
                    {
                        TaskList.Instance.Remove(fullPath);
                        TaskList.Instance.Remove(fullPathMin);
                    }

                    if (ImageSprite.IsImage(fileGroup.GetName))
                    {
                        var img = ImageSprite.Build(fileGroup, fullPath);
                        manager.AddFileByFileName(fullPath, img);
                        continue;
                    }

                    foreach (var file in fileGroup.Files)
                    {
                        var    path      = file.Path;
                        string code      = file.GetCode();
                        string customArg = file.CustomArgument;


                        if (((this.IsLessFile(path) || file.Engine == EngineType.Less) || this.IsSassFile(path) || this.IsCoffeeScriptFile(path) || file.Minify == true) && TaskList.Instance != null)
                        {
                            TaskList.Instance.Remove(path);
                        }

                        if (fileGroup.Debug)
                        {
                            var debugCode = "\r\n/* Chirpy Minify: {Minify}, MinifyWith: {MinifyWith}, File: {FilePath} */\r\n{Code}"
                                            .F(new
                            {
                                Minify     = file.Minify.GetValueOrDefault(),
                                FilePath   = path,
                                Code       = isJS ? UglifyEngine.Beautify(code) : code,
                                MinifyWith = file.MinifyWith.ToString()
                            });
                            productionFileText.AppendLine(debugCode);
                        }

                        if (this.IsLessFile(path) || file.Engine == EngineType.Less)
                        {
                            code = LessEngine.TransformToCss(path, code, projectItem);
                        }
                        else if (this.IsCoffeeScriptFile(path))
                        {
                            code = CoffeeScriptEngine.TransformToJs(path, code, projectItem);
                        }
                        else if (this.IsSassFile(path))
                        {
                            code = SassEngine.TransformToCss(path, code, projectItem);
                        }

                        if (file.Minify == true)
                        {
                            if (this.IsCssFile(path))
                            {
                                code = CssEngine.Minify(path, code, projectItem, file.MinifyWith);
                            }
                            else if (this.IsJsFile(path))
                            {
                                code = JsEngine.Minify(path, code, projectItem, file.MinifyWith, customArg);
                            }
                        }


                        productionFileText.AppendLine(code);
                    }

                    string output = productionFileText.ToString();
                    output = Utilities.ProcessText(output, fileGroup.Find, fileGroup.Replace);

                    if (fileGroup.Minify == FileGroupXml.MinifyActions.True)
                    {
                        output = isJS ? JsEngine.Minify(fullPath, output, projectItem, fileGroup.MinifyWith)
                            : CssEngine.Minify(fullPath, output, projectItem, fileGroup.MinifyWith);
                    }

                    //manager.AddFileByFileName(Utilities.GetBaseFileName(fullPath) + (isJS ? ".js" : isCSS ? ".css" : System.IO.Path.GetExtension(fullPath)), output);
                    manager.AddFileByFileName(fullPath, output);

                    if (fileGroup.Minify == FileGroupXml.MinifyActions.Both)
                    {
                        if (TaskList.Instance != null)
                        {
                            TaskList.Instance.Remove(fullPathMin);
                        }

                        output = isJS ? JsEngine.Minify(fullPath, output, projectItem, fileGroup.MinifyWith)
                            : CssEngine.Minify(fullPath, output, projectItem, fileGroup.MinifyWith);
                        manager.AddFileByFileName(fullPathMin, output);
                    }
                }

                if (projectItem != null)
                {
                    this.ReloadFileDependencies(projectItem);
                }
            }
        }