From 55adf5142c1695a595ab2e4d0b5e4bbe33ba632f Mon Sep 17 00:00:00 2001 From: xzyaoi Date: Wed, 19 Dec 2018 14:20:55 +0800 Subject: [PATCH] add feat:init --- cli/config.go | 3 +++ cli/daemon.go | 4 ++++ cli/handler.go | 14 +++++++++++++- cli/repository.go | 6 ++++++ cli/webui.go | 6 ++++++ 5 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 cli/webui.go diff --git a/cli/config.go b/cli/config.go index 4bc5fd264..d0d684fee 100644 --- a/cli/config.go +++ b/cli/config.go @@ -125,6 +125,9 @@ func validateConfig() { // create logs folder logsFolder := filepath.Join(cvpmPath, "logs") createFolderIfNotExist(logsFolder) + // create webui folder + webuiFolder := filepath.Join(cvpmPath, "webui") + createFolderIfNotExist(webuiFolder) // check if system log file exists cvpmLogPath := filepath.Join(cvpmPath, "logs", "system.log") createFileIfNotExist(cvpmLogPath) diff --git a/cli/daemon.go b/cli/daemon.go index 4509106bd..8edd05b71 100644 --- a/cli/daemon.go +++ b/cli/daemon.go @@ -4,6 +4,7 @@ You can uninstall that service by using cvpm daemon uninstall */ package main import ( + "github.com/gin-contrib/static" "github.com/fatih/color" "github.com/gin-gonic/gin" "github.com/googollee/go-socket.io" @@ -154,6 +155,8 @@ func BeforeResponse() gin.HandlerFunc { /repos -> Get to fetch Running Repos */ func runServer(port string) { + config := readConfig() + webuiFolder := filepath.Join(config.Local.LocalFolder, "webui") color.Red("Initiating") var err error socketServer, err = socketio.NewServer(nil) @@ -163,6 +166,7 @@ func runServer(port string) { r := gin.Default() r.Use(BeforeResponse()) watchLogs(socketServer) + r.Use(static.Serve("/", static.LocalFile(webuiFolder, false))) // Status Related Handlers r.GET("/status", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ diff --git a/cli/handler.go b/cli/handler.go index 5f85b2bce..bf66f0366 100644 --- a/cli/handler.go +++ b/cli/handler.go @@ -9,6 +9,7 @@ package main import ( "bufio" "fmt" + "github.com/manifoldco/promptui" "github.com/fatih/color" "github.com/getsentry/raven-go" "github.com/mitchellh/go-homedir" @@ -52,6 +53,8 @@ func InstallHandler(c *cli.Context) { color.Cyan("Installing... Please wait patiently") pip([]string{"install", "cvpm", "--user"}) return + } else if remoteURL == "webui" { + InstallWebUi() } else { color.Cyan("Installing to " + localFolder) } @@ -87,6 +90,7 @@ func DaemonHandler(c *cli.Context) { } } +// Handle Repo Related Command func RepoHandler(c *cli.Context) { taskParams := c.Args().Get(0) switch taskParams { @@ -113,6 +117,7 @@ func RepoHandler(c *cli.Context) { } } +// Handle Config Related Command func ConfigHandler(c *cli.Context) { homepath, _ := homedir.Dir() configFilePath := filepath.Join(homepath, "cvpm", "config.toml") @@ -159,5 +164,12 @@ func ConfigHandler(c *cli.Context) { } func InitHandler(c *cli.Context) { - + prompt := promptui.Prompt{ + Label: "String", + } + result, err := prompt.Run() + if err != nil { + panic(err) + } + InitNewRepo(result) } diff --git a/cli/repository.go b/cli/repository.go index e5436bbad..05d16a249 100644 --- a/cli/repository.go +++ b/cli/repository.go @@ -192,3 +192,9 @@ func InstallFromGit(remoteURL string) { writeConfig(config) PostInstallation(repoFolder) } + +// Init a new repoo by using bolierplate +func InitNewRepo (repoName string) { + bolierplateURL := "https://github.com/cvmodel/bolierplate.git" + CloneFromGit(bolierplateURL, repoName) +} diff --git a/cli/webui.go b/cli/webui.go new file mode 100644 index 000000000..7cd6104f4 --- /dev/null +++ b/cli/webui.go @@ -0,0 +1,6 @@ +package main + +// Install Web UI -> Download Latest and Unzip +func InstallWebUi () { + +}