mirror of
https://github.com/sern-handler/cli
synced 2026-06-28 02:32:20 +00:00
feat: add rename package.json, finish init
This commit is contained in:
@@ -14,7 +14,6 @@ func Initialize() {
|
||||
Language string
|
||||
Main string
|
||||
Commands string
|
||||
Prefix string
|
||||
Package string
|
||||
}{}
|
||||
|
||||
|
||||
14
pkg/initialize/models.go
Normal file
14
pkg/initialize/models.go
Normal file
@@ -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"`
|
||||
}
|
||||
@@ -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{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user