Exemplo n.º 1
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            _stillLoading = true;
            vs            = (DTE2) await GetServiceAsync(typeof(EnvDTE.DTE));

            var commandService = (await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService);

            commandService.AddCommand(new OleMenuCommand(OnCompileSassFileCommandInvoked, null, OnCompileSassFileCommandStatusQueried, new CommandID(Metadata.CmdSet.Guid, Metadata.CmdSet.CompileSassFileCommandId)));
            commandService.AddCommand(new OleMenuCommand(OnInstallNugetPackageCommandInvoked, new CommandID(Metadata.CmdSet.Guid, Metadata.CmdSet.InstallNugetPackageCommandId)));
            commandService.AddCommand(new MenuCommand(OnGotoSettingCommandInvoked, new CommandID(Metadata.CmdSet.Guid, Metadata.CmdSet.GotoSettingsCommandId)));

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            GetDialogPage(typeof(ConfigurationPage));
            var outputWindow = (IVsOutputWindow) await GetServiceAsync(typeof(SVsOutputWindow));

            if (outputWindow != null)
            {
                var guid = new Guid("455e712c-1c5a-43b9-8c70-7f8e9e0ec4f6");
                outputWindow.CreatePane(ref guid, Metadata.ProductName, 1, 1);
                outputWindow.GetPane(ref guid, out IVsOutputWindowPane pane);

                _fileWatcher = new SassWatcher(this, pane);

                await NodeJS.InstallAsync((message, counter, goal) =>
                {
                    progress?.Report(new ServiceProgressData(message, message, counter, goal));
                    System.Diagnostics.Debug.WriteLine(message);
                    pane.Writeline(message);

                    if (counter >= goal)
                    {
                        _stillLoading = false;
                        _fileWatcher.Start();
                        pane.OutputStringThreadSafe("\n\n");
                    }
                });
            }

            TryInitializeSolution();
            Microsoft.VisualStudio.Shell.Events.SolutionEvents.OnAfterOpenSolution += OnSolutionOpened;
        }
Exemplo n.º 2
0
        public static CompilerResult Compile(string sassFilePath, CompilerOptions options)
        {
            if (!File.Exists(sassFilePath))
            {
                throw new FileNotFoundException($"Could not find file at '{sassFilePath}'.");
            }

            string compiler = Path.Combine(NodeJS.InstallationDirectory, "compiler.js");

            if (!File.Exists(compiler))
            {
                throw new FileNotFoundException($"Could not find file at '{compiler}'.");
            }

            if (!string.IsNullOrEmpty(options.OutputDirectory) && !Directory.Exists(options.OutputDirectory))
            {
                Directory.CreateDirectory(options.OutputDirectory);
            }

            if (!string.IsNullOrEmpty(options.SourceMapDirectory) && !Directory.Exists(options.SourceMapDirectory))
            {
                Directory.CreateDirectory(options.SourceMapDirectory);
            }

            long start = System.DateTime.Now.Ticks;

            using (Process node = NodeJS.Execute($"/c node \"{compiler}\" \"{sassFilePath}\" {options.ToArgs()}"))
            {
                return(new CompilerResult
                {
                    SourceFile = sassFilePath,
                    Success = (node.ExitCode == 0),
                    Errors = GetErrors(node.StandardError).ToArray(),
                    GeneratedFiles = GetGeneratedFiles(node.StandardOutput).ToArray(),
                    Elapse = System.TimeSpan.FromTicks(System.DateTime.Now.Ticks - start)
                });
            }
        }