Ejemplo n.º 1
0
        /// <summary>
        /// Checks for Angular projects and ensures they exist in the SlugCIConfig.
        /// </summary>
        /// <param name="slugCiConfig"></param>
        private void ProcessAngularProjects(SlugCIConfig slugCiConfig)
        {
            if (!DirectoryExists(CISession.AngularDirectory))
            {
                Logger.Warn("No Angular directory found off root folder");
                return;
            }

            // Find all subdirectories - these are the angular projects.
            List <string> webProjects = Directory.EnumerateDirectories(CISession.AngularDirectory, "*.web").ToList();

            foreach (string webProject in webProjects)
            {
                AbsolutePath webFolder = (AbsolutePath)webProject;
                string       name      = Path.GetFileName(webFolder);
                // See if already part of config, if so, nothing to do.
                if (slugCiConfig.AngularProjects.Exists(a => a.Name == name))
                {
                    continue;
                }

                // Make sure it contains a package.json file.  If so we will assume it is a web project.
                AbsolutePath webFile = webFolder / "package.json";

                if (!FileExists(webFile))
                {
                    Logger.Warn("Angular Folder does not contain a package.json file.  NOT ADDING TO AnuglarProjects - " + webFolder);
                    continue;
                }

                slugCiConfig.AngularProjects.Add(new AngularProject(name));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Ensures the Deploy Folders have a value and that it can be accessed.  If no value then it prompts user for value
        /// </summary>
        /// <param name="config"></param>
        /// <param name="slugCiConfig"></param>
        /// <returns></returns>
        private bool ValidateDeployFolders(PublishTargetEnum config, SlugCIConfig slugCiConfig)
        {
            // Does the config have a root folder set?
            if (!slugCiConfig.IsRootFolderSpecified(config))
            {
                string name = config.ToString();

                Misc.WriteSubHeader(name + ": Set Deploy Folder");
                Console.WriteLine("The [" + config + "] deployment folder is undefined in the SlugCI config file, You can enter a value OR press enter to force the system to look for and use environment variables.",
                                  Color.DarkOrange);
                Console.WriteLine(
                    "--: If you want to always use the environment variables for these entries, just hit the Enter key.  Otherwise enter a valid path to the root location they should be deployed too.",
                    Color.DarkOrange);
                bool   invalidAnswer = true;
                string answer        = "";
                while (invalidAnswer)
                {
                    Console.WriteLine();
                    Console.WriteLine("Enter the root deployment folder for {0} [{1}]", Color.DarkCyan, name, config);
                    answer = Console.ReadLine();
                    answer = answer.Trim();
                    if (answer == string.Empty)
                    {
                        answer = "_";
                    }

                    // Make sure such a folder exists.
                    if (answer != "_")
                    {
                        if (DirectoryExists((AbsolutePath)answer))
                        {
                            invalidAnswer = false;
                        }
                    }
                    else
                    {
                        invalidAnswer = false;
                    }
                }

                if (config == PublishTargetEnum.Production)
                {
                    slugCiConfig.DeployProdRoot = answer;
                }
                else if (config == PublishTargetEnum.Alpha)
                {
                    slugCiConfig.DeployAlphaRoot = answer;
                }
                else if (config == PublishTargetEnum.Beta)
                {
                    slugCiConfig.DeployBetaRoot = answer;
                }
                else if (config == PublishTargetEnum.Development)
                {
                    slugCiConfig.DeployDevRoot = answer;
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns the current SlugCIConfig object or loads it if null or force reload is true.
        /// </summary>
        /// <param name="forceReload"></param>
        /// <returns></returns>
        public SlugCIConfig GetSlugCIConfig(bool forceReload = false)
        {
            if (CISession.SlugCIConfigObj == null || forceReload == true)
            {
                CISession.SlugCIConfigObj = SlugCIConfig = SlugCIConfig.LoadFromFile(CISession.SlugCIFileName);
            }

            return(CISession.SlugCIConfigObj);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Perform The Conversion
        /// </summary>
        /// <returns></returns>
        protected override StageCompletionStatusEnum ExecuteProcess()
        {
            if (!PreCheck())
            {
                return(StageCompletionStatusEnum.Aborted);
            }

            // Load Config file
            SlugCIConfig slugCiConfig = GetSlugCIConfig();

            if (slugCiConfig == null)
            {
                throw new ApplicationException("The FastStart option was set, but there is not a valid SlugCIConfig file.  Either remove FastStart option or fix the problem.");
            }
            IsInSlugCIFormat = true;

            return(StageCompletionStatusEnum.Success);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Run Clean process
        /// </summary>
        /// <returns></returns>
        protected override StageCompletionStatusEnum ExecuteProcess()
        {
            // See if the Root directory exists
            ControlFlow.Assert(FileSystemTasks.DirectoryExists(CISession.RootDirectory),
                               "Root Directory does not exist.  Should be specified on command line or be run from the projects entry folder");

            // See if slugci directory exists.
            if (!CISession.IsInSetupMode)
            {
                if (!FileSystemTasks.DirectoryExists(CISession.SlugCIPath) || !FileSystemTasks.FileExists(CISession.SlugCIFileName))
                {
                    AOT_Error("Are you in the Repository root folder - where .git folder for the project is located at?");
                    AOT_Error("Either change to the root folder of the project or run with --setup flag");
                    return(StageCompletionStatusEnum.Aborted);
                }
            }



            // Load the SlugCI Config for the project
            CISession.SlugCIConfigObj = SlugCIConfig.LoadFromFile(CISession.SlugCIFileName);
            if (!CISession.IsInSetupMode && CISession.SlugCIConfigObj == null)
            {
                CompletionStatus = StageCompletionStatusEnum.Failure;
                ControlFlow.Assert(CISession.SlugCIConfigObj != null, "Failure loading the SlugCI Configuration file - [ " + CISession.SlugCIFileName + " ]");
            }


            // See if version of config matches the version of SlugCI (our current instance)
            if (!CISession.IsInSetupMode)
            {
                if (SlugCIConfig.CONFIG_STRUCTURE_VERSION != CISession.SlugCIConfigObj.ConfigStructureVersion)
                {
                    //	if ( CISession.SlugCI_Version != CISession.SlugCIConfigObj.ConfigStructureVersion ) {
                    AOT_Warning("The version of the SlugCIConfig object does not match the current SlugCI version.  Setup will need to be run.");
                    CISession.IsInSetupMode = true;
                    return(StageCompletionStatusEnum.Warning);
                }
            }


            CheckForEnvironmentVariables();
            return(StageCompletionStatusEnum.Success);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds a SlugCIProject that is based upon a Visual Studio Project
        /// </summary>
        /// <param name="vsProject"></param>
        private SlugCIProject AddSlugCIProject(SlugCIConfig slugCIConfig, VisualStudioProject vsProject)
        {
            SlugCIProject slugCIProject = new SlugCIProject()
            {
                Name = vsProject.Name
            };

            slugCIProject.IsTestProject = vsProject.IsTestProject;

            if (vsProject.IsTestProject)
            {
                slugCIProject.Deploy = SlugCIDeployMethod.None;

                // Also add the Required Nuget Coverage package
                CoverletInstall(vsProject);
            }
            else
            {
                slugCIProject.Deploy = vsProject.SlugCIDeploymentMethod;
            }
            slugCIConfig.Projects.Add(slugCIProject);
            return(slugCIProject);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Ensures there is a valid SlugCI Config file and updates it if necessary OR creates it.
        /// </summary>
        /// <returns></returns>
        private bool ProcessSlugCIConfigFile()
        {
            SlugCIConfig slugCiConfig = SlugCIConfig;

            if (slugCiConfig == null)
            {
                EnsureExistingDirectory(CISession.SlugCIPath);
                slugCiConfig = new SlugCIConfig();
                slugCiConfig.DeployToVersionedFolder = true;
            }


            // Make a copy that we will compare against.
            SlugCIConfig origSlugCiConfig = slugCiConfig.Copy();

            // Ensure the version of the config file layout is set to most current.  We do this after the copy, so we can
            // detect changes in the file layout, fields, etc.
            slugCiConfig.ConfigStructureVersion = SlugCIConfig.CONFIG_STRUCTURE_VERSION;

            bool updateProjectAdd    = false;
            bool hasCopyDeployMethod = false;


            // Now go thru the Visual Studio Projects and update the config
            foreach (VisualStudioProject project in Projects)
            {
                SlugCIProject slugCIProject = slugCiConfig.GetProjectByName(project.Name);

                // New Visual Studio project that does not exist in SlugCIConfig
                if (slugCIProject == null)
                {
                    slugCIProject = AddSlugCIProject(slugCiConfig, project);
                }

                if (slugCIProject.Deploy == SlugCIDeployMethod.Copy)
                {
                    hasCopyDeployMethod = true;
                }
            }


            // Ensure Deploy Roots have values if at least one of the projects has a deploy method of Copy
            if (hasCopyDeployMethod)
            {
                foreach (PublishTargetEnum value in Enum.GetValues(typeof(PublishTargetEnum)))
                {
                    ValidateDeployFolders(value, slugCiConfig);
                }
            }


            // Add Angular Projects
            ProcessAngularProjects(slugCiConfig);


            // Determine if we need to save new config.
            if (origSlugCiConfig != slugCiConfig)
            {
                string json = JsonSerializer.Serialize <SlugCIConfig>(slugCiConfig, SlugCIConfig.SerializerOptions());
                File.WriteAllText(CISession.SlugCIFileName, json);
                AOT_Success("SlugCIConfig file updated to latest version / values");

                SlugCIConfig = GetSlugCIConfig(true);
                if (updateProjectAdd)
                {
                    Logger.Warn("The file: {0} was updated.  One ore more projects were added.  Ensure they have the correct Deploy setting.", CISession.SlugCIFileName);
                }
            }

            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Either upgrades a current config or converts an existing solution into SlugCI format
        /// </summary>
        /// <returns></returns>
        public bool Converter()
        {
            // Create src folder if it does not exist.
            if (!DirectoryExists(CISession.SourceDirectory))
            {
                Directory.CreateDirectory(CISession.SourceDirectory.ToString());
            }

            // Create Tests folder if it does not exist.
            if (!DirectoryExists(CISession.TestsDirectory))
            {
                Directory.CreateDirectory(CISession.TestsDirectory.ToString());
            }

            // Create Artifacts / Output folder if it does not exist.
            if (!DirectoryExists(CISession.OutputDirectory))
            {
                Directory.CreateDirectory(CISession.OutputDirectory.ToString());
            }


            // Load an existing SlugCI file if there is one.
            SlugCIConfig = GetSlugCIConfig();


            // Load our own version of the Visual Studio project, so we can process some info from it
            foreach (Project project in CISession.Solution.AllProjects)
            {
                VisualStudioProject vsProject = GetInitProject(project);
                Projects.Add(vsProject);
            }


            // If New to SlugCI
            if (SlugCIConfig == null)
            {
                // Determine if any of these are a test project... If so we confirm with user and then move.
                foreach (VisualStudioProject visualStudioProject in Projects)
                {
                    GetVisualStudioProjectInfoForNewProjectFromUser(visualStudioProject);
                }
                bool setupSuccess = SlugCI_NewSetup_EnsureProperDirectoryStructure(CISession.SolutionFileName);
                ControlFlow.Assert(setupSuccess, "Attempted to put solution in proper directory structure, but failed.");
            }
            else
            {
                // See if any new Projects, if so prompt for required info
                foreach (VisualStudioProject visualStudioProject in Projects)
                {
                    SlugCIProject slugCIProject = CISession.SlugCIConfigObj.GetProjectByName(visualStudioProject.Name);
                    if (slugCIProject == null)
                    {
                        GetVisualStudioProjectInfoForNewProjectFromUser(visualStudioProject);
                    }
                }
            }

            // Ensure Config file is valid and up-to-date with current Class Structure
            ProcessSlugCIConfigFile();


            return(true);
        }