Skip to content

Commit

Permalink
Merge pull request #15 from Kerosene-Labs/fix-init-bug
Browse files Browse the repository at this point in the history
Fixing a bug that would cause the base package to not be created
  • Loading branch information
hlafaille authored Oct 28, 2024
2 parents 8096bf8 + e75279b commit 6d6fa48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
11 changes: 8 additions & 3 deletions core/context/project/fs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package project

import (
"fmt"
"os"
"strings"

Expand All @@ -23,8 +24,8 @@ func GetConfigPath() (string, error) {
}
}

// getSourcePath gets the path at which there should be source files
func getSourcePath(projectConfig ProjectConfig) (string, error) {
// GetSourcePath gets the path at which there should be source files
func GetSourcePath(projectConfig ProjectConfig) (string, error) {
wd, err := os.Getwd()
if err != nil {
return "", err
Expand Down Expand Up @@ -74,7 +75,11 @@ func Persist(projectContext ProjectContext) error {

// WriteExampleCode is an internal function that writes example code to a newly created project
func WriteExampleCode(projectContext ProjectContext) error {
os.MkdirAll(projectContext.SourcePath, 0755)
fmt.Printf("%s", projectContext)
err := os.MkdirAll(projectContext.SourcePath, 0755)
if err != nil {
return err
}

// create the main file
file, err := os.Create(projectContext.SourcePath + "/Main.java")
Expand Down
17 changes: 15 additions & 2 deletions core/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,32 @@ func InitializeProject(name string, basePkg *string) {
util.ErrorQuit("An error occurred while getting the config path: %s", err)
}

// get our source path
sourcePath, err := project.GetSourcePath(config)
if err != nil {
util.ErrorQuit("An error occurred while getting the source path: %s", err)
}

// create our project context
projectContext := project.ProjectContext{
Config: config,
ConfigPath: configPath,
SourcePath: sourcePath,
}

// write some example code
println("Creating base package, writing example code")
project.WriteExampleCode(projectContext)
err = project.WriteExampleCode(projectContext)
if err != nil {
util.ErrorQuit("An error occurred while writing example code: %s", err)
}

// persist the config
println("Persisting project configuration")
project.Persist(projectContext)
err = project.Persist(projectContext)
if err != nil {
util.ErrorQuit("An error occurred while persisting the configuration: %s", err)
}

println("Done.")
}

0 comments on commit 6d6fa48

Please sign in to comment.