private void PopulateForm(ReactTemplate result)
        {
            textBoxProjectName.Text     = result.Name;
            textBoxNpmCmd.Text          = result.ReactAppCmd;
            textBoxReactAppFlags.Text   = result.ReactAppFlags;
            checkBoxNPMAuditFix.Checked = result.RunNPMAuditFix;
            checkBoxGenerateVisStudioSolution.Checked = result.CreateVisualStudioSolution;

            listViewNPMPackages.Items.Clear();
            foreach (var item in result.NpmPackageList)
            {
                AddToNpmPackageList(item.Name, item.Comment);
            }

            listViewProjectFolders.Items.Clear();
            foreach (var item in result.ProjectFolderList)
            {
                AddToProjectFoldersList(item.Name, item.Comment);
            }

            listViewBoilerPlateFiles.Items.Clear();
            foreach (var item in result.BoilerPlateFileList)
            {
                AddToBoilerplateList(item.FileName, item.SourceDir, item.DestDir);
            }
        }
        private void ToolStripButtonSaveTemplate_Click(object sender, EventArgs e)
        {
            m_reactTemplate = GenerateJsonExportFile();

            if (IsReactTemplateValid(m_reactTemplate) == false)
            {
                return;
            }

            var appPath    = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var initialDir = Path.Combine(appPath, "ReactProjectTemplates");

            var jsonData = JsonConvert.SerializeObject(m_reactTemplate, Formatting.Indented);

            var saveFileDialog = new SaveFileDialog();

            saveFileDialog.InitialDirectory = initialDir;
            saveFileDialog.Title            = "Save React Template";
            saveFileDialog.DefaultExt       = "json";
            saveFileDialog.Filter           = "json files (*.json)|*.json|All files (*.*)|*.*";
            saveFileDialog.FilterIndex      = 1;
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                FileInfo f = new FileInfo(saveFileDialog.FileName);
                //write string to file
                System.IO.File.WriteAllText(f.FullName, jsonData);

                Log.Information($"File Successfuly Saved: {f.FullName}");


                this.DialogResult = DialogResult.OK;
                return;
            }
        }
        private void ToolStripButtonLoadTemplate_Click(object sender, EventArgs e)
        {
            var appPath    = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            var initialDir = Path.Combine(appPath, "ReactProjectTemplates");

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = initialDir;
                openFileDialog.Filter           = "json files (*.json)|*.json";
                openFileDialog.FilterIndex      = 1;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    if (openFileDialog.FileName.ToLower().EndsWith(".json") == false)
                    {
                        MessageBox.Show($"Error. Please select a json file (.json)");
                        return;
                    }

                    m_reactTemplate = ImportJsonFile(openFileDialog.FileName);
                    PopulateForm(m_reactTemplate);

                    var fName = new FileInfo(openFileDialog.FileName).Name;

                    SetTitleBar(fName);
                }
            }
        }
        public static ReactTemplate ImportJsonFile(string fileLocation)
        {
            string json = File.ReadAllText(fileLocation);

            ReactTemplate result = JsonConvert.DeserializeObject <ReactTemplate>(json);

            return(result);
        }
예제 #5
0
        private static void CreateReactApp(string location, ReactTemplate template)
        {
            var file = Path.Combine(location, "_CreateReactApp.bat");

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("@echo off");
            sb.AppendLine("");
            sb.AppendLine("cd /D \"%~dp0\"");
            sb.AppendLine("cd ..");
            sb.AppendLine("echo %cd%");
            sb.AppendLine(" ");
            sb.AppendLine(":: step 01: ask the user for an app name");
            sb.AppendLine("set /p appname=Enter a name for your app[lowercase only, no spaces]:");
            sb.AppendLine("::please enter a name [lowercase only, no spaces]:");
            sb.AppendLine("echo %appname%");
            sb.AppendLine("");
            sb.AppendLine(":: step 02: create the app");
            sb.AppendLine("echo calling npx create-react-app %appname% --template typescript");
            sb.AppendLine("call npx create-react-app %appname% --template typescript ");
            sb.AppendLine("");
            sb.AppendLine(":: step 03: cd into the new directory");
            sb.AppendLine("cd %appname%");
            sb.AppendLine("echo %cd%");
            sb.AppendLine("");

            foreach (var item in template.NpmPackageList)
            {
                if (item.Included == true)
                {
                    sb.AppendLine($"call {item.Name}");
                }
            }
            sb.AppendLine("");
            sb.AppendLine(":: step 04: create some standard folders");
            sb.AppendLine("cd src");
            sb.AppendLine("echo %cd%");

            foreach (var item in template.ProjectFolderList)
            {
                if (item.Included == false)
                {
                    continue;
                }

                var folder = Path.Combine(template.GetProjectFolder(), item.Name);

                sb.AppendLine($"mkdir {folder}");
            }

            sb.AppendLine("");
            sb.AppendLine(":: step 06: finished!");
            sb.AppendLine("echo Finished");
            sb.AppendLine("set /p done=Press enter to finish");

            System.IO.File.WriteAllText(file, sb.ToString());
        }
        public static bool IsReactTemplateValid(ReactTemplate rt, bool displayError = true)
        {
            bool result = true;

            if (rt.Name.Contains(" ") == true)
            {
                result = false;
                if (displayError)
                {
                    MessageBox.Show("Project name cannot contain spaces");
                }
            }

            return(result);
        }
예제 #7
0
 public static void GenerateBatchFiles(string location, ReactTemplate template)
 {
     try
     {
         CreateReactApp(location, template);
         BuildForProduction(location);
         DeleteNodeModulesFolder(location);
         NpmAuditFix(location);
         RestoreNodeModules(location);
         ServeBuild(location);
         StartDevWebServer(location);
     }
     catch (Exception)
     {
     }
 }
        private ReactTemplate GenerateJsonExportFile()
        {
            var result = new ReactTemplate();

            result.Name                       = textBoxProjectName.Text;
            result.ProjectFolder              = textBoxLocation.Text;
            result.ReactAppCmd                = textBoxNpmCmd.Text;
            result.ReactAppFlags              = textBoxReactAppFlags.Text;
            result.RunNPMAuditFix             = checkBoxNPMAuditFix.Checked;
            result.CreateVisualStudioSolution = checkBoxGenerateVisStudioSolution.Checked;

            result.NpmPackageList.Clear();
            foreach (ListViewItem item in listViewNPMPackages.Items)
            {
                result.NpmPackageList.Add(new NpmPackage()
                {
                    Included = item.Checked, Name = item.Text, Comment = item.SubItems[1].Text
                });
            }

            result.ProjectFolderList.Clear();
            foreach (ListViewItem item in listViewProjectFolders.Items)
            {
                result.ProjectFolderList.Add(new ProjFolder()
                {
                    Included = item.Checked, Name = item.Text, Comment = item.SubItems[1].Text
                });
            }

            result.BoilerPlateFileList.Clear();
            foreach (ListViewItem item in listViewBoilerPlateFiles.Items)
            {
                result.BoilerPlateFileList.Add(new BoilerPlateFile()
                {
                    Included = item.Checked, FileName = item.Text, SourceDir = item.SubItems[1].Text, DestDir = item.SubItems[2].Text
                });
            }

            return(result);
        }