-
Notifications
You must be signed in to change notification settings - Fork 7
/
create.go
69 lines (59 loc) · 1.58 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package create
import (
"fmt"
"os"
"os/exec"
"github.com/natewong1313/go-react-ssr/cli/cmd"
"github.com/natewong1313/go-react-ssr/cli/logger"
"github.com/natewong1313/go-react-ssr/cli/utils"
"github.com/spf13/cobra"
)
// createCmd represents the create command
var createCmd = &cobra.Command{
Use: "create",
Short: "Create a new Go SSR project",
Long: "Create a new Go SSR project",
Run: create,
}
func init() {
cmd.RootCmd.AddCommand(createCmd)
}
func create(cmd *cobra.Command, args []string) {
checkNodeInstalled()
fmt.Println("Welcome to the creation wizard!")
projectDir := prompt_getProjectDirectory(args)
webFramework := prompt_selectWebFramework()
useTailwind := prompt_isUsingTailwind()
projectDirExists := utils.CheckPathExists(projectDir)
projectDirEmpty := utils.CheckPathEmpty(projectDir)
if projectDirExists && !projectDirEmpty && !prompt_shouldWipeDirectory() {
os.Exit(0)
}
if !projectDirEmpty {
wipeDirectory(projectDir)
}
bootstrapper := Bootstrapper{
ProjectDir: projectDir,
WebFramework: webFramework,
IsUsingTailwind: useTailwind,
}
bootstrapper.Start()
}
func checkNodeInstalled() bool {
cmd := exec.Command("node", "-v")
err := cmd.Run()
if err != nil {
logger.L.Error().Msg("Node.js is not installed. Please install Node and try again.")
os.Exit(1)
}
return true
}
func wipeDirectory(projectDir string) {
logger.L.Info().Msg("Wiping directory " + projectDir)
if err := os.RemoveAll(projectDir); err != nil {
utils.HandleError(err)
}
if err := os.MkdirAll(projectDir, 0777); err != nil {
utils.HandleError(err)
}
}