diff --git a/pkg/initialize/initialize.go b/pkg/initialize/initialize.go index 8b3f6eb..96dcfd5 100644 --- a/pkg/initialize/initialize.go +++ b/pkg/initialize/initialize.go @@ -14,7 +14,6 @@ func Initialize() { Language string Main string Commands string - Prefix string Package string }{} diff --git a/pkg/initialize/models.go b/pkg/initialize/models.go new file mode 100644 index 0000000..770e24e --- /dev/null +++ b/pkg/initialize/models.go @@ -0,0 +1,14 @@ +package initialize + +type PackageJSON struct { + Name string `json:"name"` + Version string `json:"version"` + Description string `json:"description"` + Main string `json:"main"` + Scripts map[string]string `json:"scripts"` + Keywords []string `json:"keywords"` + Author string `json:"author"` + License string `json:"license"` + Dependencies map[string]string `json:"dependencies"` + DevDependencies map[string]string `json:"devDependencies"` +} diff --git a/pkg/initialize/questions.go b/pkg/initialize/questions.go index 8a35227..f32f0a8 100644 --- a/pkg/initialize/questions.go +++ b/pkg/initialize/questions.go @@ -14,7 +14,7 @@ var questions = []*survey.Question{ Name: "language", Prompt: &survey.Select{ Message: "What language do you want to use?", - Options: []string{"TypeScript"}, + Options: []string{"JavaScript", "TypeScript"}, }, }, { @@ -31,13 +31,6 @@ var questions = []*survey.Question{ Default: "commands", }, }, - { - Name: "prefix", - Prompt: &survey.Input{ - Message: "What is your project's command prefix?", - Default: "!", - }, - }, { Name: "package", Prompt: &survey.Select{ diff --git a/pkg/initialize/rename.go b/pkg/initialize/rename.go index 56b6879..8d94783 100644 --- a/pkg/initialize/rename.go +++ b/pkg/initialize/rename.go @@ -1,6 +1,9 @@ package initialize import ( + "encoding/json" + "fmt" + "io/ioutil" "os" "github.com/gookit/color" @@ -31,7 +34,43 @@ func renameFolders(name string, main string, commands string) error { } func renamePackageJson(name string) error { - color.Warn.Prompt("Work in progress...") + file, err := ioutil.ReadFile(name + "/package.json") + + if err != nil { + color.Warn.Prompt("Couldn't read the package.json file.") + + return err + } + + var packageJSON PackageJSON + + err = json.Unmarshal(file, &packageJSON) + + if err != nil { + fmt.Println(err) + + color.Warn.Prompt("Couldn't unmarshal the package.json file.") + + return err + } + + packageJSON.Name = name + + file, err = json.MarshalIndent(packageJSON, "", " ") + + if err != nil { + color.Warn.Prompt("Couldn't marshal the package.json file.") + + return err + } + + err = ioutil.WriteFile(name+"/package.json", file, 0644) + + if err != nil { + color.Warn.Prompt("Couldn't write the package.json file.") + + return err + } return nil }