CreateMainFile creates the project folders and files, and writes to them depending on the selected options
()
| 243 | // CreateMainFile creates the project folders and files, |
| 244 | // and writes to them depending on the selected options |
| 245 | func (p *Project) CreateMainFile() error { |
| 246 | // check if AbsolutePath exists |
| 247 | if _, err := os.Stat(p.AbsolutePath); os.IsNotExist(err) { |
| 248 | // create directory |
| 249 | if err := os.Mkdir(p.AbsolutePath, 0o754); err != nil { |
| 250 | log.Printf("Could not create directory: %v", err) |
| 251 | return err |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | // Check if user.email is set. |
| 256 | if p.GitOptions.String() != flags.Skip { |
| 257 | |
| 258 | emailSet, err := utils.CheckGitConfig("user.email") |
| 259 | if err != nil { |
| 260 | return err |
| 261 | } |
| 262 | if !emailSet { |
| 263 | fmt.Println("user.email is not set in git config.") |
| 264 | fmt.Println("Please set up git config before trying again.") |
| 265 | panic("\nGIT CONFIG ISSUE: user.email is not set in git config.\n") |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | p.ProjectName = strings.TrimSpace(p.ProjectName) |
| 270 | |
| 271 | // Create a new directory with the project name |
| 272 | projectPath := filepath.Join(p.AbsolutePath, utils.GetRootDir(p.ProjectName)) |
| 273 | if _, err := os.Stat(projectPath); os.IsNotExist(err) { |
| 274 | err := os.MkdirAll(projectPath, 0o751) |
| 275 | if err != nil { |
| 276 | log.Printf("Error creating root project directory %v\n", err) |
| 277 | return err |
| 278 | } |
| 279 | } |
| 280 | |
| 281 | // Define Operating system |
| 282 | p.CheckOS() |
| 283 | |
| 284 | // Create the map for our program |
| 285 | p.createFrameworkMap() |
| 286 | |
| 287 | // Create go.mod |
| 288 | err := utils.InitGoMod(p.ProjectName, projectPath) |
| 289 | if err != nil { |
| 290 | log.Printf("Could not initialize go.mod in new project %v\n", err) |
| 291 | return err |
| 292 | } |
| 293 | |
| 294 | // Install the correct package for the selected framework |
| 295 | if p.ProjectType != flags.StandardLibrary { |
| 296 | err = utils.GoGetPackage(projectPath, p.FrameworkMap[p.ProjectType].packageName) |
| 297 | if err != nil { |
| 298 | log.Println("Could not install go dependency for the chosen framework") |
| 299 | return err |
| 300 | } |
| 301 | } |
| 302 |
no test coverage detected