public static async Task UpdateAllBundlesAsync(bool isBuild = false)
        {
            foreach (Project project in ProjectHelpers.GetAllProjects())
            {
                if (project.ProjectItems.Count == 0)
                {
                    continue;
                }

                string folder = ProjectHelpers.GetRootFolder(project);

                if (string.IsNullOrEmpty(folder))
                {
                    continue;
                }

                BundleFilesMenu menu = new BundleFilesMenu();

                foreach (string file in Directory.EnumerateFiles(folder, "*" + _ext, SearchOption.AllDirectories))
                {
                    if (ProjectHelpers.GetProjectItem(file) == null)
                    {
                        continue;
                    }

                    await menu.UpdateBundleAsync(file, isBuild);
                }
            }
        }
Beispiel #2
0
        public static string GetAbsolutePathFromSettings(string settingsPath, string filePath)
        {
            if (string.IsNullOrEmpty(settingsPath))
            {
                return(filePath);
            }

            string targetFileName = Path.GetFileName(filePath);
            string sourceDir      = Path.GetDirectoryName(filePath);

            // If the output path is not project-relative, combine it directly.
            if (!settingsPath.StartsWith("~/", StringComparison.OrdinalIgnoreCase) &&
                !settingsPath.StartsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                return(Path.GetFullPath(Path.Combine(sourceDir, settingsPath, targetFileName)));
            }

            string rootDir = ProjectHelpers.GetRootFolder();

            if (string.IsNullOrEmpty(rootDir))
            {
                // If no project is loaded, assume relative to file anyway
                rootDir = sourceDir;
            }

            return(Path.GetFullPath(Path.Combine(
                                        rootDir,
                                        settingsPath.TrimStart('~', '/'),
                                        targetFileName
                                        )));
        }
        private static bool GetFileName(IDataObject data, out string fileName)
        {
            string extension = "png";

            fileName = "file";

            if (data.GetDataPresent(DataFormats.FileDrop))
            {
                string fullpath = ((string[])data.GetData(DataFormats.FileDrop))[0];
                fileName  = Path.GetFileName(fullpath);
                extension = Path.GetExtension(fileName).TrimStart('.');
            }
            else
            {
                extension = GetMimeType((Bitmap)data.GetData("System.Drawing.Bitmap"));
            }

            using (var dialog = new SaveFileDialog())
            {
                dialog.FileName         = fileName;
                dialog.DefaultExt       = "." + extension;
                dialog.Filter           = extension.ToUpperInvariant() + " Files|*." + extension;
                dialog.InitialDirectory = _lastPath ?? ProjectHelpers.GetRootFolder();

                if (dialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return(false);
                }

                fileName = dialog.FileName;
            }

            return(true);
        }
Beispiel #4
0
        private async void SolutionEvents_Opened()
        {
            foreach (Project project in ProjectHelpers.GetAllProjects())
            {
                if (project.ProjectItems.Count == 0)
                {
                    continue;
                }

                string folder = ProjectHelpers.GetRootFolder(project);
                Func <string, bool, Task> bundleFunc = new BundleFilesMenu().UpdateBundleAsync;
                Func <string, bool, Task> spriteFunc = new SpriteImageMenu().UpdateSpriteAsync;

                foreach (string file in Directory.EnumerateFiles(folder, "*.*", SearchOption.AllDirectories)
                         .Where(s => s.EndsWith(".bundle") || s.EndsWith(".sprite")))
                {
                    if (ProjectHelpers.GetProjectItem(file) == null)
                    {
                        continue;
                    }

                    if (file.EndsWith(".bundle", StringComparison.OrdinalIgnoreCase))
                    {
                        await BundleGenerator.WatchFiles(await BundleDocument.FromFile(file), bundleFunc);
                    }
                    else
                    {
                        await SpriteGenerator.WatchFiles(await SpriteDocument.FromFile(file), spriteFunc);
                    }
                }
            }
        }
Beispiel #5
0
        private static string GetRootFolder()
        {
            string root = ProjectHelpers.GetRootFolder();

            if (File.Exists(root))
            {
                return(Path.GetDirectoryName(root));
            }

            return(root);
        }
        private IEnumerable <string> GetFiles()
        {
            string[] files = Directory.GetFiles(ProjectHelpers.GetRootFolder(), "*.css", SearchOption.AllDirectories);

            foreach (string file in files)
            {
                if (!file.Contains(".min.") && !file.Contains(".bundle."))
                {
                    yield return(file);
                }
            }
        }
        public static void RunOnAllFilesInProject()
        {
            string dir = ProjectHelpers.GetRootFolder();

            if (dir != null && Directory.Exists(dir))
            {
                foreach (string file in Directory.GetFiles(dir, "*.js", SearchOption.AllDirectories))
                {
                    JsHintRunner runner = new JsHintRunner(file);
                    runner.RunCompiler();
                }
            }
        }
Beispiel #8
0
        public static Task RunOnAllFilesInProjectAsync(IEnumerable <string> extensionsPattern, Func <string, LintReporter> runnerFactory)
        {
            string dir = ProjectHelpers.GetRootFolder();

            if (dir == null || !Directory.Exists(dir))
            {
                return(Task.FromResult(true));
            }

            return(Task.WhenAll(
                       extensionsPattern.SelectMany(x => Directory.EnumerateFiles(dir, x, SearchOption.AllDirectories))
                       .Where(f => ProjectHelpers.GetProjectItem(f) != null)
                       .Select(f => runnerFactory(f).RunLinterAsync().HandleErrors("linting " + f))));
        }
Beispiel #9
0
        public async Task <XDocument> WriteBundleRecipe()
        {
            string root = ProjectHelpers.GetRootFolder();

            if (string.IsNullOrEmpty(root))
            {
                root = ProjectHelpers.GetProjectFolder(FileName);
            }

            XmlWriterSettings settings = new XmlWriterSettings()
            {
                Indent = true
            };
            XNamespace xsi = "http://www.w3.org/2001/XMLSchema-instance";

            ProjectHelpers.CheckOutFileFromSourceControl(FileName);

            using (XmlWriter writer = await Task.Run(() => XmlWriter.Create(FileName, settings)))
            {
                XDocument doc = new XDocument(
                    new XElement("bundle",
                                 new XAttribute(XNamespace.Xmlns + "xsi", xsi),
                                 new XAttribute(xsi + "noNamespaceSchemaLocation", "http://vswebessentials.com/schemas/v1/bundle.xsd"),
                                 new XElement("settings",
                                              new XComment("Determines if the bundle file should be automatically optimized after creation/update."),
                                              new XElement("minify", Minified.ToString().ToLowerInvariant()),
                                              new XComment("Determine whether to generate/re-generate this bundle on building the solution."),
                                              new XElement("runOnBuild", RunOnBuild.ToString().ToLowerInvariant()),
                                              new XComment("Specifies a custom subfolder to save files to. By default, compiled output will be placed in the same folder and nested under the original file."),
                                              new XElement("outputDirectory", OutputDirectory)
                                              ),
                                 new XComment("The order of the <file> elements determines the order of the files in the bundle."),
                                 new XElement("files", BundleAssets.Select(file => new XElement("file", GetRelativePath(file, root))))
                                 )
                    );

                if (isCss)
                {
                    doc.Descendants("runOnBuild").FirstOrDefault().AddAfterSelf(
                        new XComment("Use absolute path in the generated CSS files. By default, the URLs are relative to generated bundled CSS file."),
                        new XElement("adjustRelativePaths", AdjustRelativePaths.ToString().ToLowerInvariant())
                        );
                }

                doc.Save(writer);

                return(doc);
            }
        }
Beispiel #10
0
 public static void UpdateBundles(string changedFile, bool isBuild)
 {
     if (!string.IsNullOrEmpty(changedFile))
     {
         UpdateBundle(changedFile, isBuild);
         return;
     }
     foreach (Project project in ProjectHelpers.GetAllProjects())
     {
         if (project.ProjectItems.Count > 0)
         {
             string folder = ProjectHelpers.GetRootFolder(project);
             UpdateBundle(folder, isBuild);
         }
     }
 }
Beispiel #11
0
        public DragDropPointerEffects HandleDataDropped(DragDropInfo dragDropInfo)
        {
            string reference = FileHelpers.RelativePath(ProjectHelpers.GetRootFolder(), _draggedFilename);

            if (reference.StartsWith("http://localhost:", StringComparison.OrdinalIgnoreCase))
            {
                int index = reference.IndexOf('/', 20);
                if (index > -1)
                {
                    reference = reference.Substring(index + 1).ToLowerInvariant();
                }
            }

            _view.TextBuffer.Insert(dragDropInfo.VirtualBufferPosition.Position.Position, string.Format(_format, reference));

            return(DragDropPointerEffects.Copy);
        }
        public async static Threading.Task UpdateBundles(string changedFile, bool isBuild)
        {
            if (!string.IsNullOrEmpty(changedFile))
            {
                await UpdateBundle(changedFile, isBuild);

                return;
            }

            foreach (Project project in ProjectHelpers.GetAllProjects())
            {
                if (project.ProjectItems.Count == 0)
                {
                    continue;
                }

                string folder = ProjectHelpers.GetRootFolder(project);
                await UpdateBundle(folder, isBuild);
            }
        }
        public static string ToAbsoluteFilePath(string relativeUrl, string rootFolder = null)
        {
            string imageUrl = relativeUrl.Trim(new[] { '\'', '"' });
            string filePath = string.Empty;

            if (imageUrl.StartsWith("/", StringComparison.Ordinal))
            {
                string root = rootFolder ?? ProjectHelpers.GetRootFolder();

                if (root.Contains("://"))
                {
                    filePath = root + imageUrl;
                }
                else if (!string.IsNullOrEmpty(root))
                {
                    if (!Directory.Exists(root))
                    {
                        filePath = new FileInfo(root).Directory + imageUrl;
                    }
                    else
                    {
                        return(root + imageUrl.Replace("/", "\\"));
                    }
                }
            }
            else
            {
                FileInfo      fi  = new FileInfo(EditorExtensionsPackage.DTE.ActiveDocument.FullName);
                DirectoryInfo dir = fi.Directory;

                while (imageUrl.Contains("../"))
                {
                    imageUrl = imageUrl.Remove(imageUrl.IndexOf("../", StringComparison.Ordinal), 3);
                    dir      = dir.Parent;
                }

                filePath = Path.Combine(dir.FullName, imageUrl.Replace("/", "\\"));
            }

            return(filePath);
        }
        public void Save()
        {
            XmlWriterSettings settings = new XmlWriterSettings()
            {
                Indent = true
            };

            using (XmlWriter writer = XmlWriter.Create(FileName, settings))
            {
                writer.WriteStartElement("sprite");
                writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
                writer.WriteAttributeString("xsi", "noNamespaceSchemaLocation", null, "http://vswebessentials.com/schemas/v1/sprite.xsd");

                // Settings
                writer.WriteStartElement("settings");
                writer.WriteComment("Determines if the sprite image should be automatically optimized after creation/update");
                writer.WriteElementString("optimize", Optimize ? "true" : "false");
                writer.WriteElementString("orientation", IsVertical ? "vertical" : "horizontal");
                writer.WriteElementString("outputType", FileExtension.ToString().ToLowerInvariant());
                writer.WriteEndElement(); // </settings>

                // Files
                writer.WriteComment("The order of the <file> elements determines the order of the images in the sprite.");
                writer.WriteStartElement("files");

                string root = ProjectHelpers.GetRootFolder();

                foreach (string file in ImageFiles)
                {
                    string relative = "/" + FileHelpers.RelativePath(root, file);
                    writer.WriteElementString("file", relative);
                }

                writer.WriteEndElement(); // </files>
                writer.WriteEndElement(); // </sprite>
            }
        }
        private void UpdateTextBuffer(string fileName)
        {
            int    position = TextView.Caret.Position.BufferPosition.Position;
            string relative = FileHelpers.RelativePath(ProjectHelpers.GetRootFolder() ?? "/", fileName);
            string text     = string.Format(CultureInfo.InvariantCulture, _format, relative);

            using (EditorExtensionsPackage.UndoContext("Insert Image"))
            {
                TextView.TextBuffer.Insert(position, text);

                try
                {
                    SnapshotSpan span = new SnapshotSpan(TextView.TextBuffer.CurrentSnapshot, position, _format.Length);
                    TextView.Selection.Select(span, false);

                    EditorExtensionsPackage.ExecuteCommand("Edit.FormatSelection");
                    TextView.Selection.Clear();
                }
                catch
                {
                    // Try to format the selection. Some editors handle this differently, so try/catch
                }
            }
        }