mirror of
https://github.com/sern-handler/cli
synced 2026-06-28 02:32:20 +00:00
feat: add install template, needs more features
This commit is contained in:
@@ -6,56 +6,6 @@ import (
|
||||
"github.com/AlecAivazis/survey/v2"
|
||||
)
|
||||
|
||||
var questions = []*survey.Question{
|
||||
{
|
||||
Name: "name",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your project's name?",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "language",
|
||||
Prompt: &survey.Select{
|
||||
Message: "What language do you want to use?",
|
||||
Options: []string{"JavaScript", "TypeScript"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "main",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your project's main directory?",
|
||||
Default: "src",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "commands",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your project's command directory?",
|
||||
Default: "commands",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "prefix",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your project's command prefix?",
|
||||
Default: "!",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "git",
|
||||
Prompt: &survey.Confirm{
|
||||
Message: "Do you want to initialize a git repository?",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "package",
|
||||
Prompt: &survey.Select{
|
||||
Message: "What package manager do you want to use?",
|
||||
Options: []string{"npm", "yarn", "skip"},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func Initialize() {
|
||||
answers := struct {
|
||||
Name string
|
||||
@@ -70,8 +20,10 @@ func Initialize() {
|
||||
err := survey.Ask(questions, &answers)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
fmt.Println("Project initialization failed, exiting.")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(answers)
|
||||
cloneRepository(answers.Name, answers.Language)
|
||||
}
|
||||
|
||||
54
pkg/initialize/questions.go
Normal file
54
pkg/initialize/questions.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package initialize
|
||||
|
||||
import "github.com/AlecAivazis/survey/v2"
|
||||
|
||||
var questions = []*survey.Question{
|
||||
{
|
||||
Name: "name",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your project's name?",
|
||||
},
|
||||
Validate: survey.Required,
|
||||
},
|
||||
{
|
||||
Name: "language",
|
||||
Prompt: &survey.Select{
|
||||
Message: "What language do you want to use?",
|
||||
Options: []string{"TypeScript"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "main",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your project's main directory?",
|
||||
Default: "src",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "commands",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your project's command directory?",
|
||||
Default: "commands",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "prefix",
|
||||
Prompt: &survey.Input{
|
||||
Message: "What is your project's command prefix?",
|
||||
Default: "!",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "git",
|
||||
Prompt: &survey.Confirm{
|
||||
Message: "Do you want to initialize a git repository?",
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "package",
|
||||
Prompt: &survey.Select{
|
||||
Message: "What package manager do you want to use?",
|
||||
Options: []string{"npm", "yarn", "skip"},
|
||||
},
|
||||
},
|
||||
}
|
||||
34
pkg/initialize/template.go
Normal file
34
pkg/initialize/template.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package initialize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
)
|
||||
|
||||
func cloneRepository(name string, language string) {
|
||||
_, err := git.PlainClone("templates", false, &git.CloneOptions{
|
||||
URL: "https://github.com/sern-handler/templates",
|
||||
Progress: os.Stdout,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Couldn't install the template, exiting.")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
err = os.Rename("templates/templates/"+strings.ToLower(language), name)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println("Couldn't install the template, exiting.")
|
||||
}
|
||||
|
||||
err = os.RemoveAll("templates")
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user