예제 #1
0
        public override void Build(Action <string> output = null, Action <string> error = null)
        {
            DirectoryInfo       projectParent = ShellProvider.GetProjectParentDirectoryOrExit(out FileInfo csprojFile);
            BamSettings         settings      = ShellProvider.GetSettings();
            HandlebarsDirectory handlebars    = ShellProvider.GetHandlebarsDirectory();
            string projectName        = Path.GetFileNameWithoutExtension(csprojFile.Name);
            string dockerFileContents = handlebars.Render("Dockerfile", new { AspNetCoreEnvironment = settings.Environment, ProjectName = projectName });
            string startDir           = Environment.CurrentDirectory;

            Environment.CurrentDirectory = projectParent.FullName;
            string dockerFile = Path.Combine(".", "Dockerfile");

            dockerFileContents.SafeWriteToFile(dockerFile, true);
            ProcessStartInfo startInfo = settings.DockerPath.ToStartInfo($"tag {projectName} bamapps/containers:{projectName}");
            ProcessOutput    tagOutput = startInfo.Run(msg => OutLine(msg, ConsoleColor.Blue));

            Environment.CurrentDirectory = startDir;
            if (tagOutput.ExitCode != 0)
            {
                Message.PrintLine("docker tag command failed: {0}\r\n{1}", tagOutput.StandardOutput, tagOutput.StandardError);
                Exit(1);
            }
            ProcessOutput pushOutput = settings.DockerPath.ToStartInfo("push bamapps/containers:{projectName}").Run(msg => OutLine(msg, ConsoleColor.DarkCyan));

            if (tagOutput.ExitCode != 0)
            {
                Message.PrintLine("docker push command failed: {0}\r\n{1}", tagOutput.StandardOutput, tagOutput.StandardError);
                Exit(1);
            }
        }
예제 #2
0
        public void Config()
        {
            BamSettings settings = BamSettings.Load();

            if (!settings.IsValid(msgs => Message.PrintLine(msgs, ConsoleColor.Magenta)))
            {
                settings.Save(bak => Message.PrintLine("Backed up existing file: {0}", ConsoleColor.DarkYellow, bak));
            }
        }
예제 #3
0
        public static BamSettings GetSettings()
        {
            BamSettings settings = BamSettings.Load();

            if (!settings.IsValid(msg => OutLine(msg, ConsoleColor.Red)))
            {
                Exit(1);
            }

            return(settings);
        }
예제 #4
0
        /// <summary>
        /// Tag the docker image and push it to the bamapps docker registry.
        /// </summary>
        /// <param name="output"></param>
        /// <param name="error"></param>
        public override void Push(Action <string> output = null, Action <string> error = null)
        {
            DirectoryInfo projectParent = ShellProvider.GetProjectParentDirectoryOrExit(out FileInfo csprojFile);
            string        projectName   = Path.GetFileNameWithoutExtension(csprojFile.Name);
            BamSettings   settings      = ShellProvider.GetSettings();
            string        startDir      = Environment.CurrentDirectory;

            settings.DockerPath.ToStartInfo($"tag {projectName} bamapps/images:{projectName}").Run(msg => OutLine(msg, ConsoleColor.Cyan));
            settings.DockerPath.ToStartInfo($"push bamapps/images:{projectName}").Run(msg => OutLine(msg, ConsoleColor.DarkCyan));
            Environment.CurrentDirectory = startDir;
        }
예제 #5
0
        public void Pack(Action <string> output = null, Action <string> error = null)
        {
            // find the first csproj file by looking first in the current directory then going up
            // using the parent of the csproj as the root
            // change directories into wwwroot/bam.js
            // for every webpack.config.js file in ./configs/ call
            // npx  webpack --config [configPath]

            string startDir = Environment.CurrentDirectory;

            DirectoryInfo projectParent = GetProjectParentDirectoryOrExit();
            BamSettings   settings      = GetSettings();
            DirectoryInfo wwwroot       = new DirectoryInfo(Path.Combine(projectParent.FullName, "wwwroot"));

            if (!wwwroot.Exists)
            {
                Message.PrintLine("{0} doesn't exist", ConsoleColor.Magenta, wwwroot.FullName);
                Exit(1);
            }
            DirectoryInfo bamJs = new DirectoryInfo(Path.Combine(wwwroot.FullName, "bam.js"));

            if (!bamJs.Exists)
            {
                Message.PrintLine("{0} doesn't exist", ConsoleColor.Magenta, bamJs.FullName);
                Exit(1);
            }
            Environment.CurrentDirectory = bamJs.FullName;
            DirectoryInfo configs = new DirectoryInfo(Path.Combine(bamJs.FullName, "configs"));

            FileInfo[] webpackConfigs = configs.GetFiles("webpack.config.js", SearchOption.AllDirectories);
            foreach (FileInfo config in webpackConfigs)
            {
                string configPath = config.FullName.Replace(configs.Parent.FullName, "");
                if (configPath.StartsWith(Path.DirectorySeparatorChar.ToString()))
                {
                    configPath = configPath.TruncateFront(1);
                }
                Message.PrintLine("Packing {0}", ConsoleColor.Green, configPath);

                ProcessStartInfo webPackCommand = settings.NpxPath.ToCmdStartInfo($"webpack --config {configPath}");
                ProcessOutput    packOutput     = webPackCommand.Run();
                OutLine(packOutput.StandardOutput, ConsoleColor.DarkGreen);
            }
            if (webpackConfigs.Length == 0)
            {
                Message.PrintLine("No webpack configs found in {0}", ConsoleColor.Yellow, configs.FullName);
            }
            Environment.CurrentDirectory = startDir;
        }
예제 #6
0
        public static void AspNetRazorInit()
        {
            // find the first csproj file by looking first in the current directory then going up
            // using the parent of the csproj as the root
            // - clone bam.js into wwwroot/bam.js
            // - write Startup.cs (backing up existing)
            // - write sample modules
            BamSettings   settings      = ShellProvider.GetSettings();
            DirectoryInfo projectParent = ShellProvider.FindProjectParent(out FileInfo csprojFile);

            if (csprojFile == null)
            {
                OutLine("Can't find csproj file", ConsoleColor.Magenta);

                Thread.Sleep(3000);
                Exit(1);
            }

            DirectoryInfo wwwroot = new DirectoryInfo(Path.Combine(projectParent.FullName, "wwwroot"));

            if (!wwwroot.Exists)
            {
                Warn("{0} doesn't exist, creating...", wwwroot.FullName);
                wwwroot.Create();
            }

            string bamJsPath = Path.Combine(wwwroot.FullName, "bam.js");

            if (!Directory.Exists(bamJsPath))
            {
                Message.PrintLine("Cloning bam.js to {0}", ConsoleColor.Yellow, bamJsPath);
                ProcessStartInfo cloneCommand =
                    settings.GitPath.ToStartInfo("clone https://github.com/BryanApellanes/bam.js.git wwwroot/bam.js");
                cloneCommand.Run(msg => OutLine(msg, ConsoleColor.DarkCyan));
            }

            WriteStartupCs(csprojFile);
            WriteBaseAppModules(csprojFile);
        }