コード例 #1
0
ファイル: Program.cs プロジェクト: dkontod/Serenity
        public static void Main(string[] args)
        {
            var projectJson = "project.json";

            if (!File.Exists(projectJson))
            {
                System.Console.Error.WriteLine("Can't find project.json in current directory!");
                Environment.Exit(1);
            }

            projectJson = Path.GetFullPath(projectJson);

            if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(projectJson), "wwwroot")))
            {
                throw new Exception("Can't locate wwwroot folder!");
            }

            var process = Process.Start(new ProcessStartInfo
            {
                FileName         = "dotnet",
                WorkingDirectory = Path.GetDirectoryName(projectJson),
                CreateNoWindow   = true,
                Arguments        = "restore project.json"
            });

            process.WaitForExit();
            if (process.ExitCode > 0)
            {
                Console.Error.WriteLine("Error executing dotnet restore!");
                Environment.Exit(process.ExitCode);
            }

            if (args.Length > 0 && (args[0] == "restore"))
            {
                new RestoreCommand().Run(projectJson);
            }
            else if (args.Length > 0 && (args[0] == "transform" || args[0] == "t"))
            {
                var type = args.Length < 2 ? null : args[1].ToLowerInvariant();
                if (type != null &&
                    type != "servertypings" &&
                    type != "st" &&
                    type != "clienttypes" &&
                    type != "ct" &&
                    type != "mvc")
                {
                    Console.Error.WriteLine("Invalid transform type: " + type + "!");
                    Environment.Exit(process.ExitCode);
                }

                string tsTypesJson = null;
                Func <List <ExternalType> > getTsTypes = () =>
                {
                    if (tsTypesJson == null)
                    {
                        var tsTypeLister = new TSTypeLister(Path.GetDirectoryName(projectJson));
                        var tsTypes      = tsTypeLister.List();
                        tsTypesJson = JSON.Stringify(tsTypes);
                    }

                    return(JSON.Parse <List <ExternalType> >(tsTypesJson));
                };

                if (type == null || type == "mvc")
                {
                    new MvcCommand().Run(projectJson);
                }

                if (type == null || type == "clienttypes" || type == "ct")
                {
                    new ClientTypesCommand().Run(projectJson, getTsTypes());
                }

                if (type == null || type == "servertypings" || type == "st")
                {
                    new ServerTypingsCommand().Run(projectJson, getTsTypes());
                }
            }
            else if (args.Length == 0)
            {
                System.Console.Error.WriteLine("Default action...");
                Environment.Exit(1);
            }
            else
            {
                System.Console.Error.WriteLine("Use one of 'restore', 'transform' as parameter!");
                Environment.Exit(1);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: vooba/Serenity
        public static ExitCodes Run(string[] args, IFileSystem fileSystem,
                                    Func <IBuildProjectSystem> projectSystemFactory)
        {
            if (fileSystem is null)
            {
                throw new ArgumentNullException(nameof(fileSystem));
            }

            string command = null;

            if (args.Length > 0)
            {
                command = args[0].ToLowerInvariant().TrimToEmpty();
            }

            string csproj = null;

            if (command == "-p" && args.Length > 2)
            {
                csproj  = args[1];
                command = args.Length > 2 ? args[1] : null;
            }

            if (command.IsEmptyOrNull())
            {
                WriteHelp();
                return(ExitCodes.NoCommand);
            }

            if (command == "-?" ||
                command == "--help")
            {
                WriteHelp();
                return(ExitCodes.Help);
            }

            if (csproj == null)
            {
                var csprojs = fileSystem.Directory.GetFiles(".", "*.csproj");
                if (csprojs.Length == 0)
                {
                    Console.Error.WriteLine("Can't find a project file in current directory!");
                    Console.Error.WriteLine("Please run Sergen in a folder that contains the Asp.Net Core project.");
                    return(ExitCodes.NoProjectFiles);
                }

                if (csprojs.Length > 1)
                {
                    Console.Error.WriteLine("Multiple project files found in current directory!");
                    Console.Error.WriteLine("Please run Sergen in a folder that contains only one Asp.Net Core project.");
                    return(ExitCodes.MultipleProjectFiles);
                }

                csproj = csprojs[0];
            }

            if (!fileSystem.File.Exists(csproj))
            {
                return(ExitCodes.ProjectNotFound);
            }

            var projectDir = fileSystem.Path.GetFullPath(fileSystem.Path.GetDirectoryName(csproj));

            try
            {
                if ("restore".StartsWith(command, StringComparison.Ordinal))
                {
                    return(new RestoreCommand(fileSystem, projectSystemFactory()).Run(csproj));
                }

                if ("transform".StartsWith(command, StringComparison.Ordinal) ||
                    "servertypings".StartsWith(command, StringComparison.Ordinal) ||
                    "clienttypes".StartsWith(command, StringComparison.Ordinal) ||
                    "mvct".StartsWith(command, StringComparison.Ordinal))
                {
                    List <ExternalType>         tsTypes    = null;
                    Func <List <ExternalType> > getTsTypes = () =>
                    {
                        if (tsTypes == null)
                        {
                            var tsTypeLister = new TSTypeLister(projectDir);
                            tsTypes = tsTypeLister.List();
                        }

                        return(tsTypes);
                    };

                    bool transformAll = "transform".StartsWith(command, StringComparison.Ordinal);

                    if (transformAll ||
                        "mvct".StartsWith(command, StringComparison.Ordinal))
                    {
                        new MvcCommand().Run(csproj);
                    }

                    if (transformAll ||
                        "clienttypes".StartsWith(command, StringComparison.Ordinal) || command == "mvct")
                    {
                        new ClientTypesCommand().Run(csproj, getTsTypes());
                    }

                    if (transformAll ||
                        "servertypings".StartsWith(command, StringComparison.Ordinal))
                    {
                        new ServerTypingsCommand().Run(csproj, getTsTypes());
                    }

                    return(ExitCodes.Success);
                }

                if ("generate".StartsWith(command, StringComparison.Ordinal))
                {
                    new GenerateCommand().Run(csproj, args.Skip(1).ToArray());
                    return(ExitCodes.Success);
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex);
                return(ExitCodes.Exception);
            }

            WriteHelp();
            return(ExitCodes.InvalidCommand);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: wqshabib/Serenity
        public static void Main(string[] args)
        {
            string command = null;

            if (args.Length > 0)
            {
                command = args[0].ToLowerInvariant().TrimToEmpty();
            }

            if (command.IsEmptyOrNull() ||
                command == "-?" ||
                command == "--help")
            {
                WriteHelp();
                Environment.Exit(1);
            }

            var sergenJson = "sergen.json";

            if (!File.Exists(sergenJson))
            {
                System.Console.Error.WriteLine("Can't find sergen.json in current directory!");
                System.Console.Error.WriteLine("Please run Sergen in a folder that contains the Asp.Net Core project.");
                Environment.Exit(1);
            }

            sergenJson = Path.GetFullPath(sergenJson);
            var projectDir = Path.GetDirectoryName(sergenJson);

            if (!Directory.Exists(Path.Combine(projectDir, "wwwroot")))
            {
                System.Console.Error.WriteLine("Can't find wwwroot folder in current directory!");
                System.Console.Error.WriteLine("Please run Sergen in a folder that contains the Asp.Net Core project.");
                Environment.Exit(1);
            }

            var csprojs = Directory.GetFiles(projectDir, "*.csproj");

            if (csprojs.Length > 1)
            {
                csprojs = csprojs.Where(x => !x.StartsWith("Dev.", StringComparison.OrdinalIgnoreCase)).ToArray();
            }

            if (csprojs.Length == 0)
            {
                System.Console.Error.WriteLine("Can't find a project file in current directory!");
                System.Console.Error.WriteLine("Please run Sergen in a folder that contains the Asp.Net Core project.");
                Environment.Exit(1);
            }

            if (csprojs.Length > 1)
            {
                System.Console.Error.WriteLine("Multiple project files found in current directory!");
                System.Console.Error.WriteLine("Please run Sergen in a folder that contains only one Asp.Net Core project.");
                Environment.Exit(1);
            }

            var csproj = csprojs.First();

            if ("restore".StartsWith(command))
            {
                new RestoreCommand().Run(csproj);
            }
            else if (
                "transform".StartsWith(command) ||
                "servertypings".StartsWith(command) ||
                "clienttypes".StartsWith(command) ||
                "mvc".StartsWith(command))
            {
                string tsTypesJson = null;
                Func <List <ExternalType> > getTsTypes = () =>
                {
                    if (tsTypesJson == null)
                    {
                        var tsTypeLister = new TSTypeLister(projectDir);
                        var tsTypes      = tsTypeLister.List();
                        tsTypesJson = JSON.Stringify(tsTypes);
                    }

                    return(JSON.Parse <List <ExternalType> >(tsTypesJson));
                };

                if ("transform".StartsWith(command) || "mvc".StartsWith(command))
                {
                    new MvcCommand().Run(csproj);
                }

                if ("transform".StartsWith(command) || "clienttypes".StartsWith(command))
                {
                    new ClientTypesCommand().Run(csproj, getTsTypes());
                }

                if ("transform".StartsWith(command) || "servertypings".StartsWith(command))
                {
                    new ServerTypingsCommand().Run(csproj, getTsTypes());
                }
            }
            else if ("generate".StartsWith(command))
            {
                new GenerateCommand().Run(csproj, args.Skip(1).ToArray());
            }
            else
            {
                WriteHelp();
            }
        }
コード例 #4
0
        public static void Main(string[] args)
        {
            string command = null;

            if (args.Length > 0)
            {
                command = args[0].ToLowerInvariant().TrimToEmpty();
            }

            string csproj = null;

            if (command == "-p" && args.Length > 2)
            {
                csproj  = args[1];
                command = args.Length > 2 ? args[1] : null;
            }

            if (command.IsEmptyOrNull() ||
                command == "-?" ||
                command == "--help")
            {
                WriteHelp();
                Environment.Exit(1);
            }

            if (csproj == null)
            {
                var csprojs = Directory.GetFiles(".", "*.csproj");
                if (csprojs.Length == 0)
                {
                    Console.Error.WriteLine("Can't find a project file in current directory!");
                    Console.Error.WriteLine("Please run Sergen in a folder that contains the Asp.Net Core project.");
                    Environment.Exit(1);
                }

                if (csprojs.Length > 1)
                {
                    Console.Error.WriteLine("Multiple project files found in current directory!");
                    Console.Error.WriteLine("Please run Sergen in a folder that contains only one Asp.Net Core project.");
                    Environment.Exit(1);
                }

                csproj = csprojs[0];
            }

            if (!File.Exists(csproj))
            {
                Console.Error.WriteLine("Can't find project named: " + csproj);
                Environment.Exit(1);
            }

            var projectDir = Path.GetFullPath(Path.GetDirectoryName(csproj));

            if ("restore".StartsWith(command, StringComparison.Ordinal))
            {
                MSBuildLocator.RegisterDefaults();
                new RestoreCommand().Run(csproj);
            }
            else if (
                "transform".StartsWith(command, StringComparison.Ordinal) ||
                "servertypings".StartsWith(command, StringComparison.Ordinal) ||
                "clienttypes".StartsWith(command, StringComparison.Ordinal) ||
                "mvct".StartsWith(command, StringComparison.Ordinal))
            {
                string tsTypesJson = null;
                Func <List <ExternalType> > getTsTypes = () =>
                {
                    if (tsTypesJson == null)
                    {
                        var tsTypeLister = new TSTypeLister(projectDir);
                        var tsTypes      = tsTypeLister.List();
                        tsTypesJson = JSON.Stringify(tsTypes);
                    }

                    return(JSON.Parse <List <ExternalType> >(tsTypesJson));
                };

                if ("transform".StartsWith(command, StringComparison.Ordinal) ||
                    "mvct".StartsWith(command, StringComparison.Ordinal))
                {
                    new MvcCommand().Run(csproj);
                }

                if ("transform".StartsWith(command, StringComparison.Ordinal) ||
                    "clienttypes".StartsWith(command, StringComparison.Ordinal) || command == "mvct")
                {
                    new ClientTypesCommand().Run(csproj, getTsTypes());
                }

                if ("transform".StartsWith(command, StringComparison.Ordinal) ||
                    "servertypings".StartsWith(command, StringComparison.Ordinal))
                {
                    new ServerTypingsCommand().Run(csproj, getTsTypes());
                }
            }
            else if ("generate".StartsWith(command, StringComparison.Ordinal))
            {
                new GenerateCommand().Run(csproj, args.Skip(1).ToArray());
            }
            else
            {
                WriteHelp();
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: venkatmca008/Serenity
        public static void Main(string[] args)
        {
            string command = null;

            if (args.Length > 0)
            {
                command = args[0].ToLowerInvariant().TrimToEmpty();
            }

            if (command.IsEmptyOrNull() ||
                command == "-?" ||
                command == "--help")
            {
                WriteHelp();
                Environment.Exit(1);
            }

            var projectJson = "project.json";

            if (!File.Exists(projectJson))
            {
                System.Console.Error.WriteLine("Can't find project.json in current directory!");
                System.Console.Error.WriteLine("Please run Sergen in a folder that contains the Asp.Net Core project.");
                Environment.Exit(1);
            }

            projectJson = Path.GetFullPath(projectJson);

            if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(projectJson), "wwwroot")))
            {
                System.Console.Error.WriteLine("Can't find wwwroot folder in current directory!");
                System.Console.Error.WriteLine("Please run Sergen in a folder that contains the Asp.Net Core project.");
                Environment.Exit(1);
            }

            if ("restore".StartsWith(command))
            {
                new RestoreCommand().Run(projectJson);
            }
            else if (
                "transform".StartsWith(command) ||
                "servertypings".StartsWith(command) ||
                "clienttypes".StartsWith(command) ||
                "mvc".StartsWith(command))
            {
                string tsTypesJson = null;
                Func <List <ExternalType> > getTsTypes = () =>
                {
                    if (tsTypesJson == null)
                    {
                        var tsTypeLister = new TSTypeLister(Path.GetDirectoryName(projectJson));
                        var tsTypes      = tsTypeLister.List();
                        tsTypesJson = JSON.Stringify(tsTypes);
                    }

                    return(JSON.Parse <List <ExternalType> >(tsTypesJson));
                };

                if ("transform".StartsWith(command) || "mvc".StartsWith(command))
                {
                    new MvcCommand().Run(projectJson);
                }

                if ("transform".StartsWith(command) || "clienttypes".StartsWith(command))
                {
                    new ClientTypesCommand().Run(projectJson, getTsTypes());
                }

                if ("transform".StartsWith(command) || "servertypings".StartsWith(command))
                {
                    new ServerTypingsCommand().Run(projectJson, getTsTypes());
                }
            }
            else if ("generate".StartsWith(command))
            {
                new GenerateCommand().Run(projectJson, args.Skip(1).ToArray());
            }
            else
            {
                WriteHelp();
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: volkanceylan/Serenity
        public static void Main(string[] args)
        {
            string command = null;
            if (args.Length > 0)
                command = args[0].ToLowerInvariant().TrimToEmpty();

            if (command.IsEmptyOrNull() ||
                command == "-?" ||
                command == "--help")
            {
                WriteHelp();
                Environment.Exit(1);
            }

            var projectJson = "project.json";

            if (!File.Exists(projectJson))
            {
                System.Console.Error.WriteLine("Can't find project.json in current directory!");
                System.Console.Error.WriteLine("Please run Sergen in a folder that contains the Asp.Net Core project.");
                Environment.Exit(1);
            }

            projectJson = Path.GetFullPath(projectJson);

            if (!Directory.Exists(Path.Combine(Path.GetDirectoryName(projectJson), "wwwroot")))
            {
                System.Console.Error.WriteLine("Can't find wwwroot folder in current directory!");
                System.Console.Error.WriteLine("Please run Sergen in a folder that contains the Asp.Net Core project.");
                Environment.Exit(1);
            }

            if ("restore".StartsWith(command))
            {
                new RestoreCommand().Run(projectJson);
            }
            else if (
                "transform".StartsWith(command) ||
                "servertypings".StartsWith(command) ||
                "clienttypes".StartsWith(command) ||
                "mvc".StartsWith(command))
            {
                string tsTypesJson = null;
                Func<List<ExternalType>> getTsTypes = () =>
                {
                    if (tsTypesJson == null)
                    {
                        var tsTypeLister = new TSTypeLister(Path.GetDirectoryName(projectJson));
                        var tsTypes = tsTypeLister.List();
                        tsTypesJson = JSON.Stringify(tsTypes);
                    }

                    return JSON.Parse<List<ExternalType>>(tsTypesJson);
                };

                if ("transform".StartsWith(command) || "mvc".StartsWith("command"))
                {
                    new MvcCommand().Run(projectJson);
                }

                if ("transform".StartsWith(command) || "clienttypes".StartsWith(command))
                {
                    new ClientTypesCommand().Run(projectJson, getTsTypes());
                }

                if ("transform".StartsWith(command) || "servertypings".StartsWith(command))
                {
                    new ServerTypingsCommand().Run(projectJson, getTsTypes());
                }
            }
            else if ("generate".StartsWith(command))
            {
                new GenerateCommand().Run(projectJson, args.Skip(1).ToArray());
            }
            else
            {
                WriteHelp();
            }
        }