Esempio n. 1
0
        public static List <string> GetInitialDataSqlScript()
        {
            var key  = "CLF.DataAccess.Account.DataInitial.InitData.sql";
            var sqls = EmbeddedFileHelper.GetEmbeddedFileContents(key);

            return(sqls);
        }
Esempio n. 2
0
        public Task <bool> ExecuteAsync()
        {
            return(Task.Run(() =>
            {
                string aspCoreProjectPath = "";

                if (_args.Length > 0)
                {
                    if (Directory.Exists(_args[0]))
                    {
                        aspCoreProjectPath = _args[0];
                    }
                }
                else
                {
                    aspCoreProjectPath = Directory.GetCurrentDirectory();
                }

                var currentDirectory = aspCoreProjectPath;

                Console.WriteLine("Adding our config file to your project...");

                var targetFilePath = Path.Combine(currentDirectory, ConfigName);

                if (File.Exists(targetFilePath))
                {
                    Console.WriteLine("Config file already in your project.");
                    return false;
                }

                // Deploy config file
                EmbeddedFileHelper.DeployEmbeddedFile(currentDirectory, ConfigName);

                // search .csproj
                Console.WriteLine($"Search your .csproj to add the needed {ConfigName}...");
                var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();

                // update config file with the name of the csproj
                // ToDo: If the csproj name != application name, this will fail
                string text = File.ReadAllText(targetFilePath);
                text = text.Replace("{{executable}}", Path.GetFileNameWithoutExtension(projectFile));
                File.WriteAllText(targetFilePath, text);

                Console.WriteLine($"Found your .csproj: {projectFile} - check for existing config or update it.");

                if (!EditCsProj(projectFile))
                {
                    return false;
                }

                // search launchSettings.json
                Console.WriteLine($"Search your .launchSettings to add our electron debug profile...");

                EditLaunchSettings(currentDirectory);

                Console.WriteLine($"Everything done - happy electronizing!");

                return true;
            }));
        }
Esempio n. 3
0
        public static void Do(string tempPath)
        {
            EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
            EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
            EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "build-helper.js");

            string hostApiFolder = Path.Combine(tempPath, "api");

            if (Directory.Exists(hostApiFolder) == false)
            {
                Directory.CreateDirectory(hostApiFolder);
            }
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");
            EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "autoUpdater.js", "api.");

            string splashscreenFolder = Path.Combine(tempPath, "splashscreen");

            if (Directory.Exists(splashscreenFolder) == false)
            {
                Directory.CreateDirectory(splashscreenFolder);
            }
            EmbeddedFileHelper.DeployEmbeddedFile(splashscreenFolder, "index.html", "splashscreen.");
        }
Esempio n. 4
0
        public PugRendering(INodeServices nodeServices, IOptions <PugzorViewEngineOptions> options)
        {
            _nodeServices = nodeServices;
            var tempDirectory = TemporaryDirectoryHelper.CreateTemporaryDirectory();

            EmbeddedFileHelper.ExpandEmbeddedFiles(tempDirectory);
            _options = options.Value;
        }
        public Task <bool> ExecuteAsync()
        {
            return(Task.Run(() =>
            {
                Console.WriteLine("Start Electron Desktop Application...");

                string aspCoreProjectPath = "";

                if (_args.Length > 0)
                {
                    if (Directory.Exists(_args[0]))
                    {
                        aspCoreProjectPath = _args[0];
                    }
                }
                else
                {
                    aspCoreProjectPath = Directory.GetCurrentDirectory();
                }

                string tempPath = Path.Combine(aspCoreProjectPath, "obj", "Host");
                if (Directory.Exists(tempPath) == false)
                {
                    Directory.CreateDirectory(tempPath);
                }

                string tempBinPath = Path.Combine(tempPath, "bin");
                ProcessHelper.CmdExecute($"dotnet publish -r win10-x64 --output \"{tempBinPath}\"", aspCoreProjectPath);

                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json");

                string hostApiFolder = Path.Combine(tempPath, "api");
                if (Directory.Exists(hostApiFolder) == false)
                {
                    Directory.CreateDirectory(hostApiFolder);
                }
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");

                Console.WriteLine("Start npm install...");
                ProcessHelper.CmdExecute("npm install", tempPath);

                ProcessHelper.CmdExecute(@"electron.cmd ""..\..\main.js""", Path.Combine(tempPath, "node_modules", ".bin"), false, false);

                return true;
            }));
        }
        public void EmbeddedFileHelper_Extract_DirectoryContainsFiles()
        {
            // Assuming temporary directory helper is working as should
            var tempDir = TemporaryDirectoryHelper.CreateTemporaryDirectory();

            EmbeddedFileHelper.ExpandEmbeddedFiles(tempDir);
            var directory = new DirectoryInfo(tempDir);

            Assert.NotEmpty(directory.EnumerateDirectories());
            Assert.NotEmpty(directory.EnumerateFiles());
        }
Esempio n. 7
0
        public async Task <IList <Endpoint> > GetEndpoints()
        {
            List <Endpoint> endpoints = null;

            try
            {
                var resourcePath = "Mobile.RefApp.CoreUI.Assets.Data.Endpoints.json";
                var assembly     = typeof(EndpointService).GetTypeInfo().Assembly;
                var jsonData     = await EmbeddedFileHelper.GetResourceString(assembly, resourcePath);

                if (!string.IsNullOrEmpty(jsonData))
                {
                    endpoints = JsonConvert.DeserializeObject <List <Endpoint> >(jsonData);
                }
            }
            catch (Exception ex)
            {
                _loggingService.LogError(typeof(EndpointService), ex, ex.Message);
            }
            return(endpoints);
        }
        public Task <bool> ExecuteAsync()
        {
            return(Task.Run(() =>
            {
                string aspCoreProjectPath = "";

                if (_parser.Arguments.ContainsKey(_aspCoreProjectPath))
                {
                    string projectPath = _parser.Arguments[_aspCoreProjectPath].First();
                    if (Directory.Exists(projectPath))
                    {
                        aspCoreProjectPath = projectPath;
                    }
                }
                else
                {
                    aspCoreProjectPath = Directory.GetCurrentDirectory();
                }

                var currentDirectory = aspCoreProjectPath;

                if (_parser.Arguments.ContainsKey(_manifest))
                {
                    ConfigName = "electron.manifest." + _parser.Arguments[_manifest].First() + ".json";
                    Console.WriteLine($"Adding your custom {ConfigName} config file to your project...");
                }
                else
                {
                    Console.WriteLine("Adding our config file to your project...");
                }

                var targetFilePath = Path.Combine(currentDirectory, ConfigName);

                if (File.Exists(targetFilePath))
                {
                    Console.WriteLine("Config file already in your project.");
                    return false;
                }

                // Deploy config file
                EmbeddedFileHelper.DeployEmbeddedFileToTargetFile(currentDirectory, DefaultConfigFileName, ConfigName);

                // search .csproj/.fsproj (.csproj has higher precedence)
                Console.WriteLine($"Search your .csproj/fsproj to add the needed {ConfigName}...");
                var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly)
                                  .Union(Directory.EnumerateFiles(currentDirectory, "*.fsproj", SearchOption.TopDirectoryOnly))
                                  .FirstOrDefault();

                // update config file with the name of the csproj/fsproj
                // ToDo: If the csproj/fsproj name != application name, this will fail
                string text = File.ReadAllText(targetFilePath);
                text = text.Replace("{{executable}}", Path.GetFileNameWithoutExtension(projectFile));
                File.WriteAllText(targetFilePath, text);

                var extension = Path.GetExtension(projectFile);
                Console.WriteLine($"Found your {extension}: {projectFile} - check for existing config or update it.");

                if (!EditProjectFile(projectFile))
                {
                    return false;
                }

                // search launchSettings.json
                Console.WriteLine($"Search your .launchSettings to add our electron debug profile...");

                EditLaunchSettings(currentDirectory);

                Console.WriteLine($"Everything done - happy electronizing!");

                return true;
            }));
        }
Esempio n. 9
0
        public Task <bool> ExecuteAsync()
        {
            return(Task.Run(() =>
            {
                SimpleCommandLineParser parser = new SimpleCommandLineParser();
                parser.Parse(_args);

                string port = "8000";
                if (parser.Arguments.ContainsKey(_paramPort))
                {
                    port = parser.Arguments[_paramPort][0];
                }

                string staticPort = "false";
                if (parser.Arguments.ContainsKey(_paramStaticPort))
                {
                    staticPort = parser.Arguments[_paramStaticPort][0];
                }

                string aspCoreProjectPath = "";
                if (parser.Arguments.ContainsKey(_paramPath))
                {
                    if (Directory.Exists(parser.Arguments[_paramPath][0]))
                    {
                        aspCoreProjectPath = parser.Arguments[_paramPath][0];
                    }
                    else
                    {
                        Console.WriteLine("Supplied path doesn't exist. Creating in current working directory.");
                    }
                }
                else
                {
                    aspCoreProjectPath = Directory.GetCurrentDirectory();
                }

                var currentDirectory = aspCoreProjectPath;

                Console.WriteLine("Adding our config file to your project...");

                var targetFilePath = Path.Combine(currentDirectory, ConfigName);

                if (File.Exists(targetFilePath))
                {
                    Console.WriteLine("Config file already in your project.");
                    return false;
                }

                // Deploy config file
                EmbeddedFileHelper.DeployEmbeddedFile(currentDirectory, ConfigName);

                // search .csproj
                Console.WriteLine($"Search your .csproj to add the needed {ConfigName}...");
                var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();

                string executable = GetAssemblyName(projectFile);

                string text = File.ReadAllText(targetFilePath);
                text = text.Replace("{{executable}}", executable);
                text = text.Replace("\"{{port}}\"", port);
                text = text.Replace("\"{{static}}\"", staticPort);
                File.WriteAllText(targetFilePath, text);

                Console.WriteLine($"Found your .csproj: {projectFile} - check for existing config or update it.");

                if (!EditCsProj(projectFile))
                {
                    return false;
                }

                // search launchSettings.json
                Console.WriteLine($"Search your .launchSettings to add our electron debug profile...");

                EditLaunchSettings(currentDirectory);

                Console.WriteLine($"Everything done - happy electronizing!");

                return true;
            }));
        }
Esempio n. 10
0
        public Task <bool> ExecuteAsync()
        {
            return(Task.Run(() =>
            {
                var currentDirectory = Directory.GetCurrentDirectory();

                Console.WriteLine("Adding our config file to your project...");

                var targetFilePath = Path.Combine(currentDirectory, ConfigName);

                if (File.Exists(targetFilePath))
                {
                    Console.WriteLine("Config file already in your project.");
                    return false;
                }

                // Deploy config file
                EmbeddedFileHelper.DeployEmbeddedFile(currentDirectory, ConfigName);

                // search .csproj
                Console.WriteLine($"Search your .csproj to add the needed {ConfigName}...");
                var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();

                // update config file with the name of the csproj
                // ToDo: If the csproj name != application name, this will fail
                string text = File.ReadAllText(targetFilePath);
                text = text.Replace("{{executable}}", Path.GetFileNameWithoutExtension(projectFile));
                File.WriteAllText(targetFilePath, text);

                Console.WriteLine($"Found your .csproj: {projectFile} - check for existing config or update it.");

                using (var stream = File.Open(projectFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    var xmlDocument = XDocument.Load(stream);

                    var projectElement = xmlDocument.Descendants("Project").FirstOrDefault();
                    if (projectElement == null || projectElement.Attribute("Sdk")?.Value != "Microsoft.NET.Sdk.Web")
                    {
                        Console.WriteLine($"Project file is not a compatible type of 'Microsoft.NET.Sdk.Web'. Your project: {projectElement?.Attribute("Sdk")?.Value}");
                        return false;
                    }

                    if (xmlDocument.ToString().Contains($"Content Update=\"{ConfigName}\""))
                    {
                        Console.WriteLine($"{ConfigName} already in csproj.");
                        return false;
                    }

                    Console.WriteLine($"{ConfigName} will be added to csproj.");

                    string itemGroupXmlString = "<ItemGroup>" +
                                                "<Content Update=\"" + ConfigName + "\">" +
                                                "<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>" +
                                                "</Content>" +
                                                "</ItemGroup>";

                    var newItemGroupForConfig = XElement.Parse(itemGroupXmlString);
                    xmlDocument.Root.Add(newItemGroupForConfig);

                    stream.SetLength(0);
                    stream.Position = 0;

                    xmlDocument.Save(stream);

                    Console.WriteLine($"{ConfigName} added in csproj - happy electronizing!");
                }

                return true;
            }));
        }
Esempio n. 11
0
        public Task <bool> ExecuteAsync()
        {
            return(Task.Run(() =>
            {
                if (_args.Length == 0)
                {
                    Console.WriteLine("Specify 'hosthook' to add custom npm packages.");
                    return false;
                }

                if (_args[0].ToLowerInvariant() != "hosthook")
                {
                    Console.WriteLine("Specify 'hosthook' to add custom npm packages.");
                    return false;
                }

                string aspCoreProjectPath = "";

                // Maybe ToDo: Adding the possiblity to specify a path (like we did in the InitCommand, but this would require a better command args parser)
                aspCoreProjectPath = Directory.GetCurrentDirectory();

                var currentDirectory = aspCoreProjectPath;

                var targetFilePath = Path.Combine(currentDirectory, ElectronHostHookFolderName);

                if (Directory.Exists(targetFilePath))
                {
                    Console.WriteLine("ElectronHostHook directory already in place. If you want to start over, delete the folder and invoke this command again.");
                    return false;
                }

                Console.WriteLine("Adding the ElectronHostHook folder to your project...");

                Directory.CreateDirectory(targetFilePath);

                // Deploy related files
                EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, "index.ts", "ElectronHostHook.");
                EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, "connector.ts", "ElectronHostHook.");
                EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, "package.json", "ElectronHostHook.");
                EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, "tsconfig.json", "ElectronHostHook.");
                EmbeddedFileHelper.DeployEmbeddedFile(targetFilePath, ".gitignore", "ElectronHostHook.");

                // npm for typescript compiler etc.
                Console.WriteLine("Start npm install...");
                ProcessHelper.CmdExecute("npm install", targetFilePath);

                // run typescript compiler
                // ToDo: Not sure if this runs under linux/macos
                ProcessHelper.CmdExecute(@"npx tsc -p ../../", targetFilePath);

                // search .csproj
                Console.WriteLine($"Search your .csproj to add configure CopyToPublishDirectory to 'Never'");
                var projectFile = Directory.EnumerateFiles(currentDirectory, "*.csproj", SearchOption.TopDirectoryOnly).FirstOrDefault();

                Console.WriteLine($"Found your .csproj: {projectFile} - check for existing CopyToPublishDirectory setting or update it.");

                if (!EditCsProj(projectFile))
                {
                    return false;
                }

                Console.WriteLine($"Everything done - happy electronizing with your custom npm packages!");

                return true;
            }));
        }
Esempio n. 12
0
        public Task <bool> ExecuteAsync()
        {
            return(Task.Run(() =>
            {
                Console.WriteLine("Build Electron Application...");

                string desiredPlatform = "";

                if (_args.Length > 0)
                {
                    desiredPlatform = _args[0];
                }



                string netCorePublishRid = string.Empty;
                string electronPackerPlatform = string.Empty;

                switch (desiredPlatform)
                {
                case "win":
                    netCorePublishRid = "win10-x64";
                    electronPackerPlatform = "win32";
                    break;

                case "osx":
                    netCorePublishRid = "osx-x64";
                    electronPackerPlatform = "darwin";
                    break;

                case "linux":
                    netCorePublishRid = "ubuntu-x64";
                    electronPackerPlatform = "linux";
                    break;

                default:
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                    {
                        desiredPlatform = "win";
                        netCorePublishRid = "win10-x64";
                        electronPackerPlatform = "win32";
                    }
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                    {
                        desiredPlatform = "osx";
                        netCorePublishRid = "osx-x64";
                        electronPackerPlatform = "darwin";
                    }
                    if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                    {
                        desiredPlatform = "linux";
                        netCorePublishRid = "ubuntu-x64";
                        electronPackerPlatform = "linux";
                    }

                    break;
                }


                string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform);

                Console.WriteLine("Executing dotnet publish in this directory: " + tempPath);

                string tempBinPath = Path.Combine(tempPath, "bin");

                Console.WriteLine($"Build ASP.NET Core App for {netCorePublishRid}...");

                ProcessHelper.CmdExecute($"dotnet publish -r {netCorePublishRid} --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());


                if (Directory.Exists(tempPath) == false)
                {
                    Directory.CreateDirectory(tempPath);
                }

                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json");

                string hostApiFolder = Path.Combine(tempPath, "api");
                if (Directory.Exists(hostApiFolder) == false)
                {
                    Directory.CreateDirectory(hostApiFolder);
                }
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "webContents.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "globalShortcut.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "shell.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "screen.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "clipboard.js", "api.");

                Console.WriteLine("Start npm install...");
                ProcessHelper.CmdExecute("npm install", tempPath);

                Console.WriteLine("Start npm install electron-packager...");

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // Works proper on Windows...
                    ProcessHelper.CmdExecute("npm install electron-packager --global", tempPath);
                }
                else
                {
                    // ToDo: find another solution or document it proper
                    // GH Issue https://github.com/electron-userland/electron-prebuilt/issues/48
                    Console.WriteLine("Electron Packager - make sure you invoke 'sudo npm install electron-packager --global' at " + tempPath + " manually. Sry.");
                }

                Console.WriteLine("Build Electron Desktop Application...");
                string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop");

                Console.WriteLine("Executing electron magic in this directory: " + buildPath);

                // ToDo: Need a solution for --asar support
                Console.WriteLine($"Package Electron App for Platform {electronPackerPlatform}...");
                ProcessHelper.CmdExecute($"electron-packager . --platform={electronPackerPlatform} --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath);

                Console.WriteLine("... done");

                return true;
            }));
        }
Esempio n. 13
0
        public Task <bool> ExecuteAsync()
        {
            return(Task.Run(() =>
            {
                Console.WriteLine("Build Electron Application...");

                string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop");

                Console.WriteLine("Executing dotnet publish in this directory: " + tempPath);

                string tempBinPath = Path.Combine(tempPath, "bin");

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    Console.WriteLine("Build ASP.NET Core App for Windows...");

                    ProcessHelper.CmdExecute($"dotnet publish -r win10-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    Console.WriteLine("Build ASP.NET Core App for OSX...");

                    ProcessHelper.CmdExecute($"dotnet publish -r osx-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Console.WriteLine("Build ASP.NET Core App for Linux (Ubuntu x64)...");

                    ProcessHelper.CmdExecute($"dotnet publish -r ubuntu-x64 --output \"{tempBinPath}\"", Directory.GetCurrentDirectory());
                }

                if (Directory.Exists(tempPath) == false)
                {
                    Directory.CreateDirectory(tempPath);
                }

                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "main.js");
                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package.json");
                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "package-lock.json");

                string hostApiFolder = Path.Combine(tempPath, "api");
                if (Directory.Exists(hostApiFolder) == false)
                {
                    Directory.CreateDirectory(hostApiFolder);
                }
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "ipc.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "app.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "browserWindows.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "dialog.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "menu.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "notification.js", "api.");
                EmbeddedFileHelper.DeployEmbeddedFile(hostApiFolder, "tray.js", "api.");

                Console.WriteLine("Start npm install...");
                ProcessHelper.CmdExecute("npm install", tempPath);

                Console.WriteLine("Start npm install electron-packager...");

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    // Works proper on Windows...
                    ProcessHelper.CmdExecute("npm install electron-packager --global", tempPath);
                }
                else
                {
                    // ToDo: find another solution or document it proper
                    // GH Issue https://github.com/electron-userland/electron-prebuilt/issues/48
                    Console.WriteLine("Electron Packager - make sure you invoke 'sudo npm install electron-packager --global' at " + tempPath + " manually. Sry.");
                }

                Console.WriteLine("Build Electron Desktop Application...");
                string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop");
                Console.WriteLine("Executing electron magic in this directory: " + buildPath);

                // ToDo: Need a solution for --asar support
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    Console.WriteLine("Package Electron App for Windows...");

                    ProcessHelper.CmdExecute($"electron-packager . --platform=win32 --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath);
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
                {
                    Console.WriteLine("Package Electron App for OSX...");

                    ProcessHelper.CmdExecute($"electron-packager . --platform=darwin --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath);
                }

                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    Console.WriteLine("Package Electron App for Linux...");

                    ProcessHelper.CmdExecute($"electron-packager . --platform=linux --arch=x64 --out=\"{buildPath}\" --overwrite", tempPath);
                }

                Console.WriteLine("... done");

                return true;
            }));
        }
Esempio n. 14
0
        public Task <bool> ExecuteAsync()
        {
            return(Task.Run(() =>
            {
                Console.WriteLine("Build Electron Application...");

                SimpleCommandLineParser parser = new SimpleCommandLineParser();
                parser.Parse(_args);

                //This version will be shared between the dotnet publish and electron-builder commands
                string version = null;
                if (parser.Arguments.ContainsKey(_paramVersion))
                {
                    version = parser.Arguments[_paramVersion][0];
                }

                if (!parser.Arguments.ContainsKey(_paramTarget))
                {
                    Console.WriteLine($"Error: missing '{_paramTarget}' argument.");
                    Console.WriteLine(COMMAND_ARGUMENTS);
                    return false;
                }

                var desiredPlatform = parser.Arguments[_paramTarget][0];
                string specifiedFromCustom = string.Empty;
                if (desiredPlatform == "custom" && parser.Arguments[_paramTarget].Length > 1)
                {
                    specifiedFromCustom = parser.Arguments[_paramTarget][1];
                }

                string configuration = "Release";
                if (parser.Arguments.ContainsKey(_paramDotNetConfig))
                {
                    configuration = parser.Arguments[_paramDotNetConfig][0];
                }

                var platformInfo = GetTargetPlatformInformation.Do(desiredPlatform, specifiedFromCustom);

                Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}...");

                string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform);

                if (Directory.Exists(tempPath) == false)
                {
                    Directory.CreateDirectory(tempPath);
                }
                else
                {
                    Directory.Delete(tempPath, true);
                    Directory.CreateDirectory(tempPath);
                }


                Console.WriteLine("Executing dotnet publish in this directory: " + tempPath);

                string tempBinPath = Path.Combine(tempPath, "bin");

                Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid} under {configuration}-Configuration...");

                var dotNetPublishFlags = GetDotNetPublishFlags(parser);

                var command =
                    $"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))} --self-contained";

                // output the command
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(command);
                Console.ResetColor();

                var resultCode = ProcessHelper.CmdExecute(command, Directory.GetCurrentDirectory());

                if (resultCode != 0)
                {
                    Console.WriteLine("Error occurred during dotnet publish: " + resultCode);
                    return false;
                }

                DeployEmbeddedElectronFiles.Do(tempPath);
                var nodeModulesDirPath = Path.Combine(tempPath, "node_modules");

                if (parser.Arguments.ContainsKey(_paramPackageJson))
                {
                    Console.WriteLine("Copying custom package.json.");

                    File.Copy(parser.Arguments[_paramPackageJson][0], Path.Combine(tempPath, "package.json"), true);
                }

                var checkForNodeModulesDirPath = Path.Combine(tempPath, "node_modules");

                if (Directory.Exists(checkForNodeModulesDirPath) == false || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson))
                {
                    Console.WriteLine("Start npm install...");
                    ProcessHelper.CmdExecute("npm install --production", tempPath);
                }

                Console.WriteLine("ElectronHostHook handling started...");

                string electronhosthookDir = Path.Combine(Directory.GetCurrentDirectory(), "ElectronHostHook");

                if (Directory.Exists(electronhosthookDir))
                {
                    string hosthookDir = Path.Combine(tempPath, "ElectronHostHook");
                    DirectoryCopy.Do(electronhosthookDir, hosthookDir, true, new List <string>()
                    {
                        "node_modules"
                    });

                    Console.WriteLine("Start npm install for hosthooks...");
                    ProcessHelper.CmdExecute("npm install", hosthookDir);

                    // ToDo: Not sure if this runs under linux/macos
                    ProcessHelper.CmdExecute(@"npx tsc -p . --sourceMap false", hosthookDir);
                }

                Console.WriteLine("Build Electron Desktop Application...");

                // Specifying an absolute path supercedes a relative path
                string buildPath = Path.Combine(Directory.GetCurrentDirectory(), "bin", "desktop");
                if (parser.Arguments.ContainsKey(_paramAbsoluteOutput))
                {
                    buildPath = parser.Arguments[_paramAbsoluteOutput][0];
                }
                else if (parser.Arguments.ContainsKey(_paramOutputDirectory))
                {
                    buildPath = Path.Combine(Directory.GetCurrentDirectory(), parser.Arguments[_paramOutputDirectory][0]);
                }

                Console.WriteLine("Executing electron magic in this directory: " + buildPath);

                string electronArch = "x64";
                if (parser.Arguments.ContainsKey(_paramElectronArch))
                {
                    electronArch = parser.Arguments[_paramElectronArch][0];
                }

                string electronParams = "";
                if (parser.Arguments.ContainsKey(_paramElectronParams))
                {
                    electronParams = parser.Arguments[_paramElectronParams][0];
                }

                // ToDo: Make the same thing easer with native c# - we can save a tmp file in production code :)
                Console.WriteLine("Create electron-builder configuration file...");

                string manifestFileName = "electron.manifest.json";

                if (parser.Arguments.ContainsKey(_manifest))
                {
                    manifestFileName = parser.Arguments[_manifest].First();
                }

                ProcessHelper.CmdExecute(
                    string.IsNullOrWhiteSpace(version)
                        ? $"node build-helper.js build {manifestFileName}"
                        : $"node build-helper.js build {manifestFileName} {version}", tempPath);

                Console.WriteLine($"Package Electron App for Platform {platformInfo.ElectronPackerPlatform}...");
                ProcessHelper.CmdExecute($"npx electron-builder --config=./bin/electron-builder.json --{platformInfo.ElectronPackerPlatform} --{electronArch} -c.electronVersion=13.1.5 {electronParams}", tempPath);

                Console.WriteLine("Building msi installer using wix");
                Console.WriteLine("Installing dev dependencies in temp path");
                ProcessHelper.CmdExecute("npm install --only=dev", tempPath);

                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "wix-install-builder.js");
                EmbeddedFileHelper.DeployEmbeddedFile(tempPath, "wix-config.json");

                Console.WriteLine("Updating wix configuration");
                ProcessHelper.CmdExecute($"node build-helper.js postbuild " + manifestFileName + " \"" + buildPath + "\"", tempPath);

                Console.WriteLine("Building wix msi");
                ProcessHelper.CmdExecute($"node wix-install-builder.js", tempPath);


                Console.WriteLine("... done");

                return true;
            }));
        }