コード例 #1
0
        public override void Process(Manager.VSProjectItemManager manager, string fullFileName, EnvDTE.ProjectItem projectItem, string baseFileName, string outputText)
        {
            base.Process(manager, fullFileName, projectItem, baseFileName, outputText);

            string mini = JsEngine.Minify(fullFileName, outputText, projectItem, MinifyType.gctSimple, string.Empty);

            manager.AddFileByFileName(baseFileName + this.Settings.OutputExtensionJS, mini);
        }
コード例 #2
0
ファイル: LessEngine.cs プロジェクト: victor-mesquita/chirpy
        public override void Process(Manager.VSProjectItemManager manager, string fullFileName, EnvDTE.ProjectItem projectItem, string baseFileName, string outputText)
        {
            base.Process(manager, fullFileName, projectItem, baseFileName, outputText);

            var    mode = this.GetMinifyType(fullFileName);
            string mini = CssEngine.Minify(fullFileName, outputText, projectItem, mode);

            manager.AddFileByFileName(baseFileName + this.Settings.OutputExtensionCSS, mini);
        }
コード例 #3
0
ファイル: ConfigEngine.cs プロジェクト: cbilson/chirpy
        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) || 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))
                        {
                            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);
                }
            }
        }
コード例 #4
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);
                }
            }
        }