Пример #1
0
        /// <summary>
        /// Applies patch to npm package.
        /// </summary>
        private void ApplyPatch()
        {
            foreach (KeyValuePair <string, string> pair in PatchMap)
            {
                FileInfo src  = new FileInfo(string.Format("{0}{1}patch\\{2}", ProjectPath, PackageName, pair.Key));
                FileInfo dest = new FileInfo(string.Format("{0}{1}", ProjectPath, pair.Value));

                if (!File.Exists(src.FullName))
                {
                    NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Error. {0} does not exist",
                                                         src.FullName), NpmOutputPane);
                    continue;
                }

                try
                {
                    if (!Directory.Exists(dest.DirectoryName))
                    {
                        Directory.CreateDirectory(dest.DirectoryName);
                    }
                    NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Copying {0} to {1}",
                                                         src.FullName, dest.FullName), NpmOutputPane);
                    File.Copy(src.FullName, dest.FullName, true);
                }
                catch (Exception ex)
                {
                    NpmHandler.PrintOutput(ex.Message, NpmOutputPane);
                }
            }
            NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "{0} UWP patch applied!",
                                                 PackageName), NpmOutputPane);
        }
Пример #2
0
        protected override int QueryStatusCommand(uint itemid, ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            // If we detect an npm update command from the base project (NTVS), we will:
            // 1. Run "npm dedupe" to reduce chances of deploying packages with
            //    paths that are too long.
            // 2. Patch native addons with UWP versions of the addons if they exist.
            // For #2, eventually a better solution may be to have npm and the base project
            // handle this. i.e. get to the point where "npm install serialport --winplat=uwp"
            // is supported.
            // For now this solution works well since we do not need to modify the base project.

            if (pguidCmdGroup == GuidList.NodejsNpmCmdSet &&
                prgCmds[0].cmdID == 0x302) // 0x302 is the value of cmdidNpmUpdateModules in https://github.com/Microsoft/nodejstools/blob/master/Nodejs/Product/Nodejs/PkgCmdId.cs
            {
                EnvDTE.DTE dte   = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));
                Array      projs = (Array)dte.ActiveSolutionProjects;
                if (projs.Length > 0)
                {
                    EnvDTE.Project activeProj  = (EnvDTE.Project)projs.GetValue(0);
                    string         projectPath = activeProj.FullName.Substring(0, activeProj.FullName.LastIndexOf('\\'));
                    NpmHandler     npmHandler  = new NpmHandler();

                    // Run npm dedupe
                    npmHandler.RunNpmDedupe(projectPath);

                    // Patch packages
                    npmHandler.UpdateNpmPackages(projectPath);
                }
            }

            return(base.QueryStatusCommand(itemid, ref pguidCmdGroup, cCmds, prgCmds, pCmdText));
        }
Пример #3
0
        /// <summary>
        /// Initiates patch download.
        /// </summary>
        private void DownloadPatch()
        {
            WebClient client = new WebClient();

            ZipFilePath = string.Format(CultureInfo.CurrentCulture, "{0}{1}{2}", ProjectPath, PackageName, "patch.zip");

            NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Downloading {0} UWP patch from {1}",
                                                 PackageName, PatchUri.ToString()), NpmOutputPane);
            client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadPatchCompleted);
            client.DownloadFileAsync(PatchUri, ZipFilePath);
        }
Пример #4
0
        /// <summary>
        /// Extracts and applies patch after download completes.
        /// </summary>
        private void DownloadPatchCompleted(object sender, AsyncCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Download failed: {0}",
                                                     e.Error.Message), NpmOutputPane);
                return;
            }

            NpmHandler.PrintOutput("Download complete.", NpmOutputPane);
            ExtractPatch();
            ApplyPatch();
        }
Пример #5
0
        /// <summary>
        /// Extracts patch zip file.
        /// </summary>
        private void ExtractPatch()
        {
            NpmHandler.PrintOutput(string.Format(CultureInfo.CurrentCulture, "Extracting {0} UWP patch.",
                                                 PackageName), NpmOutputPane);

            string ZipFileExtractPath = string.Format(CultureInfo.CurrentCulture, "{0}{1}patch", ProjectPath, PackageName);

            try
            {
                // Clean existing extracted path
                if (Directory.Exists(ZipFileExtractPath))
                {
                    Directory.Delete(ZipFileExtractPath, true);
                }
                ZipFile.ExtractToDirectory(ZipFilePath, ZipFileExtractPath);
            }
            catch (Exception ex)
            {
                NpmHandler.PrintOutput(ex.Message, NpmOutputPane);
                return;
            }
            NpmHandler.PrintOutput("Extraction complete.", NpmOutputPane);
        }
Пример #6
0
        protected override int QueryStatusCommand(uint itemid, ref Guid pguidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
        {
            // If we detect an npm update command from the base project (NTVS), we will:
            // 1. Run "npm dedupe" to reduce chances of deploying packages with
            //    paths that are too long.
            // 2. Patch native addons with UWP versions of the addons if they exist.
            // For #2, eventually a better solution may be to have npm and the base project
            // handle this. i.e. get to the point where "npm install serialport --winplat=uwp"
            // is supported.
            // For now this solution works well since we do not need to modify the base project.

            if (pguidCmdGroup == GuidList.NodejsNpmCmdSet &&
                prgCmds[0].cmdID == 0x302) // 0x302 is the value of cmdidNpmUpdateModules in https://github.com/Microsoft/nodejstools/blob/master/Nodejs/Product/Nodejs/PkgCmdId.cs
            {
                EnvDTE.DTE dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE));
                Array projs = (Array)dte.ActiveSolutionProjects;
                if (projs.Length > 0)
                {
                    EnvDTE.Project activeProj = (EnvDTE.Project)projs.GetValue(0);
                    string projectPath = activeProj.FullName.Substring(0, activeProj.FullName.LastIndexOf('\\'));
                    NpmHandler npmHandler = new NpmHandler();

                    // Run npm dedupe
                    npmHandler.RunNpmDedupe(projectPath);

                    // Patch packages
                    npmHandler.UpdateNpmPackages(projectPath, activeProj.ConfigurationManager.ActiveConfiguration.PlatformName);
                }
            }

            return base.QueryStatusCommand(itemid, ref pguidCmdGroup, cCmds, prgCmds, pCmdText);
        }