Пример #1
0
 private void Changed(object sender, FileSystemEventArgs e)
 {
     if (isFileSync == false)
     {
         isFileSync = true;                         // Lock
         Task.Delay(100).ContinueWith((Task t) => { // Wait for further possible changes (debounce)
             try
             {
                 do
                 {
                     isChange = false;
                     UtilCli.ConsoleWriteLineColor("FileSync...", System.ConsoleColor.Green);
                     foreach (var item in folderNameList)
                     {
                         string folderNameSource = item.Key;
                         string folderNameDest   = item.Value;
                         // UtilCli.FolderDelete(folderNameDest);
                         UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);
                     }
                 } while (isChange); // Change happened while syncing
             }
             finally
             {
                 isFileSync = false;
             }
         });
     }
     else
     {
         isChange = true;
     }
 }
Пример #2
0
        /// <summary>
        /// Build all layout Websites. For example: "Application.Website/LayoutDefault"
        /// </summary>
        private void BuildWebsite()
        {
            var configCli = ConfigCli.Load();

            // Ensure FolderNameNpmBuild is defined once only in ConfigCli.json.
            ConfigCliWebsite configCliWebsite = configCli.WebsiteList.GroupBy(item => item.FolderNameNpmBuild.ToLower()).Where(group => group.Count() > 1).FirstOrDefault()?.FirstOrDefault();

            UtilFramework.Assert(configCliWebsite == null, string.Format("ConfigCli.json Website defined more than once. Use DomainNameList instead! (FolderNameNpmBuild={0})", configCliWebsite?.FolderNameNpmBuild));

            // Delete folder Application.Server/Framework/Application.Website/
            string folderNameApplicationWebsite = UtilFramework.FolderName + "Application.Server/Framework/Application.Website/";

            UtilCli.FolderDelete(folderNameApplicationWebsite);

            foreach (var website in configCli.WebsiteList)
            {
                Console.WriteLine(string.Format("### Build Website (Begin) - {0}", website.DomainNameListToString()));

                // Delete dist folder
                string folderNameDist = UtilFramework.FolderNameParse(website.FolderNameDist);
                UtilFramework.Assert(folderNameDist != null);
                UtilCli.FolderDelete(folderNameDist);

                // npm run build
                BuildWebsiteNpm(website);
                string folderNameServer = UtilFramework.FolderNameParse("Application.Server/Framework/" + website.FolderNameDist);
                UtilFramework.Assert(folderNameServer != null, "FolderNameServer can not be null!");
                UtilFramework.Assert(folderNameServer.StartsWith("Application.Server/Framework/Application.Website/"), "FolderNameServer has to start with 'Application.Server/Framework/Application.Website/'!");

                // Copy dist folder
                string folderNameSource = UtilFramework.FolderName + folderNameDist;
                string folderNameDest   = UtilFramework.FolderName + folderNameServer;
                if (!UtilCli.FolderNameExist(folderNameSource))
                {
                    throw new Exception(string.Format("Folder does not exist! ({0})", folderNameDest));
                }

                // Layout file main.js and Angular file main.js
                // Prevent for example two main.js. Angular js can not be overridden by layout Website
                // Application.Website/LayoutDefault/dist/main.js
                // Application.Server/Framework/Framework.Angular/browser/main.js
                var fileNameList = new string[] { "runtime.js", "polyfills.js", "main.js" };
                foreach (var fileName in fileNameList)
                {
                    var fileNameFull = folderNameSource + fileName;
                    if (File.Exists(fileNameFull))
                    {
                        throw new Exception(string.Format("File conflicts with Angular! See also: https://webpack.js.org/configuration/output/ ({0})", fileNameFull));
                    }
                }

                UtilCli.FolderDelete(folderNameDest);
                UtilFramework.Assert(!UtilCli.FolderNameExist(folderNameDest));
                UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);
                UtilFramework.Assert(UtilCli.FolderNameExist(folderNameDest));

                Console.WriteLine(string.Format("### Build Website (End) - {0}", website.DomainNameListToString()));
            }
        }
Пример #3
0
        /// <summary>
        /// Build all layout Websites. For example: "Application.Website/LayoutDefault"
        /// </summary>
        private void BuildWebsite()
        {
            var configCli = ConfigCli.Load();

            // Ensure FolderNameNpmBuild is defined once only in ConfigCli.json.
            ConfigCliWebsite configCliWebsite = configCli.WebsiteList.GroupBy(item => item.FolderNameNpmBuild.ToLower()).Where(group => group.Count() > 1).FirstOrDefault()?.FirstOrDefault();

            UtilFramework.Assert(configCliWebsite == null, string.Format("ConfigCli.json Website defined more than once. Use DomainNameList instead! (FolderNameNpmBuild={0})", configCliWebsite?.FolderNameNpmBuild));

            // Delete folder Application.Server/Framework/Application.Website/
            string folderNameApplicationWebsite = UtilFramework.FolderName + "Application.Server/Framework/Application.Website/";

            UtilCli.FolderDelete(folderNameApplicationWebsite);

            foreach (var website in configCli.WebsiteList)
            {
                Console.WriteLine(string.Format("### Build Website (Begin) - {0}", website.DomainNameListToString()));

                // Delete dist folder
                string folderNameDist = UtilFramework.FolderNameParse(website.FolderNameDist);
                UtilFramework.Assert(folderNameDist != null);
                UtilCli.FolderDelete(folderNameDist);

                // npm run build
                BuildWebsiteNpm(website);
                string folderNameServer = UtilFramework.FolderNameParse(website.FolderNameServerGet(configCli));
                UtilFramework.Assert(folderNameServer != null, "FolderNameServer can not be null!");
                UtilFramework.Assert(folderNameServer.StartsWith("Application.Server/Framework/Application.Website/"), "FolderNameServer has to start with 'Application.Server/Framework/Application.Website/'!");

                // Copy dist folder
                string folderNameSource = UtilFramework.FolderName + folderNameDist;
                string folderNameDest   = UtilFramework.FolderName + folderNameServer;
                if (!UtilCli.FolderNameExist(folderNameSource))
                {
                    throw new Exception(string.Format("Folder does not exist! ({0})", folderNameDest));
                }
                UtilCli.FolderDelete(folderNameDest);
                UtilFramework.Assert(!UtilCli.FolderNameExist(folderNameDest));
                UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);
                UtilFramework.Assert(UtilCli.FolderNameExist(folderNameDest));

                Console.WriteLine(string.Format("### Build Website (End) - {0}", website.DomainNameListToString()));
            }
        }
Пример #4
0
        /// <summary>
        /// Copy folder Application.Website/Shared/CustomComponent/
        /// </summary>
        private static void BuildAngularInit()
        {
            // Delete folder Application.Website/
            string folderNameApplicationWebSite = UtilFramework.FolderName + "Framework/Framework.Angular/application/src/Application.Website/";

            UtilCli.FolderDelete(folderNameApplicationWebSite);

            // Copy folder CustomComponent/
            string folderNameSource = UtilFramework.FolderName + "Application.Website/Shared/CustomComponent/";
            string folderNameDest   = UtilFramework.FolderName + "Framework/Framework.Angular/application/src/Application.Website/Shared/CustomComponent/";

            UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);

            // Copy empty index.html file
            UtilCli.FileCopy(UtilFramework.FolderName + "Framework/Framework.Angular/application/src/index.html", UtilFramework.FolderName + "Framework/Framework.Angular/application/src/Application.Website/dist/index.html");

            // Ensure folder exists now
            UtilFramework.Assert(Directory.Exists(folderNameApplicationWebSite));
        }
Пример #5
0
        /// <summary>
        /// Build Framework/Framework.Angular/application/.
        /// </summary>
        private static void BuildAngular()
        {
            // Build SSR
            {
                string folderName = UtilFramework.FolderName + "Framework/Framework.Angular/application/";
                UtilCli.Npm(folderName, "install --loglevel error");              // Angular install. --loglevel error prevent writing to STDERR "npm WARN optional SKIPPING OPTIONAL DEPENDENCY"
                UtilCli.Npm(folderName, "run build:ssr", isRedirectStdErr: true); // Build Server-side Rendering (SSR) to folder Framework/Framework.Angular/application/server/dist/ // TODO Bug report Angular build writes to stderr. Repo steps: Delete node_modules and run npm install and then run build:ssr.
            }

            // Copy output dist folder
            {
                string folderNameSource = UtilFramework.FolderName + "Framework/Framework.Angular/application/dist/application/";
                string folderNameDest   = UtilFramework.FolderName + "Application.Server/Framework/Framework.Angular/";

                // Copy folder
                UtilCli.FolderDelete(folderNameDest);
                UtilFramework.Assert(!Directory.Exists(folderNameDest));
                UtilCli.FolderCopy(folderNameSource, folderNameDest, "*.*", true);
                UtilFramework.Assert(Directory.Exists(folderNameDest));
            }
        }
Пример #6
0
        protected internal override void Execute()
        {
            // Build angular client
            if (!UtilCli.FolderNameExist(UtilFramework.FolderName + "Application.Server/Framework/Framework.Angular/"))
            {
                var commandBuild = new CommandBuild(AppCli);
                UtilCli.OptionSet(ref commandBuild.OptionClientOnly, true);
                commandBuild.Execute();
            }

            if (optionWatch.OptionGet())
            {
                {
                    ConfigCli configCli = ConfigCli.Load();

                    Console.WriteLine("Select Website:");

                    for (int i = 0; i < configCli.WebsiteList.Count; i++)
                    {
                        Console.WriteLine(string.Format("{0}={1}", i + 1, configCli.WebsiteList[i].FolderNameNpmBuild));
                    }

                    Console.Write("Website: ");

                    var websiteIndex = int.Parse(Console.ReadLine()) - 1;

                    var website = configCli.WebsiteList[websiteIndex];

                    string folderNameNpmBuilt = UtilFramework.FolderName + website.FolderNameNpmBuild;
                    string folderNameDist     = UtilFramework.FolderName + website.FolderNameDist;

                    string folderNameAngular         = UtilFramework.FolderName + "Framework/Framework.Angular/application/";
                    string folderNameCustomComponent = UtilFramework.FolderName + "Application.Website/Shared/CustomComponent/";

                    Console.WriteLine("Copy folder dist/");
                    UtilCli.FolderCopy(folderNameDist, folderNameAngular + "src/Application.Website/dist/", "*.*", true);

                    Console.WriteLine("Copy folder CustomComponent/");
                    UtilCli.FolderCopy(folderNameCustomComponent, folderNameAngular + "src/Application.Website/Shared/CustomComponent/", "*.*", true);

                    bool isWebsiteWatch = UtilCli.ConsoleReadYesNo("Start Website npm watch?");
                    bool isFileSync     = UtilCli.ConsoleReadYesNo("Start Website FileSync (dist/ to Angular)?");
                    bool isAngular      = UtilCli.ConsoleReadYesNo("Start Angular?");
                    bool isServer       = UtilCli.ConsoleReadYesNo("Start Server?");

                    // FileSync
                    if (isFileSync)
                    {
                        FileSync fileSync = new FileSync();
                        fileSync.AddFolder(folderNameDist, folderNameAngular + "src/Application.Website/dist/");
                        fileSync.AddFolder(folderNameAngular + "src/Application.Website/Shared/CustomComponent/", folderNameCustomComponent);
                    }

                    // Website --watch
                    if (isWebsiteWatch)
                    {
                        UtilCli.Npm(folderNameNpmBuilt, "run build -- --watch", isWait: false);
                    }

                    // Angular client
                    if (isAngular)
                    {
                        UtilCli.Npm(folderNameAngular, "start -- --disable-host-check", isWait: false); // disable-host-check to allow for example http://localhost2:4200/
                    }

                    // .NET Server
                    if (isServer)
                    {
                        string folderName = UtilFramework.FolderName + @"Application.Server/";
                        UtilCli.DotNet(folderName, "run", isWait: false);
                    }

                    void heartBeat()
                    {
                        Console.WriteLine();
                        Console.WriteLine(UtilFramework.DateTimeToString(DateTime.Now));
                        if (isAngular)
                        {
                            UtilCli.ConsoleWriteLineColor("Angular: http://" + website.DomainNameList.First().DomainName + ":4200/", System.ConsoleColor.Green);
                        }
                        if (isServer)
                        {
                            UtilCli.ConsoleWriteLineColor("Server: http://" + website.DomainNameList.First().DomainName + ":50919/", System.ConsoleColor.Green);
                        }
                        if (isFileSync)
                        {
                            UtilCli.ConsoleWriteLineColor("Modify Website: " + folderNameNpmBuilt, System.ConsoleColor.Green);
                            UtilCli.ConsoleWriteLineColor("Modify CustomComponent: " + folderNameCustomComponent, System.ConsoleColor.Green);
                        }
                        if (isAngular)
                        {
                            UtilCli.ConsoleWriteLineColor("Modify Angular: " + folderNameAngular, System.ConsoleColor.Green);
                        }
                        Task.Delay(5000).ContinueWith((Task task) => heartBeat());
                    }

                    if (isFileSync || isWebsiteWatch || isAngular || isServer)
                    {
                        heartBeat();
                        while (true)
                        {
                            Console.ReadLine(); // Program would end and with it FileSync
                        }
                    }
                }
            }
            else
            {
                string folderName = UtilFramework.FolderName + @"Application.Server/";
                UtilCli.VersionBuild(() =>
                {
                    UtilCli.DotNet(folderName, "build");
                });
                UtilCli.DotNet(folderName, "run --no-build", false);
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    UtilCli.OpenWebBrowser("http://localhost:50919/"); // For port setting see also: Application.Server\Properties\launchSettings.json (applicationUrl, sslPort)
                }
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
                {
                    // Ubuntu list all running processes: 'ps'
                    // To reboot Ubuntu type on Windows command prompt: 'wsl -t Ubuntu-18.04'
                    // Ubuntu show processes tool: 'htop'
                    UtilCli.ConsoleWriteLineColor("Stop server with command 'killall -SIGKILL Application.Server node dotnet'", System.ConsoleColor.Yellow);
                }
            }
        }