///<summary>Checks whether a file should never be compiled to disk, based on filename conventions.</summary> public static bool ShouldCompile(string sourcePath) { if (Path.GetFileName(sourcePath).StartsWith("_", StringComparison.OrdinalIgnoreCase)) { return(false); } ProjectItem item = ProjectHelpers.GetProjectItem(sourcePath); if (item != null) { try { // Ignore files nested under other files such as bundle or TypeScript output ProjectItem parent = item.Collection.Parent as ProjectItem; if (parent != null && parent.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile && parent.FileNames[0].EndsWith(".sprite", StringComparison.OrdinalIgnoreCase)) { return(false); } } catch (InvalidOperationException) { } } var parentExtension = Path.GetExtension(Path.GetFileNameWithoutExtension(sourcePath)); return(!_disallowedParentExtensions.Contains(parentExtension)); }
public static bool ShouldIgnore(string file) { if (NotJsOrMinifiedOrDocumentOrNotExists(file)) { return(true); } ProjectItem item = ProjectHelpers.GetProjectItem(file); if (item != null) { try { // Ignore files nested under other files such as bundle or TypeScript output ProjectItem parent = item.Collection.Parent as ProjectItem; if (parent != null && !Directory.Exists(parent.FileNames[1]) || File.Exists(item.FileNames[1] + ".bundle")) { return(true); } } catch { // Some project types such as node.js doesn't have correct implementations of item.Collection and will throw. } } string name = Path.GetFileName(file); return(_builtInIgnoreRegex.IsMatch(name)); }
public void VsTextViewCreated(IVsTextView textViewAdapter) { var textView = EditorAdaptersFactoryService.GetWpfTextView(textViewAdapter); textView.Properties.GetOrCreateSingletonProperty(() => new MinifySelection(textViewAdapter, textView)); textView.Properties.GetOrCreateSingletonProperty(() => new JavaScriptFindReferences(textViewAdapter, textView, Navigator)); textView.Properties.GetOrCreateSingletonProperty(() => new CssExtractToFile(textViewAdapter, textView)); textView.Properties.GetOrCreateSingletonProperty(() => new NodeModuleGoToDefinition(textViewAdapter, textView)); textView.Properties.GetOrCreateSingletonProperty(() => new ReferenceTagGoToDefinition(textViewAdapter, textView)); textView.Properties.GetOrCreateSingletonProperty(() => new CommentCompletionCommandTarget(textViewAdapter, textView, AggregatorService)); textView.Properties.GetOrCreateSingletonProperty(() => new CommentIndentationCommandTarget(textViewAdapter, textView, AggregatorService, CompletionBroker)); ITextDocument document; if (TextDocumentFactoryService.TryGetTextDocument(textView.TextDataModel.DocumentBuffer, out document)) { if (ProjectHelpers.GetProjectItem(document.FilePath) == null) { return; } var jsHintLintInvoker = new LintFileInvoker(f => new JavaScriptLintReporter(new JsHintCompiler(), f), document); textView.Closed += (s, e) => jsHintLintInvoker.Dispose(); textView.TextBuffer.Properties.GetOrCreateSingletonProperty(() => jsHintLintInvoker); var jsCodeStyleLintInvoker = new LintFileInvoker(f => new JavaScriptLintReporter(new JsCodeStyleCompiler(), f), document); textView.Closed += (s, e) => jsCodeStyleLintInvoker.Dispose(); textView.TextBuffer.Properties.GetOrCreateSingletonProperty(() => jsCodeStyleLintInvoker); } }
public static async Task UpdateAllSpritesAsync(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; } SpriteImageMenu menu = new SpriteImageMenu(); foreach (string file in Directory.EnumerateFiles(folder, "*.sprite", SearchOption.AllDirectories)) { if (ProjectHelpers.GetProjectItem(file) == null) { continue; } await menu.UpdateSpriteAsync(file, isBuild); } } }
public Task CompileFilesAsync(IContentType contentType, IEnumerable <string> paths) { var exts = FileExtensionRegistry.GetFileExtensionSet(contentType); var runner = Mef.GetImport <ICompilerRunnerProvider>(contentType).GetCompiler(contentType); return(Task.WhenAll( paths.Where(f => exts.Contains(Path.GetExtension(f))) .AsParallel() .Select(fileName => { string targetPath = runner.GetTargetPath(fileName); if (File.Exists(targetPath) || ProjectHelpers.GetProjectItem(targetPath) != null) { return runner.CompileAsync(fileName, targetPath).HandleErrors("compiling" + fileName); } else { return Task.FromResult <CompilerResult>(null); } }) )); }
private async Task GenerateAsync(SpriteDocument sprite, bool hasUpdated = false) { _dte.StatusBar.Text = "Generating sprite..."; if (ProjectHelpers.GetProjectItem(sprite.FileName) == null) { ProjectHelpers.AddFileToActiveProject(sprite.FileName); } string imageFile = Path.ChangeExtension(sprite.FileName, sprite.FileExtension); if (string.IsNullOrEmpty(sprite.OutputDirectory)) { imageFile = ProjectHelpers.GetAbsolutePathFromSettings(sprite.OutputDirectory, Path.ChangeExtension(sprite.FileName, sprite.FileExtension)); } ProjectHelpers.CreateDirectoryInProject(imageFile); IEnumerable <SpriteFragment> fragments = await SpriteGenerator.MakeImage(sprite, imageFile, UpdateSpriteAsync); ProjectHelpers.AddFileToProject(sprite.FileName, imageFile); if (!hasUpdated) { WebEssentialsPackage.DTE.ItemOperations.OpenFile(sprite.FileName); } await Export(fragments, imageFile, sprite); if (sprite.Optimize) { await new ImageCompressor().CompressFilesAsync(imageFile); } _dte.StatusBar.Text = "Sprite generated"; }