Exemple #1
0
        // Builds the given project/sln for the given platforms and copies the output & package file to the output directory
        public static void BuildAndCopyToOutputFolder(string slnPath, VsVersions vsVersion, string outDir, Platforms plats)
        {
            if ((plats & Platforms.x64) != 0)
            {
                BuildSln(slnPath, vsVersion, Platforms.x64);
            }

            if ((plats & Platforms.Win32) != 0)
            {
                BuildSln(slnPath, vsVersion, Platforms.Win32);
            }

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }

            string packageDir = Path.GetDirectoryName(slnPath);

            CopyFile("package.json", packageDir, outDir);
            CopyFile("README.md", packageDir, outDir);
            CopyFile(".npmignore", packageDir, outDir);
            CopyDir("bin", packageDir, outDir);
            CopyDir("lib", packageDir, outDir);
        }
        private static string CreateBuildCmd(string moduleDirectory, VsVersions vsVersion)
        {
            string versionString;

            switch (vsVersion)
            {
            case VsVersions.Vs2012:
                versionString = "2012";
                break;

            case VsVersions.Vs2013:
                versionString = "2013";
                break;

            case VsVersions.Vs2015:
                versionString = "2015";
                break;

            case VsVersions.Vs2017:
                versionString = "2017";
                break;

            case VsVersions.Vs2019:
                versionString = "2019";
                break;

            default:
                throw new Exception("Unknown VS Version");
            }
            return(String.Format(NODE_GYP_CMD_TEMPLATE, moduleDirectory, versionString));
        }
        private static void BuildModule(string moduleDirectory, VsVersions vsVersion, bool verbose)
        {
            string cmd = CreateBuildCmd(moduleDirectory, vsVersion);
            bool result = ExecuteCommand(cmd, verbose);

            if (!result)
                throw new Exception("Failed to build project");
        }
        private static void BuildModule(string moduleDirectory, VsVersions vsVersion, bool verbose)
        {
            string cmd    = CreateBuildCmd(moduleDirectory, vsVersion);
            bool   result = ExecuteCommand(cmd, verbose);

            if (!result)
            {
                throw new Exception("Failed to build project");
            }
        }
        private static string CreateBuildCmd(string moduleDirectory, VsVersions vsVersion)
        {
            string versionString;

            if (vsVersion == VsVersions.Vs2012)
                versionString = "2012";
            else
                versionString = "2013";

            return String.Format(NODE_GYP_CMD_TEMPLATE, moduleDirectory, versionString);
        }
Exemple #6
0
        private static void BuildSln(string slnPath, VsVersions vsVersion, Platforms platform)
        {
            string cmd = CreateBuildCmd(slnPath, vsVersion, platform);

            bool result = ExecuteCommand(cmd);

            if (!result)
            {
                throw new Exception("Failed to build project");
            }
        }
Exemple #7
0
 private static string CreateBuildCmd(string slnPath, VsVersions vsVersion, Platforms platform)
 {
     if (vsVersion == VsVersions.Vs2012)
     {
         return(String.Format(MSBUILD_CMD_TEMPLATE, VS_2012_CMD, slnPath, platform.ToString()));
     }
     else
     {
         return(String.Format(MSBUILD_CMD_TEMPLATE, VS_2013_CMD, slnPath, platform.ToString()));
     }
 }
        private string VsVersionToString(VsVersions vsVersion)
        {
            switch (vsVersion)
            {
            case VsVersions.Vs2012:
                return("2012");

            case VsVersions.Vs2013:
                return("2013");

            default:
                return("2015");
            }
        }
Exemple #9
0
        static bool GenerateAndBuildNamespace(string ns, 
            VsVersions vsVersion, WinVersions winVersion,string winmd,
            string npmPackageVersion, string npmScope, string outDir, bool noDefGen, bool noBuild, bool verbose)
        {
            string moduleOutDir = Path.Combine(outDir, ns.ToLower());

            if (!Directory.Exists(moduleOutDir))
            {
                Directory.CreateDirectory(moduleOutDir);
            }

            var generator = new NodeRTProjectGenerator(winVersion, vsVersion, !noDefGen);

            Console.WriteLine("Generating code for: {0}...", ns);

            try
            {
                Reflector.GenerateProject(winmd, ns, moduleOutDir, generator, npmPackageVersion, npmScope, null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to generate code, error: {0}", e.Message);
                return false;
            }

            if (!noBuild)
            {
                Console.WriteLine("Building {0}...", ns);

                try
                {
                    NodeRTProjectBuildUtils.BuildWithNodeGyp(moduleOutDir, vsVersion, verbose);
                }
                catch (IOException e)
                {
                    Console.WriteLine("IO Error occured after building the project, error: {0}", e.Message);
                    Console.WriteLine("Generated project files are located at: {0}", moduleOutDir);
                    return false;
                }
                catch (Exception)
                {
                    Console.WriteLine("Failed to build the generated project, please try to build the project manually");
                    Console.WriteLine("Generated project files are located at: {0}", moduleOutDir);
                    return false;
                }
                Console.WriteLine("NodeRT module generated and built successfully at: {0}", moduleOutDir);
            }
            return true;
        }
Exemple #10
0
        static bool GenerateAndBuildNamespace(string ns,
                                              VsVersions vsVersion, WinVersions winVersion, string winmd,
                                              string npmPackageVersion, string npmScope, string outDir, bool noDefGen, bool noBuild, bool verbose)
        {
            string moduleOutDir = Path.Combine(outDir, ns.ToLower());

            if (!Directory.Exists(moduleOutDir))
            {
                Directory.CreateDirectory(moduleOutDir);
            }

            var generator = new NodeRTProjectGenerator(winVersion, vsVersion, !noDefGen);

            Console.WriteLine("Generating code for: {0}...", ns);

            try
            {
                Reflector.GenerateProject(winmd, ns, moduleOutDir, generator, npmPackageVersion, npmScope, null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to generate code, error: {0}", e.Message);
                return(false);
            }

            if (!noBuild)
            {
                Console.WriteLine("Building {0}...", ns);

                try
                {
                    NodeRTProjectBuildUtils.BuildWithNodeGyp(moduleOutDir, vsVersion, verbose);
                }
                catch (IOException e)
                {
                    Console.WriteLine("IO Error occured after building the project, error: {0}", e.Message);
                    Console.WriteLine("Generated project files are located at: {0}", moduleOutDir);
                    return(false);
                }
                catch (Exception)
                {
                    Console.WriteLine("Failed to build the generated project, please try to build the project manually");
                    Console.WriteLine("Generated project files are located at: {0}", moduleOutDir);
                    return(false);
                }
                Console.WriteLine("NodeRT module generated and built successfully at: {0}", moduleOutDir);
            }
            return(true);
        }
        public static bool VerifyVsAndWinVersions(WinVersions winVersion, VsVersions vsVersion, out string errorMessage)
        {
            errorMessage = null;

            if (vsVersion == VsVersions.Vs2013 && winVersion == WinVersions.v10)
            {
                errorMessage = "VS 2013 does not support building Windows 10 modules";
                return false;
            }

            if (vsVersion == VsVersions.Vs2012 && (winVersion == WinVersions.v8_1 || winVersion == WinVersions.v10))
            {
                errorMessage = "VS 2012 only supports building Windows 8 modules";
                return false;
            }

            return true;
        }
        public static bool VerifyVsAndWinVersions(WinVersions winVersion, VsVersions vsVersion, out string errorMessage)
        {
            errorMessage = null;

            if (vsVersion == VsVersions.Vs2013 && winVersion == WinVersions.v10)
            {
                errorMessage = "VS 2013 does not support building Windows 10 modules";
                return(false);
            }

            if (vsVersion == VsVersions.Vs2012 && (winVersion == WinVersions.v8_1 || winVersion == WinVersions.v10))
            {
                errorMessage = "VS 2012 only supports building Windows 8 modules";
                return(false);
            }

            return(true);
        }
        // Builds the given project/sln for the given platforms and copies the output & package file to the output directory
        public static void BuildAndCopyToOutputFolder(string slnPath, VsVersions vsVersion, string outDir, Platforms plats)
        {
            if ((plats & Platforms.x64) != 0)
                BuildSln(slnPath, vsVersion, Platforms.x64);

            if ((plats & Platforms.Win32) != 0)
                BuildSln(slnPath, vsVersion, Platforms.Win32);

            if (!Directory.Exists(outDir))
                Directory.CreateDirectory(outDir);

            string packageDir = Path.GetDirectoryName(slnPath);

            CopyFile("package.json", packageDir, outDir);
            CopyFile("README.md", packageDir, outDir);
            CopyFile(".npmignore", packageDir, outDir);
            CopyDir("bin", packageDir, outDir);
            CopyDir("lib", packageDir, outDir);
        }
        private static string CreateBuildCmd(string moduleDirectory, VsVersions vsVersion)
        {
            string versionString;

            switch (vsVersion)
            {
                case VsVersions.Vs2012:
                    versionString = "2012";
                    break;
                case VsVersions.Vs2013:
                    versionString = "2013";
                    break;
                case VsVersions.Vs2015:
                    versionString = "2015";
                    break;
                default:
                    throw new Exception("Unknown VS Version");
            }
            return String.Format(NODE_GYP_CMD_TEMPLATE, moduleDirectory, versionString);
        }
Exemple #15
0
        private void cmdGenerate_Click(object sender, EventArgs e)
        {
            // in case we have a single item just select it
            if (namespaceList.Items.Count == 1)
            {
                namespaceList.SelectedItem = namespaceList.Items[0];
            }

            if ((namespaceList.SelectedItem == null) || string.IsNullOrEmpty(txtFilename.Text))
            {
                MessageBox.Show("Please select a namespace to generate", "No namespace was chosen");
                return;
            }

            btnGenerate.Enabled = false;

            var         winMdFile      = txtFilename.Text;
            var         winRTNamespace = namespaceList.SelectedItem.ToString();
            VsVersions  vsVersion      = (VsVersions)cmbVsVersion.SelectedIndex;
            WinVersions winVersion     = (WinVersions)cmbWindowsVersion.SelectedIndex;
            string      outputFolder   = Path.Combine(txtOutputDirectory.Text, winRTNamespace.ToLower());

            string errorMessage;

            if (!NodeRTProjectGenerator.VerifyVsAndWinVersions(winVersion, vsVersion, out errorMessage))
            {
                MessageBox.Show("Unsupported Windows and VS combination:\n" + errorMessage, "Unsupported options", MessageBoxButtons.OK, MessageBoxIcon.Error);
                btnGenerate.Enabled = true;
                return;
            }

            var  generator   = new NodeRTProjectGenerator(winVersion, vsVersion, chkDefGen.Checked);
            bool buildModule = chkBuildModule.Checked;

            btnGenerate.Text = "Generating code...";
            bool succeeded = false;

            Task.Run(() =>
            {
                string modulePath;
                try
                {
                    modulePath = Reflector.GenerateProject(winMdFile, winRTNamespace, outputFolder,
                                                           generator, null, null, null);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to generate project file\n" + ex.Message,
                                    "Failed to generate project file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw ex;
                }

                MethodInvoker invoker = new MethodInvoker(delegate() { btnGenerate.Text = "Building..."; });
                btnGenerate.Invoke(invoker);

                if (buildModule)
                {
                    try
                    {
                        NodeRTProjectBuildUtils.BuildWithNodeGyp(modulePath, vsVersion);
                        succeeded = true;
                    }
                    catch (IOException ex)
                    {
                        MessageBox.Show("IO Error occured after building the project:\n" +
                                        ex.Message + "\n" +
                                        "You can access the project files at: " + outputFolder, "IO Error occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Failed to build the project from generated code.\n" +
                                        "Please try to build the project manually.\n" +
                                        "You can access the project files at: " + outputFolder, "Failed to build project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    succeeded = true;
                }
            })
            .ContinueWith((t) =>
            {
                btnGenerate.Enabled = true;
                if (chkBuildModule.Checked)
                {
                    btnGenerate.Text = "Generate and build module";
                }
                else
                {
                    btnGenerate.Text = "Generate module";
                }

                if (succeeded)
                {
                    MessageBox.Show("Yay! The generated NodeRT module is located at:\n" + outputFolder, "Success");
                }
            },
                          TaskScheduler.FromCurrentSynchronizationContext());
        }
 public NodeRTProjectGenerator(WinVersions winVersion, VsVersions vsVersion, bool isGenerateDef)
 {
     _winVersion = winVersion;
     _vsVersion = vsVersion;
     _isGenerateDef = isGenerateDef;
 }
Exemple #17
0
 // Builds the given project/sln for the given platforms and copies the output & package file to the output directory
 public static void BuildWithNodeGyp(string moduleDirectory, VsVersions vsVersion)
 {
     BuildModule(moduleDirectory, vsVersion);
 }
Exemple #18
0
        private void cmdGenerate_Click(object sender, EventArgs e)
        {
            // in case we have a single item just select it
            if (namespaceList.Items.Count == 1)
            {
                namespaceList.SelectedItem = namespaceList.Items[0];
            }

            if ((namespaceList.SelectedItem == null) || string.IsNullOrEmpty(txtFilename.Text))
            {
                MessageBox.Show("Please select a namespace to generate", "No namespace was chosen");
                return;
            }

            btnGenerate.Enabled = false;

            var        winMdFile      = txtFilename.Text;
            var        winRTNamespace = namespaceList.SelectedItem.ToString();
            VsVersions vsVersion      = (VsVersions)cmbTargetVs.SelectedIndex;

            NodeRTProjectBuildUtils.Platforms platforms = NodeRTProjectBuildUtils.Platforms.Win32;
            if (NodeRTProjectBuildUtils.IsRunningOn64Bit)
            {
                platforms |= NodeRTProjectBuildUtils.Platforms.x64;
            }

            string codeGenerationFolder = Path.Combine(txtProjectGenerationDirectory.Text, winRTNamespace.ToLower());
            string outputFolder         = Path.Combine(txtOutputDirectory.Text, winRTNamespace.ToLower());

            var generator = new NodeRTProjectGenerator(txtProjectConfigurationRoot.Text, vsVersion);

            btnGenerate.Text = "Generating code...";
            bool succeeded = false;

            Task.Run(() =>
            {
                string slnPath;
                try
                {
                    slnPath = Reflector.GenerateProject(winMdFile, winRTNamespace, codeGenerationFolder,
                                                        generator, null);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed to generate project file\n" + ex.Message,
                                    "Failed to generate project file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    throw ex;
                }

                MethodInvoker invoker = new MethodInvoker(delegate() { btnGenerate.Text = "Building..."; });
                btnGenerate.Invoke(invoker);

                try
                {
                    NodeRTProjectBuildUtils.BuildAndCopyToOutputFolder(slnPath, vsVersion, outputFolder, platforms);
                    succeeded = true;
                }
                catch (IOException ex)
                {
                    MessageBox.Show("IO Error occured after building the project:\n" +
                                    ex.Message + "\n" +
                                    "You can access the project files at: " + codeGenerationFolder, "IO Error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                catch (Exception)
                {
                    MessageBox.Show("Failed to build the project from genreated code.\n" +
                                    "Please try to build the project manually.\n" +
                                    "You can access the project files at: " + codeGenerationFolder, "Failed to build project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            })
            .ContinueWith((t) =>
            {
                btnGenerate.Enabled = true;
                btnGenerate.Text    = "Generate and Build";

                if (succeeded)
                {
                    MessageBox.Show("Yay! The generated NodeRT module is located at:\n" + outputFolder, "Success");
                }
            },
                          TaskScheduler.FromCurrentSynchronizationContext());
        }
 private static string CreateBuildCmd(string slnPath, VsVersions vsVersion, Platforms platform)
 {
     if (vsVersion == VsVersions.Vs2012)
     {
         return String.Format(MSBUILD_CMD_TEMPLATE, VS_2012_CMD, slnPath, platform.ToString());
     }
     else
     {
         return String.Format(MSBUILD_CMD_TEMPLATE, VS_2013_CMD, slnPath, platform.ToString());
     }
 }
Exemple #20
0
        static void Main(string[] args)
        {
            var argsDictionary = ParseCommandLineArgs(args);

            if (argsDictionary.ContainsKey("help"))
            {
                PrintHelp();
                return;
            }

            if (!ValidateArguments(argsDictionary))
            {
                PrintHelpAndExitWithError();
                return;
            }

            if (argsDictionary.ContainsKey("namespaces"))
            {
                PrintNamespaces(argsDictionary);
                return;
            }

            string winmd  = argsDictionary["winmd"];
            string outDir = argsDictionary["outdir"];

            bool noDefGen = argsDictionary.ContainsKey("nodefgen");
            bool noBuild  = argsDictionary.ContainsKey("nobuild");
            bool verbose  = argsDictionary.ContainsKey("verbose");

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }

            string ns             = ValueOrNull(argsDictionary, "namespace");
            string customWinMdDir = ValueOrNull(argsDictionary, "customwinmddir");

            VsVersions  vsVersion  = VsVersions.Vs2017;
            WinVersions winVersion = WinVersions.v10;

            if (argsDictionary.ContainsKey("vs"))
            {
                if (!Enum.TryParse <VsVersions>(argsDictionary["vs"], true, out vsVersion))
                {
                    Console.WriteLine("Unsupported VS version. Supported options are: VS2017, VS2015, VS2013, VS2012");
                    Environment.Exit(1);
                }
            }

            if (argsDictionary.ContainsKey("winver"))
            {
                if (!NodeRTProjectGenerator.TryParseWinVersion(argsDictionary["winver"], out winVersion))
                {
                    Console.WriteLine("Unssuported Windows version. Supported options are: 10, 8.1, 8");
                    Environment.Exit(1);
                }
            }

            string npmPackageVersion = null;

            if (argsDictionary.ContainsKey("npmversion"))
            {
                npmPackageVersion = argsDictionary["npmversion"];
            }

            string npmPackageScope = null;

            if (argsDictionary.ContainsKey("npmscope"))
            {
                npmPackageScope = argsDictionary["npmscope"];
            }

            String errorMessage = null;

            if (!NodeRTProjectGenerator.VerifyVsAndWinVersions(winVersion, vsVersion, out errorMessage))
            {
                Console.WriteLine("Unssuported Windows and VS versions combination.");
                Console.WriteLine(errorMessage);
                Environment.Exit(1);
            }

            // generate specific namespace
            if (!String.IsNullOrEmpty(ns))
            {
                GenerateAndBuildNamespace(ns, vsVersion, winVersion, winmd,
                                          npmPackageVersion, npmPackageScope,
                                          outDir, noDefGen, noBuild, verbose);
            }
            else // try to generate & build all namespaces in winmd file
            {
                List <String> failedList = new List <string>();
                Console.WriteLine("Started to generate and build all namespaces in given WinMD...\n");
                foreach (string winRtNamespace in Reflector.GetNamespaces(winmd, customWinMdDir))
                {
                    if (!GenerateAndBuildNamespace(winRtNamespace,
                                                   vsVersion, winVersion, winmd,
                                                   npmPackageVersion, npmPackageScope, outDir, noDefGen, noBuild, verbose))
                    {
                        failedList.Add(winRtNamespace);
                    }
                    Console.WriteLine();
                }

                if (failedList.Count > 0)
                {
                    Console.WriteLine("Failed to generate or build for the following namespaces:");
                    foreach (string winRtNamespace in failedList)
                    {
                        Console.WriteLine("\t{0}", winRtNamespace);
                    }
                }
                else
                {
                    Console.WriteLine("Finished!");
                }
            }
        }
Exemple #21
0
        static bool GenerateAndBuildNamespace(string nodeSrcDir, string ns, 
            VsVersions vsVersion, string winmd, string outDir, string codeGenDir)
        {
            string moduleCodeGenDir = Path.Combine(codeGenDir, ns.ToLower());
            string moduleOutDir = Path.Combine(outDir, ns.ToLower());

            if (!Directory.Exists(moduleCodeGenDir))
            {
                Directory.CreateDirectory(moduleCodeGenDir);
            }

            if (!Directory.Exists(moduleOutDir))
            {
                Directory.CreateDirectory(moduleOutDir);
            }

            if (String.IsNullOrEmpty(nodeSrcDir))
            {
                nodeSrcDir = NodeRTProjectGenerator.DefaultDir;
            }

            if (String.IsNullOrEmpty(nodeSrcDir))
            {
                Console.WriteLine("Could not resolve node src dir, please specify a --nodesrcdir argument, as described below");
                PrintHelpAndExitWithError();
            }

            NodeRTProjectBuildUtils.Platforms platforms = NodeRTProjectBuildUtils.Platforms.Win32;

            if (NodeRTProjectBuildUtils.IsRunningOn64Bit)
                platforms |=  NodeRTProjectBuildUtils.Platforms.x64;

            var generator = new NodeRTProjectGenerator(nodeSrcDir, vsVersion);

            Console.WriteLine("Generating code for: {0}...", ns);

            string slnPath;
            try
            {
                slnPath = Reflector.GenerateProject(winmd, ns, moduleCodeGenDir, generator, null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to generate code, error: {0}", e.Message);
                return false;
            }

            Console.WriteLine("Building {0}...", ns);

            try
            {
                NodeRTProjectBuildUtils.BuildAndCopyToOutputFolder(slnPath, vsVersion, moduleOutDir, platforms);
            }
            catch (IOException e)
            {
                Console.WriteLine("IO Error occured after building the project, error: {0}", e.Message);
                Console.WriteLine("Generated project files are located at: {0}", moduleCodeGenDir);
                return false;
            }
            catch (Exception)
            {
                Console.WriteLine("Failed to build the generated project, please try to build the project manually");
                Console.WriteLine("Generated project files are located at: {0}", moduleCodeGenDir);
                return false;
            }
            Console.WriteLine("NodeRT module generated and built successfully at: {0}", moduleOutDir);
            return true;
        }
 public NodeRTProjectGenerator(VsVersions vsVersion, bool isGenerateDef)
 {
     _vsVersion     = vsVersion;
     _isGenerateDef = isGenerateDef;
 }
Exemple #23
0
 public NodeRTProjectGenerator(string sourceDir, VsVersions vsVersion)
 {
     _sourceDir = sourceDir.TrimEnd('\\');
     _vsVersion = vsVersion;
 }
 // Builds the given project/sln for the given platforms and copies the output & package file to the output directory
 public static void BuildWithNodeGyp(string moduleDirectory, VsVersions vsVersion, bool verbose = false)
 {
     BuildModule(moduleDirectory, vsVersion, verbose);
 }
 public NodeRTProjectGenerator(VsVersions vsVersion, bool isGenerateDef)
 {
     _vsVersion = vsVersion;
     _isGenerateDef = isGenerateDef;
 }
        private static void BuildSln(string slnPath, VsVersions vsVersion, Platforms platform)
        {
            string cmd = CreateBuildCmd(slnPath, vsVersion, platform);
            bool result = ExecuteCommand(cmd);

            if (!result)
                throw new Exception("Failed to build project");
        }
 public NodeRTProjectGenerator(string sourceDir, VsVersions vsVersion)
 {
     _sourceDir = sourceDir.TrimEnd('\\');
     _vsVersion = vsVersion;
 }
Exemple #28
0
        static bool GenerateAndBuildNamespace(string nodeSrcDir, string ns,
                                              VsVersions vsVersion, string winmd, string outDir, string codeGenDir)
        {
            string moduleCodeGenDir = Path.Combine(codeGenDir, ns.ToLower());
            string moduleOutDir     = Path.Combine(outDir, ns.ToLower());

            if (!Directory.Exists(moduleCodeGenDir))
            {
                Directory.CreateDirectory(moduleCodeGenDir);
            }

            if (!Directory.Exists(moduleOutDir))
            {
                Directory.CreateDirectory(moduleOutDir);
            }

            if (String.IsNullOrEmpty(nodeSrcDir))
            {
                nodeSrcDir = NodeRTProjectGenerator.DefaultDir;
            }

            if (String.IsNullOrEmpty(nodeSrcDir))
            {
                Console.WriteLine("Could not resolve node src dir, please specify a --nodesrcdir argument, as described below");
                PrintHelpAndExitWithError();
            }

            NodeRTProjectBuildUtils.Platforms platforms = NodeRTProjectBuildUtils.Platforms.Win32;

            if (NodeRTProjectBuildUtils.IsRunningOn64Bit)
            {
                platforms |= NodeRTProjectBuildUtils.Platforms.x64;
            }

            var generator = new NodeRTProjectGenerator(nodeSrcDir, vsVersion);

            Console.WriteLine("Generating code for: {0}...", ns);

            string slnPath;

            try
            {
                slnPath = Reflector.GenerateProject(winmd, ns, moduleCodeGenDir, generator, null);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to generate code, error: {0}", e.Message);
                return(false);
            }

            Console.WriteLine("Building {0}...", ns);

            try
            {
                NodeRTProjectBuildUtils.BuildAndCopyToOutputFolder(slnPath, vsVersion, moduleOutDir, platforms);
            }
            catch (IOException e)
            {
                Console.WriteLine("IO Error occured after building the project, error: {0}", e.Message);
                Console.WriteLine("Generated project files are located at: {0}", moduleCodeGenDir);
                return(false);
            }
            catch (Exception)
            {
                Console.WriteLine("Failed to build the generated project, please try to build the project manually");
                Console.WriteLine("Generated project files are located at: {0}", moduleCodeGenDir);
                return(false);
            }
            Console.WriteLine("NodeRT module generated and built successfully at: {0}", moduleOutDir);
            return(true);
        }
Exemple #29
0
        static void Main(string[] args)
        {
            var argsDictionary = ParseCommandLineArgs(args);

            if (argsDictionary.ContainsKey("help"))
            {
                PrintHelp();
                return;
            }

            if (!ValidateArguments(argsDictionary))
            {
                PrintHelpAndExitWithError();
                return;
            }

            if (argsDictionary.ContainsKey("namespaces"))
            {
                PrintNamespaces(argsDictionary);
                return;
            }

            string winmd      = argsDictionary["winmd"];
            string outDir     = argsDictionary["outdir"];
            string codeGenDir = argsDictionary["codegendir"];

            if (!Directory.Exists(codeGenDir))
            {
                Directory.CreateDirectory(codeGenDir);
            }

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }

            string ns             = ValueOrNull(argsDictionary, "namespace");
            string customWinMdDir = ValueOrNull(argsDictionary, "customwinmddir");

            VsVersions vsVersion = VsVersions.Vs2013;

            string nodeSrcDir = ValueOrNull(argsDictionary, "nodesrcdir");

            if (argsDictionary.ContainsKey("vs"))
            {
                Enum.TryParse <VsVersions>(argsDictionary["vs"], true, out vsVersion);
            }

            if (String.IsNullOrEmpty(nodeSrcDir))
            {
                nodeSrcDir = NodeRTProjectGenerator.DefaultDir;
            }

            if (String.IsNullOrEmpty(nodeSrcDir))
            {
                Console.WriteLine("Could not resolve node src dir, please specify a --nodesrcdir argument, as described below");
                PrintHelpAndExitWithError();
            }

            // generate specific namespace
            if (!String.IsNullOrEmpty(ns))
            {
                GenerateAndBuildNamespace(nodeSrcDir, ns,
                                          vsVersion, winmd, outDir, codeGenDir);
            }
            else // try to generate & build all namespaces in winmd file
            {
                List <String> failedList = new List <string>();
                Console.WriteLine("Started to generate and build all namespaces in given WinMD...\n");
                foreach (string winRtNamespace in Reflector.GetNamespaces(winmd, customWinMdDir))
                {
                    if (!GenerateAndBuildNamespace(nodeSrcDir, winRtNamespace,
                                                   vsVersion, winmd,
                                                   outDir, codeGenDir))
                    {
                        failedList.Add(winRtNamespace);
                    }
                    Console.WriteLine();
                }

                if (failedList.Count > 0)
                {
                    Console.WriteLine("Failed to generate or build for the following namespaces:");
                    foreach (string winRtNamespace in failedList)
                    {
                        Console.WriteLine("\t{0}", winRtNamespace);
                    }
                }
                else
                {
                    Console.WriteLine("Finished!");
                }
            }
        }
 public NodeRTProjectGenerator(WinVersions winVersion, VsVersions vsVersion, bool isGenerateDef)
 {
     _winVersion    = winVersion;
     _vsVersion     = vsVersion;
     _isGenerateDef = isGenerateDef;
 }
 private string VsVersionToString(VsVersions vsVersion)
 {
     switch (vsVersion)
     {
         case VsVersions.Vs2012:
             return "2012";
         case VsVersions.Vs2013:
             return "2013";
         default:
             return "2015";
     }
 }
 // Builds the given project/sln for the given platforms and copies the output & package file to the output directory
 public static void BuildWithNodeGyp(string moduleDirectory, VsVersions vsVersion)
 {
     BuildModule(moduleDirectory, vsVersion);
 }
 // Builds the given project/sln for the given platforms and copies the output & package file to the output directory
 public static void BuildWithNodeGyp(string moduleDirectory, VsVersions vsVersion, bool verbose = false)
 {
     BuildModule(moduleDirectory, vsVersion, verbose);
 }